[−][src]Struct hash_rings::rendezvous::Client
A client that uses Ring<T>
.
Examples
use hash_rings::rendezvous::Client; let mut client = Client::new(); client.insert_node(&"node-1", 3); client.insert_point(&"point-1"); client.insert_point(&"point-2"); assert_eq!(client.len(), 1); assert_eq!(client.get_node(&"point-1"), &"node-1"); client.remove_point(&"point-2"); assert_eq!(client.get_points(&"node-1"), [&"point-1"]);
Methods
impl<'a, T, U> Client<'a, T, U, RandomState>
[src]
pub fn new() -> Self where
T: Hash + Eq,
U: Hash + Eq,
[src]
T: Hash + Eq,
U: Hash + Eq,
Constructs a new, empty Client<T, U>
.
Examples
use hash_rings::rendezvous::Client; let mut client: Client<&str, &str> = Client::new();
impl<'a, T, U, H> Client<'a, T, U, H>
[src]
pub fn with_hasher(hash_builder: H) -> Self where
T: Hash + Eq,
U: Hash + Eq,
H: BuildHasher + Clone,
[src]
T: Hash + Eq,
U: Hash + Eq,
H: BuildHasher + Clone,
Constructs a new, empty Client<T, U>
with a specified hash builder.
Examples
use hash_rings::rendezvous::Client; use std::collections::hash_map::DefaultHasher; use std::hash::BuildHasherDefault; type DefaultBuildHasher = BuildHasherDefault<DefaultHasher>; let mut client: Client<&str, &str, _> = Client::with_hasher(DefaultBuildHasher::default());
pub fn insert_node(&mut self, id: &'a T, replicas: usize) where
T: Hash + Eq,
U: Hash + Eq,
H: BuildHasher,
[src]
T: Hash + Eq,
U: Hash + Eq,
H: BuildHasher,
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::Client; let mut client: Client<&str, &str> = Client::new(); // "node-2" will receive three times more points than "node-1" client.insert_node(&"node-1", 1); client.insert_node(&"node-2", 3);
pub fn remove_node(&mut self, id: &T) where
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
[src]
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
Removes a node and all its replicas from the ring.
Panics
Panics if the ring is empty after removal of a node or if the node does not exist.
Examples
use hash_rings::rendezvous::Client; let mut client: Client<&str, &str> = Client::new(); client.insert_node(&"node-1", 1); client.insert_node(&"node-2", 1); client.remove_node(&"node-1");
pub fn get_points(&self, id: &T) -> Vec<&U> where
T: Hash + Eq,
U: Hash + Eq,
[src]
T: Hash + Eq,
U: Hash + Eq,
Returns the points associated with a node and its replicas.
Panics
Panics if the node does not exist.
Examples
use hash_rings::rendezvous::Client; let mut client: Client<&str, &str> = Client::new(); client.insert_node(&"node-1", 1); client.insert_point(&"point-1"); assert_eq!(client.get_points(&"node-1"), [&"point-1"]);
pub fn get_node(&self, point: &U) -> &T where
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
[src]
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
Returns the node associated with a point.
Panics
Panics if the ring is empty.
Examples
use hash_rings::rendezvous::Client; let mut client: Client<&str, &str> = Client::new(); client.insert_node(&"node-1", 1); client.insert_point(&"point-1"); assert_eq!(client.get_node(&"point-1"), &"node-1");
pub fn insert_point(&mut self, point: &'a U) -> &T where
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
[src]
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
Inserts a point into the ring and returns the node associated with the inserted point.
Panics
Panics if the ring is empty.
Examples
use hash_rings::rendezvous::Client; let mut client = Client::new(); client.insert_node(&"node-1", 1); client.insert_point(&"point-1");
pub fn remove_point(&mut self, point: &U) where
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
[src]
T: Hash + Ord,
U: Hash + Eq,
H: BuildHasher,
Removes a point from the ring.
Panics
Panics if the ring is empty.
Examples
use hash_rings::rendezvous::Client; let mut client = Client::new(); client.insert_node(&"node-1", 1); client.insert_point(&"point-1"); client.remove_point(&"point-1");
pub fn len(&self) -> usize where
T: Hash + Eq,
[src]
T: Hash + Eq,
Returns the number of nodes in the ring.
Examples
use hash_rings::rendezvous::Client; let mut client: Client<&str, &str> = Client::new(); client.insert_node(&"node-1", 3); assert_eq!(client.len(), 1);
pub fn is_empty(&self) -> bool where
T: Hash + Eq,
[src]
T: Hash + Eq,
Returns true
if the ring is empty.
Examples
use hash_rings::rendezvous::Client; let mut client: Client<&str, &str> = Client::new(); assert!(client.is_empty()); client.insert_node(&"node-1", 3); assert!(!client.is_empty());
pub fn iter(&'a self) -> impl Iterator<Item = (&'a T, Vec<&'a U>)> where
T: Hash + Eq,
U: Hash + Eq,
[src]
T: Hash + Eq,
U: Hash + Eq,
Returns an iterator over the ring. The iterator will yield nodes and points in no particular order.
Examples
use hash_rings::rendezvous::Client; let mut client = Client::new(); client.insert_node(&"node-1", 1); client.insert_point(&"point-1"); let mut iterator = client.iter(); assert_eq!(iterator.next(), Some((&"node-1", vec![&"point-1"]))); assert_eq!(iterator.next(), None);
Trait Implementations
impl<'a, T, U, H> IntoIterator for &'a Client<'a, T, U, H> where
T: Hash + Eq,
U: Hash + Eq,
[src]
T: Hash + Eq,
U: Hash + Eq,
type IntoIter = Box<dyn Iterator<Item = (&'a T, Vec<&'a U>)> + 'a>
Which kind of iterator are we turning this into?
type Item = (&'a T, Vec<&'a U>)
The type of the elements being iterated over.
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T, U, H> Default for Client<'a, T, U, H> where
T: Hash + Eq,
U: Hash + Eq,
H: BuildHasher + Default + Clone,
[src]
T: Hash + Eq,
U: Hash + Eq,
H: BuildHasher + Default + Clone,
Auto Trait Implementations
impl<'a, T, U, H> Send for Client<'a, T, U, H> where
H: Send,
T: Sync,
U: Sync,
H: Send,
T: Sync,
U: Sync,
impl<'a, T, U, H> Sync for Client<'a, T, U, H> where
H: Sync,
T: Sync,
U: Sync,
H: Sync,
T: Sync,
U: Sync,
impl<'a, T, U, H> Unpin for Client<'a, T, U, H> where
H: Unpin,
H: Unpin,
impl<'a, T, U, H> UnwindSafe for Client<'a, T, U, H> where
H: UnwindSafe,
T: RefUnwindSafe,
U: RefUnwindSafe,
H: UnwindSafe,
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<'a, T, U, H> RefUnwindSafe for Client<'a, T, U, H> where
H: RefUnwindSafe,
T: RefUnwindSafe,
U: RefUnwindSafe,
H: RefUnwindSafe,
T: RefUnwindSafe,
U: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,