Google's consistent hashing algorithm
To use maglev
, first add this to your Cargo.toml
:
toml
[dependencies]
maglev = "0.1"
Then, add this to your crate root:
```rust extern crate maglev;
use maglev::*; ```
And then, use Maglev
with ConsistentHasher
trait
```rust let m = Maglev::new(&["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"][..]);
asserteq!(*m.get(&"alice"), "Friday"); asserteq!(*m.get(&"bob"), "Wednesday"); ```
When the node list changed, ensure to use same capacity
to rebuild
```rust let m = Maglev::with_capacity(&["Monday", // "Tuesday", "Wednesday", // "Thursday", "Friday", "Saturday", "Sunday"][..], m.capacity());
asserteq!(*m.get(&"alice"), "Friday"); asserteq!(*m.get(&"bob"), "Wednesday"); ```