Struct BitSet

Source
pub struct BitSet<Conf: Config> { /* private fields */ }
Expand description

Hierarchical sparse bitset.

Tri-level hierarchy. Highest uint it can hold is Level0BitBlock::size() * Level1BitBlock::size() * DataBitBlock::size().

Only the last level contains blocks of actual data. Empty(skipped) data blocks are not allocated.

Structure optimized for intersection speed. (Other inter-bitset operations are in fact fast too - but intersection has the lowest algorithmic complexity.) Insert/remove/contains is fast O(1) too.

Implementations§

Source§

impl<Conf: Config> BitSet<Conf>

Source

pub fn serialize(&self, w: &mut impl Write) -> Result<()>

Serialize container to a binary format.

§Format

In little endian.

lvl0_mask|[lvl1_mask;..]|[data;..]
Source

pub fn deserialize(r: &mut impl Read) -> Result<Self>

Deserialize from serialized BitSet.

Source§

impl<Conf: Config> BitSet<Conf>

Source

pub const fn max_capacity() -> usize

Max usize, BitSet with this Config can hold.

Source

pub fn new() -> Self

Source

pub fn insert(&mut self, index: usize)

§Panics

Panics, if index is out of index range.

Source

pub fn insert_block(&mut self, block: DataBlock<Conf::DataBitBlock>)

§Panics

Panics, if block is out of index range.

Source

pub fn remove(&mut self, index: usize) -> bool

Returns false if index is not in bitset.

§Panics

Panics, if index is out of index range.

Source§

impl<Conf> BitSet<Conf>
where Conf: Config,

Source

pub fn block_iter<'a>(&'a self) -> BlockIter<&'a Self>

Source

pub fn iter<'a>(&'a self) -> IndexIter<&'a Self>

Source

pub fn contains(&self, index: usize) -> bool

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<Conf, Rhs> BitAnd<Rhs> for &BitSet<Conf>
where Rhs: BitSetInterface<Conf = <Self as BitSetBase>::Conf>, Conf: Config,

Source§

fn bitand(self, rhs: Rhs) -> Self::Output

Returns intersection of self and rhs bitsets.

Source§

type Output = Apply<And, &BitSet<Conf>, Rhs>

The resulting type after applying the & operator.
Source§

impl<Conf, Rhs> BitOr<Rhs> for &BitSet<Conf>
where Rhs: BitSetInterface<Conf = <Self as BitSetBase>::Conf>, Conf: Config,

Source§

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

Returns union of self and rhs bitsets.

Source§

type Output = Apply<Or, &BitSet<Conf>, Rhs>

The resulting type after applying the | operator.
Source§

impl<Conf: Config> BitSetBase for BitSet<Conf>

Source§

const TRUSTED_HIERARCHY: bool = true

Does each raised bit in hierarchy bitblock correspond to non-empty data block? Read more
Source§

type Conf = Conf

Source§

impl<Conf> BitSetInterface for &BitSet<Conf>
where Conf: Config,

Source§

fn block_iter(&self) -> BlockIter<&Self>

Source§

fn iter(&self) -> IndexIter<&Self>

Source§

fn into_block_iter(self) -> BlockIter<Self>

Source§

fn contains(&self, index: usize) -> bool

Source§

fn is_empty(&self) -> bool

O(1) if TRUSTED_HIERARCHY, O(N) otherwise.
Source§

impl<Conf, Rhs> BitXor<Rhs> for &BitSet<Conf>
where Rhs: BitSetInterface<Conf = <Self as BitSetBase>::Conf>, Conf: Config,

Source§

fn bitxor(self, rhs: Rhs) -> Self::Output

Returns symmetric difference of self and rhs bitsets.

Source§

type Output = Apply<Xor, &BitSet<Conf>, Rhs>

The resulting type after applying the ^ operator.
Source§

impl<Conf: Config> Clone for BitSet<Conf>

Source§

fn clone(&self) -> Self

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<Conf> Debug for BitSet<Conf>
where Conf: Config,

Source§

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

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

impl<Conf: Config> Default for BitSet<Conf>

Source§

fn default() -> Self

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

impl<'de, Conf: Config> Deserialize<'de> for BitSet<Conf>

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<Conf: Config> Extend<DataBlock<<Conf as Config>::DataBitBlock>> for BitSet<Conf>

Source§

fn extend<T: IntoIterator<Item = DataBlock<Conf::DataBitBlock>>>( &mut self, iter: T, )

It is allowed for blocks with the same range to repeat in iterator. Like ([1,42], [15,27,61]). Their data will be merged.

Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Conf: Config> Extend<usize> for BitSet<Conf>

Source§

fn extend<T: IntoIterator<Item = usize>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Conf: Config, const N: usize> From<[usize; N]> for BitSet<Conf>

Source§

fn from(value: [usize; N]) -> Self

Converts to this type from the input type.
Source§

impl<Conf, B> From<B> for BitSet<Conf>
where Conf: Config, B: BitSetInterface<Conf = Conf>,

Source§

fn from(bitset: B) -> Self

Materialize any BitSetInterface.

Source§

impl<Conf: Config> FromIterator<DataBlock<<Conf as Config>::DataBitBlock>> for BitSet<Conf>

Source§

fn from_iter<T: IntoIterator<Item = DataBlock<Conf::DataBitBlock>>>( iter: T, ) -> Self

It is allowed for blocks with the same range to repeat in iterator. Like ([1,42], [15,27,61]). Their data will be merged.

Source§

impl<Conf: Config> FromIterator<usize> for BitSet<Conf>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<Conf> IntoIterator for &BitSet<Conf>
where Conf: Config,

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = IndexIter<&BitSet<Conf>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<Conf, Rhs> PartialEq<Rhs> for BitSet<Conf>
where Rhs: LevelMasksIterExt<Conf = <Self as BitSetBase>::Conf>, Conf: Config,

Source§

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

Works faster with TRUSTED_HIERARCHY.

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<Conf: Config> Serialize for BitSet<Conf>

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<Conf, Rhs> Sub<Rhs> for &BitSet<Conf>
where Rhs: BitSetInterface<Conf = <Self as BitSetBase>::Conf>, Conf: Config,

Source§

fn sub(self, rhs: Rhs) -> Self::Output

Returns difference of self and rhs bitsets.

Or relative complement of rhs in self.

Source§

type Output = Apply<Sub, &BitSet<Conf>, Rhs>

The resulting type after applying the - operator.
Source§

impl<Conf> Eq for BitSet<Conf>
where Conf: Config,

Auto Trait Implementations§

§

impl<Conf> Freeze for BitSet<Conf>

§

impl<Conf> RefUnwindSafe for BitSet<Conf>

§

impl<Conf> Send for BitSet<Conf>
where <Conf as Config>::Level0BitBlock: Send, <Conf as Config>::Level0BlockIndices: Send, <Conf as Config>::Level1BitBlock: Send, <Conf as Config>::Level1BlockIndices: Send, <Conf as Config>::DataBitBlock: Send,

§

impl<Conf> Sync for BitSet<Conf>
where <Conf as Config>::Level0BitBlock: Sync, <Conf as Config>::Level0BlockIndices: Sync, <Conf as Config>::Level1BitBlock: Sync, <Conf as Config>::Level1BlockIndices: Sync, <Conf as Config>::DataBitBlock: Sync,

§

impl<Conf> Unpin for BitSet<Conf>

§

impl<Conf> UnwindSafe for BitSet<Conf>

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.
Source§

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