Struct consistent_hash::StaticHashRing [] [src]

pub struct StaticHashRing<'a, K: 'a, V: 'a, H> { /* fields omitted */ }

A hash ring which is built statically.

Once a ring instance is created, it cannot be modified afterwards.

Examples

use consistent_hash::{Node, StaticHashRing, DefaultHash};

let nodes = vec![
    Node::new("foo").quantity(5),
    Node::new("bar").quantity(5),
    Node::new("baz").quantity(1),
    Node::new("baz").quantity(2), // ignored (duplicate key)
];

let ring = StaticHashRing::new(DefaultHash, nodes.into_iter());
assert_eq!(ring.len(), 11);        // virtual node count
assert_eq!(ring.nodes().len(), 3); // real node count

assert_eq!(ring.calc_candidates(&"aa").map(|n| &n.key).collect::<Vec<_>>(),
           [&"bar", &"foo", &"baz"]);
assert_eq!(ring.calc_candidates(&"bb").map(|n| &n.key).collect::<Vec<_>>(),
           [&"foo", &"bar", &"baz"]);

Methods

impl<'a, K: 'a, V: 'a, H> StaticHashRing<'a, K, V, H> where
    K: Hash + Eq + Ord,
    H: RingHash
[src]

Makes a new StaticHashRing instance.

If multiple nodes which have the same key are contained in nodes, all of those nodes but first one are ignored.

impl<'a, K: 'a, V: 'a, H> StaticHashRing<'a, K, V, H> where
    H: RingHash
[src]

Returns the candidate nodes for item.

The higher priority node is located in front of the returned candidate sequence.

Removes the virtual node which associated to item and returns the reference to the node.

Removes the virtual node which has the highest priority for item among satisfying the predicate f, and returns the reference to the node.

impl<'a, K: 'a, V: 'a, H> StaticHashRing<'a, K, V, H>
[src]

Returns the count of the virtual nodes in this ring.

Returns the reference to the real nodes contained in this ring.

Note that the order of the returning nodes are undefined.

Trait Implementations

impl<'a, K: Debug + 'a, V: Debug + 'a, H: Debug> Debug for StaticHashRing<'a, K, V, H>
[src]

Formats the value using the given formatter.