Skip to content
callmeteusPublic

About

Zero dependency murmur2 buffer hash algorithm implementation in JavaScript

Resources

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

murmur2

npm version license

Zero-dependency JavaScript implementation of the MurmurHash2 algorithm for buffers.

Background

MurmurHash2 is a fast, non-cryptographic hash useful for partitioning, caches, and lightweight checksums.

This library was originally inspired by Austin Appleby's work, flagUpDown/murmurhash-node, and CAV2's whitespace stripping.

Install

npm install murmur2

There are no production dependencies. The package ships index.js and TypeScript definitions in index.d.ts.

Usage

CommonJS:

const murmur2 = require("murmur2");

ES modules (default import):

import murmur2 from "murmur2";

TypeScript: types are bundled with the package. Use import murmur2 from "murmur2" with esModuleInterop, or require with export = interop.

Minimal example:

const removeWhitespaces = false;
const seed = 0;

const buffer = Buffer.from([1, 2, 3, 4]);

const hash = murmur2(buffer, seed, removeWhitespaces); // 1487941662

API

Default export: a function murmur2(key, seed?, removeWhitespaces?).

Parameter Type Default Description
key Buffer, Uint8Array, or array-like byte sequence (required) Data to hash
seed number 0 Initial seed mixed into the hash
removeWhitespaces boolean false When true, strips tab, LF, CR, and space bytes before hashing

Returns: unsigned 32-bit integer (>>> 0).

Maintainers

Repository: callmeteus/murmur2

Acknowledgments

  • Arzio - contributions to the algorithm and implementation

Contributing

Issues and pull requests are welcome on GitHub.

Local development:

git clone https://github.com/callmeteus/murmur2.git
cd murmur2
npm install
npm test

Tests use node --test and require Node.js 18+. Runtime use of the package does not require that version; it applies only when running the test suite.

If you use Yarn in your workflow:

yarn test

License

MIT - Copyright (c) Gio Pavanelli

About

Zero dependency murmur2 buffer hash algorithm implementation in JavaScript

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages