static int indexFor(int h, int length) {return h & (length-1); }
This is the source code that returns the position of the element in the hash table, h is the hash, length is the capacity
Waste of space
If the capacity is not a power of 2, length-1 will not be…… This form of 1111, but…… With 1010, some locations in the hash table will never be stored, wasting space.
Reduce hash collisions
If the capacity is not a power of 2, some space will not be used, resulting in more intensive storage and more hash collisions, reducing query efficiency