Struct hash_rings::carp::Ring[][src]

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

A hashing ring implemented using the Cache Array Routing Protocol.

The Cache Array Routing Protocol calculates the relative weight for each node in the ring to distribute points according to their weights.

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64), Node::new(&"node-2", 3f64)]);

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

Methods

impl<'a, T> Ring<'a, T>
[src]

Constructs a new, empty Ring<T>.

Examples

use hash_rings::carp::Ring;

let mut ring: Ring<&str> = Ring::new(vec![]);

Inserts a node into the ring with a particular weight.

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

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64)]);

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

Removes a node from the ring.

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64), Node::new(&"node-2", 3f64)]);

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

Returns the node associated with a point.

Panics

Panics if the ring is empty.

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64)]);

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

Returns the number of nodes in the ring.

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64), Node::new(&"node-2", 3f64)]);

assert_eq!(ring.len(), 2);

Removes a node from the ring.

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64), Node::new(&"node-2", 3f64)]);

assert_eq!(ring.len(), 2);

Returns an iterator over the ring. The iterator will yield nodes and their weights in sorted by weight, and then by id. particular order.

Examples

use hash_rings::carp::{Node, Ring};

let mut ring = Ring::new(vec![Node::new(&"node-1", 1f64), Node::new(&"node-2", 3f64)]);

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

Trait Implementations

impl<'a, T> IntoIterator for &'a Ring<'a, T>
[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