1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Quantile estimation algorithms
//!
//! This module provides state-of-the-art algorithms for estimating quantiles
//! (percentiles) from streaming data.
//!
//! # Algorithms
//!
//! - [`DDSketch`] - Relative error guarantees (VLDB 2019)
//! - [`ReqSketch`] - Zero error at p100 (HRA) or p0 (LRA) (PODS 2021)
//!
//! # Choosing an Algorithm
//!
//! ## DDSketch
//!
//! **Use when:**
//! - You need relative error guarantees (error proportional to value)
//! - Your data spans multiple orders of magnitude
//! - You need to merge sketches from distributed systems
//! - You're tracking latencies, request sizes, or financial metrics
//!
//! **Characteristics:**
//! - Relative accuracy (e.g., 1% error)
//! - Fast merge operations
//! - Space: O(log(max/min))
//! - Production-proven (Datadog, ClickHouse, TimescaleDB)
//!
//! ## REQ Sketch
//!
//! **Use when:**
//! - You need **EXACT** tail quantiles (p100 or p0)
//! - Monitoring SLAs or detecting outliers
//! - Tracking maximum/minimum values with quantile distributions
//! - You need mergeable sketches with controlled space usage
//!
//! **Characteristics:**
//! - HRA mode: Zero error at p100 (maximum), optimized for p90+
//! - LRA mode: Zero error at p0 (minimum), optimized for p10-
//! - Relative error for other quantiles
//! - Space: O(k log(n/k)) where k is configurable
//! - Production-proven (Google BigQuery, Apache DataSketches)
//!
//! # Examples
//!
//! ## DDSketch Example
//!
//! ```
//! use sketch_oxide::quantiles::DDSketch;
//! use sketch_oxide::common::Sketch;
//!
//! let mut dd = DDSketch::new(0.01).unwrap(); // 1% relative error
//!
//! // Add measurements
//! for i in 1..=1000 {
//! dd.update(&(i as f64));
//! }
//!
//! // Query quantiles
//! println!("Median: {}", dd.quantile(0.5).unwrap());
//! println!("p99: {}", dd.quantile(0.99).unwrap());
//! ```
//!
//! ## REQ Sketch Example
//!
//! ```
//! use sketch_oxide::quantiles::req::{ReqSketch, ReqMode};
//!
//! // HRA mode for exact maximum tracking
//! let mut req = ReqSketch::new(128, ReqMode::HighRankAccuracy).unwrap();
//!
//! // Add measurements
//! for i in 1..=10000 {
//! req.update(i as f64);
//! }
//!
//! // p100 is EXACT (zero error)
//! assert_eq!(req.quantile(1.0), Some(10000.0));
//!
//! // Other high quantiles have relative error guarantees
//! let p99 = req.quantile(0.99).unwrap();
//! assert!(p99 >= 9800.0); // Close to true p99 = 9900
//! ```
pub use DDSketch;
pub use ;
pub use ;
pub use SplineSketch;
pub use TDigest;