pub struct CumulativeROHistogram32 { /* private fields */ }Expand description
A read-only, cumulative histogram for fast quantile queries.
This is a variant of the SparseHistogram with cumulative counts
(starting from the first bucket) for each bucket that is present.
Stores only non-zero buckets in columnar form, like SparseHistogram,
but with cumulative counts: count[i] equals the total number of
observations in buckets 0..=i (i.e., a running prefix sum). The last
element of count equals the total observation count.
CumulativeROHistogram is intended to be read-only—i.e. it shouldn’t
accept updates for new observations, because such operations would be
expensive given counts are cumulative. On the other hand, querying
percentiles is cheaper than standard or sparse histograms without
cumulative counts, which can be performed with binary search.
Additional methods to provide the percentile range each or all bucket(s)
represent are implmented to facilitate analytics based on such histograms.
Implementations§
Source§impl CumulativeROHistogram32
impl CumulativeROHistogram32
Sourcepub fn from_parts(
config: Config,
index: Vec<u32>,
count: Vec<u32>,
) -> Result<Self, Error>
pub fn from_parts( config: Config, index: Vec<u32>, count: Vec<u32>, ) -> Result<Self, Error>
Creates a cumulative histogram from its raw parts.
The count vector must contain cumulative counts (a running prefix
sum of individual bucket counts).
Returns an error if:
indexandcounthave different lengths- any index is out of range for the config
- the indices are not in strictly ascending order
- the counts are not strictly non-decreasing
- any count is zero
Sourcepub fn into_parts(self) -> (Config, Vec<u32>, Vec<u32>)
pub fn into_parts(self) -> (Config, Vec<u32>, Vec<u32>)
Consumes the histogram, returning the config, index, and cumulative count vectors.
Sourcepub fn total_count(&self) -> u64
pub fn total_count(&self) -> u64
Returns the total number of observations across all buckets.
Sourcepub fn bucket_quantile_range(&self, bucket_idx: usize) -> Option<(f64, f64)>
pub fn bucket_quantile_range(&self, bucket_idx: usize) -> Option<(f64, f64)>
Returns the quantile range (lower, upper) for the bucket at
position bucket_idx in the sparse representation.
loweris the fraction of observations strictly before this bucket (in[0.0, 1.0]).upperis the fraction of observations at or before this bucket (in[0.0, 1.0]).
Returns None if the histogram is empty or bucket_idx is out of
range.
Sourcepub fn iter_with_quantiles(&self) -> QuantileRangeIter32<'_>
pub fn iter_with_quantiles(&self) -> QuantileRangeIter32<'_>
Returns an iterator yielding (Bucket, lower_quantile, upper_quantile)
for each non-zero bucket.
Each Bucket contains the individual (non-cumulative) count.
The quantile range (lower, upper) indicates the fraction of total
observations before and up to this bucket.
Sourcepub fn iter(&self) -> CumulativeIter32<'_>
pub fn iter(&self) -> CumulativeIter32<'_>
Returns an iterator across the non-zero histogram buckets.
Each Bucket contains the individual (non-cumulative) count for
that bucket.
Sourcepub fn quantiles(
&self,
quantiles: &[f64],
) -> Result<Option<QuantilesResult>, Error>
pub fn quantiles( &self, quantiles: &[f64], ) -> Result<Option<QuantilesResult>, Error>
Compute quantiles for the given values.
Sourcepub fn quantile(&self, quantile: f64) -> Result<Option<QuantilesResult>, Error>
pub fn quantile(&self, quantile: f64) -> Result<Option<QuantilesResult>, Error>
Compute a single quantile.
Sourcepub fn as_ref(&self) -> CumulativeROHistogram32Ref<'_>
pub fn as_ref(&self) -> CumulativeROHistogram32Ref<'_>
Returns a borrowed view over this histogram’s storage.
Trait Implementations§
Source§impl Clone for CumulativeROHistogram32
impl Clone for CumulativeROHistogram32
Source§fn clone(&self) -> CumulativeROHistogram32
fn clone(&self) -> CumulativeROHistogram32
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CumulativeROHistogram32
impl Debug for CumulativeROHistogram32
Source§impl From<&CumulativeROHistogram32> for CumulativeROHistogram
impl From<&CumulativeROHistogram32> for CumulativeROHistogram
Source§fn from(h: &CumulativeROHistogram32) -> Self
fn from(h: &CumulativeROHistogram32) -> Self
Source§impl<'a> From<&'a CumulativeROHistogram32> for CumulativeROHistogram32Ref<'a>
impl<'a> From<&'a CumulativeROHistogram32> for CumulativeROHistogram32Ref<'a>
Source§fn from(h: &'a CumulativeROHistogram32) -> Self
fn from(h: &'a CumulativeROHistogram32) -> Self
Source§impl From<&Histogram32> for CumulativeROHistogram32
impl From<&Histogram32> for CumulativeROHistogram32
Source§fn from(histogram: &Histogram32) -> Self
fn from(histogram: &Histogram32) -> Self
Source§impl From<&SparseHistogram32> for CumulativeROHistogram32
impl From<&SparseHistogram32> for CumulativeROHistogram32
Source§fn from(histogram: &SparseHistogram32) -> Self
fn from(histogram: &SparseHistogram32) -> Self
Source§impl<'a> IntoIterator for &'a CumulativeROHistogram32
impl<'a> IntoIterator for &'a CumulativeROHistogram32
Source§impl PartialEq for CumulativeROHistogram32
impl PartialEq for CumulativeROHistogram32
Source§impl TryFrom<&Histogram> for CumulativeROHistogram32
Direct path for the snapshot pipeline:
Histogram (delta) → CumulativeROHistogram32.
impl TryFrom<&Histogram> for CumulativeROHistogram32
Direct path for the snapshot pipeline:
Histogram (delta) → CumulativeROHistogram32.
Single pass: accumulate non-zero buckets, fail with Error::Overflow
if the running total ever exceeds u32::MAX.
Source§impl TryFrom<&SparseHistogram> for CumulativeROHistogram32
Direct path: SparseHistogram → CumulativeROHistogram32.
impl TryFrom<&SparseHistogram> for CumulativeROHistogram32
Direct path: SparseHistogram → CumulativeROHistogram32.
Single pass: cumulative running sum, total-only overflow check.