| Crates.io | jumpch |
| lib.rs | jumpch |
| version | 2.0.0 |
| created_at | 2022-07-04 16:51:29.403312+00 |
| updated_at | 2025-10-05 15:35:02.816956+00 |
| description | Jump Consistent Hashing is a fast, minimal memory, consistent hash algorithm. |
| homepage | |
| repository | https://github.com/Mnwa/jumpch |
| max_upload_size | |
| id | 619047 |
| size | 22,440 |
Jump Consistent Hashing is a fast, minimal‑memory, consistent hashing algorithm. Compared to the classic algorithm by Karger et al., Jump Consistent Hash requires no storage, runs faster, and better evens out keys across buckets while minimizing remapping when the number of buckets changes.
This crate provides a tiny, dependency‑free implementation suitable for sharding, partitioning, load balancing, and cache key distribution.
Add this to your Cargo.toml:
[dependencies]
jumpch = "*"
High‑level adapter implementing Hasher:
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use jumpch::JumpHasher;
fn main() {
let mut hasher: JumpHasher<DefaultHasher> = JumpHasher::new(1000);
"test".hash(&mut hasher);
let bucket = hasher.finish(); // 0..1000
assert!(bucket < 1000);
}
Low‑level function if you already have a 64‑bit key:
fn main() {
let bucket = jumpch::hash(123456u64, 1000u32);
assert!(bucket < 1000);
}
JumpHasher<H>: a Hasher adapter that yields the bucket index via finish().hash(key, slots) -> u32: compute the bucket directly.Slots(u32): newtype wrapper; panics on 0.< slots.slots, the same key always maps to the same bucket.PRs and issues are welcome.
Dual‑licensed under MIT and Apache‑2.0; choose either license.