pub struct HashRing<T: Clone, S = RandomState> { /* private fields */ }Expand description
A concurrent, consistent hash ring.
Provides the following features:
- Lookup optimized ring storage.
- Key overrides that allow you to pin a key to a specific node.
Implementations§
Source§impl<T> HashRing<T>where
T: Clone,
impl<T> HashRing<T>where
T: Clone,
Sourcepub fn add_node<K: Hash>(&self, key: K, node: T) -> Option<T>
pub fn add_node<K: Hash>(&self, key: K, node: T) -> Option<T>
Adds a node to the existing set of nodes in the ring, this will replace an entry if one exists.
Sourcepub fn remove_node<K: Hash>(&self, key: K) -> Option<T>
pub fn remove_node<K: Hash>(&self, key: K) -> Option<T>
Removes a node from the existing set of nodes.
Sourcepub fn add_nodes<K: Hash, I: IntoIterator<Item = (K, T)>>(&self, nodes: I)
pub fn add_nodes<K: Hash, I: IntoIterator<Item = (K, T)>>(&self, nodes: I)
Adds a collection of nodes to the existing set of nodes in the ring, replacing any existing entries if they exist.
Sourcepub fn set_nodes<K: Hash, I: IntoIterator<Item = (K, T)>>(&self, nodes: I)
pub fn set_nodes<K: Hash, I: IntoIterator<Item = (K, T)>>(&self, nodes: I)
Replaces the nodes in the ring with a new set of nodes.
Sourcepub fn find_node<K: Hash>(&self, key: K) -> Option<T>
pub fn find_node<K: Hash>(&self, key: K) -> Option<T>
Returns the node responsible for key. If there are no nodes in the ring, it will return None.
Sourcepub fn map_node<K: Hash, F: FnMut(Option<&T>)>(&self, key: K, map: F)
pub fn map_node<K: Hash, F: FnMut(Option<&T>)>(&self, key: K, map: F)
Finds the node responsible for the given key and passes it to map.
Sourcepub fn add_override<K: Hash>(&self, key: K, node: T) -> Option<T>
pub fn add_override<K: Hash>(&self, key: K, node: T) -> Option<T>
Adds an override to the ring.
Sourcepub fn add_overrides<K: Hash, I: IntoIterator<Item = (K, T)>>(
&self,
overrides: I,
)
pub fn add_overrides<K: Hash, I: IntoIterator<Item = (K, T)>>( &self, overrides: I, )
Adds a collection of overrides to the ring.
Sourcepub fn set_overrides<K: Hash, I: IntoIterator<Item = (K, T)>>(
&self,
overrides: I,
)
pub fn set_overrides<K: Hash, I: IntoIterator<Item = (K, T)>>( &self, overrides: I, )
Replaces the overrides in the ring with a new set of overrides.
Sourcepub fn remove_override<K: Hash>(&self, key: K) -> Option<T>
pub fn remove_override<K: Hash>(&self, key: K) -> Option<T>
Removes an existing override from the ring.
Trait Implementations§
Auto Trait Implementations§
impl<T, S = RandomState> !Freeze for HashRing<T, S>
impl<T, S = RandomState> !RefUnwindSafe for HashRing<T, S>
impl<T, S> Send for HashRing<T, S>
impl<T, S> Sync for HashRing<T, S>
impl<T, S> Unpin for HashRing<T, S>where
S: Unpin,
impl<T, S> UnwindSafe for HashRing<T, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more