pub struct BitMatrix<B: BitBlock = u32> { /* private fields */ }Expand description
A matrix of bits.
Implementations§
Source§impl<B: BitBlock> BitMatrix<B>
impl<B: BitBlock> BitMatrix<B>
Sourcepub fn new(rows: usize, row_bits: usize) -> Self
pub fn new(rows: usize, row_bits: usize) -> Self
Create a new BitMatrix with specific numbers of bits in columns and rows.
Sourcepub fn grow(&mut self, num_rows: usize, value: bool)
pub fn grow(&mut self, num_rows: usize, value: bool)
Grows the matrix in-place, adding num_rows rows filled with value.
Sourcepub fn sub_matrix<R: RangeBounds<usize>>(&self, range: R) -> BitSubMatrix<'_, B>
pub fn sub_matrix<R: RangeBounds<usize>>(&self, range: R) -> BitSubMatrix<'_, B>
Returns a slice of the matrix’s rows.
Sourcepub fn sub_matrix_mut<R: RangeBounds<usize>>(
&mut self,
range: R,
) -> BitSubMatrixMut<'_, B>
pub fn sub_matrix_mut<R: RangeBounds<usize>>( &mut self, range: R, ) -> BitSubMatrixMut<'_, B>
Returns a slice of the matrix’s rows.
Sourcepub fn split_at(&self, row: usize) -> (BitSubMatrix<'_, B>, BitSubMatrix<'_, B>)
pub fn split_at(&self, row: usize) -> (BitSubMatrix<'_, B>, BitSubMatrix<'_, B>)
Given a row’s index, returns a slice of all rows above that row, a reference to said row, and a slice of all rows below.
Functionally equivalent to (self.sub_matrix(0..row), &self[row], self.sub_matrix(row..self.num_rows())).
Sourcepub fn split_at_mut(
&mut self,
row: usize,
) -> (BitSubMatrixMut<'_, B>, BitSubMatrixMut<'_, B>)
pub fn split_at_mut( &mut self, row: usize, ) -> (BitSubMatrixMut<'_, B>, BitSubMatrixMut<'_, B>)
Given a row’s index, returns a slice of all rows above that row, a reference to said row, and a slice of all rows below.
Sourcepub fn iter_row(&self, row: usize) -> impl Iterator<Item = bool> + '_
pub fn iter_row(&self, row: usize) -> impl Iterator<Item = bool> + '_
Iterate over bits in the specified row.
Sourcepub fn transitive_closure(&mut self)
pub fn transitive_closure(&mut self)
Computes the transitive closure of the binary relation represented by this square bit matrix.
Modifies this matrix in place using Warshall’s algorithm.
After this operation, the matrix will describe a transitive
relation. This means that, for any indices a, b, c,
if M[(a, b)] and M[(b, c)], then M[(a, c)].
§Complexity
The time complexity is O(n^3), where n is the number
of columns and rows.
§Panics
The matrix must be square for this operation to succeed.
Sourcepub fn is_square(&self) -> bool
pub fn is_square(&self) -> bool
Determines whether the number of rows equals the number of columns.
This means the matrix is square.
Sourcepub fn reflexive_closure(&mut self)
pub fn reflexive_closure(&mut self)
Computes the reflexive closure of the binary relation represented by this bit matrix. The matrix can be rectangular.
The reflexive closure means that for every x`` that will be within bounds, M[(x, x)]` is true.
In other words, modifies this matrix in-place by making all bits on the diagonal set.
Trait Implementations§
impl<B: Eq + BitBlock> Eq for BitMatrix<B>
Source§impl<B: BitBlock> Index<(usize, usize)> for BitMatrix<B>
Returns true if a bit is enabled in the matrix, or false otherwise.
impl<B: BitBlock> Index<(usize, usize)> for BitMatrix<B>
Returns true if a bit is enabled in the matrix, or false otherwise.
The first index in the tuple is row number, and the second is column number.
Source§impl<B: BitBlock> Index<usize> for BitMatrix<B>
Gains immutable access to the matrix’s row in the form of a BitSlice.
impl<B: BitBlock> Index<usize> for BitMatrix<B>
Gains immutable access to the matrix’s row in the form of a BitSlice.
Source§impl<B: BitBlock> IndexMut<usize> for BitMatrix<B>
Gains mutable access to the matrix’s row in the form of a BitSlice.
impl<B: BitBlock> IndexMut<usize> for BitMatrix<B>
Gains mutable access to the matrix’s row in the form of a BitSlice.