pub type Clumped<S, O = Vec<usize>> = Chunked<S, ClumpedOffsets<O>>;Expand description
Clumped is a variation of Chunked that compactly represents equidistant offsets as
“clumps”, hence the name.
In order for this type to compose with other container decorators, the clumped offsets must be declumped where necessary to enable efficient iteration. For this reason composition may have some overhead.
Aliased Type§
pub struct Clumped<S, O = Vec<usize>> {
pub chunks: ClumpedOffsets<O>,
pub data: S,
}Fields§
§chunks: ClumpedOffsets<O>This can be either offsets of a uniform chunk size, if chunk size is specified at compile time.
data: SImplementations§
Source§impl<S: Set> Clumped<S>
impl<S: Set> Clumped<S>
Sourcepub fn from_sizes_and_counts(
sizes: impl AsRef<[usize]>,
counts: impl AsRef<[usize]>,
data: S,
) -> Self
pub fn from_sizes_and_counts( sizes: impl AsRef<[usize]>, counts: impl AsRef<[usize]>, data: S, ) -> Self
Constructs a Clumped collection of elements from a set of sizes and counts
sizes and counts determine the number of elements in each chunk. The
length of sizes must be equal to the the length of counts. Each
element in sizes corresponds to chunk size, while the corresponding
element in counts tells how many times this chunk size is repeated.
The dot product between sizes and counts must be equal to the length of the given
data.
§Panics
This function will panic if sizes and counts have different lengths or
if the dot product between sizes and counts is not equal to data.len().
§Example
use flatk::*;
let s = Clumped::from_sizes_and_counts(vec![3,2], vec![2,1], vec![1,2,3,4,5,6,7,8]);
let mut iter = s.iter();
assert_eq!(&[1, 2, 3][..], iter.next().unwrap());
assert_eq!(&[4, 5, 6][..], iter.next().unwrap());
assert_eq!(&[7, 8][..], iter.next().unwrap());
assert_eq!(None, iter.next());Source§impl<S: Set, O: AsRef<[usize]>> Clumped<S, O>
impl<S: Set, O: AsRef<[usize]>> Clumped<S, O>
Sourcepub fn from_clumped_offsets(chunk_offsets: O, offsets: O, data: S) -> Self
pub fn from_clumped_offsets(chunk_offsets: O, offsets: O, data: S) -> Self
Construct a Clumped collection of elements given a collection of
“clumped” offsets into S. This is the most efficient constructor for creating Clumped
types, however it is also the most error prone.
chunk_offsets, identify the offsets into a conceptually “chunked” version of S.
offsets is a corresponding the collection of offsets into S itself.
In theory, these should specify the places where the chunk size (or stride) changes within
S, however this is not always necessary.
§Panics
The absolute value of offsets (this applies to both offsets as well as chunk_offsets)
is not significant, however their relative quantities are. More specifically, for
offsets, if x is the first offset, then the last element of offsets must always be
data.len() + x. For chunk_offsets the same holds but data is substituted by the
conceptual collection of chunks stored in data. This also implies that offsets cannot be
empty. This function panics if any one of these invariants isn’t satisfied.
This function will also panic if offsets and chunk_offsets have different lengths.
Although the validity of offsets is easily checked, the same is not true for
chunk_offsets, since the implied stride must divide into the size of each clump, and
checking this at run time is expensive. As such a malformed Clumped may cause panics
somewhere down the line. For ensuring a valid construction, use the
Self::from_sizes_and_counts constructor.
§Example
use flatk::*;
let v = vec![1,2, 3,4, 5,6, 7,8,9];
// The following splits v intos 3 pairs and a triplet.
let s = Clumped::from_clumped_offsets(vec![0,3,4], vec![0,6,9], v);
let mut iter = s.iter();
assert_eq!(&[1,2][..], iter.next().unwrap());
assert_eq!(&[3,4][..], iter.next().unwrap());
assert_eq!(&[5,6][..], iter.next().unwrap());
assert_eq!(&[7,8,9][..], iter.next().unwrap());
assert_eq!(None, iter.next());