Java use int result = result * 31 + C
to compute hash value. Just curious why 31 was chosen.
As stated in Effective Java:
The value 31 was chosen because of it's an odd prime. If it were even and the multiplication overflowed, information would be lost. Because multiplication by 2 is equivalent shifting.
for overflowing, why long type can not be used? Is it a trade-off about hash collision and memory usages?