4 ms·
IIRC, the real reason for this "power of 2" is for fast rehashing when the table grows. Calculate a 32 bit hash and store it all, but if your table currently h
by ericsink 14y ago
IIRC, the real reason for this "power of 2" is for fast rehashing when the table grows. Calculate a 32 bit hash and store it all, but if your table currently has 1024 entries, only use 10 bits of it. Later, when your table grows to 2048 entries, you can just mask off 11 bits worth instead of recomputing every hash.
But, since the hash table is not going to grow in this particular case, any perf gain from using a power of 2 will probably be far less important.
- eridius 14y agoHe's using a power of 2 so he can use a bitwise-and to mask out his hash into the number of array indexes.