ketama-hash-ring 11.2.0

Zero-dependency consistent hashing suite implementing Jump Consistent Hash, weighted Ketama virtual-node rings, and Google Maglev O(1) lookup tables.
Documentation
use super::*;

/// Precomputed Granlund-Montgomery reciprocal multiplier for branchless `u64` modulo.
#[derive(Clone, Copy, Debug)]
pub(crate) struct FastDivU64 {
    /// Original divisor.
    pub(crate) divisor: u64,
    /// Reciprocal multiplier.
    pub(crate) mul: u64,
    /// First post-subtraction right shift.
    pub(crate) sh1: u32,
    /// Final right shift.
    pub(crate) sh2: u32,
}

/// Google Maglev O(1) consistent hashing lookup table with minimal disruption on node changes.
#[derive(Clone, Debug)]
pub struct MaglevHash<N> {
    /// Prime lookup table size `M`.
    pub(crate) table_size: usize,
    /// Precomputed fast reciprocal divider for `hash % table_size`.
    pub(crate) fast_div: FastDivU64,
    /// Backend node payloads in stable registration order.
    pub(crate) values: Vec<N>,
    /// Compact `M`-entry lookup table mapping slot -> index in `values`.
    pub(crate) lookup: MaglevTable,
}