-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove booster dependency #49
Conversation
auto hash_t = hasher_t(x.first); | ||
auto hash_u = hasher_u(x.second); | ||
|
||
hash_u ^= hash_t + 0x9e3779b9 + (hash_u<<6) + (hash_u>>2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this 0x9e3779b9
value comes from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the magic value used by boost themselves: https://stackoverflow.com/questions/35985960/c-why-is-boosthash-combine-the-best-way-to-combine-hash-values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind to mention it in the commit message? Magic numbers can easily become the reason for a misunderstanding or doubt, IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done >:)
a9a66b7
to
e819e76
Compare
This avoids depending on boost for anything, which simplifies the list of dependencies. Instead, we inline their hash_combine implementation, including the magic constants, even if it isn't the best possible hash combinator [1]. The hasher class organization was taken from [2]. Since the hash of std::optional<unsigned> should be the same as the hash of unsigned when it contains a value [3], and on libstdc++ and libc++ that hash is simply the identity function [4], it felt more appropriate to use hash_u (the second member of the pair) as the seed, so it gets some additional mixing. [1] https://stackoverflow.com/q/35985960/9512804 [2] https://stackoverflow.com/a/20602159/9512804 [3] https://en.cppreference.com/w/cpp/utility/optional/hash [4] https://tessil.github.io/2016/08/29/benchmark-hopscotch-map.html
e819e76
to
c3f0b15
Compare
No description provided.