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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! This crate provides histogram implementations that are conceptually similar
//! to HdrHistogram, with modifications to the bucket construction and indexing
//! algorithms that we believe provide a simpler implementation and more
//! efficient runtime compared to the reference implementation of HdrHistogram.
//!
//! # Types
//!
//! - [`Histogram`] — standard histogram with `u64` counters. Use for
//! single-threaded recording and percentile queries.
//! - [`Histogram32`] — like [`Histogram`] but with `u32` counters.
//! - [`AtomicHistogram`] — atomic histogram for concurrent recording. Take a
//! snapshot with [`AtomicHistogram::load`] or [`AtomicHistogram::drain`] to
//! query percentiles.
//! - [`AtomicHistogram32`] — like [`AtomicHistogram`] but with `u32` counters.
//! - [`SparseHistogram`] — compact representation storing only non-zero
//! buckets. Useful for serialization and storage.
//! - [`SparseHistogram32`] — like [`SparseHistogram`] but with `u32` counters.
//! - [`CumulativeROHistogram`] — read-only histogram with cumulative counts
//! for fast quantile queries via binary search.
//! - [`CumulativeROHistogram32`] — like [`CumulativeROHistogram`] but with
//! `u32` counters.
//!
//! # Example
//!
//! ```
//! use histogram::{Histogram, Quantile};
//!
//! let mut h = Histogram::new(7, 64).unwrap();
//!
//! for value in 1..=100 {
//! h.increment(value).unwrap();
//! }
//!
//! // Quantiles use the 0.0..=1.0 scale
//! let r50 = h.quantile(0.5).unwrap().unwrap();
//! let r99 = h.quantile(0.99).unwrap().unwrap();
//! // quantile() returns Result<Option<QuantilesResult>, Error>
//! // outer unwrap: quantile value is valid
//! // inner unwrap: histogram is non-empty
//!
//! let p50 = r50.get(&Quantile::new(0.5).unwrap()).unwrap();
//! let p99 = r99.get(&Quantile::new(0.99).unwrap()).unwrap();
//! println!("p50: {}-{}", p50.start(), p50.end());
//! println!("p99: {}-{}", p99.start(), p99.end());
//! ```
//!
//! # Counter Width
//!
//! All four histogram types ship in two flavors:
//!
//! - u64-counter family ([`Histogram`], [`AtomicHistogram`],
//! [`SparseHistogram`], [`CumulativeROHistogram`]): the default.
//! - u32-counter siblings ([`Histogram32`], [`AtomicHistogram32`],
//! [`SparseHistogram32`], [`CumulativeROHistogram32`]): half the memory
//! and serialization size; counts up to 2^32 − 1 per bucket.
//!
//! Conversions: widening (`u32` → `u64`) is infallible (`From`); narrowing
//! (`u64` → `u32`) is fallible (`TryFrom`, returns [`Error::Overflow`]).
//! Direct cross-variant + narrowing paths support the snapshot pipeline.
//!
//! # Recommended Pipeline
//!
//! Pick the histogram type based on the *role* it plays:
//!
//! - **Recording — `AtomicHistogram` or `Histogram`.** Counts are unbounded
//! over the lifetime of the process; `u64` is the safe choice.
//! - **Snapshot delta — `Histogram`, then narrowed.** Compute the delta with
//! `checked_sub`, then `TryFrom` into the analytics type.
//! - **Read-only analytics — `CumulativeROHistogram32`.** Halved size, O(log n)
//! quantile queries, total-count check is cheaper than per-bucket.
//!
//! ```
//! use histogram::{AtomicHistogram, CumulativeROHistogram32, Histogram};
//!
//! let recorder = AtomicHistogram::new(7, 64).unwrap();
//! # let snap_t0 = recorder.load();
//! let snap_t1 = recorder.load();
//! let delta = snap_t1.checked_sub(&snap_t0).unwrap();
//! let analytic: CumulativeROHistogram32 =
//! CumulativeROHistogram32::try_from(&delta).unwrap();
//! ```
//!
//! # Background
//! Please see: <https://h2histogram.org>
pub use ;
pub use Bucket;
pub use Config;
pub use ;
pub use ;
pub use Error;
pub use ;
pub use ;
pub use ;