Crate maglev [] [src]

Maglev hashing - A consistent hashing algorithm from Google

Maglev: A Fast and Reliable Software Network Load Balancer

Example

use maglev::*;

let m = Maglev::new(&["Monday",
                      "Tuesday",
                      "Wednesday",
                      "Thursday",
                      "Friday",
                      "Saturday",
                      "Sunday"][..]);

assert_eq!(*m.get(&"alice"), "Friday");
assert_eq!(*m.get(&"bob"), "Wednesday");

// When the node list changed, ensure to use same `capacity` to rebuild the lookup table.

let m = Maglev::with_capacity(&["Monday",
                                // "Tuesday",
                                "Wednesday",
                                // "Thursday",
                                "Friday",
                                "Saturday",
                                "Sunday"][..],
                              m.capacity());

assert_eq!(*m.get(&"alice"), "Friday");
assert_eq!(*m.get(&"bob"), "Wednesday");

Structs

Maglev

Maglev lookup table

Traits

ConsistentHasher

Consistent hasher is a special kind of hashing such that when a hash table is resized, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of slots.