pub type ChunkedN<S> = UniChunked<S, usize>;Expand description
Define aliases for common uniform chunked types.
Aliased Type§
pub struct ChunkedN<S> {
pub data: S,
pub chunk_size: usize,
}Fields§
§data: S§chunk_size: usizeImplementations§
Source§impl<S: Default> ChunkedN<S>
impl<S: Default> ChunkedN<S>
Sourcepub fn with_stride(n: usize) -> Self
pub fn with_stride(n: usize) -> Self
Create an empty UniChunked collection that groups elements into n
sized chunks.
§Example
use flatk::*;
let mut s = ChunkedN::<Vec<_>>::with_stride(3);
s.push(&[1,2,3][..]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3][..]), iter.next());
assert_eq!(None, iter.next());Source§impl<S: Set> ChunkedN<S>
impl<S: Set> ChunkedN<S>
Sourcepub fn from_flat_with_stride(n: usize, data: S) -> Self
pub fn from_flat_with_stride(n: usize, data: S) -> Self
Create a UniChunked collection that groups the elements of the
original set into uniformly sized groups at compile time.
§Example
use flatk::*;
let s = ChunkedN::from_flat_with_stride(3, vec![1,2,3,4,5,6]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3][..]), iter.next());
assert_eq!(Some(&[4,5,6][..]), iter.next());
assert_eq!(None, iter.next());Source§impl<S> ChunkedN<S>
impl<S> ChunkedN<S>
pub fn iter<'a>(&'a self) -> Chunks<S::Type> ⓘwhere
S: View<'a>,
Sourcepub fn iter_mut<'a>(&'a mut self) -> Chunks<S::Type> ⓘwhere
S: ViewMut<'a>,
pub fn iter_mut<'a>(&'a mut self) -> Chunks<S::Type> ⓘwhere
S: ViewMut<'a>,
Mutably iterate over Chunked data.
§Example
use flatk::*;
let mut s = ChunkedN::from_flat_with_stride(3, vec![1,2,3,4,5,6]);
s.view_mut().isolate(1).copy_from_slice(&[0; 3]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3][..]), iter.next());
assert_eq!(Some(&[0,0,0][..]), iter.next());
assert_eq!(None, iter.next());Trait Implementations§
Source§impl<T> Index<usize> for ChunkedN<&[T]>
impl<T> Index<usize> for ChunkedN<&[T]>
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Immutably index the ChunkedN 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 s = ChunkedN::from_flat_with_stride(3, vec![1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
assert_eq!([7,8,9], s.view()[2]);Source§impl<T> Index<usize> for ChunkedN<&mut [T]>
impl<T> Index<usize> for ChunkedN<&mut [T]>
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Immutably index the ChunkedN 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 s = ChunkedN::from_flat_with_stride(3, vec![1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
assert_eq!([7,8,9], s.view_mut()[2]);Source§impl<T> Index<usize> for ChunkedN<Vec<T>>
impl<T> Index<usize> for ChunkedN<Vec<T>>
Source§fn index(&self, idx: usize) -> &Self::Output
fn index(&self, idx: usize) -> &Self::Output
Index the ChunkedN 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 s = ChunkedN::from_flat_with_stride(3, vec![1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
assert_eq!([7,8,9], s[2]);Source§impl<T> IndexMut<usize> for ChunkedN<&mut [T]>
impl<T> IndexMut<usize> for ChunkedN<&mut [T]>
Source§fn index_mut(&mut self, idx: usize) -> &mut Self::Output
fn index_mut(&mut self, idx: usize) -> &mut Self::Output
Mutably index the ChunkedN 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,0,0,0,10,11,12];
let mut s = ChunkedN::from_flat_with_stride(3, v.as_mut_slice());
s[2].copy_from_slice(&[7,8,9]);
assert_eq!(vec![1,2,3,4,5,6,7,8,9,10,11,12], v);Source§impl<T> IndexMut<usize> for ChunkedN<Vec<T>>
impl<T> IndexMut<usize> for ChunkedN<Vec<T>>
Source§fn index_mut(&mut self, idx: usize) -> &mut Self::Output
fn index_mut(&mut self, idx: usize) -> &mut Self::Output
Mutably index the ChunkedN 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 v = vec![1,2,3,4,5,6,0,0,0,10,11,12];
let mut s = ChunkedN::from_flat_with_stride(3, v);
s[2].copy_from_slice(&[7,8,9]);
assert_eq!(vec![1,2,3,4,5,6,7,8,9,10,11,12], s.into_storage().to_vec());Source§impl<S> IntoIterator for ChunkedN<S>where
S: Set + IntoChunkIterator,
impl<S> IntoIterator for ChunkedN<S>where
S: Set + IntoChunkIterator,
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Convert a ChunkedN collection into an iterator over grouped elements.
§Example
use flatk::*;
let mut s = ChunkedN::from_flat_with_stride(3, vec![1,2,3,4,5,6]);
let mut iter = s.view().into_iter();
assert_eq!(Some(&[1,2,3][..]), iter.next());
assert_eq!(Some(&[4,5,6][..]), iter.next());
assert_eq!(None, iter.next());Source§type Item = <S as IntoChunkIterator>::Item
type Item = <S as IntoChunkIterator>::Item
Source§type IntoIter = <S as IntoChunkIterator>::IterType
type IntoIter = <S as IntoChunkIterator>::IterType
Source§impl<S: Set + SwapChunks> PermuteInPlace for ChunkedN<S>
This is a more general implementation of permute in place that is also used for slices.
impl<S: Set + SwapChunks> PermuteInPlace for ChunkedN<S>
This is a more general implementation of permute in place that is also used for slices.
Source§fn permute_in_place(&mut self, permutation: &[usize], seen: &mut [bool])
fn permute_in_place(&mut self, permutation: &[usize], seen: &mut [bool])
Permute this collection according to the given permutation.
The given permutation must have length equal to this collection.
The slice seen is provided to keep track of which elements have already been seen.
seen is assumed to be initialized to false and have length equal or
larger than this collection.
Source§impl<S> Push<&[<S as Set>::Elem]> for ChunkedN<S>
impl<S> Push<&[<S as Set>::Elem]> for ChunkedN<S>
Source§fn push(&mut self, element: &[<S as Set>::Elem])
fn push(&mut self, element: &[<S as Set>::Elem])
Push a grouped element onto the ChunkedN type.
§Example
use flatk::*;
let mut s = ChunkedN::from_flat_with_stride(3, vec![1,2,3]);
s.push(&[4,5,6]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3][..]), iter.next());
assert_eq!(Some(&[4,5,6][..]), iter.next());
assert_eq!(None, iter.next());Source§impl<S: RemovePrefix> RemovePrefix for ChunkedN<S>
impl<S: RemovePrefix> RemovePrefix for ChunkedN<S>
Source§fn remove_prefix(&mut self, n: usize)
fn remove_prefix(&mut self, n: usize)
n elements from the beginning.Source§impl<S: Set> Set for ChunkedN<S>
An implementation of Set for a UniChunked collection of any type that
can be grouped into sub-elements whose size is determined at run-time.
impl<S: Set> Set for ChunkedN<S>
An implementation of Set for a UniChunked collection of any type that
can be grouped into sub-elements whose size is determined at run-time.
Source§fn len(&self) -> usize
fn len(&self) -> usize
Compute the length of this UniChunked collection as the number of
grouped elements in the set.
§Example
use flatk::*;
let s = ChunkedN::from_flat_with_stride(2, vec![0,1,2,3,4,5]);
assert_eq!(s.len(), 3);
let s = ChunkedN::from_flat_with_stride(3, vec![0,1,2,3,4,5]);
assert_eq!(s.len(), 2);Source§type Atom = <S as Set>::Atom
type Atom = <S as Set>::Atom
Elem.fn is_empty(&self) -> bool
Source§impl<S: SplitAt + Set> SplitAt for ChunkedN<S>
impl<S: SplitAt + Set> SplitAt for ChunkedN<S>
Source§fn split_at(self, mid: usize) -> (Self, Self)
fn split_at(self, mid: usize) -> (Self, Self)
Split the current set into two distinct sets at the given index mid.
§Example
use flatk::*;
let s = ChunkedN::from_flat_with_stride(2, vec![0,1,2,3]);
let (l, r) = s.split_at(1);
assert_eq!(l, ChunkedN::from_flat_with_stride(2, vec![0,1]));
assert_eq!(r, ChunkedN::from_flat_with_stride(2, vec![2,3]));