reqsketch-rs
An implementation of the Relative Error Quantiles (REQ) sketch algorithm in Rust.
Overview
REQ sketch is a probabilistic data structure for approximate quantile estimation with relative error guarantees, particularly useful for streaming scenarios where you need to estimate quantiles over large data streams with bounded memory usage.
This implementation is based on the paper "Relative Error Streaming Quantiles" by Graham Cormode, Zohar Karnin, Edo Liberty, Justin Thaler, and Pavel Veselý. A lot of inspiration was taken from the C++ implementation in Apache DataSketches https://datasketches.apache.org/docs/REQ/ReqSketch.html
Basic Usage
use ;
Sketch Merging
let mut sketch1 = new;
let mut sketch2 = new;
// Add data to both sketches
for i in 0..1000
// Merge sketch2 into sketch1
sketch1.merge?;
REQ Rank Error Analysis
Generate DataSketches-style rank error plots:
# Generate HRA and LRA rank error plots:
# Creates: assets/req_rank_error_hra.png, assets/req_rank_error_lra.png
These plots demonstrate the key REQ characteristic: error tapering toward the optimized tail (rank 1.0 for HRA, rank 0.0 for LRA)
High Rank Accuracy (HRA) Mode:

Low Rank Accuracy (LRA) Mode:

Examples
Run the examples to see the sketch in action:
Benchmarks
Run performance benchmarks:
# Run all benchmarks
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Licensed under the MIT or Apache License.