How can I generate hash value for a byte array, in J2ME?
It doesn't have to be very very secure but it should be fast.
How can I generate hash value for a byte array, in J2ME?
It doesn't have to be very very secure but it should be fast.
If you already have a dependency on Apache Commons Lang you may as well use HashCodeBuilder
:
new HashCodeBuilder().append(bytes).toHashCode();
As suggested by Josh Bloch in his Effective Java book:
public int hashCode() {
int result = 17;
for (int i = 0; i < array.length; i++) {
result = 31*result + (int)array[i];
}
return result;
}