Struct hash_rings::mpc::Ring[][src]

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

A hashing ring implemented using multi-probe consistent hashing.

Multi-probe consistent hashing is a variation on consistent hashing where instead of the nodes being hashed multiple times to reduce variance, the keys are hashed multiple times. Each key is hashed hash_count times and the closest node over all hashes is returned.

Examples

use hash_rings::mpc::Ring;

let mut ring = Ring::new(2);

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

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"));
assert_eq!(iterator.next(), None);

Methods

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

Constructs a new, empty Ring<T> that hashes hash_count times when a key is inserted.

Examples

use hash_rings::mpc::Ring;

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

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::mpc::Ring;

let mut ring: Ring<&str> = Ring::new(2);
ring.insert_node(&"node-1");

Removes a node.

Examples

use hash_rings::mpc::Ring;

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

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

Returns the node associated with a point.

Panics

Panics if the ring is empty.

Examples

use hash_rings::mpc::Ring;

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

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

Returns the number of nodes in the ring.

Examples

use hash_rings::mpc::Ring;

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

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

Returns true if the ring is empty.

Examples

use hash_rings::mpc::Ring;

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

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

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

Examples

use hash_rings::mpc::Ring;

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

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

Trait Implementations

impl<'a, T> IntoIterator for &'a Ring<'a, T> where
    T: Hash + Eq
[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

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