Struct histogram::SparseHistogram
source · pub struct SparseHistogram {
pub config: Config,
pub index: Vec<usize>,
pub count: Vec<u64>,
}
Expand description
This histogram is a sparse, columnar representation of the regular Histogram. It is significantly smaller than a regular Histogram when a large number of buckets are zero, which is a frequent occurence. It stores an individual vector for each field of non-zero buckets. Assuming index[0] = n, (index[0], count[0]) corresponds to the nth bucket.
Fields§
§config: Config
parameters representing the resolution and the range of the histogram tracking request latencies
index: Vec<usize>
indices for the non-zero buckets in the histogram
count: Vec<u64>
histogram bucket counts corresponding to the indices
Implementations§
source§impl SparseHistogram
impl SparseHistogram
sourcepub fn new(grouping_power: u8, max_value_power: u8) -> Result<Self, Error>
pub fn new(grouping_power: u8, max_value_power: u8) -> Result<Self, Error>
Construct a new histogram from the provided parameters. See the
documentation for crate::Config
to understand their meaning.
sourcepub fn with_config(config: &Config) -> Self
pub fn with_config(config: &Config) -> Self
Creates a new histogram using a provided crate::Config
.
sourcepub fn wrapping_add(
&self,
h: &SparseHistogram
) -> Result<SparseHistogram, Error>
pub fn wrapping_add( &self, h: &SparseHistogram ) -> Result<SparseHistogram, Error>
Adds the other histogram to this histogram and returns the result as a new histogram.
An error is returned if the two histograms have incompatible parameters. Buckets which have values in both histograms are allowed to wrap.
sourcepub fn percentile(&self, percentile: f64) -> Result<Bucket, Error>
pub fn percentile(&self, percentile: f64) -> Result<Bucket, Error>
Return a single percentile from this histogram.
The percentile should be in the inclusive range 0.0..=100.0
. For
example, the 50th percentile (median) can be found using 50.0
.
sourcepub fn downsample(&self, grouping_power: u8) -> Result<SparseHistogram, Error>
pub fn downsample(&self, grouping_power: u8) -> Result<SparseHistogram, Error>
Returns a new histogram with a reduced grouping power. The reduced grouping power should lie in the range (0..existing grouping power).
This works by iterating over every bucket in the existing histogram and inserting the contained values into the new histogram. While we do not know the exact values of the data points (only that they lie within the bucket’s range), it does not matter since the bucket is not split during downsampling and any value can be used.
Trait Implementations§
source§impl Clone for SparseHistogram
impl Clone for SparseHistogram
source§fn clone(&self) -> SparseHistogram
fn clone(&self) -> SparseHistogram
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SparseHistogram
impl Debug for SparseHistogram
source§impl From<&Histogram> for SparseHistogram
impl From<&Histogram> for SparseHistogram
source§impl From<&Snapshot> for SparseHistogram
impl From<&Snapshot> for SparseHistogram
source§impl PartialEq for SparseHistogram
impl PartialEq for SparseHistogram
source§fn eq(&self, other: &SparseHistogram) -> bool
fn eq(&self, other: &SparseHistogram) -> bool
self
and other
values to be equal, and is used
by ==
.