ChunkedN

Type Alias ChunkedN 

Source
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: usize

Implementations§

Source§

impl<S: Default> ChunkedN<S>

Source

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>

Source

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<T> ChunkedN<Vec<T>>

Source

pub fn reserve(&mut self, new_length: usize)

Source§

impl<T> ChunkedN<Vec<T>>

Source

pub fn resize(&mut self, new_length: usize, default: &[T])
where T: Clone,

Source§

impl<S> ChunkedN<S>

Source

pub fn iter<'a>(&'a self) -> Chunks<S::Type>
where S: View<'a>,

Source

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]>

Source§

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§

type Output = [T]

The returned type after indexing.
Source§

impl<T> Index<usize> for ChunkedN<&mut [T]>

Source§

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§

type Output = [T]

The returned type after indexing.
Source§

impl<T> Index<usize> for ChunkedN<Vec<T>>

Source§

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§

type Output = [T]

The returned type after indexing.
Source§

impl<T> IndexMut<usize> for ChunkedN<&mut [T]>

Source§

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>>

Source§

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>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = <S as IntoChunkIterator>::IterType

Which kind of iterator are we turning this into?
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.

Source§

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>
where S: Set + Push<<S as Set>::Elem>, <S as Set>::Elem: Clone,

Source§

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>

Source§

fn remove_prefix(&mut self, n: usize)

Remove 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.

Source§

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 Elem = Vec<<S as Set>::Elem>

Owned element of the set.
Source§

type Atom = <S as Set>::Atom

The most basic element contained by this collection. If this collection contains other collections, this type should be different than Elem.
Source§

fn is_empty(&self) -> bool

Source§

impl<S: SplitAt + Set> SplitAt for ChunkedN<S>

Source§

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]));
Source§

impl<S, M: Unsigned> SplitPrefix<M> for ChunkedN<S>
where S: SplitAt + Set,

Source§

type Prefix = UniChunked<S, usize>

Source§

fn split_prefix(self) -> Option<(Self::Prefix, Self)>

Split N items from the beginning of the collection. Read more
Source§

impl<S: SwapChunks> SwapChunks for ChunkedN<S>

Source§

fn swap_chunks(&mut self, begin_a: usize, begin_b: usize, chunk_size: usize)

Swap equal sized contiguous chunks in this collection.
Source§

impl<S: Truncate> Truncate for ChunkedN<S>

Source§

fn truncate(&mut self, new_len: usize)

Source§

impl<S, M> UniChunkable<M> for ChunkedN<S>

Source§

impl<'a, S> ViewIterator<'a> for ChunkedN<S>
where S: View<'a>, <S as View<'a>>::Type: SplitAt + Set + Dummy,

Source§

type Item = <S as View<'a>>::Type

Source§

type Iter = Chunks<<S as View<'a>>::Type>

Source§

fn view_iter(&'a self) -> Self::Iter

Source§

impl<'a, S> ViewMutIterator<'a> for ChunkedN<S>
where S: ViewMut<'a>, <S as ViewMut<'a>>::Type: SplitAt + Set + Dummy,

Source§

type Item = <S as ViewMut<'a>>::Type

Source§

type Iter = Chunks<<S as ViewMut<'a>>::Type>

Source§

fn view_mut_iter(&'a mut self) -> Self::Iter

Source§

impl<S> DynamicRangeIndexType for ChunkedN<S>