Skip to main content

Mergeable

Trait Mergeable 

Source
pub trait Mergeable: Sized + Send {
    // Required method
    fn merge(&mut self, other: Self);

    // Provided method
    fn merge_all(stats: Vec<Self>) -> Option<Self> { ... }
}
Expand description

Trait for statistics that can be merged from parallel computations

This is the key trait that enables parallel processing:

  1. Each thread computes partial statistics on its chunk
  2. Partial statistics are merged at the end

§Properties

For correct parallel computation, merge must be:

  • Associative: (a ⊕ b) ⊕ c = a ⊕ (b ⊕ c)
  • Commutative: a ⊕ b = b ⊕ a

Where ⊕ represents the merge operation.

Required Methods§

Source

fn merge(&mut self, other: Self)

Merge another stats object into this one

After merging, self should contain the combined statistics as if both datasets were processed together.

Provided Methods§

Source

fn merge_all(stats: Vec<Self>) -> Option<Self>

Merge multiple stats objects into one (convenience method)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Mergeable for BamStats

Implementation of Mergeable for parallel statistics computation

Merges BAM statistics from multiple threads/chunks. All statistics are correctly combined using the underlying Mergeable implementations for RunningStats and CategoryCounter.

Source§

impl Mergeable for BedStats

Implementation of Mergeable for parallel statistics computation

Merges BED statistics from multiple threads/chunks. All statistics are correctly combined using the underlying Mergeable implementations for RunningStats and CategoryCounter.

Source§

impl Mergeable for FastqStats

Implementation of Mergeable for parallel statistics computation

Merges FASTQ statistics from multiple threads/chunks. All statistics are correctly combined using the underlying Mergeable implementations for RunningStats and CategoryCounter.

Source§

impl Mergeable for SamStats

Implementation of Mergeable for parallel statistics computation

Merges SAM statistics from multiple threads/chunks. All statistics are correctly combined using the underlying Mergeable implementations for RunningStats and CategoryCounter.

Source§

impl Mergeable for RunningStats

Implementation of Mergeable for parallel statistics computation

Uses Chan’s parallel variance algorithm to correctly merge running statistics from multiple threads.

Reference: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm

Source§

impl<T: Hash + Eq + Send> Mergeable for CategoryCounter<T>

Implementation of Mergeable for parallel statistics computation

Merges category counts from multiple threads by summing counts for each category.