PHP Murmurhash3 and MySql Murmurhash3 sometimes don't match -


i'm using murmurhash3 create unique hashes text entries. when text entries created, i'm using this php implementation, returns 32 bit hash integer, hash value. hash stored in binary(16) database column. need update our existing database i'm using this mysql implementation update database. in order match php created hash, i'm base converting , lower-casing it.

update column set hash=lower(conv(murmur_hash_v3(concat(column1, column2), 0), 10, 32)); 

it matches php version 80% of time, isn't going cut it. example, hashing string 'engtest' creates 15d15m in php , 3uqiuqa in mysql. however, string 'engtest sentence' creates same hash in both. doing wrong?

figured out. php's integer type signed , murmurhash producing negative hash values didnt match positive mysql values. solution format php's hash value using sprintf format set "%u" before base conversion.

$hash = murmurhash3_int($text);  return base_convert(sprintf("%u\n", $hash), 10, 32); 

see php crc32 docs more info.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -