Skip to main content
This release is 1 version behind 0.1.1 — the latest version of @jabr/fliphash. Jump to latest

Constant-time consistent range-hashing algorithm

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
70%
Published
3 months ago (0.1.0)

fliphash

A Typescript implementation of FlipHash, a consistent range-hashing algorithm. It is similar to JumpHash, but with constant time complexity and low memory requirements.

Examples

import Fliphash from "fliphash/mod.ts"

const hasher = await Fliphash.instance()

hasher.hash_string("abc",   8) // => 0
hasher.hash_string("abc",  16) // => 15
hasher.hash_string("abc",  32) // => 26
hasher.hash_string("abc", 271) // => 117

hasher.hash_bigint(1234n,   8) // => 2
hasher.hash_bigint(1234n,  16) // => 2
hasher.hash_bigint(1234n,  32) // => 2
hasher.hash_bigint(1234n, 271) // => 147

const alt = await Fliphash.instance(987654321n)
alt.hash_string("abc",   8) // => 6
alt.hash_string("abc", 271) // => 269
alt.hash_bigint(1234n,   8) // => 6
alt.hash_bigint(1234n, 271) // => 114

References

Derived from the Rust fliphash crate based on the FlipHash: A Constant-Time Consistent Range-Hashing Algorithm paper. Uses XXH3 and Moremur hash implementations for string and integer keys, respectively.

See also

  • xxHash64 - A fast, simple xxHash64 (and XXH3) implementation in TypeScript/WASM

License

This project is licensed under the terms of the MIT license.

Add Package

deno add jsr:@jabr/fliphash

Import symbol

import * as mod from "@jabr/fliphash";

---- OR ----

Import directly with a jsr specifier

import * as mod from "jsr:@jabr/fliphash";

Add Package

npx jsr add @jabr/fliphash

Import symbol

import * as mod from "@jabr/fliphash";

Add Package

yarn dlx jsr add @jabr/fliphash

Import symbol

import * as mod from "@jabr/fliphash";

Add Package

pnpm dlx jsr add @jabr/fliphash

Import symbol

import * as mod from "@jabr/fliphash";

Add Package

bunx jsr add @jabr/fliphash

Import symbol

import * as mod from "@jabr/fliphash";