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>

source

pub fn new(num_rows: usize, num_columns: usize) -> BitMatrix<R, C>

Creates a new rows x columns matrix, initially empty.

source

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.

source

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

source

fn range(&self, row: R) -> (usize, usize)

The range of bits for a given row.

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

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

source

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

Sets every cell in row to true.

source

pub fn words(&self) -> &[u64]

Gets a slice of the underlying words.

source

pub fn iter(&self, row: R) -> BitIter<'_, C>

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

source

pub fn count(&self, row: R) -> usize

Returns the number of elements in row.

Trait Implementations§

source§

impl<R: Clone + Idx, C: Clone + Idx> Clone for BitMatrix<R, C>

source§

fn clone(&self) -> BitMatrix<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: Idx, C: Idx> Debug for BitMatrix<R, C>

source§

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

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

impl<R, C, __D: Decoder> Decodable<__D> for BitMatrix<R, C>
where R: Decodable<__D> + Idx, C: Decodable<__D> + Idx,

source§

fn decode(__decoder: &mut __D) -> Self

source§

impl<R, C, __E: Encoder> Encodable<__E> for BitMatrix<R, C>
where R: Encodable<__E> + Idx, C: Encodable<__E> + Idx,

source§

fn encode(&self, __encoder: &mut __E)

source§

impl<R: Hash + Idx, C: Hash + Idx> Hash for BitMatrix<R, C>

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<R: PartialEq + Idx, C: PartialEq + Idx> PartialEq for BitMatrix<R, C>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: Eq + Idx, C: Eq + Idx> Eq for BitMatrix<R, C>

source§

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>

§

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

§

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

§

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

§

impl<R, C> UnwindSafe for BitMatrix<R, C>
where C: UnwindSafe, R: 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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: 40 bytes