rust_tensors/sparse_tensor.rs
1use crate::addressable::Addressable;
2use std::collections::hash_map::{Iter, IterMut};
3use std::collections::HashMap;
4
5pub trait SparseTensor<T, A: Addressable> {
6 /// Creates a new instance of a sparse tensor given the address-value-map
7 fn new(address_value_map: HashMap<A, T>) -> Self;
8 /// Attempts to retrieve a reference to the value at the address.
9 /// Returns None if the address is outside the given bound
10 fn get(&self, address: &A) -> Option<&T>;
11 fn get_mut(&mut self, address: &A) -> Option<&mut T>;
12 /// Attempts to reassign the value at the given index. Returns Err if the given address is out of bounds.
13 fn set(&mut self, address: &A, value: T) -> Option<T>;
14 /// Returns an Address-Value Iterator of all Address Value Pairs stored in the Sparse Tensor
15 fn iter(&self) -> Iter<'_, A, T>;
16 /// Returns a Mutable Address-Value Iterator of all Address Value Pairs stored in the Sparse Tensor
17 fn iter_mut(&mut self) -> IterMut<'_, A, T>;
18}