Open murkle opened 8 years ago
Why were the hashCode()
implementations changed in comparison to the OpenJDK implementations anyway? GWT seems to support the required Double.doubleToLongBits(double)
method, see http://www.gwtproject.org/doc/latest/RefJreEmulation.html
Good hashCode functions use prime numbers as multipliers - 32 is "not fully" prime. To build a hashCode from multiple numbers, there is no point in multiplying each number with the same prime before adding them. Instead, the current result must be multiplied with a prime before adding the next number.
Instead of
public void append(Double value) {
hashcode += (value.hashCode() * 32);
}
something like that should be used:
public void append(Double value) {
hashcode = hashcode * 31 + value.hashCode();
}
This project is from 7 years ago - I guess GWT didn't support hashCode() then :)
The logic in HashCode is wrong - this will give the same answer if you send the numbers in a different order.
hashcode += (value.hashCode() * 32);
http://stackoverflow.com/questions/892618/create-a-hashcode-of-two-numbers suggests
hashcode += hashcode * 31 + value.hashCode();