use super::{SlotSet, StableSlot};
impl SlotSet {
pub fn empty() -> Self {
Self(super::membership::Membership::new())
}
pub fn one(slot: StableSlot) -> Self {
let mut slots = super::membership::Membership::new();
slots.insert(slot.value());
Self(slots)
}
#[allow(
clippy::arithmetic_side_effects,
reason = "range storage contains at most 2^32 slots; chunk ordinals and word cardinalities stay within those bounds"
)]
pub(in crate::storage::warp_table::secondary_index) fn try_from_words<Error>(
word_count: usize,
mut fill: impl FnMut(&mut [u64]) -> Result<(), Error>,
) -> Result<Self, Error> {
use super::membership::Chunk;
use crate::storage::query_workspace::chunk::read::{ChunkRead, ReadPayload};
use crate::storage::warp_table::inconsistency::invariant_violation;
if word_count > 1_usize << 26 {
invariant_violation("range membership exceeds the slot universe");
}
let mut result = super::membership::Membership::new();
let mut remaining = word_count;
for high in 0..word_count.div_ceil(1024) {
let mut chunk = [0_u64; 1024];
let active = remaining.min(1024);
let words = chunk
.get_mut(..active)
.unwrap_or_else(|| invariant_violation("range chunk exceeds its word bound"));
fill(words)?;
let len: u32 = words.iter().map(|word| word.count_ones()).sum();
if len != 0 {
result.len += u64::from(len);
result.chunks.push(Chunk::from_read(
high as u16,
ChunkRead {
len,
payload: ReadPayload::Dense(&chunk),
},
));
}
remaining -= active;
}
Ok(Self(result))
}
}