maglev 0.2.1

Maglev - Google's consistent hashing algorithm
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::hash::Hash;

/// 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.
pub trait ConsistentHasher<N: Sized> {
    /// Returns all nodes in arbitrary order.
    fn nodes(&self) -> &[N];

    /// Returns the number of slots in the lookup table.
    fn capacity(&self) -> usize;

    /// Returns a reference to the node corresponding to the key.
    fn get<Q: ?Sized>(&self, key: &Q) -> Option<&N>
    where
        Q: Hash + Eq;
}