Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.
/ farmhash.wasm Public archive

WebAssembly implementation of Google FarmHash

License

Notifications You must be signed in to change notification settings

cjihrig/farmhash.wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

farmhash.wasm

Current Version Build Status via Travis CI Dependencies belly-button-style

WebAssembly implementation of Google FarmHash. This module began life as a quasi-fork of the farmhash module.

Basic Usage

'use strict';
const {
  hash32,
  hash32WithSeed,
  hash64,
  hash64WithSeed,
  hash64WithSeeds,
  fingerprint32,
  fingerprint64
} = require('farmhash.wasm');

console.log(hash32('foobar'));
console.log(hash32(Buffer.from('foobar')));
console.log(hash32WithSeed('foobar', 128));
console.log(hash32WithSeed(Buffer.from('foobar'), 128));
console.log(hash64('foobar'));
console.log(hash64(Buffer.from('foobar')));
console.log(hash64WithSeed('foobar', 0));
console.log(hash64WithSeed(Buffer.from('foobar'), 0));
console.log(hash64WithSeeds('foobar', 0, 0));
console.log(hash64WithSeeds(Buffer.from('foobar'), 0, 0));
console.log(fingerprint32('foobar'));
console.log(fingerprint32(Buffer.from('foobar')));
console.log(fingerprint64('foobar'));
console.log(fingerprint64(Buffer.from('foobar')));

API

farmhash.wasm exports the following methods.

hash32(input)

  • Arguments
    • input (string or Buffer) - Value to be hashed.
  • Returns
    • result (number) - A 32-bit unsigned integer hash value of input.

hash32WithSeed(input, seed)

  • Arguments
    • input (string or Buffer) - Value to be hashed.
    • seed (integer) - Number to use as a seed.
  • Returns
    • result (number) - A 32-bit unsigned integer hash value of input.

hash64(input)

  • Arguments
    • input (string or Buffer) - Value to be hashed.
  • Returns
    • result (string) - A string representation of a 64-bit unsigned integer hash value of input.

hash64WithSeed(input, seed)

  • Arguments
    • input (string or Buffer) - Value to be hashed.
    • seed (integer) - Number to use as a seed.
  • Returns
    • result (string) - A string representation of a 64-bit unsigned integer hash value of input.

hash64WithSeeds(input, seed1, seed2)

  • Arguments
    • input (string or Buffer) - Value to be hashed.
    • seed1 and seed2 (integer) - Numbers to use as a seed.
  • Returns
    • result (string) - A string representation of a 64-bit unsigned integer hash value of input.

fingerprint32(input)

  • Arguments
    • input (string or Buffer) - Value to fingerprint.
  • Returns
    • result (number) - A 32-bit unsigned integer fingerprint value of input.

fingerprint64(input)

  • Arguments
    • input (string or Buffer) - Value to fingerprint.
  • Returns
    • result (number) - A string representation of a 64-bit unsigned integer fingerprint value of input.