pub struct HashRing<T, 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.
In order to call find_node, T must implement Clone,
this is to prevent blocking for too long and keep the ring as up to date as possible.
Implementations§
source§impl<T> HashRing<T>
impl<T> HashRing<T>
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 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.