Struct sampling::histogram::AtomicHistogramFloat
source · pub struct AtomicHistogramFloat<T> { /* private fields */ }
Expand description
Generic Histogram struct
Implementations§
source§impl<T> AtomicHistogramFloat<T>
impl<T> AtomicHistogramFloat<T>
source§impl<T> AtomicHistogramFloat<T>
impl<T> AtomicHistogramFloat<T>
sourcepub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
pub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
Create a new Historgram
- right exclusive, left inclusive
- if you want
right
to behave (almost) the same as an inclusive border, consider usingnew(left, right + T::EPSILON, bins)
(make sure, that adding Epsilon actually changes the value!)
sourcepub fn interval_length(&self) -> T
pub fn interval_length(&self) -> T
Returns the length of the interval
sourcepub fn bin_iter(&self) -> impl Iterator<Item = &[T; 2]>
pub fn bin_iter(&self) -> impl Iterator<Item = &[T; 2]>
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);
sourcepub fn bin_hits_iter(&self) -> impl Iterator<Item = (&[T; 2], usize)>
pub fn bin_hits_iter(&self) -> impl Iterator<Item = (&[T; 2], usize)>
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);
sourcepub fn increment<B: Borrow<T>>(&self, val: B) -> Result<usize, HistErrors>
pub fn increment<B: Borrow<T>>(&self, val: B) -> Result<usize, HistErrors>
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
sourcepub fn increment_quiet<B: Borrow<T>>(&self, val: B)
pub fn increment_quiet<B: Borrow<T>>(&self, val: B)
Increment hit count
Increments the hit count of the bin corresponding to val
.
If no bin corresponding to val
exists, nothing happens
Trait Implementations§
source§impl<T> AtomicHistogram for AtomicHistogramFloat<T>
impl<T> AtomicHistogram for AtomicHistogramFloat<T>
source§fn count_multiple_index(
&self,
index: usize,
count: usize
) -> Result<(), HistErrors>
fn count_multiple_index( &self, index: usize, count: usize ) -> Result<(), HistErrors>
Uses SeqCst
source§fn hist(&self) -> &[AtomicUsize]
fn hist(&self) -> &[AtomicUsize]
source§fn count_index(&self, index: usize) -> Result<(), HistErrors>
fn count_index(&self, index: usize) -> Result<(), HistErrors>
source§fn any_bin_zero(&self) -> bool
fn any_bin_zero(&self) -> bool
source§impl<T> AtomicHistogramVal<T> for AtomicHistogramFloat<T>
impl<T> AtomicHistogramVal<T> for AtomicHistogramFloat<T>
source§fn borders_clone(&self) -> Result<Vec<T>, HistErrors>
fn borders_clone(&self) -> Result<Vec<T>, HistErrors>
consider using self.borders()
source§fn count_val<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>
fn count_val<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>
Ok(index)
, if inside of hist, Err(_)
if val is invalidsource§fn distance<V: Borrow<T>>(&self, val: V) -> f64
fn distance<V: Borrow<T>>(&self, val: V) -> f64
source§fn first_border(&self) -> T
fn first_border(&self) -> T
source§fn last_border(&self) -> T
fn last_border(&self) -> T
source§fn not_inside<V: Borrow<T>>(&self, val: V) -> bool
fn not_inside<V: Borrow<T>>(&self, val: V) -> bool
is_inside