Skip to main content

CumulativeROHistogram32

Struct CumulativeROHistogram32 

Source
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

Source

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:

  • index and count have 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
Source

pub fn into_parts(self) -> (Config, Vec<u32>, Vec<u32>)

Consumes the histogram, returning the config, index, and cumulative count vectors.

Source

pub fn config(&self) -> Config

Returns the bucket configuration.

Source

pub fn index(&self) -> &[u32]

Returns a slice of the non-zero bucket indices.

Source

pub fn count(&self) -> &[u32]

Returns a slice of the cumulative bucket counts.

Source

pub fn total_count(&self) -> u64

Returns the total number of observations across all buckets.

Source

pub fn len(&self) -> usize

Returns the number of non-zero buckets.

Source

pub fn is_empty(&self) -> bool

Returns true if the histogram contains no observations.

Source

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.

  • lower is the fraction of observations strictly before this bucket (in [0.0, 1.0]).
  • upper is 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.

Source

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.

Source

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.

Source

pub fn quantiles( &self, quantiles: &[f64], ) -> Result<Option<QuantilesResult>, Error>

Compute quantiles for the given values.

Source

pub fn quantile(&self, quantile: f64) -> Result<Option<QuantilesResult>, Error>

Compute a single quantile.

Source

pub fn as_ref(&self) -> CumulativeROHistogram32Ref<'_>

Returns a borrowed view over this histogram’s storage.

Trait Implementations§

Source§

impl Clone for CumulativeROHistogram32

Source§

fn clone(&self) -> CumulativeROHistogram32

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CumulativeROHistogram32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&CumulativeROHistogram32> for CumulativeROHistogram

Source§

fn from(h: &CumulativeROHistogram32) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a CumulativeROHistogram32> for CumulativeROHistogram32Ref<'a>

Source§

fn from(h: &'a CumulativeROHistogram32) -> Self

Converts to this type from the input type.
Source§

impl From<&Histogram32> for CumulativeROHistogram32

Source§

fn from(histogram: &Histogram32) -> Self

Converts to this type from the input type.
Source§

impl From<&SparseHistogram32> for CumulativeROHistogram32

Source§

fn from(histogram: &SparseHistogram32) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a CumulativeROHistogram32

Source§

type Item = Bucket

The type of the elements being iterated over.
Source§

type IntoIter = CumulativeIter32<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for CumulativeROHistogram32

Source§

fn eq(&self, other: &CumulativeROHistogram32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl SampleQuantiles for CumulativeROHistogram32

Source§

fn quantiles(&self, quantiles: &[f64]) -> Result<Option<QuantilesResult>, Error>

Compute quantiles for the given values. Read more
Source§

fn quantile(&self, quantile: f64) -> Result<Option<QuantilesResult>, Error>

Compute a single quantile. Convenience wrapper around quantiles.
Source§

impl TryFrom<&CumulativeROHistogram> for CumulativeROHistogram32

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(h: &CumulativeROHistogram) -> Result<Self, Error>

Performs the conversion.
Source§

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§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(h: &Histogram) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<&SparseHistogram> for CumulativeROHistogram32

Direct path: SparseHistogramCumulativeROHistogram32.

Single pass: cumulative running sum, total-only overflow check.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(h: &SparseHistogram) -> Result<Self, Error>

Performs the conversion.
Source§

impl Eq for CumulativeROHistogram32

Source§

impl StructuralPartialEq for CumulativeROHistogram32

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.