pub struct ConsistentHashRing<N> { /* private fields */ }Expand description
Weighted Ketama virtual-node consistent hash ring with SoA cache-friendly binary search.
Implementations§
Source§impl<N> ConsistentHashRing<N>
Core ring management and lookup operations for ConsistentHashRing.
impl<N> ConsistentHashRing<N>
Core ring management and lookup operations for ConsistentHashRing.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of physical nodes currently in the ring.
§Returns
usize- Count of physical nodes.
Sourcepub fn virtual_len(&self) -> usize
pub fn virtual_len(&self) -> usize
Returns the total number of virtual points on the hash ring.
§Returns
usize- Virtual ring entry count.
Sourcepub fn add_node<S>(&mut self, id: S, value: N)
pub fn add_node<S>(&mut self, id: S, value: N)
Inserts or replaces a physical node with unit weight (1).
§Arguments
S- Stable node identifier string.N- Node payload value.
Sourcepub fn add_weighted_node<S>(&mut self, id: S, value: N, weight: usize)
pub fn add_weighted_node<S>(&mut self, id: S, value: N, weight: usize)
Inserts or replaces a physical node with an explicit relative weight (>= 1).
§Arguments
S- Stable node identifier string.N- Node payload value.usize- Positive weight scaling virtual node count.
Sourcepub fn remove_node(&mut self, id: &str) -> Option<N>
pub fn remove_node(&mut self, id: &str) -> Option<N>
Trait Implementations§
Source§impl<N: Clone> Clone for ConsistentHashRing<N>
impl<N: Clone> Clone for ConsistentHashRing<N>
Source§impl<N: Debug> Debug for ConsistentHashRing<N>
impl<N: Debug> Debug for ConsistentHashRing<N>
Source§impl<N> Default for ConsistentHashRing<N>
Default construction for ConsistentHashRing.
impl<N> Default for ConsistentHashRing<N>
Default construction for ConsistentHashRing.
Source§fn default() -> Self
fn default() -> Self
Creates an empty ring with DEFAULT_VIRTUAL_NODES virtual nodes per unit weight.
§Returns
Self- Empty consistent hash ring.
Auto Trait Implementations§
impl<N> Forget for ConsistentHashRing<N>
impl<N> Freeze for ConsistentHashRing<N>where
*const u8 is !null: Freeze,
PhantomData<RingNode<N>>: Freeze,
PhantomData<u64>: Freeze,
PhantomData<u32>: Freeze,
impl<N> Move for ConsistentHashRing<N>
impl<N> RefUnwindSafe for ConsistentHashRing<N>where
N: RefUnwindSafe,
impl<N> Send for ConsistentHashRing<N>
impl<N> Sync for ConsistentHashRing<N>
impl<N> Unpin for ConsistentHashRing<N>
impl<N> UnsafeUnpin for ConsistentHashRing<N>where
*const u8 is !null: UnsafeUnpin,
PhantomData<RingNode<N>>: UnsafeUnpin,
PhantomData<u64>: UnsafeUnpin,
PhantomData<u32>: UnsafeUnpin,
impl<N> UnwindSafe for ConsistentHashRing<N>where
RawVecInner: UnwindSafe,
N: UnwindSafe,
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