Skip to main content

BitMatrix

Struct BitMatrix 

Source
pub struct BitMatrix<B: BitBlock = u32> { /* private fields */ }
Expand description

A matrix of bits.

Implementations§

Source§

impl<B: BitBlock> BitMatrix<B>

Source

pub fn new(rows: usize, row_bits: usize) -> Self

Create a new BitMatrix with specific numbers of bits in columns and rows.

Source

pub fn num_cols(&self) -> usize

Returns the number of columns.

Source

pub fn size(&self) -> (usize, usize)

Returns the matrix’s size as (rows, columns).

Source

pub fn set(&mut self, row: usize, col: usize, enabled: bool)

Sets the value of a bit.

§Panics

Panics if (row, col) is out of bounds.

Source

pub fn fill(&mut self, enabled: bool)

Sets the value of all bits.

Source

pub fn grow(&mut self, num_rows: usize, value: bool)

Grows the matrix in-place, adding num_rows rows filled with value.

Source

pub fn truncate(&mut self, num_rows: usize)

Truncates the matrix.

Source

pub fn sub_matrix<R: RangeBounds<usize>>(&self, range: R) -> BitSubMatrix<'_, B>

Returns a slice of the matrix’s rows.

Source

pub fn sub_matrix_mut<R: RangeBounds<usize>>( &mut self, range: R, ) -> BitSubMatrixMut<'_, B>

Returns a slice of the matrix’s rows.

Source

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())).

Source

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.

Source

pub fn iter_row(&self, row: usize) -> impl Iterator<Item = bool> + '_

Iterate over bits in the specified row.

Source

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.

Source

pub fn is_square(&self) -> bool

Determines whether the number of rows equals the number of columns.

This means the matrix is square.

Source

pub fn is_empty(&self) -> bool

Determines whether the matrix is empty.

Source

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§

Source§

impl<B: Clone + BitBlock> Clone for BitMatrix<B>

Source§

fn clone(&self) -> BitMatrix<B>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Debug + BitBlock> Debug for BitMatrix<B>

Source§

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

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

impl<B: Default + BitBlock> Default for BitMatrix<B>

Source§

fn default() -> BitMatrix<B>

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

impl<B: Eq + BitBlock> Eq for BitMatrix<B>

Source§

impl<B: Hash + BitBlock> Hash for BitMatrix<B>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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§

type Output = bool

The returned type after indexing.
Source§

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

Performs the indexing (container[index]) operation. Read more
Source§

impl<B: BitBlock> Index<usize> for BitMatrix<B>

Gains immutable access to the matrix’s row in the form of a BitSlice.

Source§

type Output = BitSlice<B>

The returned type after indexing.
Source§

fn index(&self, row: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<B: BitBlock> IndexMut<usize> for BitMatrix<B>

Gains mutable access to the matrix’s row in the form of a BitSlice.

Source§

fn index_mut(&mut self, row: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<B: Ord + BitBlock> Ord for BitMatrix<B>

Source§

fn cmp(&self, other: &BitMatrix<B>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<B: PartialEq + BitBlock> PartialEq for BitMatrix<B>

Source§

fn eq(&self, other: &BitMatrix<B>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<B: PartialOrd + BitBlock> PartialOrd for BitMatrix<B>

Source§

fn partial_cmp(&self, other: &BitMatrix<B>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B: PartialEq + BitBlock> StructuralPartialEq for BitMatrix<B>

Auto Trait Implementations§

§

impl<B> Freeze for BitMatrix<B>

§

impl<B> RefUnwindSafe for BitMatrix<B>
where B: RefUnwindSafe,

§

impl<B> Send for BitMatrix<B>
where B: Send,

§

impl<B> Sync for BitMatrix<B>
where B: Sync,

§

impl<B> Unpin for BitMatrix<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for BitMatrix<B>

§

impl<B> UnwindSafe for BitMatrix<B>
where B: 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, 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.