Skip to main content

BitVector

Struct BitVector 

Source
pub struct BitVector { /* private fields */ }
Expand description

Stores booleans as individual bits - 8x smaller than Vec<bool>.

Supports bitwise operations (and, or, not) for combining filter results efficiently.

Implementations§

Source§

impl BitVector

Source

pub fn new() -> Self

Creates an empty bit vector.

Source

pub fn with_capacity(bits: usize) -> Self

Creates a bit vector with the specified capacity (in bits).

Source

pub fn from_bools(bools: &[bool]) -> Self

Creates a bit vector from a slice of booleans.

Source

pub fn filled(len: usize, value: bool) -> Self

Creates a bit vector with all bits set to the same value.

Source

pub fn zeros(len: usize) -> Self

Creates a bit vector with all bits set to false (0).

Source

pub fn ones(len: usize) -> Self

Creates a bit vector with all bits set to true (1).

Source

pub fn len(&self) -> usize

Returns the number of bits.

Source

pub fn is_empty(&self) -> bool

Returns whether the bit vector is empty.

Source

pub fn get(&self, index: usize) -> Option<bool>

Gets the bit at the given index.

Source

pub fn set(&mut self, index: usize, value: bool)

Sets the bit at the given index.

§Panics

Panics if index >= len.

Source

pub fn push(&mut self, value: bool)

Appends a bit to the end.

Source

pub fn count_ones(&self) -> usize

Returns the number of bits set to true.

Source

pub fn count_zeros(&self) -> usize

Returns the number of bits set to false.

Source

pub fn to_bools(&self) -> Vec<bool>

Converts back to a Vec<bool>.

§Panics

Panics if an internal index is out of bounds (invariant violation).

Source

pub fn iter(&self) -> impl Iterator<Item = bool> + '_

Returns an iterator over the bits.

§Panics

Panics if an internal index is out of bounds (invariant violation).

Source

pub fn ones_iter(&self) -> impl Iterator<Item = usize> + '_

Returns an iterator over indices where bits are true.

§Panics

Panics if an internal index is out of bounds (invariant violation).

Source

pub fn zeros_iter(&self) -> impl Iterator<Item = usize> + '_

Returns an iterator over indices where bits are false.

§Panics

Panics if an internal index is out of bounds (invariant violation).

Source

pub fn data(&self) -> &[u64]

Returns the raw data.

Source

pub fn compression_ratio(&self) -> f64

Returns the compression ratio (original bytes / compressed bytes).

Source

pub fn and(&self, other: &Self) -> Self

Performs bitwise AND with another bit vector.

The result has the length of the shorter vector.

Source

pub fn or(&self, other: &Self) -> Self

Performs bitwise OR with another bit vector.

The result has the length of the shorter vector.

Source

pub fn not(&self) -> Self

Performs bitwise NOT.

Source

pub fn xor(&self, other: &Self) -> Self

Performs bitwise XOR with another bit vector.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serializes to bytes.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Deserializes from bytes.

§Errors

Returns Err if the byte slice is too short or contains invalid data.

Trait Implementations§

Source§

impl Clone for BitVector

Source§

fn clone(&self) -> BitVector

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 BitVector

Source§

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

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

impl Default for BitVector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for BitVector

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromIterator<bool> for BitVector

Source§

fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for BitVector

Source§

fn eq(&self, other: &BitVector) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for BitVector

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for BitVector

Source§

impl StructuralPartialEq for BitVector

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,