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]

Makes a new RendezvousNodes instance.

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]

Inserts a new candidate node.

If a node which equals to node exists, it will be removed and returned as Some(N).

Removes the specified node from the candidates.

If the node does not exist, this method will return None.

Returns true if the specified node exists in this candidate set, otherwise false.

impl<N, H> RendezvousNodes<N, H>
[src]

Returns the count of the candidate nodes.

Returns an iterator over the nodes of this candidate set.

Trait Implementations

impl<N: Debug, H: Debug> Debug for RendezvousNodes<N, H>
[src]

Formats the value using the given formatter.

impl<N: Clone, H: Clone> Clone for RendezvousNodes<N, H>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<N> Default for RendezvousNodes<N, DefaultNodeHasher> where N: PartialEq + Hash
[src]

Returns the "default value" for a type. Read more

impl<N, H> IntoIterator for RendezvousNodes<N, H>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<N, H> Extend<N> for RendezvousNodes<N, H> where N: PartialEq + Hash
[src]

Extends a collection with the contents of an iterator. Read more