Skip to main content

SparseVector

Trait SparseVector 

Source
pub trait SparseVector<T, I>: Clone + IntoIterator<Item = (T, I)> {
Show 13 methods // Required methods fn new() -> Self; fn unsafe_insert(&mut self, index: I, value: T); fn add_or_insert(&mut self, index: I, value: T); fn get(&self, index: &I) -> T; fn len(&self) -> usize; fn is_empty(&self) -> bool; fn mul_by(&mut self, factor: T); fn mul_element_by(&mut self, index: I, factor: T); fn trim(&mut self, cutoff: T); fn retain(&mut self, f: impl FnMut(&(T, I)) -> bool); fn normalize(&mut self); fn iter<'a>(&'a self) -> impl Iterator<Item = &'a (T, I)> where T: 'a, I: 'a; // Provided method fn reserve(&mut self, _additional: usize) { ... }
}
Expand description

A sparse vector keyed by index type I with values of type T.

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.

Required Methods§

Source

fn new() -> Self

Construct an empty sparse vector.

Source

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

Inserts an element without checking whether the index already exists.

Source

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

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

Source

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

Retrieve the value at index, or zero if absent.

Source

fn len(&self) -> usize

Number of stored entries.

Source

fn is_empty(&self) -> bool

true if no entries are stored.

Source

fn mul_by(&mut self, factor: T)

Multiply every entry’s value by factor.

Source

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

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

Source

fn trim(&mut self, cutoff: T)

Drop entries whose magnitude is at most |cutoff|.

Source

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

Drop entries failing the predicate f.

Source

fn normalize(&mut self)

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

Source

fn iter<'a>(&'a self) -> impl Iterator<Item = &'a (T, I)>
where T: 'a, I: 'a,

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

Provided Methods§

Source

fn reserve(&mut self, _additional: usize)

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, I> SparseVector<T, I> for Vec<(T, I)>

Source§

fn new() -> Self

Source§

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

Source§

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

Source§

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

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn mul_by(&mut self, factor: T)

Source§

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

Source§

fn trim(&mut self, cutoff: T)

Source§

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

Source§

fn reserve(&mut self, additional: usize)

Source§

fn iter<'a>(&'a self) -> impl Iterator<Item = &'a (T, I)>
where T: 'a, I: 'a,

Source§

fn normalize(&mut self)

Implementors§