Skip to main content

RleBatch

Struct RleBatch 

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

Source

pub fn new() -> Self

An empty batch.

Source

pub fn len(&self) -> usize

The number of sequences.

Source

pub fn is_empty(&self) -> bool

Source

pub fn keys(&self) -> &[K]

Source

pub fn offsets(&self) -> &[usize]

Run boundaries per sequence; len() + 1 entries.

Source

pub fn ends(&self) -> &[i64]

The run ends of all sequences, back to back.

Source

pub fn values(&self) -> &[V]

The run values of all sequences, back to back.

Source

pub fn get_index(&self, position: usize) -> Option<RleRef<'_, V>>

The sequence at position, or None if out of range.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, RleRef<'_, V>)>

Iterates over (key, sequence) in key order.

Source

pub fn into_parts(self) -> (Vec<K>, Vec<usize>, Vec<i64>, Vec<V>)

Splits the batch into keys, offsets, ends and values.

Source

pub fn reduce<T, F>(&self, f: F) -> Vec<T>
where K: Send + Sync, V: Sync, T: Send, F: Fn(RleRef<'_, V>) -> T + Sync,

Computes f for every sequence in parallel, in key order.

Source

pub fn map_rles<W, F>(&self, f: F) -> RleBatch<K, W>
where K: Clone + Send + Sync, V: Sync, W: Send, F: Fn(RleRef<'_, V>) -> Rle<W> + Sync,

Transforms every sequence in parallel, keeping the keys.

Source

pub fn shift(&self, distance: i64, fill: V) -> RleBatch<K, V>
where K: Clone + Send + Sync, V: Clone + Identical + Send + Sync,

Shifts every sequence; see RleLike::shift.

Source

pub fn reversed(&self) -> RleBatch<K, V>
where K: Clone + Send + Sync, V: Clone + Send + Sync,

Reverses every sequence; see RleLike::reversed.

Source§

impl<K, V> RleBatch<K, V>

Source

pub fn collapse<K2, F, G>( &self, key: F, fill: Option<&V>, f: G, ) -> Result<RleBatch<K2, V>>
where K: Send + Sync, K2: Hash + Eq + Clone + Send + Sync, V: Clone + Identical + Send + Sync, F: Fn(&K) -> K2, G: Fn(&V, &V) -> V + Sync,

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>

Source

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.

Source

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.

Source

pub fn push(&mut self, key: K, rle: Rle<V>) -> Result<()>

Appends a sequence under a new key.

Source

pub fn position<Q>(&self, key: &Q) -> Option<usize>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

The position of key, if present.

Source

pub fn get<Q>(&self, key: &Q) -> Option<RleRef<'_, V>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

The sequence for key, if present.

Source

pub fn getitems<Q>( &self, keys: &[Q], starts: &[i64], ends: &[i64], ) -> Result<RleBatch<usize, V>>
where K: Borrow<Q>, Q: Hash + Eq, V: Clone,

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.

Source

pub fn slice_reduce<'a, Q, T, F>( &'a self, keys: &[Q], starts: &[i64], ends: &[i64], f: F, ) -> Result<Vec<T>>
where K: Borrow<Q> + Send + Sync, Q: Hash + Eq + Sync, V: Sync, T: Send, F: Fn(SliceView<'a, V>) -> T + Sync,

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.

Source

pub fn concat(batches: &[&RleBatch<K, V>]) -> RleBatch<K, V>
where K: Send + Sync, V: Clone + Identical + Send + Sync,

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.

Source

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>>
where K: Send + Sync, V: Sync, B: Sync, C: Identical + Send, F: Fn(&V, &B) -> C + Sync,

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, V> Add<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: Add<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the + operation. Read more
Source§

impl<K, V> BitAnd<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: BitAnd<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the & operation. Read more
Source§

impl<K, V> BitOr<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: BitOr<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the | operation. Read more
Source§

impl<K, V> BitXor<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: BitXor<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the ^ operation. Read more
Source§

impl<K: Clone, V: Clone> Clone for RleBatch<K, V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug> Debug for RleBatch<K, V>

Source§

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

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

impl<K, V> Default for RleBatch<K, V>

Source§

fn default() -> Self

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

impl<K, V> Div<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: Div<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the / operation. Read more
Source§

impl<K, V> Mul<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: Mul<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the * operation. Read more
Source§

impl<K: PartialEq, V: Identical> PartialEq for RleBatch<K, V>

Same keys in the same order, and each pair of sequences equals.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<K, V> Sub<&RleBatch<K, V>> for &RleBatch<K, V>
where K: Hash + Eq + Clone + Send + Sync, V: Sub<Output = V> + Clone + Default + Identical + Send + Sync,

Source§

type Output = RleBatch<K, V>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &RleBatch<K, V>) -> RleBatch<K, V>

Performs the - operation. Read more

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>
where Vec<K>: Send, Vec<V>: Send, OnceLock<HashMap<K, usize>>: Send,

§

impl<K, V> Sync for RleBatch<K, V>
where Vec<K>: Sync, Vec<V>: Sync, OnceLock<HashMap<K, usize>>: Sync,

§

impl<K, V> Unpin for RleBatch<K, V>
where Vec<K>: Unpin, Vec<V>: Unpin, OnceLock<HashMap<K, usize>>: Unpin,

§

impl<K, V> UnsafeUnpin for RleBatch<K, V>

§

impl<K, V> UnwindSafe for RleBatch<K, V>

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<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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.