Struct flatk::ClumpedOffsets[][src]

pub struct ClumpedOffsets<O = Vec<usize>> {
    pub chunk_offsets: Offsets<O>,
    pub offsets: Offsets<O>,
}

A collection of clumped offsets into another collection.

A version of Offsets that combines consecutive equidistant offsets.

Example

To see the correspondence between Offsets and ClumpedOffsets, consider the following example

    use flatk::{Offsets, ClumpedOffsets};

    // with `Offsets` we might have offsets like
    let off = Offsets::new(vec![0, 3, 6, 9, 12, 16, 20, 24, 27, 30, 33, 36, 39]);
    // which can be represented in `ClumpedOffsets` as
    let clumped_off = ClumpedOffsets::new(vec![0, 4, 7, 12], vec![0, 12, 24, 39]);
    // Note that ClumpedOffsets would be more compact if the triplets could be combined,
    // which would require reorganizing the data indexed by the offsets.

    assert_eq!(ClumpedOffsets::from(off), clumped_off);

ClumpedOffsets can be a lot more memory efficient when a chunked collection is mostly uniformly chunked. However, in the worst case, when each consecutive stride is different, this representation can be three times the size of standard Offsets.

Fields

chunk_offsets: Offsets<O>offsets: Offsets<O>

Implementations

impl<O: AsRef<[usize]>> ClumpedOffsets<O>[src]

pub fn double_ended_sizes(&self) -> DEUnclumpedSizes<'_>[src]

An iterator over effective (unclumped) sizes that implements DoubleEndedIterator.

Notes

This iterator is used to implement the parallel sizes iterator to enable parallel iteration of Chunked types with clumped offsets. However, this iterator can also be used as is for efficient backwards iteration.

pub fn par_offset_values_and_sizes(
    &self
) -> ParUnclumpedOffsetValuesAndSizes<'_>
[src]

Parallel version of offsets_and_sizes.

impl<O: AsRef<[usize]>> ClumpedOffsets<O>[src]

pub fn first_chunk_offset_value(&self) -> usize[src]

pub fn last_chunk_offset_value(&self) -> usize[src]

pub fn num_clump_offsets(&self) -> usize[src]

Returns the number of clump offsets represented by ClumpedOffsets.

This is typically significantly smaller than self.num_offsets().

pub fn num_clumps(&self) -> usize[src]

Returns the number of clumps represented by ClumpedOffsets.

pub fn clump_stride(&self, index: usize) -> usize[src]

Compute the stride of the clump at the given index.

Panics

This function panics if index is greater than or equal to self.num_clumps().

impl<O: AsRef<[usize]>> ClumpedOffsets<O>[src]

pub fn sizes(&self) -> UnclumpedSizes<'_>

Notable traits for UnclumpedSizes<'a>

impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
[src]

An iterator over effective (unclumped) sizes producing an increment for advancing the data pointer.

This helps for implementing iterators over Chunked types.

Example

    use flatk::{Offsets, ClumpedOffsets};

    let off = Offsets::new(vec![0, 3, 6, 9, 12, 16, 20, 24, 27, 30, 33, 36, 39]);
    let clumped = ClumpedOffsets::from(off);
    let mut clumped_iter = clumped.sizes();
    for _ in 0..4 {
        assert_eq!(clumped_iter.next(), Some(3));
    }
    for _ in 0..3 {
        assert_eq!(clumped_iter.next(), Some(4));
    }
    for _ in 0..5 {
        assert_eq!(clumped_iter.next(), Some(3));
    }
    assert_eq!(clumped_iter.next(), None);

pub fn iter<'a>(&'a self) -> impl Iterator<Item = usize> + 'a[src]

An iterator over unclumped offsets.

This is equivalent to iterating over Offsets after conversion, but it doesn't require any additional allocations.

pub fn values(&self) -> UnclumpedOffsetValues<'_>

Notable traits for UnclumpedOffsetValues<'a>

impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
[src]

An iterator over unclumped offsets.

This is equivalent to iterating over Offsets after conversion, but it doesn't require any additional allocations.

impl<O: AsRef<[usize]>> ClumpedOffsets<O>[src]

pub fn new(chunk_offsets: O, offsets: O) -> Self[src]

Construct new ClumpedOffsets from a given valid set of clumped offsets represented as an array of usizes.

It is possible to create an invalid ClumpedOffsets struct using this constructor, however it is safe.

Panics

This function will panic if either chunk_offsets or offsets is empty.

pub unsafe fn from_raw(chunk_offsets: O, offsets: O) -> Self[src]

An unchecked version of the new constructor.

Safety

Calling this function with empty chunk_offsets or offsets may cause undefined behaviour in safe APIs.

Trait Implementations

impl Clear for ClumpedOffsets[src]

impl<O: Clone> Clone for ClumpedOffsets<O>[src]

impl<O: Copy> Copy for ClumpedOffsets<O>[src]

impl<O: Debug> Debug for ClumpedOffsets<O>[src]

impl Default for ClumpedOffsets<Vec<usize>>[src]

A default set of offsets must allocate.

impl<O: Dummy> Dummy for ClumpedOffsets<O>[src]

A dummy set of offsets will not allocate, but the resulting type does not correspond to valid offsets.

unsafe fn dummy() -> Self[src]

This function creates an invalid ClumpedOffsets, but it does not allocate.

impl<O: AsRef<[usize]> + Set> From<ClumpedOffsets<O>> for Offsets[src]

fn from(clumped_offsets: ClumpedOffsets<O>) -> Self[src]

Convert ClumpedOffsets into owned Offsets.

This function causes allocations.

impl<O: AsRef<[usize]> + Set> From<Offsets<O>> for ClumpedOffsets[src]

fn from(offsets: Offsets<O>) -> Self[src]

Convert Offsets to owned ClumpedOffsets.

This function causes allocations.

Example

use flatk::{Offsets, ClumpedOffsets};
let offsets = Offsets::new(vec![0, 3, 6, 9, 12, 16, 20, 24, 27, 30, 33, 36, 39]);
let clumped_offsets = ClumpedOffsets::new(vec![0, 4, 7, 12], vec![0, 12, 24, 39]);
assert_eq!(ClumpedOffsets::from(offsets), clumped_offsets);

impl FromIterator<usize> for ClumpedOffsets[src]

impl<'a, O> GetIndex<'a, ClumpedOffsets<O>> for usize where
    ClumpedOffsets<O>: GetOffset
[src]

type Output = usize

impl<'a, O> GetIndex<'a, ClumpedOffsets<O>> for &usize where
    ClumpedOffsets<O>: GetOffset
[src]

type Output = usize

impl<O: AsRef<[usize]>> GetOffset for ClumpedOffsets<O>[src]

unsafe fn offset_value_unchecked(&self, index: usize) -> usize[src]

A version of offset_value without bounds checking.

Safety

It is assumed that index is strictly less than self.num_offsets().

fn num_offsets(&self) -> usize[src]

Get the total number of offsets.

This is one more than the number of chunks represented.

impl<O> IndexRange for ClumpedOffsets<O> where
    Self: GetOffset
[src]

fn index_range(&self, range: Range<usize>) -> Option<Range<usize>>[src]

Return the [begin..end) bound of the chunk at the given index.

impl<'a> IntoOffsetValuesAndSizes for ClumpedOffsets<&'a [usize]>[src]

impl<O: IntoOwned> IntoOwned for ClumpedOffsets<O>[src]

type Owned = ClumpedOffsets<O::Owned>

impl<'a> IntoParOffsetValuesAndSizes for ClumpedOffsets<&'a [usize]>[src]

type ParIter = ParUnclumpedOffsetValuesAndSizes<'a>

fn into_par_offset_values_and_sizes(self) -> Self::ParIter[src]

Returns a parallel iterator over chunk offsets and sizes represented by the stored Offsets.

impl<'a> IntoSizes for ClumpedOffsets<&'a [usize]>[src]

type Iter = UnclumpedSizes<'a>

fn into_sizes(self) -> UnclumpedSizes<'a>

Notable traits for UnclumpedSizes<'a>

impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
[src]

Returns an iterator over chunk sizes represented by the stored ClumpedOffsets.

impl<'a> IntoValues for ClumpedOffsets<&'a [usize]>[src]

type Iter = UnclumpedOffsetValues<'a>

fn into_values(self) -> UnclumpedOffsetValues<'a>

Notable traits for UnclumpedOffsetValues<'a>

impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
[src]

Returns an iterator over offset values represented by the stored Offsets.

impl<O> IsolateIndex<ClumpedOffsets<O>> for usize where
    ClumpedOffsets<O>: GetOffset
[src]

type Output = usize

impl<O: PartialEq> PartialEq<ClumpedOffsets<O>> for ClumpedOffsets<O>[src]

impl<O: RemovePrefix + Set> RemovePrefix for ClumpedOffsets<O>[src]

impl<O: Reserve> Reserve for ClumpedOffsets<O>[src]

impl<O: AsRef<[usize]>> Set for ClumpedOffsets<O>[src]

type Elem = usize

Owned element of the set.

type Atom = usize

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

impl<'a> SplitOffsetsAt for ClumpedOffsets<&'a [usize]>[src]

fn split_offsets_with_intersection_at(
    self,
    mid_off: usize
) -> (ClumpedOffsets<&'a [usize]>, ClumpedOffsets<&'a [usize]>, usize)
[src]

Same as split_offsets_at, but in addition, return the offset of the middle element (intersection): this is the value offsets[mid] - offsets[0].

Panics

Calling this function with an empty slice or with mid greater than or equal to its length will cause a panic.

This function will also panic when trying to split a clump since the offsets cannot be modified or created.

fn split_offsets_at(
    self,
    mid: usize
) -> (ClumpedOffsets<&'a [usize]>, ClumpedOffsets<&'a [usize]>)
[src]

Splits clumped offsets at the given index into two such that each resulting ClumpedOffsets is valid. This means that the element at index mid is shared between the two outputs.

Panics

Calling this function with an empty slice or with mid greater than or equal to its length will cause a panic.

This function will also panic when trying to split a clump since the offsets cannot be modified or created.

impl<O> StructuralPartialEq for ClumpedOffsets<O>[src]

impl<O: Truncate> Truncate for ClumpedOffsets<O>[src]

impl<'a, O: AsRef<[usize]>> View<'a> for ClumpedOffsets<O>[src]

type Type = ClumpedOffsets<&'a [usize]>

impl<'a, O: AsMut<[usize]>> ViewMut<'a> for ClumpedOffsets<O>[src]

type Type = ClumpedOffsets<&'a mut [usize]>

impl<O: Viewed> Viewed for ClumpedOffsets<O>[src]

Auto Trait Implementations

impl<O> RefUnwindSafe for ClumpedOffsets<O> where
    O: RefUnwindSafe
[src]

impl<O> Send for ClumpedOffsets<O> where
    O: Send
[src]

impl<O> Sync for ClumpedOffsets<O> where
    O: Sync
[src]

impl<O> Unpin for ClumpedOffsets<O> where
    O: Unpin
[src]

impl<O> UnwindSafe for ClumpedOffsets<O> where
    O: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> AsSlice<T> for T[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<'a, S, I> Get<'a, I> for S where
    I: GetIndex<'a, S>, 
[src]

type Output = <I as GetIndex<'a, S>>::Output

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<S, I> Isolate<I> for S where
    I: IsolateIndex<S>, 
[src]

type Output = <I as IsolateIndex<S>>::Output

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.