Struct rustc_index::bit_set::BitMatrix
source · pub struct BitMatrix<R: Idx, C: Idx> {
num_rows: usize,
num_columns: usize,
words: SmallVec<[u64; 2]>,
marker: PhantomData<(R, C)>,
}
Expand description
A fixed-size 2D bit matrix type with a dense representation.
R
and C
are index types used to identify rows and columns respectively;
typically newtyped usize
wrappers, but they can also just be usize
.
All operations that involve a row and/or column index will panic if the index exceeds the relevant bound.
Fields§
§num_rows: usize
§num_columns: usize
§words: SmallVec<[u64; 2]>
§marker: PhantomData<(R, C)>
Implementations§
source§impl<R: Idx, C: Idx> BitMatrix<R, C>
impl<R: Idx, C: Idx> BitMatrix<R, C>
sourcepub fn new(num_rows: usize, num_columns: usize) -> BitMatrix<R, C>
pub fn new(num_rows: usize, num_columns: usize) -> BitMatrix<R, C>
Creates a new rows x columns
matrix, initially empty.
sourcepub fn from_row_n(row: &BitSet<C>, num_rows: usize) -> BitMatrix<R, C>
pub fn from_row_n(row: &BitSet<C>, num_rows: usize) -> BitMatrix<R, C>
Creates a new matrix, with row
used as the value for every row.
pub fn rows(&self) -> impl Iterator<Item = R>
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 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 intersect_rows(&self, row1: R, row2: R) -> Vec<C>
pub fn intersect_rows(&self, row1: R, row2: R) -> Vec<C>
Returns those indices that are true in rows a
and b
. This
is an O(n) operation where n is the number of elements
(somewhat independent from the actual size of the
intersection, in particular).
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 union_row_with(&mut self, with: &BitSet<C>, write: R) -> bool
pub fn union_row_with(&mut self, with: &BitSet<C>, write: R) -> bool
Adds the bits from with
to the bits from row write
, and
returns true
if anything changed.
sourcepub fn insert_all_into_row(&mut self, row: R)
pub fn insert_all_into_row(&mut self, row: R)
Sets every cell in row
to true.
Trait Implementations§
source§impl<R: PartialEq + Idx, C: PartialEq + Idx> PartialEq for BitMatrix<R, C>
impl<R: PartialEq + Idx, C: PartialEq + Idx> PartialEq for BitMatrix<R, C>
impl<R: Eq + Idx, C: Eq + Idx> Eq for BitMatrix<R, C>
impl<R: Idx, C: Idx> StructuralPartialEq for BitMatrix<R, C>
Auto Trait Implementations§
impl<R, C> Freeze for BitMatrix<R, C>
impl<R, C> RefUnwindSafe for BitMatrix<R, C>where
R: RefUnwindSafe,
C: RefUnwindSafe,
impl<R, C> Send for BitMatrix<R, C>
impl<R, C> Sync for BitMatrix<R, C>
impl<R, C> Unpin for BitMatrix<R, C>
impl<R, C> UnwindSafe for BitMatrix<R, C>where
R: UnwindSafe,
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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: 40 bytes