rustc_index::bit_set

Struct SparseBitMatrix

source
pub struct SparseBitMatrix<R, C>
where R: Idx, C: Idx,
{ num_columns: usize, rows: IndexVec<R, Option<HybridBitSet<C>>>, }
Expand description

A fixed-column-size, variable-row-size 2D bit matrix with a moderately sparse representation.

Initially, every row has no explicit representation. If any bit within a row is set, the entire row is instantiated as Some(<HybridBitSet>). Furthermore, any previously uninstantiated rows prior to it will be instantiated as None. Those prior rows may themselves become fully instantiated later on if any of their bits are set.

R and C are index types used to identify rows and columns respectively; typically newtyped usize wrappers, but they can also just be usize.

Fields§

§num_columns: usize§rows: IndexVec<R, Option<HybridBitSet<C>>>

Implementations§

source§

impl<R: Idx, C: Idx> SparseBitMatrix<R, C>

source

pub fn new(num_columns: usize) -> Self

Creates a new empty sparse bit matrix with no rows or columns.

source

fn ensure_row(&mut self, row: R) -> &mut HybridBitSet<C>

source

pub fn insert(&mut self, row: R, column: C) -> bool

Sets the cell at (row, column) to true. Put another way, insert column to the bitset for row.

Returns true if this changed the matrix.

source

pub fn remove(&mut self, row: R, column: C) -> bool

Sets the cell at (row, column) to false. Put another way, delete column from the bitset for row. Has no effect if row does not exist.

Returns true if this changed the matrix.

source

pub fn clear(&mut self, row: R)

Sets all columns at row to false. Has no effect if row does not exist.

source

pub fn contains(&self, row: R, column: C) -> bool

Do the bits from row contain column? Put another way, is the matrix cell at (row, column) true? Put yet another way, if the matrix represents (transitive) reachability, can row reach column?

source

pub fn union_rows(&mut self, read: R, write: R) -> bool

Adds the bits from row read to the bits from row write, and returns true if anything changed.

This is used when computing transitive reachability because if you have an edge write -> read, because in that case write can reach everything that read can (and potentially more).

source

pub fn insert_all_into_row(&mut self, row: R)

Insert all bits in the given row.

source

pub fn rows(&self) -> impl Iterator<Item = R>

source

pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_

Iterates through all the columns set to true in a given row of the matrix.

source

pub fn row(&self, row: R) -> Option<&HybridBitSet<C>>

source

pub fn intersect_row<Set>(&mut self, row: R, set: &Set) -> bool
where HybridBitSet<C>: BitRelations<Set>,

Intersects row with set. set can be either BitSet or HybridBitSet. Has no effect if row does not exist.

Returns true if the row was changed.

source

pub fn subtract_row<Set>(&mut self, row: R, set: &Set) -> bool
where HybridBitSet<C>: BitRelations<Set>,

Subtracts set from row. set can be either BitSet or HybridBitSet. Has no effect if row does not exist.

Returns true if the row was changed.

source

pub fn union_row<Set>(&mut self, row: R, set: &Set) -> bool
where HybridBitSet<C>: BitRelations<Set>,

Unions row with set. set can be either BitSet or HybridBitSet.

Returns true if the row was changed.

Trait Implementations§

source§

impl<R, C> Clone for SparseBitMatrix<R, C>
where R: Idx + Clone, C: Idx + Clone,

source§

fn clone(&self) -> SparseBitMatrix<R, C>

Returns a copy 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<R, C> Debug for SparseBitMatrix<R, C>
where R: Idx + Debug, C: Idx + Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, C> Freeze for SparseBitMatrix<R, C>

§

impl<R, C> RefUnwindSafe for SparseBitMatrix<R, C>
where C: RefUnwindSafe,

§

impl<R, C> Send for SparseBitMatrix<R, C>
where C: Send,

§

impl<R, C> Sync for SparseBitMatrix<R, C>
where C: Sync,

§

impl<R, C> Unpin for SparseBitMatrix<R, C>
where C: Unpin,

§

impl<R, C> UnwindSafe for SparseBitMatrix<R, C>
where C: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes