Comments (8)
@BrannonKing please note this library is maintained by the Boost Community Maintenance Team - the fastest resolution for your issue is to submit a pull request with new code. What you suggested sounds like an interesting idea.
from dynamic_bitset.
This one here (#1) has done it 5 years ago but weirdly enough it has never been merged.
from dynamic_bitset.
@BrannonKing In the meantime you can use something like:
#include <boost/dynamic_bitset.hpp>
#include <boost/functional/hash.hpp>
namespace std {
template<> struct hash<boost::dynamic_bitset<>> {
std::size_t operator()(const boost::dynamic_bitset<>& bs) const {
std::string h;
boost::to_string(bs, h);
return std::hash<std::string>{}(h);
}
};
}
And include that before everything else. Bear in mind though that for instance 00100 and 100 won't have the same hash. But if I'm not mistaken they aren't equal anyway (which, I think, is annoying).
from dynamic_bitset.
00100
and 100
are two different bitsets, why would they be equal?
from dynamic_bitset.
Are they really though? There is no point in arguing on that as it won't be changed but if you consider a bitset as an ordered set of bits, I don't think they should.
At least two of the main uses of bitsets (representing a number by its bits and the existence/appartenance of indexed objects) fall under the closed-world assumption.
00100
and 100
both represent the same number and item number 4 is inexistant/absent in both as well. For the latter use we can argue that one represents the existence of 5 objects and the other of 3 but without all the preconditions it would work the same if test(4)
was false
in both cases (instead of false
and hitting the precondition).
Anyway, it doesn't really matter now that it has been done like that for ages.
from dynamic_bitset.
You are making a lot of dangerous assumptions:
- Assuming the overall length is meaningless.
- Assuming the consumer is going to convert the content to integers / leading zeroes are ignored.
What if this dynamic_bitset is storing free disk sectors? In one case, sector 2 is free, and in the other case, sector 0 is free. How could these possibly be equal?
from dynamic_bitset.
I probably wasn’t clear but sequences of bits have to be read from right to left. In both cases it’s a 4.
from dynamic_bitset.
Even in that case the dynamic_bitset size() may be used to store important information like the total number of sectors (in my example) and therefore I would argue they are still not equal, and therefore should have different hash values.
from dynamic_bitset.
Related Issues (20)
- Valgrind failures in test4 with wchar_t support enabled HOT 4
- Adding hardware supported popcount (and other functions) HOT 2
- Release notes for 1.69.0 HOT 2
- New range based set methods have caused ambiguity HOT 5
- Hardware supported popcount breaks on Windows with CPUs that don't support SSE4 HOT 11
- MSVC hardware-assisted popcount implementation
- Release Notes for 1.70.0 HOT 1
- gcc-4.8 on xenial fails unit test 4 (streaming)
- Coverity flagged issue (investigate) HOT 1
- Release Notes for 1.71.0 HOT 1
- std::vector<boost::dynamic_bitset<>>unable to free memory HOT 5
- dynamic_bitset cannot be used in a parallel program HOT 3
- boost/dynamic_bitset/dynamic_bitset.hpp:111:20: -Wdeprecated-copy warning
- Release notes for 1.80
- Hide internals (dispatch_init(), init_from_block_range(), m_append())
- Possible improvement for is_proper_subset_of
- It seems that the latest develop branch has 'stdext::hash_value' compile failure
- Make buffer_type changeable
- Missing change in Boost 1.80.0 Unix distributable as opposed to the Windows one
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynamic_bitset.