A JavaScript implementation of the 128bit variant of Murmur3. It was written with the following constraints in mind:
Under the covers this implementation uses Closure Library's goog.math.Long. Either the entire Closure library can be included or a dependency free copy can be used.
Performance tests have not yet been run. There are places in which there are a few different ways to use goog.math.Long
which may affect performance. These have not yet been investigated (though some of them have been noted).
The equivalent Java (Guava) and JavaScript are provided as an example:
Java (Guava):
final int seed = 0; final byte[] bytes = { (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF, (byte)0xFE, (byte)0xED, (byte)0xFA, (byte)0xCE }; com.google.common.hash.HashFunction hashFunction = com.google.common.hash.Hashing.murmur3_128(seed); com.google.common.hash.HashCode hashCode = hashFunction.newHasher() .putBytes(bytes) .hash(); System.err.println(hashCode.asLong());
JavaScript:
var seed = 0; var rawKey = new ArrayBuffer(8); var byteView = new Int8Array(rawKey); byteView[0] = 0xDE; byteView[1] = 0xAD; byteView[2] = 0xBE; byteView[3] = 0xEF; byteView[4] = 0xFE; byteView[5] = 0xED; byteView[6] = 0xFA; byteView[7] = 0xCE; console.log(murmur3.hash128(rawKey, seed));
Refer to the unit tests for more examples.
Other JavaScript ImplementationsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4