Struct histogram::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 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<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<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 snapshot(&self) -> Snapshot

Produce a snapshot from this histogram.

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 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<'a> IntoIterator for &'a Histogram

§

type Item = Bucket

The type of the elements being iterated over.
§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Histogram

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.