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]
K: Hash + Eq + Ord,
H: RingHash,
fn new<I>(hash: H, nodes: I) -> Self where
I: Iterator<Item = Node<K, V>>,
I: Iterator<Item = Node<K, V>>,
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]
H: RingHash,
fn calc_candidates<T: Hash>(&self, item: &T) -> Candidates<K, V>
Returns the candidate nodes for item
.
The higher priority node is located in front of the returned candidate sequence.
fn take<T: Hash>(&mut self, item: &T) -> Option<&Node<K, V>>
Removes the virtual node which associated to item
and returns the reference to the node.
fn take_if<T: Hash, F>(&mut self, item: &T, f: F) -> Option<&Node<K, V>> where
F: Fn(&Node<K, V>) -> bool,
F: Fn(&Node<K, V>) -> bool,
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]
fn len(&self) -> usize
Returns the count of the virtual nodes in this ring.
fn nodes(&self) -> &[Node<K, V>]
Returns the reference to the real nodes contained in this ring.
Note that the order of the returning nodes are undefined.