Giter VIP home page Giter VIP logo

xxhash-asm's Introduction

xxHash-asm.js - Javascript port of xxHash

NOTE: THIS LIBRARY CURRENTLY DOES NOT WORK. DO NOT USE!

The is an emscripten javascript build of xxHash, which is a super fast hashing library.

I also added a barebones wrapper so you don't have to mess with all the memory allocation and emscripten Module.ccall nonsense.

###Demo

https://diafygi.github.io/xxhash-asm/

###How to use

  1. Include the library.
<script src="xxhash-asm.js"></script>
  1. Call the xxHash() function, which returns an integer for the hash.
//accepts strings
console.log(
    xxHash("Hello World!")
);

//accepts typed arrays
console.log(
    xxHash(new Uint8Array([1,2,3,4]))
);

//can be seeded
console.log(
    xxHash("Seed me!", 12345)
);

###How to build yourself

  1. emcc -O2 -s EXPORTED_FUNCTIONS="['_XXH32']" c/xxhash.c -o xxhash-asm.js
  2. Add the following wrapper function to the beginning of xxhash-asm.js
function xxHash(arr, seed){
    //convert string input to typed array
    if(typeof(arr) === "string"){
        var tmp_arr = new Uint32Array(arr.length);
        for(var i = 0; i < arr.length; i++){
            tmp_arr[i] = arr[i].charCodeAt();
        }
        arr = tmp_arr;
    }
    //run xxhash array
    var len = arr.length * arr.BYTES_PER_ELEMENT;
    var buf = Module._malloc(len);
    Module.HEAPU8.set(arr, buf);
    var result = Module.ccall('XXH32', 'number', ['number', 'number', 'number'], [buf, len, seed || 0]);
    Module._free(buf);
    return result;
}

###License

This code is released under the BSD New license, which is the same as the original xxHash library.

xxhash-asm's People

Contributors

diafygi avatar

Stargazers

Ramkesh Sahani avatar

Watchers

 avatar James Cloos avatar  avatar Ramkesh Sahani avatar

Forkers

ralic ramkesh2019

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.