pub(crate) const SLOTS_PER_WORD: usize = 10;
#[inline]
pub(crate) fn word_count(total_slots: usize) -> usize {
total_slots.div_ceil(SLOTS_PER_WORD)
}
#[derive(Clone, Copy)]
pub(crate) struct MembershipKey {
bits: u64,
}
impl MembershipKey {
#[inline]
pub(crate) fn from_signature(signature: u64) -> Self {
let first = signature & 63;
let second = (signature >> 32) & 63;
Self {
bits: (1_u64 << first) | (1_u64 << second),
}
}
#[inline]
pub(crate) const fn bits(self) -> u64 {
self.bits
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
pub(crate) fn word(signature: u64, word_count: usize) -> usize {
let product = u128::from(signature) * word_count as u128;
(product >> 64) as usize
}
}
#[derive(Clone, Copy)]
pub(crate) struct MembershipRegion {
pub(crate) offset: usize,
pub(crate) words: usize,
}
impl MembershipRegion {
pub(crate) const EMPTY: Self = Self {
offset: 0,
words: 0,
};
}