pub struct Chunked<S, O = Offsets> {
pub chunks: O,
pub data: S,
}Expand description
A partitioning of the collection S into distinct chunks.
Fields§
§chunks: OThis can be either offsets of a uniform chunk size, if chunk size is specified at compile time.
data: SImplementations§
Source§impl<'a, S, O> Chunked<S, O>
impl<'a, S, O> Chunked<S, O>
Sourcepub fn par_iter_mut(
&'a mut self,
) -> ChunkedParIter<<<O as View<'a>>::Type as IntoParOffsetValuesAndSizes>::ParIter, <S as ViewMut<'a>>::Type>
pub fn par_iter_mut( &'a mut self, ) -> ChunkedParIter<<<O as View<'a>>::Type as IntoParOffsetValuesAndSizes>::ParIter, <S as ViewMut<'a>>::Type>
Produce a parallel iterator over elements (borrowed slices) of a Chunked.
Source§impl<'a, S, T, I, O> Chunked<Sparse<S, T, I>, Offsets<O>>
impl<'a, S, T, I, O> Chunked<Sparse<S, T, I>, Offsets<O>>
Sourcepub fn sort_chunks_by_index(&'a mut self)
pub fn sort_chunks_by_index(&'a mut self)
Sort each sparse chunk by the source index.
§Example
use flatk::*;
let sparse = Sparse::from_dim(vec![0,2,1,2,0], 4, vec![1,2,3,4,5]);
let mut chunked = Chunked::from_sizes(vec![3,2], sparse);
chunked.sort_chunks_by_index();
assert_eq!(chunked.storage(), &[1,3,2,5,4]);
assert_eq!(chunked.data().indices(), &[0,1,2,0,2]);Source§impl<'a, S, T, I, O> Chunked<Sparse<S, T, I>, Offsets<O>>
impl<'a, S, T, I, O> Chunked<Sparse<S, T, I>, Offsets<O>>
Sourcepub fn compressed<E>(
&'a self,
combine: impl FnMut(&mut E::Owned, E),
) -> Chunked<Sparse<S::Owned, T>, Offsets>
pub fn compressed<E>( &'a self, combine: impl FnMut(&mut E::Owned, E), ) -> Chunked<Sparse<S::Owned, T>, Offsets>
Combine elements in each sorted chunk with the same index using the given function.
Assuming that the chunks are sorted by index, this function will combine adjacent elements with the same index into one element.
§Example
use flatk::*;
let sparse = Sparse::from_dim(vec![0,2,1,1,2,0,2], 4, vec![1,2,3,4,5,6,7]);
let mut chunked = Chunked::from_sizes(vec![4,3], sparse);
chunked.sort_chunks_by_index();
let compressed = chunked.compressed(|a, b| *a += *b);
assert_eq!(compressed.view().offsets().into_inner(), &[0,3,5]);
assert_eq!(compressed.view().storage(), &[1,7,2,6,12]);
assert_eq!(compressed.view().data().indices(), &[0,1,2,0,2]);Source§impl<'a, S, T, I, O> Chunked<Sparse<S, T, I>, Offsets<O>>
impl<'a, S, T, I, O> Chunked<Sparse<S, T, I>, Offsets<O>>
Sourcepub fn pruned<E>(
&'a self,
combine: impl FnMut(&mut E::Owned, E),
keep: impl FnMut(usize, usize, &E::Owned) -> bool,
map: impl FnMut(usize, usize),
) -> Chunked<Sparse<S::Owned, T>, Offsets>
pub fn pruned<E>( &'a self, combine: impl FnMut(&mut E::Owned, E), keep: impl FnMut(usize, usize, &E::Owned) -> bool, map: impl FnMut(usize, usize), ) -> Chunked<Sparse<S::Owned, T>, Offsets>
Prune elements according to a given predicate and combine them in each sorted chunk with the same index.
Assuming that the chunks are sorted by index, this function will combine adjacent elements with the same index into one element.
This is a more general version of compressed that allows you to prune unwanted elements.
In addition the combine and keep functions get an additional target
index where each element will be written to.
§Examples
A simple example.
use flatk::*;
let sparse = Sparse::from_dim(vec![0,2,1,1,2,0,2], 4, vec![1.0, 2.0, 0.1, 0.01, 5.0, 0.001, 7.0]);
let mut chunked = Chunked::from_sizes(vec![4,3], sparse);
chunked.sort_chunks_by_index();
let pruned = chunked.pruned(|a, b| *a += *b, |_, _, &val| val > 0.01, |_,_| {});
assert_eq!(pruned.view().offsets().into_inner(), &[0,3,4]);
assert_eq!(pruned.view().storage(), &[1.0, 0.11, 2.0, 12.0]); // 0.001 is pruned.
assert_eq!(pruned.view().data().indices(), &[0,1,2,2]);The following example extends on the previous example but shows how one may construct a mapping from original elements to the pruned output.
use flatk::*;
let indices = vec![0, 2, 1, 1, 2, 0, 2];
let num_indices = indices.len();
let sparse = Sparse::from_dim(indices, 4, vec![1.0, 2.0, 0.1, 0.01, 5.0, 0.001, 7.0]);
let mut chunked = Chunked::from_sizes(vec![4,3], sparse);
chunked.sort_chunks_by_index();
let mut mapping = vec![None; num_indices];
let pruned = chunked.pruned(|a, b| {
*a += *b
}, |_, _, &val| {
val > 0.01
}, |src, dst| mapping[src] = Some(dst));
// As before, the resulting structure is pruned.
assert_eq!(pruned.view().offsets().into_inner(), &[0,3,4]);
assert_eq!(pruned.view().storage(), &[1.0, 0.11, 2.0, 12.0]); // 0.001 is pruned.
assert_eq!(pruned.view().data().indices(), &[0,1,2,2]);
assert_eq!(mapping, vec![Some(0), Some(1), Some(1), Some(2), None, Some(3), Some(3)]);Source§impl<S, O> Chunked<S, O>
impl<S, O> Chunked<S, O>
Source§impl<S: Set> Chunked<S>
impl<S: Set> Chunked<S>
Sourcepub fn from_sizes(sizes: impl AsRef<[usize]>, data: S) -> Self
pub fn from_sizes(sizes: impl AsRef<[usize]>, data: S) -> Self
Construct a Chunked collection of elements from a set of sizes that
determine the number of elements in each chunk. The sum of the sizes
must be equal to the length of the given data.
§Panics
This function will panic if the sum of all given sizes is greater than
data.len().
§Example
use flatk::*;
let s = Chunked::from_sizes(vec![3,1,2], vec![1,2,3,4,5,6]);
let mut iter = s.iter();
assert_eq!(vec![1,2,3], iter.next().unwrap().to_vec());
assert_eq!(vec![4], iter.next().unwrap().to_vec());
assert_eq!(vec![5,6], iter.next().unwrap().to_vec());
assert_eq!(None, iter.next());Source§impl<S: Set> Chunked<S, ClumpedOffsets>
impl<S: Set> Chunked<S, ClumpedOffsets>
Sourcepub fn from_sizes_and_counts(
sizes: impl AsRef<[usize]>,
counts: impl AsRef<[usize]>,
data: S,
) -> Self
pub fn from_sizes_and_counts( sizes: impl AsRef<[usize]>, counts: impl AsRef<[usize]>, data: S, ) -> Self
Constructs a Clumped collection of elements from a set of sizes and counts
sizes and counts determine the number of elements in each chunk. The
length of sizes must be equal to the the length of counts. Each
element in sizes corresponds to chunk size, while the corresponding
element in counts tells how many times this chunk size is repeated.
The dot product between sizes and counts must be equal to the length of the given
data.
§Panics
This function will panic if sizes and counts have different lengths or
if the dot product between sizes and counts is not equal to data.len().
§Example
use flatk::*;
let s = Clumped::from_sizes_and_counts(vec![3,2], vec![2,1], vec![1,2,3,4,5,6,7,8]);
let mut iter = s.iter();
assert_eq!(&[1, 2, 3][..], iter.next().unwrap());
assert_eq!(&[4, 5, 6][..], iter.next().unwrap());
assert_eq!(&[7, 8][..], iter.next().unwrap());
assert_eq!(None, iter.next());Source§impl<S: Set, O: AsRef<[usize]>> Chunked<S, Offsets<O>>
impl<S: Set, O: AsRef<[usize]>> Chunked<S, Offsets<O>>
Sourcepub fn from_offsets(offsets: O, data: S) -> Self
pub fn from_offsets(offsets: O, data: S) -> Self
Construct a Chunked collection of elements given a collection of
offsets into S. This is the most efficient constructor for creating
variable sized chunks, however it is also the most error prone.
§Panics
The absolute value of offsets is not significant, however their
relative quantities are. More specifically, if x is the first offset,
then the last element of offsets must always be data.len() + x.
This also implies that offsets cannot be empty. This function panics
if any one of these invariants isn’t satisfied.
§Example
use flatk::*;
let s = Chunked::from_offsets(vec![0,3,4,6], vec![1,2,3,4,5,6]);
let mut iter = s.iter();
assert_eq!(vec![1,2,3], iter.next().unwrap().to_vec());
assert_eq!(vec![4], iter.next().unwrap().to_vec());
assert_eq!(vec![5,6], iter.next().unwrap().to_vec());
assert_eq!(None, iter.next());Source§impl<S: Set, O: AsRef<[usize]>> Chunked<S, ClumpedOffsets<O>>
impl<S: Set, O: AsRef<[usize]>> Chunked<S, ClumpedOffsets<O>>
Sourcepub fn from_clumped_offsets(chunk_offsets: O, offsets: O, data: S) -> Self
pub fn from_clumped_offsets(chunk_offsets: O, offsets: O, data: S) -> Self
Construct a Clumped collection of elements given a collection of
“clumped” offsets into S. This is the most efficient constructor for creating Clumped
types, however it is also the most error prone.
chunk_offsets, identify the offsets into a conceptually “chunked” version of S.
offsets is a corresponding the collection of offsets into S itself.
In theory, these should specify the places where the chunk size (or stride) changes within
S, however this is not always necessary.
§Panics
The absolute value of offsets (this applies to both offsets as well as chunk_offsets)
is not significant, however their relative quantities are. More specifically, for
offsets, if x is the first offset, then the last element of offsets must always be
data.len() + x. For chunk_offsets the same holds but data is substituted by the
conceptual collection of chunks stored in data. This also implies that offsets cannot be
empty. This function panics if any one of these invariants isn’t satisfied.
This function will also panic if offsets and chunk_offsets have different lengths.
Although the validity of offsets is easily checked, the same is not true for
chunk_offsets, since the implied stride must divide into the size of each clump, and
checking this at run time is expensive. As such a malformed Clumped may cause panics
somewhere down the line. For ensuring a valid construction, use the
Self::from_sizes_and_counts constructor.
§Example
use flatk::*;
let v = vec![1,2, 3,4, 5,6, 7,8,9];
// The following splits v intos 3 pairs and a triplet.
let s = Clumped::from_clumped_offsets(vec![0,3,4], vec![0,6,9], v);
let mut iter = s.iter();
assert_eq!(&[1,2][..], iter.next().unwrap());
assert_eq!(&[3,4][..], iter.next().unwrap());
assert_eq!(&[5,6][..], iter.next().unwrap());
assert_eq!(&[7,8,9][..], iter.next().unwrap());
assert_eq!(None, iter.next());Source§impl<S: Set, O> Chunked<S, O>
impl<S: Set, O> Chunked<S, O>
Sourcepub fn into_inner(self) -> (O, S)
pub fn into_inner(self) -> (O, S)
Convert this Chunked into its inner representation, which consists of
a collection of offsets (first output) along with the underlying data
storage type (second output).
§Example
use flatk::*;
let data = vec![1,2,3,4,5,6];
let offsets = vec![0,3,4,6];
let s = Chunked::from_offsets(offsets.clone(), data.clone());
assert_eq!(s.into_inner(), (Offsets::new(offsets), data));Sourcepub fn as_inner_mut(&mut self) -> (&mut O, &mut S)
pub fn as_inner_mut(&mut self) -> (&mut O, &mut S)
This function mutably borrows the inner structure of the chunked collection.
Source§impl<S, O> Chunked<S, O>where
O: GetOffset,
impl<S, O> Chunked<S, O>where
O: GetOffset,
Sourcepub fn offset(&self, index: usize) -> usize
pub fn offset(&self, index: usize) -> usize
Return the offset into data of the element at the given index.
This function returns the total length of data if index is equal to
self.len().
§Panics
This function panics if index is larger than self.len().
§Example
use flatk::*;
let s = Chunked::from_offsets(vec![2,5,6,8], vec![1,2,3,4,5,6]);
assert_eq!(0, s.offset(0));
assert_eq!(3, s.offset(1));
assert_eq!(4, s.offset(2));Sourcepub fn offset_value(&self, index: usize) -> usize
pub fn offset_value(&self, index: usize) -> usize
Return the raw offset value of the element at the given index.
§Panics
This function panics if index is larger than self.len().
§Example
use flatk::*;
let s = Chunked::from_offsets(vec![2,5,6,8], vec![1,2,3,4,5,6]);
assert_eq!(2, s.offset_value(0));
assert_eq!(5, s.offset_value(1));
assert_eq!(6, s.offset_value(2));Source§impl<S, O> Chunked<S, Offsets<O>>
impl<S, O> Chunked<S, Offsets<O>>
Sourcepub fn transfer_forward(&mut self, chunk_index: usize, num_elements: usize)
pub fn transfer_forward(&mut self, chunk_index: usize, num_elements: usize)
Move a number of elements from a chunk at the given index to the following chunk. If the last chunk is selected, then the transferred elements are effectively removed.
This operation is efficient and only performs one write on a single
element in an array of usize.
§Example
use flatk::*;
let v = vec![1,2,3,4,5];
let mut c = Chunked::from_sizes(vec![3,2], v);
let mut c_iter = c.iter();
assert_eq!(Some(&[1,2,3][..]), c_iter.next());
assert_eq!(Some(&[4,5][..]), c_iter.next());
assert_eq!(None, c_iter.next());
// Transfer 2 elements from the first chunk to the next.
c.transfer_forward(0, 2);
let mut c_iter = c.iter();
assert_eq!(Some(&[1][..]), c_iter.next());
assert_eq!(Some(&[2,3,4,5][..]), c_iter.next());
assert_eq!(None, c_iter.next());Sourcepub fn transfer_forward_all_but(
&mut self,
chunk_index: usize,
num_elements_to_keep: usize,
)
pub fn transfer_forward_all_but( &mut self, chunk_index: usize, num_elements_to_keep: usize, )
Like transfer_forward but specify the number of elements to keep
instead of the number of elements to transfer in the chunk at
chunk_index.
Source§impl<S, O> Chunked<S, Offsets<O>>
impl<S, O> Chunked<S, Offsets<O>>
Sourcepub fn transfer_backward(&mut self, chunk_index: usize, num_elements: usize)
pub fn transfer_backward(&mut self, chunk_index: usize, num_elements: usize)
Move a number of elements from a chunk at the given index to the previous chunk.
If the first chunk is selected, then the transferred elements are explicitly removed, which may cause reallocation if the underlying storage type manages memory.
This operation is efficient and only performs one write on a single
element in an array of usize, unless a reallocation is triggered.
§Example
use flatk::*;
let v = vec![1,2,3,4,5];
let mut c = Chunked::from_sizes(vec![3,2], v);
let mut c_iter = c.iter();
assert_eq!(Some(&[1,2,3][..]), c_iter.next());
assert_eq!(Some(&[4,5][..]), c_iter.next());
assert_eq!(None, c_iter.next());
// Transfer 1 element from the second chunk to the previous.
c.transfer_backward(1, 1);
let mut c_iter = c.iter();
assert_eq!(Some(&[1,2,3,4][..]), c_iter.next());
assert_eq!(Some(&[5][..]), c_iter.next());
assert_eq!(None, c_iter.next());Source§impl<S> Chunked<S>
impl<S> Chunked<S>
Sourcepub fn from_nested_vec(nested_data: Vec<Vec<<S as Set>::Elem>>) -> Self
pub fn from_nested_vec(nested_data: Vec<Vec<<S as Set>::Elem>>) -> Self
Construct a Chunked Vec from a nested Vec.
§Example
use flatk::*;
let s = Chunked::<Vec<_>>::from_nested_vec(vec![vec![1,2,3],vec![4],vec![5,6]]);
let mut iter = s.iter();
assert_eq!(vec![1,2,3], iter.next().unwrap().to_vec());
assert_eq!(vec![4], iter.next().unwrap().to_vec());
assert_eq!(vec![5,6], iter.next().unwrap().to_vec());
assert_eq!(None, iter.next());Source§impl<S, O> Chunked<S, O>
impl<S, O> Chunked<S, O>
Sourcepub fn trim_data(&mut self) -> usize
pub fn trim_data(&mut self) -> usize
Remove any unused data past the last offset. Return the number of elements removed.
§Example
use flatk::*;
let mut s = 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 a zero sized chunk at the end.
s.transfer_forward(2, 2);
assert_eq!(6, s.data().len());
assert_eq!(3, s.len());
s.trim_data(); // Remove unindexed elements.
assert_eq!(4, s.data().len());Source§impl<S, O> Chunked<S, O>
impl<S, O> Chunked<S, O>
Sourcepub fn trim(&mut self) -> usize
pub fn trim(&mut self) -> usize
Remove any empty chunks at the end of the collection and any unindexed data past the last offset. Return the number of chunks removed.
§Example
use flatk::*;
let mut s = 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.transfer_forward(2, 2);
assert_eq!(6, s.data().len());
assert_eq!(3, s.len());
s.trim(); // Remove unindexed elements.
assert_eq!(4, s.data().len());Source§impl<S, O> Chunked<S, O>
impl<S, O> Chunked<S, O>
Sourcepub fn push_slice(&mut self, element: &[<S as Set>::Elem])
pub fn push_slice(&mut self, element: &[<S as Set>::Elem])
Push a slice of elements onto this Chunked.
This can be more efficient than pushing from an iterator.
§Example
use flatk::*;
let mut s = Chunked::from_offsets(vec![0,3,5], vec![1,2,3,4,5]);
assert_eq!(2, s.len());
s.push_slice(&[1,2]);
assert_eq!(3, s.len());Source§impl<S, O> Chunked<S, O>
impl<S, O> Chunked<S, O>
Sourcepub fn push_iter<I: IntoIterator>(&mut self, iter: I)
pub fn push_iter<I: IntoIterator>(&mut self, iter: I)
Push a chunk using an iterator over chunk elements.
§Example
use flatk::*;
let mut s = Chunked::from_offsets(vec![0,3,5], vec![1,2,3,4,5]);
assert_eq!(2, s.len());
s.push_iter(std::iter::repeat(100).take(4));
assert_eq!(3, s.len());
assert_eq!(&[100; 4][..], s.view().at(2));Source§impl<S, O> Chunked<S, Offsets<O>>
impl<S, O> Chunked<S, Offsets<O>>
Sourcepub fn extend_last<I: IntoIterator<Item = <S as Set>::Elem>>(&mut self, iter: I)
pub fn extend_last<I: IntoIterator<Item = <S as Set>::Elem>>(&mut self, iter: I)
Extend the last chunk with the given iterator.
§Example
use flatk::*;
let mut s = Chunked::from_offsets(vec![0,3,5], vec![1,2,3,4,5]);
assert_eq!(2, s.len());
s.extend_last(std::iter::repeat(100).take(2));
assert_eq!(2, s.len());
assert_eq!(&[4, 5, 100, 100][..], s.view().at(1));Source§impl<'a, S, O> Chunked<S, O>
impl<'a, S, O> Chunked<S, O>
Sourcepub fn iter(
&'a self,
) -> ChunkedIter<<<O as View<'a>>::Type as IntoOffsetValuesAndSizes>::Iter, <S as View<'a>>::Type> ⓘ
pub fn iter( &'a self, ) -> ChunkedIter<<<O as View<'a>>::Type as IntoOffsetValuesAndSizes>::Iter, <S as View<'a>>::Type> ⓘ
Produce an iterator over elements (borrowed slices) of a Chunked.
§Examples
The following simple example demonstrates how to iterate over a Chunked
of integers stored in a flat Vec.
use flatk::*;
let s = Chunked::from_offsets(vec![0,3,4,6], vec![1,2,3,4,5,6]);
let mut iter = s.iter();
let mut e0_iter = iter.next().unwrap().iter();
assert_eq!(Some(&1), e0_iter.next());
assert_eq!(Some(&2), e0_iter.next());
assert_eq!(Some(&3), e0_iter.next());
assert_eq!(None, e0_iter.next());
assert_eq!(Some(&[4][..]), iter.next());
assert_eq!(Some(&[5,6][..]), iter.next());
assert_eq!(None, iter.next());Nested Chunkeds can also be used to create more complex data organization:
use flatk::*;
let s0 = Chunked::from_offsets(vec![0,3,4,6,9,11], vec![1,2,3,4,5,6,7,8,9,10,11]);
let s1 = Chunked::from_offsets(vec![0,1,4,5], s0);
let mut iter1 = s1.iter();
let v0 = iter1.next().unwrap();
let mut iter0 = v0.iter();
assert_eq!(Some(&[1,2,3][..]), iter0.next());
assert_eq!(None, iter0.next());
let v0 = iter1.next().unwrap();
let mut iter0 = v0.iter();
assert_eq!(Some(&[4][..]), iter0.next());
assert_eq!(Some(&[5,6][..]), iter0.next());
assert_eq!(Some(&[7,8,9][..]), iter0.next());
assert_eq!(None, iter0.next());
let v0 = iter1.next().unwrap();
let mut iter0 = v0.iter();
assert_eq!(Some(&[10,11][..]), iter0.next());
assert_eq!(None, iter0.next());Source§impl<'a, S, O> Chunked<S, O>
impl<'a, S, O> Chunked<S, O>
Sourcepub fn iter_mut(
&'a mut self,
) -> ChunkedIter<<<O as View<'a>>::Type as IntoOffsetValuesAndSizes>::Iter, <S as ViewMut<'a>>::Type> ⓘ
pub fn iter_mut( &'a mut self, ) -> ChunkedIter<<<O as View<'a>>::Type as IntoOffsetValuesAndSizes>::Iter, <S as ViewMut<'a>>::Type> ⓘ
Produce a mutable iterator over elements (borrowed slices) of a
Chunked.
§Example
use flatk::*;
let mut s = Chunked::from_offsets(vec![0,3,4,6], vec![1,2,3,4,5,6]);
for i in s.view_mut().iter_mut() {
for j in i.iter_mut() {
*j += 1;
}
}
let mut iter = s.iter();
assert_eq!(vec![2,3,4], iter.next().unwrap().to_vec());
assert_eq!(vec![5], iter.next().unwrap().to_vec());
assert_eq!(vec![6,7], iter.next().unwrap().to_vec());
assert_eq!(None, iter.next());Nested Chunkeds can also be used to create more complex data organization:
use flatk::*;
let mut s0 = Chunked::from_offsets(vec![0,3,4,6,9,11], vec![0,1,2,3,4,5,6,7,8,9,10]);
let mut s1 = Chunked::from_offsets(vec![0,1,4,5], s0);
for mut v0 in s1.view_mut().iter_mut() {
for i in v0.iter_mut() {
for j in i.iter_mut() {
*j += 1;
}
}
}
let v1 = s1.view();
let mut iter1 = v1.iter();
let v0 = iter1.next().unwrap();
let mut iter0 = v0.iter();
assert_eq!(Some(&[1,2,3][..]), iter0.next());
assert_eq!(None, iter0.next());
let v0 = iter1.next().unwrap();
let mut iter0 = v0.iter();
assert_eq!(Some(&[4][..]), iter0.next());
assert_eq!(Some(&[5,6][..]), iter0.next());
assert_eq!(Some(&[7,8,9][..]), iter0.next());
assert_eq!(None, iter0.next());
let v0 = iter1.next().unwrap();
let mut iter0 = v0.iter();
assert_eq!(Some(&[10,11][..]), iter0.next());
assert_eq!(None, iter0.next());Trait Implementations§
Source§impl<'a, S, O> AtomIterator<'a> for Chunked<S, O>where
S: AtomIterator<'a>,
impl<'a, S, O> AtomIterator<'a> for Chunked<S, O>where
S: AtomIterator<'a>,
Source§impl<'a, S, O> AtomMutIterator<'a> for Chunked<S, O>where
S: AtomMutIterator<'a>,
impl<'a, S, O> AtomMutIterator<'a> for Chunked<S, O>where
S: AtomMutIterator<'a>,
type Item = <S as AtomMutIterator<'a>>::Item
type Iter = <S as AtomMutIterator<'a>>::Iter
fn atom_mut_iter(&'a mut self) -> Self::Iter
Source§impl<T, S: CloneWithStorage<T>, O: Clone> CloneWithStorage<T> for Chunked<S, O>
impl<T, S: CloneWithStorage<T>, O: Clone> CloneWithStorage<T> for Chunked<S, O>
type CloneType = Chunked<<S as CloneWithStorage<T>>::CloneType, O>
fn clone_with_storage(&self, storage: T) -> Self::CloneType
Source§impl<'a, S, O> FromIterator<&'a [<S as Set>::Elem]> for Chunked<S, O>
impl<'a, S, O> FromIterator<&'a [<S as Set>::Elem]> for Chunked<S, O>
Source§fn from_iter<T>(iter: T) -> Self
fn from_iter<T>(iter: T) -> Self
Construct a Chunked collection from an iterator over immutable slices.
§Example
use flatk::*;
let v = [&[1,2,3][..], &[4][..], &[5,6][..]];
let s: Chunked::<Vec<_>> = v.iter().cloned().collect();
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3][..]), iter.next());
assert_eq!(Some(&[4][..]), iter.next());
assert_eq!(Some(&[5,6][..]), iter.next());
assert_eq!(None, iter.next());Source§impl<S> FromIterator<Vec<<S as Set>::Elem>> for Chunked<S>
impl<S> FromIterator<Vec<<S as Set>::Elem>> for Chunked<S>
Source§fn from_iter<T>(iter: T) -> Self
fn from_iter<T>(iter: T) -> Self
Construct a Chunked from an iterator over Vec types.
§Example
use flatk::*;
use std::iter::FromIterator;
let s = Chunked::<Vec<_>>::from_iter(vec![vec![1,2,3],vec![4],vec![5,6]].into_iter());
let mut iter = s.iter();
assert_eq!(vec![1,2,3], iter.next().unwrap().to_vec());
assert_eq!(vec![4], iter.next().unwrap().to_vec());
assert_eq!(vec![5,6], iter.next().unwrap().to_vec());
assert_eq!(None, iter.next());Source§impl<'a, S, O> GetIndex<'a, Chunked<S, O>> for &usize
impl<'a, S, O> GetIndex<'a, Chunked<S, O>> for &usize
Source§fn get(self, chunked: &Chunked<S, O>) -> Option<Self::Output>
fn get(self, chunked: &Chunked<S, O>) -> Option<Self::Output>
Get an element of the given Chunked collection.
§Example
use flatk::*;
let v = vec![0, 1, 4, 6];
let data = (1..=6).collect::<Vec<_>>();
let s = Chunked::from_offsets(v.as_slice(), data.view());
assert_eq!(Some(&[1][..]), s.get(&0));
assert_eq!(Some(&[2,3,4][..]), s.get(&1));
assert_eq!(Some(&[5,6][..]), s.get(&2));type Output = <S as Get<'a, Range<usize>>>::Output
Source§impl<'a, S, O> GetIndex<'a, Chunked<S, O>> for Range<usize>
impl<'a, S, O> GetIndex<'a, Chunked<S, O>> for Range<usize>
Source§fn get(self, chunked: &Chunked<S, O>) -> Option<Self::Output>
fn get(self, chunked: &Chunked<S, O>) -> Option<Self::Output>
Get a [begin..end) subview of the given Chunked collection.
§Example
use flatk::*;
let data = (1..=6).collect::<Vec<_>>();
let offsets = vec![1, 2, 5, 7]; // Offsets don't have to start at 0
let s = Chunked::from_offsets(offsets.as_slice(), data.view());
let v = s.get(1..3).unwrap();
assert_eq!(Some(&[2,3,4][..]), v.get(0));
assert_eq!(Some(&[5,6][..]), v.get(1));type Output = Chunked<<S as Get<'a, Range<usize>>>::Output, <O as Get<'a, Range<usize>>>::Output>
Source§impl<'a, S, O> GetIndex<'a, Chunked<S, O>> for usize
impl<'a, S, O> GetIndex<'a, Chunked<S, O>> for usize
Source§fn get(self, chunked: &Chunked<S, O>) -> Option<Self::Output>
fn get(self, chunked: &Chunked<S, O>) -> Option<Self::Output>
Get an element of the given Chunked collection.
§Example
use flatk::*;
let v = vec![0, 1, 4, 6];
let data = (1..=6).collect::<Vec<_>>();
let s = Chunked::from_offsets(v.as_slice(), data.view());
assert_eq!(Some(&[1][..]), s.get(0));
assert_eq!(Some(&[2,3,4][..]), s.get(1));
assert_eq!(Some(&[5,6][..]), s.get(2));type Output = <S as Get<'a, Range<usize>>>::Output
Source§impl<T, O> Index<usize> for Chunked<&[T], O>
impl<T, O> Index<usize> for Chunked<&[T], O>
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Immutably index the Chunked borrowed slice by usize.
Note that this works for chunked collections that are themselves not chunked, since the
item at the index of a doubly chunked collection is itself chunked, which cannot be
represented by a single borrow. For more complex indexing use the get method provided by
the Get trait.
§Example
use flatk::*;
let v = vec![1,2,3,4,5,6,7,8,9,10,11];
let s = Chunked::from_offsets(vec![0,3,4,6,9,11], v.as_slice());
assert_eq!(&[5,6], &s[2]);Source§impl<T, O> Index<usize> for Chunked<&mut [T], O>
impl<T, O> Index<usize> for Chunked<&mut [T], O>
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Immutably index the Chunked mutably borrowed slice by usize.
Note that this works for chunked collections that are themselves not chunked, since the
item at the index of a doubly chunked collection is itself chunked, which cannot be
represented by a single borrow. For more complex indexing use the get method provided by
the Get trait.
§Example
use flatk::*;
let mut v = vec![1,2,3,4,5,6,7,8,9,10,11];
let s = Chunked::from_offsets(vec![0,3,4,6,9,11], v.as_mut_slice());
assert_eq!(&[5,6], &s[2]);Source§impl<T, O> Index<usize> for Chunked<Vec<T>, O>
impl<T, O> Index<usize> for Chunked<Vec<T>, O>
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Get reference to a chunk at the given index.
Note that this works for Chunked collections that are themselves NOT Chunked, since a
chunk of a doubly Chunked collection is itself Chunked, which cannot be represented by
a single borrow. For more complex indexing use the get method provided by the Get
trait.
§Example
use flatk::*;
let v = vec![1,2,3,4,5,6,7,8,9,10,11];
let s = Chunked::from_offsets(vec![0,3,4,6,9,11], v.clone());
assert_eq!(2, (&s[2]).len());
assert_eq!(&[5,6], &s[2]);Source§impl<T, O> IndexMut<usize> for Chunked<&mut [T], O>
impl<T, O> IndexMut<usize> for Chunked<&mut [T], O>
Source§fn index_mut(&mut self, idx: usize) -> &mut Self::Output
fn index_mut(&mut self, idx: usize) -> &mut Self::Output
Mutably index the Chunked mutably borrowed slice by usize.
Note that this works for chunked collections that are themselves not
chunked, since the item at the index of a doubly chunked collection is
itself chunked, which cannot be represented by a single borrow. For more
complex indexing use the get method provided by the Get trait.
§Example
use flatk::*;
let mut v = vec![1,2,3,4,0,0,7,8,9,10,11];
let mut s = Chunked::from_offsets(vec![0,3,4,6,9,11], v.as_mut_slice());
s[2].copy_from_slice(&[5,6]);
assert_eq!(vec![1,2,3,4,5,6,7,8,9,10,11], v);Source§impl<T, O> IndexMut<usize> for Chunked<Vec<T>, O>
impl<T, O> IndexMut<usize> for Chunked<Vec<T>, O>
Source§fn index_mut(&mut self, idx: usize) -> &mut Self::Output
fn index_mut(&mut self, idx: usize) -> &mut Self::Output
Mutably index the Chunked Vec by usize.
Note that this works for chunked collections that are themselves not chunked, since the
item at the index of a doubly chunked collection is itself chunked, which cannot be
represented by a single borrow. For more complex indexing use the get method provided by
the Get trait.
§Example
use flatk::*;
let mut v = vec![1,2,3,4,0,0,7,8,9,10,11];
let mut s = Chunked::from_offsets(vec![0,3,4,6,9,11], v.clone());
s[2].copy_from_slice(&[5,6]);
assert_eq!(vec![1,2,3,4,5,6,7,8,9,10,11], s.into_storage());Source§impl<S> IntoIterator for Chunked<S>
impl<S> IntoIterator for Chunked<S>
Source§impl<'a, S, O> IntoIterator for Chunked<S, O>where
O: IntoOffsetValuesAndSizes + GetOffset,
S: SplitAt + Set + Dummy,
O::Iter: ExactSizeIterator,
impl<'a, S, O> IntoIterator for Chunked<S, O>where
O: IntoOffsetValuesAndSizes + GetOffset,
S: SplitAt + Set + Dummy,
O::Iter: ExactSizeIterator,
Source§impl<S, O> IntoOwnedData for Chunked<S, O>where
S: IntoOwnedData,
impl<S, O> IntoOwnedData for Chunked<S, O>where
S: IntoOwnedData,
type OwnedData = Chunked<<S as IntoOwnedData>::OwnedData, O>
fn into_owned_data(self) -> Self::OwnedData
fn clone_into(self, target: &mut Self::OwnedData)
Source§impl<S, O> IntoParallelIterator for Chunked<S, O>
impl<S, O> IntoParallelIterator for Chunked<S, O>
Source§impl<S: IntoStorage, O> IntoStorage for Chunked<S, O>
impl<S: IntoStorage, O> IntoStorage for Chunked<S, O>
Source§fn into_storage(self) -> Self::StorageType
fn into_storage(self) -> Self::StorageType
Strip all organizational information from this set, returning the underlying storage type.
§Example
use flatk::*;
let v = vec![1,2,3,4,5,6,7,8,9,10,11];
let s0 = Chunked::from_offsets(vec![0,3,4,6,9,11], v.clone());
let s1 = Chunked::from_offsets(vec![0,1,4,5], s0.clone());
assert_eq!(s1.into_storage(), v);
assert_eq!(s0.into_storage(), v);type StorageType = <S as IntoStorage>::StorageType
Source§impl<S, O> IsolateIndex<Chunked<S, O>> for Range<usize>
impl<S, O> IsolateIndex<Chunked<S, O>> for Range<usize>
Source§impl<S, O> IsolateIndex<Chunked<S, O>> for usize
impl<S, O> IsolateIndex<Chunked<S, O>> for usize
Source§impl<S: MapStorage<Out>, O, Out> MapStorage<Out> for Chunked<S, O>
impl<S: MapStorage<Out>, O, Out> MapStorage<Out> for Chunked<S, O>
Source§impl<S, O, L> Push<L> for Chunked<S, O>
impl<S, O, L> Push<L> for Chunked<S, O>
Source§fn push(&mut self, element: L)
fn push(&mut self, element: L)
Push a slice of elements onto this Chunked.
§Examples
use flatk::*;
let mut s = Chunked::<Vec<usize>>::from_offsets(vec![0,1,4], vec![0,1,2,3]);
s.push(vec![4,5]);
let v1 = s.view();
let mut view1_iter = v1.into_iter();
assert_eq!(Some(&[0][..]), view1_iter.next());
assert_eq!(Some(&[1,2,3][..]), view1_iter.next());
assert_eq!(Some(&[4,5][..]), view1_iter.next());
assert_eq!(None, view1_iter.next());use flatk::*;
let mut s = Chunked::from_offsets(vec![0,3,5], vec![1,2,3,4,5]);
assert_eq!(2, s.len());
s.push(&[1,2]);
assert_eq!(3, s.len());Source§impl<S: RemovePrefix, O: RemovePrefix + AsRef<[usize]>> RemovePrefix for Chunked<S, O>
Required for subsets of chunked collections.
impl<S: RemovePrefix, O: RemovePrefix + AsRef<[usize]>> RemovePrefix for Chunked<S, O>
Required for subsets of chunked collections.
Source§fn remove_prefix(&mut self, n: usize)
fn remove_prefix(&mut self, n: usize)
Remove a prefix of size n from a chunked collection.
§Example
use flatk::*;
let mut s = Chunked::<Vec<usize>>::from_offsets(vec![0,1,4,6], vec![0,1,2,3,4,5]);
s.remove_prefix(2);
let mut iter = s.iter();
assert_eq!(Some(&[4,5][..]), iter.next());
assert_eq!(None, iter.next());Source§impl<S, O> Set for Chunked<S, O>
impl<S, O> Set for Chunked<S, O>
Source§fn len(&self) -> usize
fn len(&self) -> usize
Get the number of elements in a Chunked.
§Example
use flatk::*;
let s = Chunked::from_offsets(vec![0,3,4,6], vec![1,2,3,4,5,6]);
assert_eq!(3, s.len());Source§type Atom = <S as Set>::Atom
type Atom = <S as Set>::Atom
Elem.fn is_empty(&self) -> bool
Source§impl<S, O> SplitFirst for Chunked<S, O>
impl<S, O> SplitFirst for Chunked<S, O>
Source§impl<S, O, N> SplitPrefix<N> for Chunked<S, O>
impl<S, O, N> SplitPrefix<N> for Chunked<S, O>
Source§impl<S: Storage, O> Storage for Chunked<S, O>
impl<S: Storage, O> Storage for Chunked<S, O>
Source§fn storage(&self) -> &Self::Storage
fn storage(&self) -> &Self::Storage
Return an immutable reference to the underlying storage type.
§Example
use flatk::*;
let v = vec![1,2,3,4,5,6,7,8,9,10,11];
let s0 = Chunked::from_offsets(vec![0,3,4,6,9,11], v.clone());
let s1 = Chunked::from_offsets(vec![0,1,4,5], s0.clone());
assert_eq!(s1.storage(), &v);
assert_eq!(s0.storage(), &v);type Storage = <S as Storage>::Storage
Source§impl<S: StorageInto<T>, O, T> StorageInto<T> for Chunked<S, O>
Pass through the conversion for structure type Chunked.
impl<S: StorageInto<T>, O, T> StorageInto<T> for Chunked<S, O>
Pass through the conversion for structure type Chunked.
type Output = Chunked<<S as StorageInto<T>>::Output, O>
fn storage_into(self) -> Self::Output
Source§impl<S: StorageMut, O> StorageMut for Chunked<S, O>
impl<S: StorageMut, O> StorageMut for Chunked<S, O>
Source§fn storage_mut(&mut self) -> &mut Self::Storage
fn storage_mut(&mut self) -> &mut Self::Storage
Return a mutable reference to the underlying storage type.
§Example
use flatk::*;
let mut v = vec![1,2,3,4,5,6,7,8,9,10,11];
let mut s0 = Chunked::from_offsets(vec![0,3,4,6,9,11], v.clone());
let mut s1 = Chunked::from_offsets(vec![0,1,4,5], s0.clone());
assert_eq!(s1.storage_mut(), &mut v);
assert_eq!(s0.storage_mut(), &mut v);Source§impl<'a, S: StorageView<'a>, O> StorageView<'a> for Chunked<S, O>
impl<'a, S: StorageView<'a>, O> StorageView<'a> for Chunked<S, O>
Source§fn storage_view(&'a self) -> Self::StorageView
fn storage_view(&'a self) -> Self::StorageView
Return a view to the underlying storage type.
§Example
use flatk::*;
let v = vec![1,2,3,4,5,6,7,8,9,10,11];
let s0 = Chunked::from_offsets(vec![0,3,4,6,9,11], v.clone());
let s1 = Chunked::from_offsets(vec![0,1,4,5], s0.clone());
assert_eq!(s1.storage_view(), v.as_slice());
assert_eq!(s0.storage_view(), v.as_slice());type StorageView = <S as StorageView<'a>>::StorageView
Source§impl<'a, S, O> View<'a> for Chunked<S, O>
impl<'a, S, O> View<'a> for Chunked<S, O>
Source§fn view(&'a self) -> Self::Type
fn view(&'a self) -> Self::Type
Create a contiguous immutable (shareable) view into this set.
§Example
use flatk::*;
let s = Chunked::<Vec<usize>>::from_offsets(vec![0,1,4,6], vec![0,1,2,3,4,5]);
let v1 = s.view();
let v2 = v1.clone();
let mut view1_iter = v1.clone().into_iter();
assert_eq!(Some(&[0][..]), view1_iter.next());
assert_eq!(Some(&[1,2,3][..]), view1_iter.next());
assert_eq!(Some(&[4,5][..]), view1_iter.next());
assert_eq!(None, view1_iter.next());
for (a,b) in v1.into_iter().zip(v2.into_iter()) {
assert_eq!(a,b);
}type Type = Chunked<<S as View<'a>>::Type, <O as View<'a>>::Type>
Source§impl<'a, S, O> ViewIterator<'a> for Chunked<S, O>
impl<'a, S, O> ViewIterator<'a> for Chunked<S, O>
Source§impl<'a, S, O> ViewMut<'a> for Chunked<S, O>
impl<'a, S, O> ViewMut<'a> for Chunked<S, O>
Source§fn view_mut(&'a mut self) -> Self::Type
fn view_mut(&'a mut self) -> Self::Type
Create a contiguous mutable (unique) view into this set.
§Example
use flatk::*;
let mut s = Chunked::<Vec<usize>>::from_offsets(vec![0,1,4,6], vec![0,1,2,3,4,5]);
let mut v1 = s.view_mut();
v1.iter_mut().next().unwrap()[0] = 100;
let mut view1_iter = v1.iter();
assert_eq!(Some(&[100][..]), view1_iter.next());
assert_eq!(Some(&[1,2,3][..]), view1_iter.next());
assert_eq!(Some(&[4,5][..]), view1_iter.next());
assert_eq!(None, view1_iter.next());type Type = Chunked<<S as ViewMut<'a>>::Type, <O as View<'a>>::Type>
Source§impl<'a, S, O> ViewMutIterator<'a> for Chunked<S, O>
impl<'a, S, O> ViewMutIterator<'a> for Chunked<S, O>
impl<S: Copy, O: Copy> Copy for Chunked<S, O>
impl<S, I> DynamicRangeIndexType for Chunked<S, I>
impl<S, O> StructuralPartialEq for Chunked<S, O>
impl<S, I> ValueType for Chunked<S, I>
impl<S: Viewed, I: Viewed> Viewed for Chunked<S, I>
Auto Trait Implementations§
impl<S, O> Freeze for Chunked<S, O>
impl<S, O> RefUnwindSafe for Chunked<S, O>where
O: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, O> Send for Chunked<S, O>
impl<S, O> Sync for Chunked<S, O>
impl<S, O> Unpin for Chunked<S, O>
impl<S, O> UnwindSafe for Chunked<S, O>where
O: UnwindSafe,
S: UnwindSafe,
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<'a, S, I> Get<'a, I> for Swhere
I: GetIndex<'a, S>,
impl<'a, S, I> Get<'a, I> for Swhere
I: GetIndex<'a, S>,
type Output = <I as GetIndex<'a, S>>::Output
fn get(&self, idx: I) -> Option<<I as GetIndex<'a, S>>::Output>
Source§fn at(&self, idx: I) -> Self::Output
fn at(&self, idx: I) -> Self::Output
get that will panic if the equivalent get call is None,
which typically means that the given index is out of bounds. Read moreSource§unsafe fn at_unchecked(&self, idx: I) -> Self::Output
unsafe fn at_unchecked(&self, idx: I) -> Self::Output
Source§impl<S> IntoChunkIterator for S
impl<S> IntoChunkIterator for S
type Item = S
type IterType = ChunkedNIter<S>
Source§fn into_chunk_iter(
self,
chunk_size: usize,
) -> <S as IntoChunkIterator>::IterType
fn into_chunk_iter( self, chunk_size: usize, ) -> <S as IntoChunkIterator>::IterType
chunk_size.
One notable difference between this trait and chunks* methods on slices is that
chunks_iter should panic when the underlying data cannot split into chunk_size sized
chunks exactly.