Skip to content

ppvm_tableau::sparsevec

sparsevec

ppvm_tableau::sparsevec

[`SparseVector`](sparsevec::SparseVector) trait and implementations.

classSparseVectorsource

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 + IntoIterator

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

source

methodadd_or_insertsource

ppvm_tableau::sparsevec::SparseVector::add_or_insert

fn add_or_insert(&mut self, index: I, value: T)

Parameters

NameTypeDescription
indexI
valueT

Add `value` into the entry at `index`, creating it if absent.

source

methodgetsource

ppvm_tableau::sparsevec::SparseVector::get

fn get(&self, index: &I) -> T

Parameters

NameTypeDescription
index&amp;I

Returns

T

Retrieve the value at `index`, or zero if absent.

source

methodis_emptysource

ppvm_tableau::sparsevec::SparseVector::is_empty

fn is_empty(&self) -> bool

Returns

bool

`true` if no entries are stored.

source

methoditersource

ppvm_tableau::sparsevec::SparseVector::iter

fn iter<'a>(&'a self) -> impl Iterator

Returns

impl Iterator

Borrow the stored entries as an iterator without consuming the vector.

source

methodlensource

ppvm_tableau::sparsevec::SparseVector::len

fn len(&self) -> usize

Returns

usize

Number of stored entries.

source

methodmul_bysource

ppvm_tableau::sparsevec::SparseVector::mul_by

fn mul_by(&mut self, factor: T)

Parameters

NameTypeDescription
factorT

Multiply every entry’s value by `factor`.

source

methodmul_element_bysource

ppvm_tableau::sparsevec::SparseVector::mul_element_by

fn mul_element_by(&mut self, index: I, factor: T)

Parameters

NameTypeDescription
indexI
factorT

Multiply the value at `index` by `factor`. No-op if absent.

source

methodnewsource

ppvm_tableau::sparsevec::SparseVector::new

fn new() -> Self

Returns

Self

Construct an empty sparse vector.

source

methodnormalizesource

ppvm_tableau::sparsevec::SparseVector::normalize

fn normalize(&mut self)

L2-normalize the vector in place. Panics on zero norm.

source

methodreservesource

ppvm_tableau::sparsevec::SparseVector::reserve

fn reserve(&mut self, _additional: usize)

Parameters

NameTypeDescription
_additionalusize

Reserve capacity for at least `additional` more entries. Backings that don’t support pre-allocation can leave this as a no-op.

source

methodretainsource

ppvm_tableau::sparsevec::SparseVector::retain

fn retain(&mut self, f: impl FnMut(&(T, I)) -> bool)

Parameters

NameTypeDescription
fimpl FnMut(&amp;(T, I)) -&gt; bool

Drop entries failing the predicate `f`.

source

methodtrimsource

ppvm_tableau::sparsevec::SparseVector::trim

fn trim(&mut self, cutoff: T)

Parameters

NameTypeDescription
cutoffT

Drop entries whose magnitude is at most `|cutoff|`.

source

methodunsafe_insertsource

ppvm_tableau::sparsevec::SparseVector::unsafe_insert

fn unsafe_insert(&mut self, index: I, value: T)

Parameters

NameTypeDescription
indexI
valueT

Inserts an element without checking whether the index already exists.

source