ketama_hash_ring/ring/struct.rs
1/// One physical node entry stored in a [`ConsistentHashRing`].
2#[derive(Clone, Debug, Eq, PartialEq)]
3pub(crate) struct RingNode<N> {
4 /// Unique stable identifier used to hash virtual replicas.
5 pub(crate) id: String,
6 /// Relative weight (`>= 1`) scaling virtual node count.
7 pub(crate) weight: usize,
8 /// User-supplied node value.
9 pub(crate) value: N,
10}
11
12/// Weighted Ketama virtual-node consistent hash ring with SoA cache-friendly binary search.
13#[derive(Clone, Debug)]
14pub struct ConsistentHashRing<N> {
15 /// Virtual nodes per unit of weight.
16 pub(crate) virtual_nodes: usize,
17 /// Physical nodes indexed by compact `u32`.
18 pub(crate) nodes: Vec<RingNode<N>>,
19 /// Sorted contiguous virtual-node hash points for L1-dense binary search.
20 pub(crate) ring_hashes: Vec<u64>,
21 /// Parallel compact `u32` physical node index for each virtual point.
22 pub(crate) ring_nodes: Vec<u32>,
23}