Clarification on magic numbers
Posted: 21 May 2015, 19:42
Good day to all,
I have a question related to perfect hashing. I`m interested maybe at some point implementing a hashing function, but before that I need to know the basics.
For example, http://en.wikipedia.org/wiki/De_Bruijn_sequence
Sadly, I don`t understand De Bruijn sequence. But even so, say these numbers aren`t related right?
My question is why are these exact numbers chosen to do the multiplication ( Does it relate to magic square? ) I wasn`t able to search any information on the net.
Thanks
I have a question related to perfect hashing. I`m interested maybe at some point implementing a hashing function, but before that I need to know the basics.
For example, http://en.wikipedia.org/wiki/De_Bruijn_sequence
Sadly, I don`t understand De Bruijn sequence. But even so, say these numbers aren`t related right?
- Code: Select all
unsigned int v;
int r;
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
My question is why are these exact numbers chosen to do the multiplication ( Does it relate to magic square? ) I wasn`t able to search any information on the net.
Thanks