Murmur ExampleWhile hashing methods such as MD5 and SHA-1 use cryto methods, the Murmur and FNV hashes uses a non-cryptographic hash function. The Murmur hash, designed by Austin Appleby, uses a non-cryptographic hash function. This can be used for general hash-based lookups. It has a good performance compared with other hashing methods, and generally provide a good balance between performance and CPU utilization. Also it performs well in terms of hash collisions. [Theory] Other non-crypto hashes: [Meow][xxHash][Siphash][FVN][Murmur][Spooky][o1hash][CRC-32][wyhash][CityHash][FarmHash][Non-crypto][C/C++: CityHash, Farmhash, MUM, xxHash, Spooky and Murmur][Pearson][C++: t1ha][C++: Spooky][C++: xxHash][C++: MUM][C++: FNV][C++: MetroHash][C++: CityHash][C++: FarmHash][C++: Murmur][C++: Halftimehash][C++: HighwayHash][C++: SipHash][C++: ClHash][C++: FalkHash][C++: wyHash][C++: Fibonacci][C++: Lookup3] The results are then:
|
Examples
- Try "The quick brown fox jumps over the lazy dog". Try!, which should give a Murmur hash of: 0x6c1b07bc7bbc4be347939ac4a93c437a Check and an FNV hash of A8B2F3117DE37ACE and F3F9B7F5E7E47110 for FNV1a
- Try "The quick brown fox jumps over the lazy dog.". Try!, which should give a Murmur hash of: 0xc902e99e1f4899cde7b68789a3a15d69 and an FNV hash of 8B8DD4B8E989AC24 and 75C4D4D9092C6C5A for FNV1a Check
Code
I have used Hashlib for Version 2, and custom code for Version 3:
using Hashlib; byte[] key = new byte[4]; key[0] = 0; key[1] = 0; key[2] = 0; key[3]=0; var hash1 = HashFactory.Hash128.CreateMurmur3_128(); hash1.Key = key; byte[] res1 = hash1.ComputeString(word, Encoding.ASCII).GetBytes(); ViewData["mur"] = ByteArrayToHexString(res1); var hash2 = HashFactory.Hash64.CreateMurmur2(); var crc64 = hash2.ComputeString(word, Encoding.ASCII).GetULong(); ViewData["mur2"] = longToHex(crc64); var hash3 = HashFactory.Hash64.CreateFNV(); crc64 = hash3.ComputeString(word, Encoding.ASCII).GetULong(); ViewData["mur3"] = longToHex(crc64); var hash4 = HashFactory.Hash64.CreateFNV1a(); crc64 = hash4.ComputeString(word, Encoding.ASCII).GetULong(); ViewData["mur4"] = longToHex(crc64); public string longToHex(ulong l) { return String.Format("{0:X}", l); }
We can also check using the smhasher library in Python:
$ cat sm.py import smhasher msg="The quick brown fox jumps over the lazy dog" res=smhasher.murmur3_x64_128(msg,0) print('%s\n %d\n %s\n' % (msg, res, hex(res))) msg="The quick brown fox jumps over the lazy dog" res=smhasher.murmur3_x64_64(msg,0) print('%s\n %d\n %s\n' % (msg, res, hex(res))) root@bills-mbp:~$ python sm.py The quick brown fox jumps over the lazy dog 143696972470007425495137670989352813434 0x6c1b07bc7bbc4be347939ac4a93c437aL The quick brown fox jumps over the lazy dog 7789828486578588643 0x6c1b07bc7bbc4be3L