Skip to main content

Crate reqsketch

Crate reqsketch 

Source
Expand description

§REQSketch - Relative Error Quantiles Sketch

Relative Error Quantiles sketch algorithm in Rust. This implementation is based on the paper “Relative Error Streaming Quantiles” by Graham Cormode, Zohar Karnin, Edo Liberty, Justin Thaler, Pavel Veselý.

And on the C++ implementation in Apache DataSketches https://github.com/apache/datasketches-cpp

§Quick Start

use reqsketch::{ReqSketch, SearchCriteria, Result};

fn main() -> Result<()> {
    let mut sketch = ReqSketch::new();

    // Add values to the sketch
    for i in 0..10000 {
        sketch.update(i as f64);
    }

    // Query quantiles with proper error handling
    let median = sketch.quantile(0.5, SearchCriteria::Inclusive)?;
    let p99 = sketch.quantile(0.99, SearchCriteria::Inclusive)?;

    // Query ranks with proper error handling
    let rank = sketch.rank(&5000.0, SearchCriteria::Inclusive)?;

    // For repeated queries, take an owned snapshot once and query it.
    // The view stays valid (and unchanged) while the sketch keeps updating.
    let view = sketch.sorted_view();
    let p25 = view.quantile(0.25, SearchCriteria::Inclusive)?;
    let p75 = view.quantile(0.75, SearchCriteria::Inclusive)?;

    println!("Median: {}, P99: {}, Rank of 5000: {}", median, p99, rank);
    println!("IQR: [{}, {}]", p25, p75);
    Ok(())
}

Re-exports§

pub use builder::ReqSketchBuilder;
pub use error::ReqError;
pub use error::Result;
pub use iter::ReqSketchIterator;
pub use sorted_view::SortedView;

Modules§

builder
Builder pattern implementation for REQ sketch construction.
error
Error types for the REQ sketch library.
iter
Iterator implementations for REQ sketch inspection.
sorted_view
Sorted view implementation for efficient quantile queries.

Structs§

ReqSketch
A Relative Error Quantiles sketch for approximate quantile estimation.

Enums§

RankAccuracy
Configuration for rank accuracy optimization
SearchCriteria
Search criteria for quantile/rank operations

Traits§

TotalOrd
Trait for total ordering that handles NaN consistently.