rustc_index::bit_set

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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 R: Send, C: Send,

§

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

§

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

§

impl<R, C> UnwindSafe for BitMatrix<R, C>
where R: UnwindSafe, C: 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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
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
Source§

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

Source§

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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,

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.

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