pub struct SparseBitMatrix<R, C>{
num_columns: usize,
rows: IndexVec<R, Option<BitSet<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(<BitSet>)
.
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<BitSet<C>>>
Implementations§
Source§impl<R: Idx, C: Idx> SparseBitMatrix<R, C>
impl<R: Idx, C: Idx> SparseBitMatrix<R, C>
Sourcepub fn new(num_columns: usize) -> Self
pub fn new(num_columns: usize) -> Self
Creates a new empty sparse bit matrix with no rows or columns.
fn ensure_row(&mut self, row: R) -> &mut BitSet<C>
Sourcepub fn insert(&mut self, row: R, column: C) -> bool
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.
Sourcepub fn remove(&mut self, row: R, column: C) -> bool
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.
Sourcepub fn clear(&mut self, row: R)
pub fn clear(&mut self, row: R)
Sets all columns at row
to false. Has no effect if row
does
not exist.
Sourcepub fn contains(&self, row: R, column: C) -> bool
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
?
Sourcepub fn union_rows(&mut self, read: R, write: R) -> bool
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).
Sourcepub fn insert_all_into_row(&mut self, row: R)
pub fn insert_all_into_row(&mut self, row: R)
Insert all bits in the given row.
pub fn rows(&self) -> impl Iterator<Item = R>
Sourcepub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_
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.
pub fn row(&self, row: R) -> Option<&BitSet<C>>
Sourcepub fn intersect_row<Set>(&mut self, row: R, set: &Set) -> boolwhere
BitSet<C>: BitRelations<Set>,
pub fn intersect_row<Set>(&mut self, row: R, set: &Set) -> boolwhere
BitSet<C>: BitRelations<Set>,
Intersects row
with set
. set
can be either BitSet
or
ChunkedBitSet
. Has no effect if row
does not exist.
Returns true if the row was changed.
Sourcepub fn subtract_row<Set>(&mut self, row: R, set: &Set) -> boolwhere
BitSet<C>: BitRelations<Set>,
pub fn subtract_row<Set>(&mut self, row: R, set: &Set) -> boolwhere
BitSet<C>: BitRelations<Set>,
Subtracts set
from row
. set
can be either BitSet
or
ChunkedBitSet
. Has no effect if row
does not exist.
Returns true if the row was changed.
Trait Implementations§
Source§impl<R, C> Clone for SparseBitMatrix<R, C>
impl<R, C> Clone for SparseBitMatrix<R, C>
Source§fn clone(&self) -> SparseBitMatrix<R, C>
fn clone(&self) -> SparseBitMatrix<R, C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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