[−][src]Struct flatk::Sparse
A Sparse
data set S
where the sparsity pattern is given by I
as select
indices into a larger range.
Fields
selection: Select<T, I>
source: S
Methods
impl<S, I> Sparse<S, RangeTo<usize>, I> where
S: Set,
I: AsRef<[usize]>,
[src]
S: Set,
I: AsRef<[usize]>,
pub fn from_dim(indices: I, dim: usize, values: S) -> Self
[src]
Create a sparse collection from the given set of indices
, a
dim
ension and a set of values
.
The corresponding sparse collection will represent a collection
of size dim
which stores only the given values
at the specified
indices
. Note that dim
may be smaller than values.len()
, in
which case a position in the sparse data structure may contain multiple
values.
Example
use flatk::*; let v = vec![1,2,3,4,5,6]; let sparse = Sparse::from_dim(vec![0,2,0,2,0,3], 4, v.as_slice()); // The iterator traverses only non-vacant elements. let mut iter = sparse.iter(); // Returns (position, source, target) triplets assert_eq!(Some((0, &1, 0)), iter.next()); assert_eq!(Some((2, &2, 2)), iter.next()); assert_eq!(Some((0, &3, 0)), iter.next()); assert_eq!(Some((2, &4, 2)), iter.next()); assert_eq!(Some((0, &5, 0)), iter.next()); assert_eq!(Some((3, &6, 3)), iter.next()); assert_eq!(None, iter.next());
impl<S, T, I> Sparse<S, T, I> where
S: Set,
T: Set,
I: AsRef<[usize]>,
[src]
S: Set,
T: Set,
I: AsRef<[usize]>,
pub fn new(selection: Select<T, I>, source: S) -> Self
[src]
The most general constructor for a sparse collection taking a selection of values and their corresponding data.
Panics
This function will panic if selection
and source
have different sizes.
impl<S, T, I> Sparse<S, T, I>
[src]
pub fn extend_pruned<S2, T2, I2, B>(
&mut self,
other: Sparse<S2, T2, I2>,
combine: impl FnMut(&mut B::Owned, B),
keep: impl FnMut(usize, &B::Owned) -> bool
) where
S2: IntoIterator<Item = B>,
I2: AsRef<[usize]>,
B: IntoOwned,
Self: Push<(usize, B::Owned)>,
[src]
&mut self,
other: Sparse<S2, T2, I2>,
combine: impl FnMut(&mut B::Owned, B),
keep: impl FnMut(usize, &B::Owned) -> bool
) where
S2: IntoIterator<Item = B>,
I2: AsRef<[usize]>,
B: IntoOwned,
Self: Push<(usize, B::Owned)>,
Extend the current sparse collection with a pruned and compressed version of the given
sparse collection, other
.
Example
use flatk::*; let v = vec![1,2,3,4,5,6]; let sparse = Sparse::from_dim(vec![0,2,2,2,0,3], 4, v.as_slice()); let mut compressed = Sparse::from_dim(Vec::new(), 4, Vec::new()); compressed.extend_pruned(sparse, |a, b| *a += *b, |_, _| true); let mut iter = compressed.iter(); // Returns (position, source, target) pairs assert_eq!(Some((0, &1, 0)), iter.next()); assert_eq!(Some((2, &9, 2)), iter.next()); assert_eq!(Some((0, &5, 0)), iter.next()); assert_eq!(Some((3, &6, 3)), iter.next()); assert_eq!(None, iter.next());
impl<'a, S, T, I> Sparse<S, T, I>
[src]
pub fn source(&self) -> &S
[src]
Get a reference to the underlying source data.
pub fn source_mut(&mut self) -> &mut S
[src]
Get a mutable reference to the underlying source data.
pub fn selection(&self) -> &Select<T, I>
[src]
Get a reference to the underlying selection.
pub fn selection_mut(&mut self) -> &mut Select<T, I>
[src]
pub fn indices(&self) -> &I
[src]
Get a reference to the underlying indices.
pub fn indices_mut(&mut self) -> &mut I
[src]
impl<'a, S, T, I> Sparse<S, T, I> where
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
T: Set + Get<'a, usize> + View<'a>,
I: AsRef<[usize]>,
[src]
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
T: Set + Get<'a, usize> + View<'a>,
I: AsRef<[usize]>,
pub fn iter(
&'a self
) -> impl Iterator<Item = (usize, <<S as View<'a>>::Type as IntoIterator>::Item, <T as Get<'a, usize>>::Output)>
[src]
&'a self
) -> impl Iterator<Item = (usize, <<S as View<'a>>::Type as IntoIterator>::Item, <T as Get<'a, usize>>::Output)>
impl<'a, S, T, I> Sparse<S, T, I> where
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
[src]
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
pub fn source_iter(
&'a self
) -> <<S as View<'a>>::Type as IntoIterator>::IntoIter
[src]
&'a self
) -> <<S as View<'a>>::Type as IntoIterator>::IntoIter
impl<'a, S, T, I> Sparse<S, T, I> where
I: AsRef<[usize]>,
[src]
I: AsRef<[usize]>,
pub fn index_iter(&'a self) -> Cloned<Iter<'a, usize>>
[src]
impl<'a, S, T, I> Sparse<S, T, I> where
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
I: AsRef<[usize]>,
[src]
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
I: AsRef<[usize]>,
pub fn indexed_source_iter(
&'a self
) -> Zip<Cloned<Iter<'a, usize>>, <<S as View<'a>>::Type as IntoIterator>::IntoIter>
[src]
&'a self
) -> Zip<Cloned<Iter<'a, usize>>, <<S as View<'a>>::Type as IntoIterator>::IntoIter>
impl<'a, S, T, I> Sparse<S, T, I> where
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
[src]
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
A mutable iterator over the source elements in S
pub fn source_iter_mut(
&'a mut self
) -> <<S as ViewMut<'a>>::Type as IntoIterator>::IntoIter
[src]
&'a mut self
) -> <<S as ViewMut<'a>>::Type as IntoIterator>::IntoIter
impl<'a, S, T, I> Sparse<S, T, I> where
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
I: AsRef<[usize]>,
[src]
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
I: AsRef<[usize]>,
A mutable iterator can only iterate over the source elements in S
and not
the target elements in T
since we would need scheduling to modify
potentially overlapping mutable references.
pub fn indexed_source_iter_mut(
&'a mut self
) -> impl Iterator<Item = (usize, <<S as ViewMut<'a>>::Type as IntoIterator>::Item)>
[src]
&'a mut self
) -> impl Iterator<Item = (usize, <<S as ViewMut<'a>>::Type as IntoIterator>::Item)>
impl<'a, S, T, I> Sparse<S, T, I> where
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
I: AsMut<[usize]>,
[src]
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
I: AsMut<[usize]>,
A mutable iterator can only iterate over the source elements in S
and not
the target elements in T
since we would need scheduling to modify
potentially overlapping mutable references.
pub fn iter_mut(
&'a mut self
) -> Zip<IterMut<'a, usize>, <<S as ViewMut<'a>>::Type as IntoIterator>::IntoIter>
[src]
&'a mut self
) -> Zip<IterMut<'a, usize>, <<S as ViewMut<'a>>::Type as IntoIterator>::IntoIter>
impl<'a, S, T, I> Sparse<S, T, I> where
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
I: AsMut<[usize]>,
[src]
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
I: AsMut<[usize]>,
Mutably iterate over the selected indices.
pub fn index_iter_mut(
&'a mut self
) -> impl Iterator<Item = (&'a mut usize, <<S as View<'a>>::Type as IntoIterator>::Item)>
[src]
&'a mut self
) -> impl Iterator<Item = (&'a mut usize, <<S as View<'a>>::Type as IntoIterator>::Item)>
impl<S, O, T, I> Sparse<Chunked<S, O>, T, I> where
S: Set + Truncate,
O: AsRef<[usize]> + Truncate + Set,
I: Truncate,
[src]
S: Set + Truncate,
O: AsRef<[usize]> + Truncate + Set,
I: Truncate,
pub fn trim(&mut self) -> usize
[src]
Remove any empty elements (indexed chunks) at the end of the collection and any unindexed data past the last offset. Return the number of elements removed.
Example
use flatk::*; let mut s = Sparse::from_dim(vec![0,1,2], 3, Chunked::from_sizes(vec![1,3,2], vec![1,2,3,4,5,6])); assert_eq!(3, s.len()); // Transferring the last two elements past the indexed stack. // This creates an empty chunk at the end. s.source_mut().transfer_forward(2, 2); assert_eq!(6, s.storage().len()); assert_eq!(3, s.len()); s.trim(); // remove unindexed elements. assert_eq!(4, s.storage().len());
Trait Implementations
impl<'a, S, T, I> AtomIterator<'a> for Sparse<S, T, I> where
S: AtomIterator<'a>,
[src]
S: AtomIterator<'a>,
impl<'a, S, T, I> AtomMutIterator<'a> for Sparse<S, T, I> where
S: AtomMutIterator<'a>,
[src]
S: AtomMutIterator<'a>,
impl<S: ChunkSize, T, I> ChunkSize for Sparse<S, T, I>
[src]
fn chunk_size(&self) -> usize
[src]
impl<S: Clear, T, I: Clear> Clear for Sparse<S, T, I>
[src]
impl<S: Clone, T: Clone, I: Clone> Clone for Sparse<S, T, I>
[src]
impl<T: Clone, S: CloneWithStorage<U>, I: Clone, U> CloneWithStorage<U> for Sparse<S, T, I>
[src]
type CloneType = Sparse<S::CloneType, T, I>
fn clone_with_storage(&self, storage: U) -> Self::CloneType
[src]
impl<S: Copy, T: Copy, I: Copy> Copy for Sparse<S, T, I>
[src]
impl<S: Debug, T: Debug, I: Debug> Debug for Sparse<S, T, I>
[src]
impl<S: Dummy, T: Dummy, I: Dummy> Dummy for Sparse<S, T, I>
[src]
impl<S, T> Extend<(usize, <S as Set>::Elem)> for Sparse<S, T> where
S: Set + Extend<<S as Set>::Elem>,
[src]
S: Set + Extend<<S as Set>::Elem>,
impl<'a, S, T, I> GetIndex<'a, Sparse<S, T, I>> for usize where
I: AsRef<[usize]>,
S: Get<'a, usize>,
[src]
I: AsRef<[usize]>,
S: Get<'a, usize>,
type Output = (usize, <S as Get<'a, usize>>::Output)
fn get(self, sparse: &Sparse<S, T, I>) -> Option<Self::Output>
[src]
impl<S: IntoFlat, T, I> IntoFlat for Sparse<S, T, I>
[src]
type FlatType = S::FlatType
fn into_flat(self) -> Self::FlatType
[src]
Convert the sparse set into its raw storage representation.
impl<S: IntoOwned, T: IntoOwned, I: IntoOwned> IntoOwned for Sparse<S, T, I>
[src]
type Owned = Sparse<S::Owned, T::Owned, I::Owned>
fn into_owned(self) -> Self::Owned
[src]
fn clone_into(self, target: &mut Self::Owned)
[src]
impl<S, T, I> IntoOwnedData for Sparse<S, T, I> where
S: IntoOwnedData,
[src]
S: IntoOwnedData,
type OwnedData = Sparse<S::OwnedData, T, I>
fn into_owned_data(self) -> Self::OwnedData
[src]
fn clone_into(self, target: &mut Self::OwnedData)
[src]
impl<S, T, I> IsolateIndex<Sparse<S, T, I>> for usize where
I: Isolate<usize>,
<I as Isolate<usize>>::Output: Borrow<usize>,
S: Isolate<usize>,
T: Isolate<usize>,
[src]
I: Isolate<usize>,
<I as Isolate<usize>>::Output: Borrow<usize>,
S: Isolate<usize>,
T: Isolate<usize>,
type Output = (<I as Isolate<usize>>::Output, <S as Isolate<usize>>::Output, <T as Isolate<usize>>::Output)
fn try_isolate(self, sparse: Sparse<S, T, I>) -> Option<Self::Output>
[src]
impl<S, T, I> IsolateIndex<Sparse<S, T, I>> for Range<usize> where
S: Isolate<Range<usize>>,
I: Isolate<Range<usize>>,
[src]
S: Isolate<Range<usize>>,
I: Isolate<Range<usize>>,
type Output = Sparse<S::Output, T, I::Output>
fn try_isolate(self, sparse: Sparse<S, T, I>) -> Option<Self::Output>
[src]
impl<S, T, I, N: Unsigned> IsolateIndex<Sparse<S, T, I>> for StaticRange<N> where
Range<usize>: IsolateIndex<Sparse<S, T, I>>,
[src]
Range<usize>: IsolateIndex<Sparse<S, T, I>>,
type Output = <Range<usize> as IsolateIndex<Sparse<S, T, I>>>::Output
fn try_isolate(self, set: Sparse<S, T, I>) -> Option<Self::Output>
[src]
impl<S: PartialEq, T: PartialEq, I: PartialEq> PartialEq<Sparse<S, T, I>> for Sparse<S, T, I>
[src]
fn eq(&self, other: &Sparse<S, T, I>) -> bool
[src]
fn ne(&self, other: &Sparse<S, T, I>) -> bool
[src]
impl<S: PermuteInPlace, T, I: PermuteInPlace> PermuteInPlace for Sparse<S, T, I>
[src]
impl<S, T, I, A> Push<(usize, A)> for Sparse<S, T, I> where
S: Set<Elem = A> + Push<A>,
I: Push<usize>,
[src]
S: Set<Elem = A> + Push<A>,
I: Push<usize>,
impl<S: RemovePrefix, T, I: RemovePrefix> RemovePrefix for Sparse<S, T, I>
[src]
fn remove_prefix(&mut self, n: usize)
[src]
impl<S: Reserve, T, I: Reserve> Reserve for Sparse<S, T, I>
[src]
fn reserve_with_storage(&mut self, n: usize, storage_n: usize)
[src]
fn reserve(&mut self, n: usize)
[src]
impl<S: Set, T, I> Set for Sparse<S, T, I>
[src]
type Elem = (usize, S::Elem)
Owned element of the set.
type Atom = S::Atom
The most basic element contained by this collection. If this collection contains other collections, this type should be different than Elem
. Read more
fn len(&self) -> usize
[src]
Get the length of this sparse collection.
Example
use flatk::*; let v = vec![1,2,3,4,5]; let sparse = Sparse::from_dim(vec![0,2,2,1,1], 3, v.as_slice()); assert_eq!(5, sparse.len());
fn is_empty(&self) -> bool
[src]
impl<S, T, I> SplitAt for Sparse<S, T, I> where
S: Set + SplitAt,
T: Set + Clone,
I: SplitAt,
[src]
S: Set + SplitAt,
T: Set + Clone,
I: SplitAt,
impl<S: Storage, T, I> Storage for Sparse<S, T, I>
[src]
type Storage = S::Storage
fn storage(&self) -> &Self::Storage
[src]
Return an immutable reference to the underlying storage type of source data.
Example
use flatk::*; let v = vec![1,2,3,4,5,6,7,8,9,10,11,12]; let s0 = Chunked3::from_flat(v.clone()); let s1 = Sparse::from_dim(vec![0, 2, 2, 0], 4, s0.clone()); assert_eq!(s1.storage(), &v);
impl<S: StorageInto<U>, T, I, U> StorageInto<U> for Sparse<S, T, I>
[src]
Pass through the conversion for structure type Subset
.
impl<S: StorageMut, T, I> StorageMut for Sparse<S, T, I>
[src]
fn storage_mut(&mut self) -> &mut Self::Storage
[src]
Return a mutable reference to the underlying storage type of source data.
Example
use flatk::*; let mut v = vec![1,2,3,4,5,6,7,8,9,10,11,12]; let mut s0 = Chunked3::from_flat(v.clone()); let mut s1 = Sparse::from_dim(vec![0, 2, 2, 0], 4, s0.clone()); assert_eq!(s1.storage_mut(), &mut v);
impl<'a, S: StorageView<'a>, T, I> StorageView<'a> for Sparse<S, T, I>
[src]
type StorageView = S::StorageView
fn storage_view(&'a self) -> Self::StorageView
[src]
Return a view to the underlying storage type of source data.
Example
use flatk::*; let v = vec![1,2,3,4,5,6,7,8,9,10,11,12]; let s0 = Chunked3::from_flat(v.clone()); let s1 = Sparse::from_dim(vec![0, 2, 2, 0], 4, s0.clone()); assert_eq!(s1.storage_view(), v.as_slice());
impl<S, T, I> StructuralPartialEq for Sparse<S, T, I>
[src]
impl<S: Truncate, T, I: Truncate> Truncate for Sparse<S, T, I>
[src]
impl<S, T, I, M> UniChunkable<M> for Sparse<S, T, I>
[src]
impl<S, T, I> ValueType for Sparse<S, T, I>
[src]
impl<'a, S, T, I> View<'a> for Sparse<S, T, I> where
S: View<'a>,
T: View<'a>,
I: AsRef<[usize]>,
[src]
S: View<'a>,
T: View<'a>,
I: AsRef<[usize]>,
impl<'a, S, T, I> ViewIterator<'a> for Sparse<S, T, I> where
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
[src]
S: View<'a>,
<S as View<'a>>::Type: Set + IntoIterator,
type Item = <<S as View<'a>>::Type as IntoIterator>::Item
type Iter = <<S as View<'a>>::Type as IntoIterator>::IntoIter
fn view_iter(&'a self) -> Self::Iter
[src]
impl<'a, S, T, I> ViewMut<'a> for Sparse<S, T, I> where
S: Set + ViewMut<'a>,
T: Set + View<'a>,
I: AsMut<[usize]>,
[src]
S: Set + ViewMut<'a>,
T: Set + View<'a>,
I: AsMut<[usize]>,
impl<'a, S, T, I> ViewMutIterator<'a> for Sparse<S, T, I> where
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
[src]
S: ViewMut<'a>,
<S as ViewMut<'a>>::Type: Set + IntoIterator,
type Item = <<S as ViewMut<'a>>::Type as IntoIterator>::Item
type Iter = <<S as ViewMut<'a>>::Type as IntoIterator>::IntoIter
fn view_mut_iter(&'a mut self) -> Self::Iter
[src]
impl<S: Viewed, T: Viewed, I: Viewed> Viewed for Sparse<S, T, I>
[src]
Auto Trait Implementations
impl<S, T, I> RefUnwindSafe for Sparse<S, T, I> where
I: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
I: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<S, T, I> Send for Sparse<S, T, I> where
I: Send,
S: Send,
T: Send,
I: Send,
S: Send,
T: Send,
impl<S, T, I> Sync for Sparse<S, T, I> where
I: Sync,
S: Sync,
T: Sync,
I: Sync,
S: Sync,
T: Sync,
impl<S, T, I> Unpin for Sparse<S, T, I> where
I: Unpin,
S: Unpin,
T: Unpin,
I: Unpin,
S: Unpin,
T: Unpin,
impl<S, T, I> UnwindSafe for Sparse<S, T, I> where
I: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
I: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AsSlice<T> for T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<'a, S, I> Get<'a, I> for S where
I: GetIndex<'a, S>,
[src]
I: GetIndex<'a, S>,
type Output = <I as GetIndex<'a, S>>::Output
fn get(&Self, I) -> Option<<I as GetIndex<'a, S>>::Output>
[src]
fn at(&self, idx: I) -> Self::Output
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<S> IntoChunkIterator for S where
S: Set + SplitAt + Dummy,
[src]
S: Set + SplitAt + Dummy,
type Item = S
type IterType = ChunkedNIter<S>
fn into_chunk_iter(Self, usize) -> <S as IntoChunkIterator>::IterType
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<S, I> Isolate<I> for S where
I: IsolateIndex<S>,
[src]
I: IsolateIndex<S>,
type Output = <I as IsolateIndex<S>>::Output
fn try_isolate(Self, I) -> Option<<S as Isolate<I>>::Output>
[src]
fn isolate(self, idx: I) -> Self::Output where
Self: Sized,
[src]
Self: Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,