Hulahoop

A fast and efficient consistent hashing implementation, with support for virtual nodes.
Usage
use HashRing;
let mut ring: = default;
// Nodes only need to implement Hash
// Provide a weight to define the number of virtual nodes
ring.insert;
ring.insert;
// Keys also only need to implement Hash
assert_eq!;
assert_eq!;
ring.remove;
assert_eq!;
assert_eq!;
HashRing uses Arc under the hood to allocate memory only per node and not for every virtual node added via the weight parameter.
The Hashring is Send + Sync.
Hashers
Per default, hulahoop uses std::collections::hash_map::DefaultHasher to hash values.
Custom hashers can be used with the HashRing::with_hasher() method:
use FxHasher;
let mut ring: = with_hasher;
For convenience, the faster hasher FxHasher can be used by activating the fxhash feature of this crate.
Benchmarks
| DefaultHasher | FxHasher (feature=fxhash) | |
|---|---|---|
| Get (key length = 10) | 13ns | 8ns |
| Get (key length = 100) | 31ns | 12ns |
| Get (key length = 1000) | 305ns | 137ns |
| Add (weight = 1) | 290ns | 210ns |
| Add (weight = 10) | 1.4us | 1.0us |
| Add (weight = 100) | 17.0us | 14.3us |
License
This project is licensed optionally under either:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)