Question: Text p 484 Execise 3.4.33 A bad string hash function. Consider the following hashCode() implementation for String, which was used in early versions of Java:
Text p 484 Execise 3.4.33 A bad string hash function. Consider the following hashCode() implementation
for String, which was used in early versions of Java:
public int hashCode() { int hash = 0; int skip = Math.max(1, length() / 8); for (int i = 0; i < length(); i += skip) hash = (hash * 37) + charAt(i); return hash; } |
Explain why you think the designers chose this implementation
and then
explain why you think it was abandoned in favor
of the one in the previous exercise (p.484 Ex 3.4.32)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
