pub struct RendezvousHasher<H, B>where
H: Hasher,
B: BuildHasher<Hasher = H>,{ /* private fields */ }Expand description
A hasher implementation for the Rendezvous (HRW - Highest Random Weight) hashing algorithm.
Rendezvous hashing provides a way to consistently distribute keys across a set of nodes, with minimal redistribution when nodes are added or removed. It’s particularly useful for distributed systems that need to balance load across multiple servers.
This implementation works with any hasher that implements std::hash::Hasher.
Implementations§
Source§impl<H, B> RendezvousHasher<H, B>where
H: Hasher,
B: BuildHasher<Hasher = H>,
impl<H, B> RendezvousHasher<H, B>where
H: Hasher,
B: BuildHasher<Hasher = H>,
Sourcepub fn new(build_hasher: B) -> Self
pub fn new(build_hasher: B) -> Self
Creates a new RendezvousHasher with the provided build hasher.
Sourcepub fn select<'a, K, N>(&self, key: &K, nodes: &'a [N]) -> Option<&'a N>
pub fn select<'a, K, N>(&self, key: &K, nodes: &'a [N]) -> Option<&'a N>
Selects the preferred node for a given key from a list of nodes.
This method computes a hash score for each node combined with the key, and returns the node with the highest score.
§Parameters
key- The key to hashnodes- A slice of nodes to choose from
§Returns
A reference to the selected node, or None if the nodes slice is empty
Trait Implementations§
Source§impl<H, B> Clone for RendezvousHasher<H, B>
impl<H, B> Clone for RendezvousHasher<H, B>
Source§fn clone(&self) -> RendezvousHasher<H, B>
fn clone(&self) -> RendezvousHasher<H, B>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<H, B> Freeze for RendezvousHasher<H, B>where
B: Freeze,
impl<H, B> RefUnwindSafe for RendezvousHasher<H, B>where
B: RefUnwindSafe,
H: RefUnwindSafe,
impl<H, B> Send for RendezvousHasher<H, B>
impl<H, B> Sync for RendezvousHasher<H, B>
impl<H, B> Unpin for RendezvousHasher<H, B>
impl<H, B> UnwindSafe for RendezvousHasher<H, B>where
B: UnwindSafe,
H: 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