python - 128 bit Integer hash function -
looking string integer hash function values in range of mysql bigint unsigned
datatype (0 <= n <= 18446744073709551615
). converting md5/sha1 integer base of 16 not fit requirement.
java uses rolling hash should work you
from java.lang.string
:
public int hashcode() { int h = hash; if (h == 0 && count > 0) { int off = offset; char val[] = value; int len = count; (int = 0; < len; i++) { h = 31*h + val[off++]; } hash = h; } return h; }
the idea calculate hash :
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
to deal overflow, can add step hash checked against 18446744073709551615
, if larger take mod
of hash , 18446744073709551615
.
Comments
Post a Comment