Daninet / hash-wasm

Lightning fast hash functions using hand-tuned WebAssembly binaries
https://npmjs.com/package/hash-wasm
Other
894 stars 50 forks source link

Feature Request: 32 bit hash output #16

Closed ronag closed 2 years ago

ronag commented 3 years ago

It would be nice if we could get a Number out of e.g. xxHash. Right now I have to parse the output hex which is rather slow. I'm using the hash to calculate a index into a form of hash map.

Daninet commented 3 years ago

Did you try using "createXXHash32()"?

I did some measurements and I didn't see significant performance difference between returning numbers directly from the library and the following code:

const { createXXHash32 } = require("hash-wasm");
const xxhash32 = await createXXHash32();

function doHash(data) {
    const arr = xxhash32.init().update(data).digest('binary');
    const num = (((arr[0]*256+arr[1])*256+arr[2])*256)+arr[3];
    return num;
}

doHash('hello');