pub struct RleBatch<K, V> { /* private fields */ }Expand description
Many run-length encoded sequences, each identified by a key.
The sequences are stored back to back in shared arrays, like an Arrow list
column: sequence i is runs offsets[i]..offsets[i + 1] of ends and
values, and its ends restart at 0. Keys can be any hashable type; use a
tuple for keys made of several parts. Key order is preserved.
Operations over the whole batch run in parallel across sequences.
Implementations§
Source§impl<K, V> RleBatch<K, V>
impl<K, V> RleBatch<K, V>
pub fn is_empty(&self) -> bool
pub fn keys(&self) -> &[K]
Sourcepub fn get_index(&self, position: usize) -> Option<RleRef<'_, V>>
pub fn get_index(&self, position: usize) -> Option<RleRef<'_, V>>
The sequence at position, or None if out of range.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, RleRef<'_, V>)>
pub fn iter(&self) -> impl Iterator<Item = (&K, RleRef<'_, V>)>
Iterates over (key, sequence) in key order.
Sourcepub fn into_parts(self) -> (Vec<K>, Vec<usize>, Vec<i64>, Vec<V>)
pub fn into_parts(self) -> (Vec<K>, Vec<usize>, Vec<i64>, Vec<V>)
Splits the batch into keys, offsets, ends and values.
Sourcepub fn reduce<T, F>(&self, f: F) -> Vec<T>
pub fn reduce<T, F>(&self, f: F) -> Vec<T>
Computes f for every sequence in parallel, in key order.
Sourcepub fn map_rles<W, F>(&self, f: F) -> RleBatch<K, W>
pub fn map_rles<W, F>(&self, f: F) -> RleBatch<K, W>
Transforms every sequence in parallel, keeping the keys.
Sourcepub fn shift(&self, distance: i64, fill: V) -> RleBatch<K, V>
pub fn shift(&self, distance: i64, fill: V) -> RleBatch<K, V>
Shifts every sequence; see RleLike::shift.
Source§impl<K, V> RleBatch<K, V>
impl<K, V> RleBatch<K, V>
Sourcepub fn collapse<K2, F, G>(
&self,
key: F,
fill: Option<&V>,
f: G,
) -> Result<RleBatch<K2, V>>
pub fn collapse<K2, F, G>( &self, key: F, fill: Option<&V>, f: G, ) -> Result<RleBatch<K2, V>>
Combines the sequences whose keys map to the same new key, folding
each group with f in key order, in parallel across groups.
For example, batch.collapse(|(chrom, _strand)| chrom.clone(), Some(&0), |a, b| a + b) adds the strands of each chromosome together. New keys
appear in order of first appearance. Sequences of different lengths are
padded with fill; with no fill value that is an error.
Source§impl<K: Hash + Eq + Clone, V> RleBatch<K, V>
impl<K: Hash + Eq + Clone, V> RleBatch<K, V>
Sourcepub fn from_rles<I: IntoIterator<Item = (K, Rle<V>)>>(rles: I) -> Result<Self>
pub fn from_rles<I: IntoIterator<Item = (K, Rle<V>)>>(rles: I) -> Result<Self>
Builds a batch from (key, sequence) pairs. Duplicate keys are an error.
Sourcepub fn from_parts(
keys: Vec<K>,
offsets: Vec<usize>,
ends: Vec<i64>,
values: Vec<V>,
) -> Result<Self>
pub fn from_parts( keys: Vec<K>, offsets: Vec<usize>, ends: Vec<i64>, values: Vec<V>, ) -> Result<Self>
Builds a batch from its flat parts, validating them.
Sourcepub fn getitems<Q>(
&self,
keys: &[Q],
starts: &[i64],
ends: &[i64],
) -> Result<RleBatch<usize, V>>
pub fn getitems<Q>( &self, keys: &[Q], starts: &[i64], ends: &[i64], ) -> Result<RleBatch<usize, V>>
Many slices at once: slice k is keys[k]’s sequence at
starts[k]..ends[k], clamped. A missing key gives an empty slice.
The result is keyed by slice number.
Sourcepub fn slice_reduce<'a, Q, T, F>(
&'a self,
keys: &[Q],
starts: &[i64],
ends: &[i64],
f: F,
) -> Result<Vec<T>>
pub fn slice_reduce<'a, Q, T, F>( &'a self, keys: &[Q], starts: &[i64], ends: &[i64], f: F, ) -> Result<Vec<T>>
Reduces many slices with f without copying them, in parallel: slice
k is keys[k]’s sequence at starts[k]..ends[k], clamped. A missing
key gives an empty slice.
Sourcepub fn concat(batches: &[&RleBatch<K, V>]) -> RleBatch<K, V>
pub fn concat(batches: &[&RleBatch<K, V>]) -> RleBatch<K, V>
Joins the batches end to end key by key, in parallel: each key’s sequences are concatenated in batch order, and a batch without the key contributes nothing. Keys appear in order of first appearance.
Sourcepub fn zip_with<B, C, F>(
&self,
other: &RleBatch<K, B>,
how: How,
fill_a: Option<&V>,
fill_b: Option<&B>,
f: F,
) -> Result<RleBatch<K, C>>
pub fn zip_with<B, C, F>( &self, other: &RleBatch<K, B>, how: How, fill_a: Option<&V>, fill_b: Option<&B>, f: F, ) -> Result<RleBatch<K, C>>
Combines the sequences of two batches key by key with f, in parallel,
merging identical neighbours in each result.
how picks the keys; keys appear in the left batch’s order, followed
by keys only in the right batch. Sequences of different lengths, and
keys missing on one side, are padded with that side’s fill value; with
no fill value that is an error naming the output position.
Trait Implementations§
Source§impl<K: PartialEq, V: Identical> PartialEq for RleBatch<K, V>
Same keys in the same order, and each pair of sequences
equals.
impl<K: PartialEq, V: Identical> PartialEq for RleBatch<K, V>
Same keys in the same order, and each pair of sequences
equals.
Auto Trait Implementations§
impl<K, V> !Freeze for RleBatch<K, V>
impl<K, V> RefUnwindSafe for RleBatch<K, V>
impl<K, V> Send for RleBatch<K, V>
impl<K, V> Sync for RleBatch<K, V>
impl<K, V> Unpin for RleBatch<K, V>
impl<K, V> UnsafeUnpin for RleBatch<K, V>
impl<K, V> UnwindSafe for RleBatch<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more