histogram

Struct Histogram

Source
pub struct Histogram { /* private fields */ }
Expand description

A histogram that uses plain 64bit counters for each bucket.

Implementations§

Source§

impl Histogram

Source

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.

Source

pub fn with_config(config: &Config) -> Self

Creates a new histogram using a provided crate::Config.

Source

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.

Source

pub fn increment(&mut self, value: u64) -> Result<(), Error>

Increment the counter for the bucket corresponding to the provided value by one.

Source

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

Source

pub fn as_slice(&self) -> &[u64]

Get a reference to the raw counters.

Source

pub fn as_mut_slice(&mut self) -> &mut [u64]

Get a mutable reference to the raw counters.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn wrapping_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.

Source

pub fn config(&self) -> Config

Returns the bucket configuration of the histogram.

Trait Implementations§

Source§

impl Clone for Histogram

Source§

fn clone(&self) -> Histogram

Returns a copy 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 Histogram

Source§

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

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

impl From<&Histogram> for SparseHistogram

Source§

fn from(histogram: &Histogram) -> Self

Converts to this type from the input type.
Source§

impl From<&SparseHistogram> for Histogram

Source§

fn from(other: &SparseHistogram) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a Histogram

Source§

type Item = Bucket

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'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 Histogram

Source§

fn eq(&self, other: &Histogram) -> 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 Eq for Histogram

Source§

impl StructuralPartialEq for Histogram

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.