ClumpedOffsets

Struct ClumpedOffsets 

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

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§

Source§

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

Source

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

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.

Source

pub fn par_offset_values_and_sizes( &self, ) -> ParUnclumpedOffsetValuesAndSizes<'_>

Parallel version of offsets_and_sizes.

Source§

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

Source

pub fn first_chunk_offset_value(&self) -> usize

Source

pub fn last_chunk_offset_value(&self) -> usize

Source

pub fn num_clump_offsets(&self) -> usize

Returns the number of clump offsets represented by ClumpedOffsets.

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

Source

pub fn num_clumps(&self) -> usize

Returns the number of clumps represented by ClumpedOffsets.

Source

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

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

Source§

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

Source

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

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

pub fn iter(&self) -> impl Iterator<Item = usize> + '_

An iterator over unclumped offsets.

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

Source

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

An iterator over unclumped offsets.

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

Source§

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

Source

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

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.

Source

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

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§

Source§

impl Clear for ClumpedOffsets

Source§

fn clear(&mut self)

Remove all elements from the current set without necessarily deallocating the space previously used.
Source§

impl<O: Clone> Clone for ClumpedOffsets<O>

Source§

fn clone(&self) -> ClumpedOffsets<O>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<O: Debug> Debug for ClumpedOffsets<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClumpedOffsets<Vec<usize>>

A default set of offsets must allocate.

Source§

fn default() -> Self

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

impl<O: Dummy> Dummy for ClumpedOffsets<O>

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

Source§

unsafe fn dummy() -> Self

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

Source§

impl Extend<(usize, usize)> for ClumpedOffsets

Source§

fn extend<T: IntoIterator<Item = (usize, usize)>>(&mut self, iter: T)

Extend this set of clumped offsets with a given iterator over chunk-offset and offset pairs.

This operation automatically shifts the merged offsets in the iterator to start from the last offset in self.

Note that there will be 1 less offset added to self than produced by iter since the first offset is only used to determine the relative magnitude of the rest and corresponds to the last offset in self.

Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

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

Source§

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

Convert ClumpedOffsets into owned Offsets.

This function causes allocations.

Source§

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

Source§

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

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

impl FromIterator<usize> for ClumpedOffsets

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = usize>,

Creates a value from an iterator. Read more
Source§

impl<'a, O> GetIndex<'a, ClumpedOffsets<O>> for &usize

Source§

type Output = usize

Source§

fn get(self, clumped_offsets: &ClumpedOffsets<O>) -> Option<Self::Output>

Gets the value in the set at this index.
Source§

unsafe fn at_unchecked(self, set: &S) -> Self::Output
where Self: Sized,

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

impl<'a, O> GetIndex<'a, ClumpedOffsets<O>> for usize

Source§

type Output = usize

Source§

fn get(self, clumped_offsets: &ClumpedOffsets<O>) -> Option<Self::Output>

Gets the value in the set at this index.
Source§

unsafe fn at_unchecked(self, set: &S) -> Self::Output
where Self: Sized,

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

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

Source§

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

A version of offset_value without bounds checking.

§Safety

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

Source§

fn num_offsets(&self) -> usize

Get the total number of offsets.

This is one more than the number of chunks represented.

Source§

fn chunk_len(&self, chunk_index: usize) -> usize

Get the length of the chunk at the given index. Read more
Source§

unsafe fn chunk_len_unchecked(&self, chunk_index: usize) -> usize

Get the length of the chunk at the given index without bounds checking. Read more
Source§

fn offset_value(&self, index: usize) -> usize

Return the raw value corresponding to the offset at the given index. Read more
Source§

fn offset(&self, index: usize) -> usize

Returns the offset at the given index with respect to (minus) the first offset. This function returns the total length of data if index is equal to self.len(). Read more
Source§

unsafe fn offset_unchecked(&self, index: usize) -> usize

A version of offset without bounds checking. Read more
Source§

fn last_offset(&self) -> usize

Get the last offset. Read more
Source§

fn first_offset(&self) -> usize

Get the first offset. Read more
Source§

fn last_offset_value(&self) -> usize

Get the raw value corresponding to the last offset.
Source§

fn first_offset_value(&self) -> usize

Get the raw value corresponding to the first offset.
Source§

impl<O> IndexRange for ClumpedOffsets<O>
where Self: GetOffset,

Source§

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

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

Source§

unsafe fn index_range_unchecked(&self, range: Range<usize>) -> Range<usize>

Safety Read more
Source§

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

Source§

impl<O: IntoOwned> IntoOwned for ClumpedOffsets<O>

Source§

type Owned = ClumpedOffsets<<O as IntoOwned>::Owned>

Source§

fn into_owned(self) -> Self::Owned

Source§

fn clone_into(self, target: &mut Self::Owned)

Source§

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

Source§

fn into_par_offset_values_and_sizes(self) -> Self::ParIter

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

Source§

type ParIter = ParUnclumpedOffsetValuesAndSizes<'a>

Source§

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

Source§

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

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

Source§

type Iter = UnclumpedSizes<'a>

Source§

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

Source§

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

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

Source§

type Iter = UnclumpedOffsetValues<'a>

Source§

impl<O> IsolateIndex<ClumpedOffsets<O>> for usize

Source§

type Output = usize

Source§

unsafe fn isolate_unchecked( self, clumped_offsets: ClumpedOffsets<O>, ) -> Self::Output

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

fn try_isolate(self, clumped_offsets: ClumpedOffsets<O>) -> Option<Self::Output>

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

impl<O: PartialEq> PartialEq for ClumpedOffsets<O>

Source§

fn eq(&self, other: &ClumpedOffsets<O>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<O: RemovePrefix + Set> RemovePrefix for ClumpedOffsets<O>

Source§

fn remove_prefix(&mut self, n: usize)

Remove n elements from the beginning.
Source§

impl<O: Reserve> Reserve for ClumpedOffsets<O>

Source§

fn reserve_with_storage(&mut self, n: usize, storage_n: usize)

Source§

fn reserve(&mut self, n: usize)

Source§

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

Source§

type Elem = usize

Owned element of the set.
Source§

type Atom = usize

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

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

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

Source§

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

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.

Source§

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

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.

Source§

impl<O: Truncate> Truncate for ClumpedOffsets<O>

Source§

fn truncate(&mut self, new_len: usize)

Source§

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

Source§

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

Source§

fn view(&'a self) -> Self::Type

Source§

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

Source§

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

Source§

fn view_mut(&'a mut self) -> Self::Type

Source§

impl<O: Copy> Copy for ClumpedOffsets<O>

Source§

impl<O> StructuralPartialEq for ClumpedOffsets<O>

Source§

impl<O: Viewed> Viewed for ClumpedOffsets<O>

Auto Trait Implementations§

§

impl<O> Freeze for ClumpedOffsets<O>
where O: Freeze,

§

impl<O> RefUnwindSafe for ClumpedOffsets<O>
where O: RefUnwindSafe,

§

impl<O> Send for ClumpedOffsets<O>
where O: Send,

§

impl<O> Sync for ClumpedOffsets<O>
where O: Sync,

§

impl<O> Unpin for ClumpedOffsets<O>
where O: Unpin,

§

impl<O> UnwindSafe for ClumpedOffsets<O>
where O: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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

Source§

fn get(&self, idx: I) -> Option<<I as GetIndex<'a, S>>::Output>

Source§

fn at(&self, idx: I) -> Self::Output

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

unsafe fn at_unchecked(&self, idx: I) -> Self::Output

Return a value at the given index. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<S, I> Isolate<I> for S
where I: IsolateIndex<S>,

Source§

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

Source§

unsafe fn isolate_unchecked(self, idx: I) -> <S as Isolate<I>>::Output

Unchecked version of isolate. Read more
Source§

fn try_isolate(self, idx: I) -> Option<<S as Isolate<I>>::Output>

Source§

fn isolate(self, idx: I) -> Self::Output
where Self: Sized,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T, N> PushArrayToVec<N> for T
where T: Clone, N: Array<T>,

Source§

fn push_to_vec(element: <N as Array<T>>::Array, set: &mut Vec<T>)

This method tells this type how it can be pushed to a Vec as an array.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.