Struct hash_rings::rendezvous::Ring[][src]

pub struct Ring<'a, T> where
    T: 'a, 
{ /* fields omitted */ }

A hashing ring implemented using rendezvous hashing.

Rendezvous hashing is based on based on assigning a pseudorandom value to node-point pair. A point is mapped to the node that yields the greatest value associated with the node-point pair. By mapping the weights to [0, 1) using logarithms, rendezvous hashing can be modified to handle weighted nodes.

Examples

use hash_rings::rendezvous::Ring;

let mut ring = Ring::new();

ring.insert_node(&"node-1", 1);
ring.insert_node(&"node-2", 3);

ring.remove_node(&"node-1");

assert_eq!(ring.get_node(&"point-1"), &"node-2");
assert_eq!(ring.len(), 1);

let mut iterator = ring.iter();
assert_eq!(iterator.next(), Some((&"node-2", 3)));
assert_eq!(iterator.next(), None);

Methods

impl<'a, T> Ring<'a, T> where
    T: Hash + Ord
[src]

Constructs a new, empty Ring<T>.

Examples

use hash_rings::rendezvous::Ring;

let mut ring: Ring<&str> = Ring::new();

Inserts a node into the ring with a number of replicas.

Increasing the number of replicas will increase the number of expected points mapped to the node. For example, a node with three replicas will receive approximately three times more points than a node with one replica.

Examples

use hash_rings::rendezvous::Ring;

let mut ring: Ring<&str> = Ring::new();

// "node-2" will receive three times more points than "node-1"
ring.insert_node(&"node-1", 1);
ring.insert_node(&"node-2", 3);

Removes a node and all its replicas from the ring.

Examples

use hash_rings::rendezvous::Ring;

let mut ring: Ring<&str> = Ring::new();

ring.insert_node(&"node-1", 1);
ring.insert_node(&"node-2", 1);
ring.remove_node(&"node-2");

Returns the node associated with a point.

Panics

Panics if the ring is empty.

Examples

use hash_rings::rendezvous::Ring;

let mut ring: Ring<&str> = Ring::new();

ring.insert_node(&"node-1", 1);
assert_eq!(ring.get_node(&"point-1"), &"node-1");

Returns the number of nodes in the ring.

Examples

use hash_rings::rendezvous::Ring;

let mut ring: Ring<&str> = Ring::new();

ring.insert_node(&"node-1", 3);
assert_eq!(ring.len(), 1);

Returns true if the ring is empty.

Examples

use hash_rings::rendezvous::Ring;

let mut ring: Ring<&str> = Ring::new();

assert!(ring.is_empty());
ring.insert_node(&"node-1", 3);
assert!(!ring.is_empty());

Returns an iterator over the ring. The iterator will yield nodes and the replica count in no particular order.

Examples

use hash_rings::rendezvous::Ring;

let mut ring = Ring::new();
ring.insert_node(&"node-1", 1);

let mut iterator = ring.iter();
assert_eq!(iterator.next(), Some((&"node-1", 1)));
assert_eq!(iterator.next(), None);

Trait Implementations

impl<'a, T> IntoIterator for &'a Ring<'a, T> where
    T: Hash + Ord
[src]

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

impl<'a, T> Default for Ring<'a, T> where
    T: Hash + Ord
[src]

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

Auto Trait Implementations

impl<'a, T> Send for Ring<'a, T> where
    T: Sync

impl<'a, T> Sync for Ring<'a, T> where
    T: Sync