Crate jumpch

Crate jumpch 

Source
Expand description

Jumpch: Jump Consistent Hashing for Rust

A tiny, fast, and allocation‑free implementation of the Jump Consistent Hash algorithm. Use it to map arbitrary keys (strings, numbers, structs) to a stable bucket index when the number of buckets changes over time (e.g., sharding, partitioning, load balancing).

Key points

  • Deterministic: the same key always maps to the same bucket for a fixed number of slots.
  • Minimal memory and very fast.
  • Great for distributed systems and caches where nodes/partitions change.

Quick example

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use jumpch::JumpHasher;

let mut hasher: JumpHasher<DefaultHasher> = JumpHasher::new(1000);
"some-key".hash(&mut hasher);
let bucket = hasher.finish(); // in range 0..1000
println!("bucket = {}", bucket);

Low‑level function

let bucket = jumpch::hash(123456u64, 1000u32);
assert!(bucket < 1000);

Structs§

JumpHasher
A Hasher adapter that turns any standard hasher into a Jump Consistent Hash bucket picker.
Slots
Wrapper type for the number of buckets (also called “slots”).

Functions§

hash
Computes the Jump Consistent Hash bucket index for a given key and number of slots.