Struct flatk::ClumpedOffsets [−][src]
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
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.
Parallel version of offsets_and_sizes
.
Returns the number of clump offsets represented by ClumpedOffsets
.
This is typically significantly smaller than self.num_offsets()
.
Returns the number of clumps represented by ClumpedOffsets
.
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()
.
pub fn sizes(&self) -> UnclumpedSizes<'_>ⓘNotable traits for UnclumpedSizes<'a>impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
pub fn sizes(&self) -> UnclumpedSizes<'_>ⓘNotable traits for UnclumpedSizes<'a>impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
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);
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;
pub fn values(&self) -> UnclumpedOffsetValues<'_>ⓘNotable traits for UnclumpedOffsetValues<'a>impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
An iterator over unclumped offsets.
This is equivalent to iterating over Offsets
after conversion, but it doesn’t require any
additional allocations.
Construct new ClumpedOffsets
from a given valid set of clumped offsets represented as an
array of usize
s.
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.
Trait Implementations
A default set of offsets must allocate.
A dummy set of offsets will not allocate, but the resulting type does not correspond to valid offsets.
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
.
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Convert ClumpedOffsets
into owned Offsets
.
This function causes allocations.
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);
Creates a value from an iterator. Read more
A version of offset_value
without bounds checking.
Safety
It is assumed that index
is strictly less than self.num_offsets()
.
Get the total number of offsets.
This is one more than the number of chunks represented.
Get the length of the chunk at the given index. Read more
Get the length of the chunk at the given index without bounds checking. Read more
Return the raw value corresponding to the offset at the given index. Read more
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
A version of offset
without bounds checking. Read more
Get the last offset. Read more
Get the first offset. Read more
Get the raw value corresponding to the last offset.
Get the raw value corresponding to the first offset.
type Iter = UnclumpedOffsetValuesAndSizes<'a>
fn into_offset_values_and_sizes(self) -> UnclumpedOffsetValuesAndSizes<'a>ⓘNotable traits for UnclumpedOffsetValuesAndSizes<'a>impl<'a> Iterator for UnclumpedOffsetValuesAndSizes<'a> type Item = (usize, usize);
impl<'a> Iterator for UnclumpedOffsetValuesAndSizes<'a> type Item = (usize, usize);
type Owned = ClumpedOffsets<O::Owned>
Returns a parallel iterator over chunk offsets and sizes represented by the stored Offsets
.
type ParIter = ParUnclumpedOffsetValuesAndSizes<'a>
fn into_sizes(self) -> UnclumpedSizes<'a>ⓘNotable traits for UnclumpedSizes<'a>impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
fn into_sizes(self) -> UnclumpedSizes<'a>ⓘNotable traits for UnclumpedSizes<'a>impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
impl<'a> Iterator for UnclumpedSizes<'a> type Item = usize;
Returns an iterator over chunk sizes represented by the stored ClumpedOffsets
.
type Iter = UnclumpedSizes<'a>
fn into_values(self) -> UnclumpedOffsetValues<'a>ⓘNotable traits for UnclumpedOffsetValues<'a>impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
fn into_values(self) -> UnclumpedOffsetValues<'a>ⓘNotable traits for UnclumpedOffsetValues<'a>impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
impl<'a> Iterator for UnclumpedOffsetValues<'a> type Item = usize;
Returns an iterator over offset values represented by the stored Offsets
.
type Iter = UnclumpedOffsetValues<'a>
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Remove n
elements from the beginning.
fn split_offsets_with_intersection_at(
self,
mid_off: usize
) -> (ClumpedOffsets<&'a [usize]>, ClumpedOffsets<&'a [usize]>, usize)
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.
fn split_offsets_at(
self,
mid: usize
) -> (ClumpedOffsets<&'a [usize]>, ClumpedOffsets<&'a [usize]>)
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.
Auto Trait Implementations
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
Mutably borrows from an owned value. Read more
type Output = <I as IsolateIndex<S>>::Output
Unchecked version of isolate
. Read more