Git Product home page Git Product logo

js-murmur3-128's Introduction

js-murmur3-128

A JavaScript implementation of the 128bit variant of Murmur3. It was written with the following constraints in mind:

  1. For the same input, it must produce a hash that is equivalent to:
  2. It must be usable in the browser

Latest Version

Notes

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).

Usage

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 Implementations

  • murmurhash-js only contains the 32bit variant.
  • node-murmurhash is based off of murmurhash-js and as a result only contains the 32bit variant.
  • murmur3 did not seem to match the Java (Guava) output. (The first 8 bytes would match but the remaining would not.)
  • murmurhash3-js only contains the 32bit variant.
  • node-murmurhash3 provides both the 32bit and 128bit variants (through its binding to the C++ implementation) but cannot be used in the browser.

js-murmur3-128's People

Contributors

rgrzywinski avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.