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

Generic Histogram struct

Implementations

similar to self.borders_clone but does not allocate memory

Create a new Historgram
  • right exclusive, left inclusive
  • if you want right to behave (almost) the same as an inclusive border, consider using new(left, right + T::EPSILON, bins) (make sure, that adding Epsilon actually changes the value!)

Returns the length of the interval

Iterator over all the bins

In AtomicHistogramFloat a bin is defined by two values: The left border (inclusive) and the right border (exclusive)

Here you get an iterator which iterates over said borders. The Iterator returns a borrowed Array of length two, where the first value is the left (inclusive) border and the second value is the right (exclusive) border

Example
use sampling::histogram::*;
 
let hist = AtomicHistogramFloat::<f32>::new(0.0, 1.0, 2).unwrap();
let mut iter = hist.bin_iter();
assert_eq!(iter.next(), Some(&[0.0, 0.5]));
assert_eq!(iter.next(), Some(&[0.5, 1.0]));
assert_eq!(iter.next(), None);
Iterate over all bins

In AtomicHistogramFloat a bin is defined by two values: The left border (inclusive) and the right border (exclusive)

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

Item of Iterator

(&[left_border, right_border], number_of_hits)

Example
use sampling::histogram::*;
 
let mut hist = AtomicHistogramFloat::<f64>::new(0.0, 1.0, 2).unwrap();
 
hist.increment_quiet(0.5);
hist.increment_quiet(0.71253782387);
 
let mut iter = hist.bin_hits_iter();
assert_eq!(iter.next(), Some((&[0.0, 0.5], 0)));
assert_eq!(iter.next(), Some((&[0.5, 1.0], 2)));
assert_eq!(iter.next(), None);
Increment hit count of bin

This will increment the hit count of the bin corresponding to the value val. If the bin was valid it will return the index of the corresponding bin

Increment hit count

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

Trait Implementations

Uses SeqCst

How many bins the histogram contains
the created histogram Read more
reset the histogram to zero
self.hist[index] += 1, Err() if index out of bounds
check if any bin was not hit yet Read more

consider using self.borders()

count val. Ok(index), if inside of hist, Err(_) if val is invalid
calculates some sort of absolute distance to the nearest valid bin Read more
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
    does a value correspond to a valid bin?
    opposite of is_inside
    convert val to the respective histogram index
    Formats the value using the given formatter. Read more
    Deserialize this value from the given Serde deserializer. Read more
    Converts to this type from the input type.
    Converts to this type from the input type.
    Distance metric for how far a value is from a valid interval 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 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.