Struct flatk::UniChunked[][src]

pub struct UniChunked<S, N> {
    pub data: S,
    pub chunk_size: N,
}
Expand description

UniChunked Assigns a stride N to the specified collection.

Example

use flatk::*;
let s = Chunked2::from_flat(vec![1,2,3,4,5,6]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2]), iter.next());
assert_eq!(Some(&[3,4]), iter.next());
assert_eq!(Some(&[5,6]), iter.next());
assert_eq!(None, iter.next());

Fields

data: Schunk_size: N

Implementations

Create a UniChunked collection from a Vec of arrays.

Example
use flatk::*;
let v = vec![[1,2,3],[4,5,6],[7,8,9]];
let c = Chunked3::from_array_vec(v);
assert_eq!(c.data(), &vec![1,2,3,4,5,6,7,8,9]);

Create a UniChunked collection from a slice of arrays.

Example
use flatk::*;
let v = vec![[1,2,3],[4,5,6],[7,8,9]];
let c = Chunked3::from_array_vec(v.clone());
assert_eq!(c.data(), &[1,2,3,4,5,6,7,8,9]);

Create a UniChunked collection from a mutable slice of arrays.

Example
use flatk::*;
let mut v = vec![[1,2,3],[4,5,6],[7,8,9]];
let c = Chunked3::from_array_slice_mut(v.as_mut_slice());
assert_eq!(c.data(), &mut [1,2,3,4,5,6,7,8,9]);

Convert this UniChunked collection into arrays.

Example
use flatk::*;
let mut v = vec![[1,2,3],[4,5,6],[7,8,9]];

// Convert to and from a `Vec` of arrays.
let v_new = Chunked3::from_array_vec(v.clone()).into_arrays();
assert_eq!(v.clone(), v_new);

// Convert to and from an immutable slice of arrays.
let v_new = Chunked3::from_array_slice(v.as_slice()).into_arrays();
assert_eq!(v.as_slice(), v_new);

// Convert to and from a mutable slice of arrays.
let mut v_exp = v.clone();
let v_result = Chunked3::from_array_slice_mut(v.as_mut_slice()).into_arrays();
assert_eq!(v_exp.as_mut_slice(), v_result);

Get a immutable reference to the underlying data.

Example
use flatk::*;
let v = vec![1,2,3,4,5,6];
let s = Chunked3::from_flat(v.clone());
assert_eq!(&v, s.data());

Get a mutable reference to the underlying data.

Example
use flatk::*;
let mut v = vec![1,2,3,4,5,6];
let mut s = Chunked3::from_flat(v.clone());
v[2] = 100;
s.data_mut()[2] = 100;
assert_eq!(&v, s.data());

Create an empty UniChunked collection that groups elements into N sized chunks.

Example
use flatk::*;
let mut s = Chunked3::<Vec<usize>>::new();
assert_eq!(s, Chunked3::from_flat(Vec::new()));
s.push([1,2,3]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3]), iter.next());
assert_eq!(None, iter.next());

Create a UniChunked collection that groups the elements of the original set into uniformly sized groups at compile time.

Example
use flatk::*;
let s = Chunked3::from_flat(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());

Convert this UniChunked collection into its inner representation.

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());

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());

This function panics if src has doesn’t have a length equal to self.len()*N::value().

This function panics if src has doesn’t have a length equal to self.len()*N::value().

This function panics if src has doesn’t have a length equal to self.len().

This function panics if src has doesn’t have a length equal to self.len().

Extend this chunked Vec from a slice of arrays.

Example
use flatk::*;
let mut s = Chunked2::from_flat(vec![0,1,2,3]);
s.extend_from_slice(&[[4,5], [6,7]]);
assert_eq!(s.data(), &vec![0,1,2,3,4,5,6,7]);

Produces an iterator over borrowed grouped elements of UniChunked.

Examples

The following is a simple test for iterating over a uniformly organized Vec.

use flatk::*;
let mut s = UniChunked::<_, U2>::from_flat(vec![1,2,3,4]);
let mut iter = s.iter();
assert_eq!(Some(&[1,2]), iter.next());
assert_eq!(Some(&[3,4]), iter.next());
assert_eq!(None, iter.next());

A more complex example consists of data organized as a nested UniChunked.

use flatk::*;
let s0 = UniChunked::<_, U2>::from_flat(vec![1,2, 3,4, 5,6, 7,8, 9,10, 11,12]);
let s1 = UniChunked::<_, U3>::from_flat(s0);
let mut iter1 = s1.iter();
let mut s0 = iter1.next().unwrap();
let mut iter0 = s0.iter();
assert_eq!(Some(&[1,2]), iter0.next());
assert_eq!(Some(&[3,4]), iter0.next());
assert_eq!(Some(&[5,6]), iter0.next());
assert_eq!(None, iter0.next());
let s0 = iter1.next().unwrap();
let mut iter0 = s0.iter();
assert_eq!(Some(&[7,8]), iter0.next());
assert_eq!(Some(&[9,10]), iter0.next());
assert_eq!(Some(&[11,12]), iter0.next());
assert_eq!(None, iter0.next());

Produces an iterator over mutably borrowed grouped elements of UniChunked.

Examples

The following example shows a simple modification of a uniformly organized Vec.

use flatk::*;
let mut s = UniChunked::<_, U2>::from_flat(vec![0,1,2,3]);
for i in s.iter_mut() {
    i[0] += 1;
    i[1] += 1;
}
let mut iter = s.iter();
assert_eq!(Some(&[1,2]), iter.next());
assert_eq!(Some(&[3,4]), iter.next());
assert_eq!(None, iter.next());

Nested UniChunkeds can also be modified as follows:

use flatk::*;
let mut s0 = UniChunked::<_, U2>::from_flat(vec![1,2, 3,4, 5,6, 7,8, 9,10, 11,12]);
let mut s1 = UniChunked::<_, U3>::from_flat(s0);
for mut i in s1.iter_mut() {
    for j in i.iter_mut() {
        j[0] += 1;
        j[1] += 2;
    }
}
let mut iter1 = s1.iter();
let s0 = iter1.next().unwrap();
let mut iter0 = s0.iter();
assert_eq!(Some(&[2,4]), iter0.next());
assert_eq!(Some(&[4,6]), iter0.next());
assert_eq!(Some(&[6,8]), iter0.next());
assert_eq!(None, iter0.next());
let s0 = iter1.next().unwrap();
let mut iter0 = s0.iter();
assert_eq!(Some(&[8,10]), iter0.next());
assert_eq!(Some(&[10,12]), iter0.next());
assert_eq!(Some(&[12,14]), iter0.next());
assert_eq!(None, iter0.next());

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

Performs the conversion.

Get the size of each chunk in this collection.

Remove all elements from the current set without necessarily deallocating the space previously used. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Constructs a potentially invalid instance of a type. Read more

Extend a UniChunked collection from an iterator over set elements.

Example
use flatk::*;

let v = vec![[1,2,3],[4,5,6]];
let mut s = Chunked3::from_array_vec(v);

let more = vec![[7,8,9],[10,11,12]];
s.extend(more.iter().cloned());
let mut iter = s.iter();
assert_eq!(Some(&[1,2,3]), iter.next());
assert_eq!(Some(&[4,5,6]), iter.next());
assert_eq!(Some(&[7,8,9]), iter.next());
assert_eq!(Some(&[10,11,12]), iter.next());
assert_eq!(None, iter.next());

We can do this with nested chunked types, although the we would need to first convert the incoming iterator into an appropriate chunked type, in this case it is Chunked2<[i32; 4]>.

use flatk::*;

let v = vec![[1i32,2],[3,4],[5,6],[7,8]];
let mut s = Chunked2::from_flat(Chunked2::from_array_vec(v));

let more = Chunked2::from_flat(Chunked2::from_array_vec(vec![[9, 10], [11, 12]]));
s.extend(more.into_iter());
let mut iter = s.iter().map(|i| i.into_arrays());
assert_eq!(Some(&[[1,2], [3,4]]), iter.next());
assert_eq!(Some(&[[5,6], [7,8]]), iter.next());
assert_eq!(Some(&[[9,10], [11,12]]), iter.next());
assert_eq!(None, iter.next());

In the wake of const-generics, this will become a whole lot more ergonomic.

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Construct a UniChunked collection from an iterator that produces chunked elements.

Example
use flatk::*;
let v = vec![[1,2,3],[4,5,6]];
let s: Chunked3::<Vec<usize>> = v.into_iter().collect();
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());

Get a statically sized subview of the given UniChunked collection.

Gets the value in the set at this index. Read more

Get an element of the given UniChunked collection.

Gets the value in the set at this index. Read more

Get an element of the given UniChunked collection.

Gets the value in the set at this index. Read more

Get a [begin..end) subview of the given UniChunked collection.

Gets the value in the set at this index. Read more

Get an element of the given ChunkedN collection.

Gets the value in the set at this index. Read more

Get a [begin..end) subview of the given ChunkedN collection.

Gets the value in the set at this index. Read more

Index the UniChunked 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 = Chunked3::from_flat(vec![1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
assert_eq!([7,8,9], s[2]);

The returned type after indexing.

Immutably index the UniChunked 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 = Chunked3::from_flat(vec![1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
assert_eq!([7,8,9], s.view()[2]);

The returned type after indexing.

Immutably index the UniChunked 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 = Chunked3::from_flat(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]);

The returned type after indexing.

Mutably index the UniChunked 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 = Chunked3::from_flat(v);
s[2] = [7,8,9];
assert_eq!(vec![1,2,3,4,5,6,7,8,9,10,11,12], s.into_storage().to_vec());

Mutably index the UniChunked 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 = Chunked3::from_flat(v.as_mut_slice());
s[2] = [7,8,9];
assert_eq!(vec![1,2,3,4,5,6,7,8,9,10,11,12], v);

Convert a UniChunked collection into an iterator over grouped elements.

Example
use flatk::*;
let mut s = UniChunked::<_, U3>::from_flat(vec![1,2,3,4,5,6]);
let mut iter = s.into_iter();
assert_eq!(Some([1,2,3]), iter.next());
assert_eq!(Some([4,5,6]), iter.next());
assert_eq!(None, iter.next());

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Convert this UniChunked collection to an owned one.

Example
use flatk::*;
let v = vec![1,2,3,4,5,6];
let s_view = UniChunked::<_, U3>::from_flat(v.as_slice());
let s_owned = UniChunked::<_, U3>::from_flat(v.clone());
assert_eq!(s_view.into_owned(), s_owned);

Convert a UniChunked collection into a parallel iterator over grouped elements.

The type of item that the parallel iterator will produce.

The parallel iterator type that will be created.

This function should panic if this collection length is not a multiple of N. Read more

Simply call this method for all types that implement SplitPrefix<N>.

Strip away the uniform organization of the underlying data, and return the underlying data.

Attempts to isolate a value in the given set at this index. Read more

Attempts to isolate a value in the given set at this index. Read more

Isolate a chunk of the given UniChunked collection.

Attempts to isolate a value in the given set at this index. Read more

Isolate a [begin..end) range of the given UniChunked collection.

Attempts to isolate a value in the given set at this index. Read more

Isolate a chunk of the given ChunkedN collection.

Attempts to isolate a value in the given set at this index. Read more

Isolate a [begin..end) range of the given ChunkedN collection.

Attempts to isolate a value in the given set at this index. Read more

Map the underlying storage type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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.

Push a grouped element onto the UniChunked type. The pushed element must have exactly N sub-elements.

Example
use flatk::*;
let mut s = UniChunked::<_, U3>::from_flat(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());

Push a chunk with size N.

Required for building Subsets of UniChunked types.

Remove n elements from the beginning.

An implementation of Set for a UniChunked collection of any type that can be grouped as N sub-elements.

Compute the length of this UniChunked collection as the number of grouped elements in the set.

Example
use flatk::*;
let s = UniChunked::<_, U2>::from_flat(vec![0,1,2,3,4,5]);
assert_eq!(s.len(), 3);
let s = UniChunked::<_, U3>::from_flat(vec![0,1,2,3,4,5]);
assert_eq!(s.len(), 2);

Owned element of the set.

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

Split the current set into two distinct sets at the given index mid.

Example
use flatk::*;
let s = Chunked2::from_flat(vec![0,1,2,3]);
let (l, r) = s.split_at(1);
assert_eq!(l, Chunked2::from_flat(vec![0,1]));
assert_eq!(r, Chunked2::from_flat(vec![2,3]));

Split off the first element without checking if one exists. Read more

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

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,12];
let mut s0 = Chunked2::from_flat(v.clone());
let s1 = ChunkedN::from_flat_with_stride(3, s0.clone());
assert_eq!(s1.storage(), &v);
assert_eq!(s0.storage(), &v);
assert_eq!(s0.view_mut().storage(), v.as_slice());

Pass through the conversion for structure type UniChunked.

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,12];
let mut s0 = Chunked2::from_flat(v.clone());
let mut s1 = ChunkedN::from_flat_with_stride(3, s0.clone());
assert_eq!(s1.storage_mut(), &mut v);
assert_eq!(s0.storage_mut(), &mut v);

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,12];
let s0 = Chunked2::from_flat(v.clone());
let s1 = ChunkedN::from_flat_with_stride(3, s0.clone());
assert_eq!(s1.storage_view(), v.as_slice());
assert_eq!(s0.storage_view(), v.as_slice());

Swap equal sized contiguous chunks in this collection.

Create a UniChunked contiguous immutable (shareable) view into the underlying collection.

Example
use flatk::*;
let s = UniChunked::<_, U2>::from_flat(vec![0,1,2,3]);
let v1 = s.view(); // s is now inaccessible.
let v2 = v1.clone();
let mut view1_iter = v1.iter();
assert_eq!(Some(&[0,1]), view1_iter.next());
assert_eq!(Some(&[2,3]), view1_iter.next());
assert_eq!(None, view1_iter.next());
for ((a, b), c) in v1.iter().zip(v2.iter()).zip(s.iter()) {
    assert_eq!(a,b);
    assert_eq!(b,c);
}

Create a UniChunked contiguous mutable (unique) view into the underlying collection.

Example
use flatk::*;
let mut s = Chunked2::from_flat(vec![0,1,2,3]);
let mut v = s.view_mut();
{
   v.iter_mut().next().unwrap()[0] = 100;
}
let mut view_iter = v.iter();
assert_eq!(Some(&[100,1]), view_iter.next());
assert_eq!(Some(&[2,3]), view_iter.next());
assert_eq!(None, view_iter.next());

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Return a value at the given index. This is provided as the checked version of get that will panic if the equivalent get call is None, which typically means that the given index is out of bounds. Read more

Return a value at the given index. Read more

Performs the conversion.

Produce a chunk iterator with the given stride 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. Read more

Unchecked version of isolate. Read more

Return a value at the given index. This is provided as the checked version of try_isolate that will panic if the equivalent try_isolate call is None, which typically means that the given index is out of bounds. Read more

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.