https://github.com/jabr/fliphash
Constant-time consistent range-hashing algorithm
https://github.com/jabr/fliphash
Last synced: 2 months ago
JSON representation
Constant-time consistent range-hashing algorithm
- Host: GitHub
- URL: https://github.com/jabr/fliphash
- Owner: jabr
- License: other
- Created: 2024-07-08T00:12:35.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-10T04:51:24.000Z (11 months ago)
- Last Synced: 2025-03-15T00:11:14.788Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# fliphash
A Typescript implementation of [FlipHash](https://arxiv.org/pdf/2402.17549), a consistent range-hashing algorithm. It is similar to JumpHash, but with constant time complexity and low memory requirements.
## Examples
```typescript
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) // => 117hasher.hash_bigint(1234n, 8) // => 2
hasher.hash_bigint(1234n, 16) // => 2
hasher.hash_bigint(1234n, 32) // => 2
hasher.hash_bigint(1234n, 271) // => 147const 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](https://docs.rs/fliphash/latest/fliphash/) based on the [FlipHash: A Constant-Time Consistent Range-Hashing Algorithm](https://arxiv.org/pdf/2402.17549) paper. Uses [XXH3](https://xxhash.com/) and [Moremur](https://mostlymangling.blogspot.com/2019/12/stronger-better-morer-moremur-better.html) hash implementations for string and integer keys, respectively.
## See also
* [xxHash64](https://github.com/jabr/xxhash64) - A fast, simple xxHash64 (and XXH3) implementation in TypeScript/WASM
## License
This project is licensed under the terms of the [Apache License, Version 2.0](LICENSE.txt).