mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
DRY up and document magic constant used for hash maps
This commit is contained in:
@@ -15,6 +15,28 @@
|
||||
class HashMaps // : beast::Uncopayble
|
||||
{
|
||||
public:
|
||||
/** Golden ratio constant used in hashing functions.
|
||||
|
||||
The magic number is supposed to be 32 random bits, where each is
|
||||
equally likely to be 0 or 1, and with no simple correlation between
|
||||
the bits. A common way to find a string of such bits is to use the
|
||||
binary expansion of an irrational number; in this case, that number
|
||||
is the reciprocal of the golden ratio:
|
||||
|
||||
@code
|
||||
|
||||
phi = (1 + sqrt(5)) / 2
|
||||
2^32 / phi = 0x9e3779b9
|
||||
|
||||
@endcode
|
||||
|
||||
References:
|
||||
|
||||
http://stackoverflow.com/questions/4948780/magic-number-in-boosthash-combine
|
||||
http://burtleburtle.net/bob/hash/doobs.html
|
||||
*/
|
||||
static std::size_t const goldenRatio = 0x9e3779b9;
|
||||
|
||||
/** Retrieve the singleton.
|
||||
|
||||
@return The global instance of the singleton.
|
||||
|
||||
Reference in New Issue
Block a user