Struct histogram::Config

source ·
pub struct Config { /* private fields */ }
Expand description

The configuration of a histogram which determines the bucketing strategy and therefore the relative error and memory utilization of a histogram.

  • grouping_power - controls the number of buckets that are used to span consecutive powers of two. Lower values result in less memory usage since fewer buckets will be created. However, this will result in larger relative error as each bucket represents a wider range of values.
  • max_value_power - controls the largest value which can be stored in the histogram. 2^(max_value_power) - 1 is the inclusive upper bound for the representable range of values.

§How to choose parameters for your data

Please see https://observablehq.com/@iopsystems/h2histogram for an in-depth discussion about the bucketing strategy and an interactive calculator that lets you explore how these parameters result in histograms with varying error guarantees and memory utilization requirements.

§The short version

§Grouping Power

grouping_power should be set such that 2^(-1 * grouping_power) is an acceptable relative error. Rephrased, we can plug-in the acceptable relative error into grouping_power = ceil(log2(1/e)). For example, if we want to limit the error to 0.1% (0.001) we should set grouping_power = 7.

§Max Value Power

max_value_power should be the closest power of 2 that is larger than the largest value you expect in your data. If your only guarantee is that the values are all u64, then setting this to 64 may be reasonable if you can tolerate a bit of relative error.

§Resulting size

If we want to allow any value in a range of unsigned types, the amount of memory for the histogram is approximately:

powererroru16u32u64
225%0.6 KiB1 KiB2 KiB
312.5%1 KiB2 KiB4 KiB
46.25%2 KiB4 KiB8 KiB
53.13%3 KiB7 KiB15 KiB
61.56%6 KiB14 KiB30 KiB
7.781%10 KiB26 KiB58 KiB
8.391%18 KiB50 KiB114 KiB
9.195%32 KiB96 KiB224 KiB
10.098%56 KiB184 KiB440 KiB
11.049%96 KiB352 KiB864 KiB
12.025%160 KiB672 KiB1.7 MiB

§Constraints:

  • max_value_power must be in the range 0..=64
  • max_value_power must be greater than `grouping_power

Implementations§

source§

impl Config

source

pub const fn new(grouping_power: u8, max_value_power: u8) -> Result<Self, Error>

Create a new histogram Config from the parameters. See the struct documentation crate::Config for the meaning of the parameters and their constraints.

source

pub const fn grouping_power(&self) -> u8

Returns the grouping power that was used to create this configuration.

source

pub const fn max_value_power(&self) -> u8

Returns the max value power that was used to create this configuration.

source

pub fn error(&self) -> f64

Returns the relative error (in percentage) of this configuration. This only applies to the logarithmic bins of the histogram (linear bins have a width of 1 and no error). For histograms with no logarithmic bins, error for the entire histogram is zero.

source

pub const fn total_buckets(&self) -> usize

Return the total number of buckets needed for this config.

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

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 Config

source§

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

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

impl PartialEq for Config

source§

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

source§

impl StructuralPartialEq for Config

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> 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,

§

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>,

§

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>,

§

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.