Struct rendezvous_hash::RendezvousNodes
[−]
[src]
pub struct RendezvousNodes<N, H> { /* fields omitted */ }
A candidate node set of a rendezvous for clients that are requiring the same item.
Examples
use rendezvous_hash::RendezvousNodes; // Constructs a node (a.k.a., server, site, etc) set. let mut nodes = RendezvousNodes::default(); nodes.insert("foo"); nodes.insert("bar"); nodes.insert("baz"); nodes.insert("qux"); // Finds candidate nodes for an item (a.k.a., object). assert_eq!(nodes.calc_candidates(&1).collect::<Vec<_>>(), [&"bar", &"baz", &"foo", &"qux"]); assert_eq!(nodes.calc_candidates(&"key").collect::<Vec<_>>(), [&"qux", &"bar", &"foo", &"baz"]); // Update the node set. // (The relative order between existing nodes are preserved) nodes.remove(&"baz"); assert_eq!(nodes.calc_candidates(&1).collect::<Vec<_>>(), [&"bar", &"foo", &"qux"]); assert_eq!(nodes.calc_candidates(&"key").collect::<Vec<_>>(), [&"qux", &"bar", &"foo"]);
Methods
impl<N, H> RendezvousNodes<N, H> where N: PartialEq + Hash, H: NodeHasher<N>
[src]
fn new(hasher: H) -> Self
Makes a new RendezvousNodes
instance.
fn calc_candidates<T: Hash>(&mut self, item: &T) -> Candidates<N>
Returns the candidate nodes for item
.
The higher priority node is located in front of the returned candidate sequence.
Note that this method takes O(n log n)
steps
(where n
is the return value of self.len()
).
impl<N, H> RendezvousNodes<N, H> where N: PartialEq + Hash
[src]
fn insert(&mut self, node: N) -> Option<N>
Inserts a new candidate node.
If a node which equals to node
exists, it will be removed and returned as Some(N)
.
fn remove<M>(&mut self, node: &M) -> Option<N> where N: Borrow<M>, M: PartialEq
Removes the specified node from the candidates.
If the node does not exist, this method will return None
.
fn contains<M>(&self, node: &M) -> bool where N: Borrow<M>, M: PartialEq
Returns true
if the specified node exists in this candidate set, otherwise false
.
impl<N, H> RendezvousNodes<N, H>
[src]
fn len(&self) -> usize
Returns the count of the candidate nodes.
fn iter(&self) -> Iter<N>
Returns an iterator over the nodes of this candidate set.
Trait Implementations
impl<N: Debug, H: Debug> Debug for RendezvousNodes<N, H>
[src]
impl<N: Clone, H: Clone> Clone for RendezvousNodes<N, H>
[src]
fn clone(&self) -> RendezvousNodes<N, H>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<N> Default for RendezvousNodes<N, DefaultNodeHasher> where N: PartialEq + Hash
[src]
impl<N, H> IntoIterator for RendezvousNodes<N, H>
[src]
type Item = N
The type of the elements being iterated over.
type IntoIter = IntoIter<N>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<N, H> Extend<N> for RendezvousNodes<N, H> where N: PartialEq + Hash
[src]
fn extend<T>(&mut self, iter: T) where T: IntoIterator<Item=N>
Extends a collection with the contents of an iterator. Read more