pub struct HistogramFast<T> { /* private fields */ }
Expand description

Faster version of HistogramInt for Integers

provided the bins should be: (left, left +1, …, right - 1) then you should use this version!

Implementations

Get left border, inclusive

Get right border, inclusive

Create a new interval
  • same as Self::new_inclusive(left, right - 1) though with checks
  • That makes left an inclusive and right an exclusive border
Create new histogram with inclusive borders
  • Err if left > right
  • left is inclusive border
  • right is inclusive border
Iterator over all the bins

In HistogramFast is hit only when a value matches the corresponding bin exactly, which means there exists a map between bins and corresponding values that would hit them. So a bin is perfectly defined by one value. That is what we are iterating over here

This iterates over these values

Example
use sampling::histogram::HistogramFast;
 
let hist = HistogramFast::<u8>::new_inclusive(2, 5).unwrap();
let vec: Vec<u8> =  hist.bin_iter().collect();
assert_eq!(&vec, &[2, 3, 4, 5]);
Iterator over all the bins

In HistogramFast is hit only when a value matches the corresponding bin exactly, which means there exists a map between bins and corresponding values that would hit them.

This iterates over these values as well as the corresponding hit count (i.e., how often the corresponding bin was hit)

Item of Iterator

(value_corresponding_to_bin, number_of_hits)

Example
use sampling::histogram::HistogramFast;
 
let mut hist = HistogramFast::<u8>::new_inclusive(2, 5).unwrap();
hist.increment(4).unwrap();
hist.increment(5).unwrap();
hist.increment(5).unwrap();
let vec: Vec<(u8, usize)> =  hist.bin_hits_iter().collect();
assert_eq!(&vec, &[(2, 0), (3, 0), (4, 1), (5, 2)]);

checks if the range of two Histograms is equal, i.e., if they have the same bin borders

Add other histogram to self
  • will fail if the ranges are not equal, i.e., if equal_range returns false
  • Otherwise the hitcount of the bins of self will be increased by the corresponding hitcount of other.
  • other will be unchanged
Increment hit count

If val is inside the histogram, the corresponding bin count will be increased by 1 and the index corresponding to the bin in returned: Ok(index). Otherwise an Error is returned

Note

This is the same as HistogramVal::count_val

Increment hit count

Increments the hit count of the bin corresponding to val. If no bin corresponding to val exists, nothing happens

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
self.hist[index] += count, Err() if index out of bounds
the created histogram
How many bins the histogram contains
reset the histogram to zero
self.hist[index] += 1, Err() if index out of bounds
check if any bin was not hit yet
Create a histogram, which encapsulates the histograms passed Read more
Get bin difference between histograms Read more
Distance metric for how far a value is from a valid interval Read more
partition the interval Read more
Creates a vector containing borders

How to understand the borders?

Lets say we have a Vector containing [a,b,c], then the first bin contains all values T for which a <= T < b, the second bin all values T for which b <= T < c. In this case, there are only two bins.

Errors
  • returns Err(Overflow) if right border is T::MAX
  • creates and returns borders otherwise
  • Note: even if Err(Overflow) is returned, this does not provide any problems for the rest of the implementation, as the border vector is not used internally for HistogramFast
get the left most border (inclusive)
  • get second last border from the right
  • should be the same as let b = self.borders_clone().expect("overflow"); assert_eq!(self.second_last_border(), b[b.len()-2])
  • Read more
    calculates some sort of absolute distance to the nearest valid bin Read more
    convert val to the respective histogram index
    does a value correspond to a valid bin?
    opposite of is_inside
    count val. Ok(index), if inside of hist, Err(_) if val is invalid
    Will compare leftest bin first. if they are equal: will compare right bin Read more
    Serialize this value into the given Serde serializer. Read more

    Auto Trait Implementations

    Blanket Implementations

    Gets the TypeId of self. Read more
    Immutably borrows from an owned value. Read more
    Mutably borrows from an owned value. Read more
    Cast from Self to T
    Try converting from Self to T
    Cast to integer, truncating Read more
    Cast to the nearest integer Read more
    Cast the floor to an integer Read more
    Cast the ceiling to an integer Read more
    Try converting to integer with truncation Read more
    Try converting to the nearest integer Read more
    Try converting the floor to an integer Read more
    Try convert the ceiling to an integer Read more
    Convert from T to Self
    Try converting from T to Self

    Returns the argument unchanged.

    Calls U::from(self).

    That is, this conversion is whatever the implementation of From<T> for U chooses to do.

    The alignment of pointer.
    The type for initializers.
    Initializes a with the given initializer. Read more
    Dereferences the given pointer. Read more
    Mutably dereferences the given pointer. Read more
    Drops the object pointed to by the given pointer. Read more
    The resulting type after obtaining ownership.
    Creates owned data from borrowed data, usually by cloning. Read more
    Uses borrowed data to replace owned data, usually by cloning. Read more
    The type returned in the event of a conversion error.
    Performs the conversion.
    The type returned in the event of a conversion error.
    Performs the conversion.