Crate rolling_median

Crate rolling_median 

Source
Expand description

§rolling-median

Computes the median of a data set, using a “rolling” (online) algorithm.

It uses two heaps (a “min” heap and a “max” heap) to efficiently keep track of the “middle” element.

§Complexity

The push() operation has a complexity of: O(log(n))

The get() operation has a complexity of: O(1)

§Usage

Here is a simple example that demonstrates how to use it in your code:

use rolling_median::Median;

const VALUES: [f64; 6usize] = [3.27f64, 4.60f64, 5.95f64, 9.93f64, 7.79f64, 4.73f64];

fn main() {
    let mut rolling_median = Median::new();

    for value in VALUES {
        rolling_median.push(value).expect("Invalid value!");
        println!("Median, so far: {}", rolling_median.get().expect("No result!"))
    }

    println!("Final median: {}", rolling_median.get().expect("No result!"))
}

👉 Please see the Median struct for details!

Modules§

float_utils

Structs§

Median
Computes the median of a data set, using a “rolling” (online) algorithm