#[non_exhaustive]pub struct CsVecRef<'a, T> { /* private fields */ }Expand description
An immutable view of a sparse vector.
This provides efficient read-only access to sparse vector data without allocation. Sparse vectors store only non-zero elements and their indices, making them memory-efficient for vectors with few non-zero elements.
§Format
The sparse vector uses two parallel arrays:
indices: Indices of non-zero elementsvalues: Non-zero values corresponding to each index
§Examples
use algebra_sparse::CsVecRef;
let indices = [0, 2, 4];
let values = [1.0, 3.0, 5.0];
let sparse_vec = CsVecRef::from_parts_unchecked(&indices, &values, 6);
// Iterate over non-zero elements
for (index, value) in sparse_vec.iter() {
println!("vec[{}] = {}", index, value);
}Implementations§
Source§impl<'a, T> CsVecRef<'a, T>
impl<'a, T> CsVecRef<'a, T>
Sourcepub fn from_parts_unchecked(
indices: &'a [usize],
values: &'a [T],
len: usize,
) -> Self
pub fn from_parts_unchecked( indices: &'a [usize], values: &'a [T], len: usize, ) -> Self
Creates a CsVecRef from raw parts without checking validity.
§Safety
This function does not validate that the provided parts form a valid sparse vector.
The indices and values arrays should have the same length, and indices should be
in ascending order and within bounds [0, len).
§Arguments
indices- Indices of non-zero elementsvalues- Non-zero values corresponding to each indexlen- Total length of the vector
Sourcepub fn iter(&self) -> impl Iterator<Item = (usize, T)>where
T: Copy,
pub fn iter(&self) -> impl Iterator<Item = (usize, T)>where
T: Copy,
Returns an iterator over the non-zero elements of the vector.
The iterator yields tuples of (index, value) for each non-zero element.
§Returns
An iterator over (index, value) pairs
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the total length of the vector.
This is the full length of the vector, not the number of non-zero elements.
§Returns
The total length including zero elements
Trait Implementations§
Source§impl<'a, T: Real> Add<Matrix<T, Dyn, Const<1>, ViewStorage<'a, T, Dyn, Const<1>, Const<1>, Dyn>>> for CsVecRef<'a, T>
impl<'a, T: Real> Add<Matrix<T, Dyn, Const<1>, ViewStorage<'a, T, Dyn, Const<1>, Const<1>, Dyn>>> for CsVecRef<'a, T>
impl<'a, T: Copy> Copy for CsVecRef<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for CsVecRef<'a, T>
impl<'a, T> RefUnwindSafe for CsVecRef<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for CsVecRef<'a, T>where
T: Sync,
impl<'a, T> Sync for CsVecRef<'a, T>where
T: Sync,
impl<'a, T> Unpin for CsVecRef<'a, T>
impl<'a, T> UnwindSafe for CsVecRef<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.