Struct rendezvous_hash::HeterogeneousRendezvousNodes [] [src]

pub struct HeterogeneousRendezvousNodes<N, H> { /* fields omitted */ }

A heterogeneous candidate node set of a rendezvous for clients that are requiring the same item.

"heterogeneous" means that each node can have a different capacity.

Examples

use std::collections::HashMap;
use rendezvous_hash::Capacity;
use rendezvous_hash::HeterogeneousRendezvousNodes;

let mut nodes = HeterogeneousRendezvousNodes::default();
nodes.insert("foo", Capacity::new(70).unwrap());
nodes.insert("bar", Capacity::new(20).unwrap());
nodes.insert("baz", Capacity::new(9).unwrap());
nodes.insert("qux", Capacity::new(1).unwrap());

let mut counts = HashMap::new();
for item in 0..10000 {
    let node = nodes.calc_candidates(&item).nth(0).unwrap();
    *counts.entry(node.0.to_string()).or_insert(0) += 1;
}
assert_eq!(((counts["foo"] as f64) / 100.0).round(), 70.0);
assert_eq!(((counts["bar"] as f64) / 100.0).round(), 20.0);
assert_eq!(((counts["baz"] as f64) / 100.0).round(), 9.0);
assert_eq!(((counts["qux"] as f64) / 100.0).round(), 1.0);

Methods

impl<N, H> HeterogeneousRendezvousNodes<N, H> where N: PartialEq + Ord + Hash,
        H: for<'a> NodeHasher<(&'a N, u16)>
[src]

Makes a new HeterogeneousRendezvousNodes 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 * m + n log n) steps (where n is the return value of self.len() and m is the maximum value among the capacities of the nodes.)

impl<N, H> HeterogeneousRendezvousNodes<N, H> where N: PartialEq + Hash
[src]

Inserts a new candidate node which has the capacity capacity.

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

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> HeterogeneousRendezvousNodes<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 HeterogeneousRendezvousNodes<N, H>
[src]

Formats the value using the given formatter.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

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

impl<N, H> IntoIterator for HeterogeneousRendezvousNodes<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, Capacity)> for HeterogeneousRendezvousNodes<N, H> where N: PartialEq + Hash
[src]

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