ppvm_tableau::sparsevec
sparsevec¶
ppvm_tableau::sparsevec
[`SparseVector`](sparsevec::SparseVector) trait and implementations.
classSparseVector¶source
ppvm_tableau::sparsevec::SparseVector
Rust trait. A sparse vector keyed by index type `I` with values of type `T`.
pub trait SparseVector<T, I>: Clone + IntoIteratorUsed by GeneralizedTableau to store the coefficient over each branching bitstring. The default implementation is `Vec<(T, I)>`; alternative backings (BTreeMap, HashMap, etc.) can be provided by downstream code.
sourcemethodadd_or_insert¶source
ppvm_tableau::sparsevec::SparseVector::add_or_insert
fn add_or_insert(&mut self, index: I, value: T)Parameters
| Name | Type | Description |
|---|---|---|
index | I | |
value | T |
Add `value` into the entry at `index`, creating it if absent.
sourcemethodget¶source
ppvm_tableau::sparsevec::SparseVector::get
fn get(&self, index: &I) -> TParameters
| Name | Type | Description |
|---|---|---|
index | &I |
Returns
T
Retrieve the value at `index`, or zero if absent.
sourcemethodis_empty¶source
ppvm_tableau::sparsevec::SparseVector::is_empty
methoditer¶source
ppvm_tableau::sparsevec::SparseVector::iter
fn iter<'a>(&'a self) -> impl IteratorReturns
impl Iterator
Borrow the stored entries as an iterator without consuming the vector.
sourcemethodlen¶source
ppvm_tableau::sparsevec::SparseVector::len
methodmul_by¶source
ppvm_tableau::sparsevec::SparseVector::mul_by
fn mul_by(&mut self, factor: T)Parameters
| Name | Type | Description |
|---|---|---|
factor | T |
Multiply every entry’s value by `factor`.
sourcemethodmul_element_by¶source
ppvm_tableau::sparsevec::SparseVector::mul_element_by
fn mul_element_by(&mut self, index: I, factor: T)Parameters
| Name | Type | Description |
|---|---|---|
index | I | |
factor | T |
Multiply the value at `index` by `factor`. No-op if absent.
sourcemethodnew¶source
ppvm_tableau::sparsevec::SparseVector::new
methodnormalize¶source
ppvm_tableau::sparsevec::SparseVector::normalize
methodreserve¶source
ppvm_tableau::sparsevec::SparseVector::reserve
fn reserve(&mut self, _additional: usize)Parameters
| Name | Type | Description |
|---|---|---|
_additional | usize |
Reserve capacity for at least `additional` more entries. Backings that don’t support pre-allocation can leave this as a no-op.
sourcemethodretain¶source
ppvm_tableau::sparsevec::SparseVector::retain
fn retain(&mut self, f: impl FnMut(&(T, I)) -> bool)Parameters
| Name | Type | Description |
|---|---|---|
f | impl FnMut(&(T, I)) -> bool |
Drop entries failing the predicate `f`.
sourcemethodtrim¶source
ppvm_tableau::sparsevec::SparseVector::trim
fn trim(&mut self, cutoff: T)Parameters
| Name | Type | Description |
|---|---|---|
cutoff | T |
Drop entries whose magnitude is at most `|cutoff|`.
sourcemethodunsafe_insert¶source
ppvm_tableau::sparsevec::SparseVector::unsafe_insert
fn unsafe_insert(&mut self, index: I, value: T)Parameters
| Name | Type | Description |
|---|---|---|
index | I | |
value | T |
Inserts an element without checking whether the index already exists.
source