pub struct Histogram { /* private fields */ }
Expand description
A histogram that uses plain 64bit counters for each bucket.
Implementations§
Source§impl Histogram
impl Histogram
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 from_buckets(
grouping_power: u8,
max_value_power: u8,
buckets: Vec<u64>,
) -> Result<Self, Error>
pub fn from_buckets( grouping_power: u8, max_value_power: u8, buckets: Vec<u64>, ) -> Result<Self, Error>
Creates a new histogram using a provided crate::Config
and the
provided collection of buckets.
Sourcepub fn increment(&mut self, value: u64) -> Result<(), Error>
pub fn increment(&mut self, value: u64) -> Result<(), Error>
Increment the counter for the bucket corresponding to the provided value by one.
Sourcepub fn add(&mut self, value: u64, count: u64) -> Result<(), Error>
pub fn add(&mut self, value: u64, count: u64) -> Result<(), Error>
Add some count to the counter for the bucket corresponding to the provided value
Sourcepub fn as_mut_slice(&mut self) -> &mut [u64]
pub fn as_mut_slice(&mut self) -> &mut [u64]
Get a mutable reference to the raw counters.
Sourcepub fn percentiles(
&self,
percentiles: &[f64],
) -> Result<Option<Vec<(f64, Bucket)>>, Error>
pub fn percentiles( &self, percentiles: &[f64], ) -> Result<Option<Vec<(f64, Bucket)>>, Error>
Return a collection of percentiles from this histogram.
Each percentile should be in the inclusive range 0.0..=100.0
. For
example, the 50th percentile (median) can be found using 50.0
.
The results will be sorted by the percentile.
Sourcepub fn percentile(&self, percentile: f64) -> Result<Option<Bucket>, Error>
pub fn percentile(&self, percentile: f64) -> Result<Option<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<Histogram, Error>
pub fn downsample(&self, grouping_power: u8) -> Result<Histogram, Error>
Returns a new histogram with a reduced grouping power. The reduced grouping power should lie in the range (0..existing grouping power).
The difference in grouping powers determines how much histogram size is reduced by, with every step approximately halving the total number of buckets (and hence total size of the histogram), while doubling the relative error.
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.
Sourcepub fn checked_add(&self, other: &Histogram) -> Result<Histogram, Error>
pub fn checked_add(&self, other: &Histogram) -> Result<Histogram, 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 or if there is an overflow.
Sourcepub fn wrapping_add(&self, other: &Histogram) -> Result<Histogram, Error>
pub fn wrapping_add(&self, other: &Histogram) -> Result<Histogram, 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.
Sourcepub fn checked_sub(&self, other: &Histogram) -> Result<Histogram, Error>
pub fn checked_sub(&self, other: &Histogram) -> Result<Histogram, Error>
Subtracts the other histogram from this histogram and returns the result as a new histogram.
An error is returned if the two histograms have incompatible parameters or if there is an overflow.
Trait Implementations§
Source§impl From<&Histogram> for SparseHistogram
impl From<&Histogram> for SparseHistogram
Source§impl From<&SparseHistogram> for Histogram
impl From<&SparseHistogram> for Histogram
Source§fn from(other: &SparseHistogram) -> Self
fn from(other: &SparseHistogram) -> Self
Source§impl<'a> IntoIterator for &'a Histogram
impl<'a> IntoIterator for &'a Histogram
impl Eq for Histogram
impl StructuralPartialEq for Histogram
Auto Trait Implementations§
impl Freeze for Histogram
impl RefUnwindSafe for Histogram
impl Send for Histogram
impl Sync for Histogram
impl Unpin for Histogram
impl UnwindSafe for Histogram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)