Skip to main content

Block

Struct Block 

Source
#[repr(transparent)]
struct Block([u32; 8]);
Expand description

A single 256-bit block, the basic unit of the Split Block Bloom Filter.

A block is eight contiguous 32-bit words ([u32; 8]). Each word is an independent bit-array of 32 positions:

  Block (256 bits total)
  ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  │ word 0 │ word 1 │ word 2 │ word 3 │ word 4 │ word 5 │ word 6 │ word 7 │
  │ 32 bits│ 32 bits│ 32 bits│ 32 bits│ 32 bits│ 32 bits│ 32 bits│ 32 bits│
  └────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┘

When a value is inserted, Block::mask picks one bit in each word (8 bits total), and those bits are OR’d in. When checking, we verify all 8 bits are set.

Tuple Fields§

§0: [u32; 8]

Implementations§

Source§

impl Block

Source

const ZERO: Block

Source

fn mask(x: u32) -> Self

Produce a block where each of the 8 words has exactly one bit set.

For each word i the bit position is derived from x:

  y = (x wrapping* SALT[i]) >> 27   // top 5 bits → value in 0..31
  word[i] = 1 << y                  // exactly one bit set per word

Because only the top 5 bits survive the shift, each word picks one of 32 possible bit positions. The eight SALT constants spread the choices so different words usually light up different positions.

Key property: the mask depends only on x (a u32) and the fixed SALT constants — it is independent of the filter size. This is why folding preserves bit patterns (see Lemma 2 in tests).

Source

fn insert(&mut self, hash: u32)

OR the mask bits into this block (block[i] |= mask[i]).

After insertion the 8 bits chosen by mask(hash) are guaranteed set; bits previously set by other hashes are preserved.

Source

fn check(&self, hash: u32) -> bool

Check membership: returns true when every bit from mask(hash) is already set in this block (block[i] & mask[i] != 0 for all 8 words).

A true result means “probably present” (other inserts may have set the same bits). A false is definitive — the value was never inserted.

Source§

impl Block

Source

fn count_ones(self) -> u32

Count the total number of set bits across all 8 words.

Computes popcount on each word separately and sums. Keeping the popcount separate from the OR allows the compiler to batch SIMD popcount instructions (e.g., cnt.16b on ARM NEON) instead of interleaving them with OR operations.

Trait Implementations§

Source§

impl BitOr for Block

Source§

type Output = Block

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign for Block

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<usize> for Block

Source§

type Output = u32

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Block

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Copy for Block

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnsafeUnpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<T> Ungil for T
where T: Send,