I've looked into a lot of questions on this site about whether one should use prime number or power of 2 for mod. Thankfully, I understood the idea
However, my situation is different. I couldn't find any question that dealt with the right array size when resizing hash tables.
I am implementing a hash table that may need to grow and shrink as the number of stored keys varies. I have a hashcode function that uniformly hashes keys to positive 32-bit integers. The table itself will use a smaller array of approximate size M. So which of the following is best choice for the hash function that takes the hashcode to produce a value between 0 and P-1 where P is close to M?
a) Modulo P where P is a prime closest to M
b) Modulo P where P is the power of 2 closest to M
c) Either
d) Neither
I've been trying to figure this out for hours, but with no luck.