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]
impl<'a, T> Ring<'a, T> where
T: Hash + Eq,
pub fn new(hash_count: u64) -> Self
[src]
pub fn new(hash_count: u64) -> Self
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);
pub fn insert_node(&mut self, id: &'a T)
[src]
pub fn insert_node(&mut self, id: &'a T)
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");
pub fn remove_node(&mut self, id: &T)
[src]
pub fn remove_node(&mut self, id: &T)
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");
pub fn get_node<U>(&self, point: &U) -> &T where
U: Hash,
[src]
pub fn get_node<U>(&self, point: &U) -> &T where
U: Hash,
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");
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
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);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
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());
pub fn iter(
&'a self
) -> impl Iterator<Item = &'a T>
[src]
pub fn iter(
&'a self
) -> impl Iterator<Item = &'a T>
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]
impl<'a, T> IntoIterator for &'a Ring<'a, T> where
T: Hash + Eq,