Scalable Hash Functions
You’ve now seen how important it is that a hash function aligns with the size of a hash table’s underlying array. Now, determining the size of the array depends primarily on the number of values you expect to insert. In Volume 1, Chapter 8, I discussed the recommendation that a hash table should have 10 slots for every 7 pieces of data. (There are other recommendations out there, as well as other factors to consider when making this decision, but I won’t get into the nitty-gritty details here.)
Once you determine the array size, you need to carefully choose a hash function that will distribute values uniformly across the array.
If, for instance, we decided that our underlying array should have 500 slots, the hash function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access