Struct sampling::histogram::HistogramFast
source · 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§
source§impl<T> HistogramFast<T>where
T: Copy,
impl<T> HistogramFast<T>where
T: Copy,
source§impl<T> HistogramFast<T>where
T: PrimInt + HasUnsignedVersion + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
impl<T> HistogramFast<T>where
T: PrimInt + HasUnsignedVersion + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
sourcepub fn new(left: T, right: T) -> Result<Self, HistErrors>
pub fn new(left: T, right: T) -> Result<Self, HistErrors>
Create a new interval
- same as
Self::new_inclusive(left, right - 1)
though with checks - That makes
left
an inclusive andright
an exclusive border
sourcepub fn new_inclusive(left: T, right: T) -> Result<Self, HistErrors>
pub fn new_inclusive(left: T, right: T) -> Result<Self, HistErrors>
Create new histogram with inclusive borders
Err
ifleft > right
left
is inclusive borderright
is inclusive border
sourcepub fn bin_iter(&self) -> impl Iterator<Item = T>
pub fn bin_iter(&self) -> impl Iterator<Item = T>
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]);
sourcepub fn bin_hits_iter(&self) -> impl Iterator<Item = (T, usize)> + '_
pub fn bin_hits_iter(&self) -> impl Iterator<Item = (T, usize)> + '_
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)]);
sourcepub fn equal_range(&self, other: &Self) -> boolwhere
T: Eq,
pub fn equal_range(&self, other: &Self) -> boolwhere
T: Eq,
checks if the range of two Histograms is equal, i.e., if they have the same bin borders
sourcepub fn try_add(&mut self, other: &Self) -> Result<(), ()>where
T: Eq,
pub fn try_add(&mut self, other: &Self) -> Result<(), ()>where
T: Eq,
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
sourcepub fn increment<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>
pub fn increment<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>
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
sourcepub fn increment_quiet<V: Borrow<T>>(&mut self, val: V)
pub fn increment_quiet<V: Borrow<T>>(&mut self, val: V)
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> BinDisplay for HistogramFast<T>where
T: PrimInt + HasUnsignedVersion + Copy + Display + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
impl<T> BinDisplay for HistogramFast<T>where
T: PrimInt + HasUnsignedVersion + Copy + Display + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
source§impl<T: Clone> Clone for HistogramFast<T>
impl<T: Clone> Clone for HistogramFast<T>
source§fn clone(&self) -> HistogramFast<T>
fn clone(&self) -> HistogramFast<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for HistogramFast<T>
impl<T: Debug> Debug for HistogramFast<T>
source§impl<'de, T> Deserialize<'de> for HistogramFast<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for HistogramFast<T>where
T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T> Histogram for HistogramFast<T>
impl<T> Histogram for HistogramFast<T>
source§fn count_multiple_index(
&mut self,
index: usize,
count: usize
) -> Result<(), HistErrors>
fn count_multiple_index( &mut self, index: usize, count: usize ) -> Result<(), HistErrors>
source§fn count_index(&mut self, index: usize) -> Result<(), HistErrors>
fn count_index(&mut self, index: usize) -> Result<(), HistErrors>
source§fn any_bin_zero(&self) -> bool
fn any_bin_zero(&self) -> bool
source§impl<T> HistogramCombine for HistogramFast<T>where
Self: HistogramVal<T>,
T: PrimInt + HasUnsignedVersion + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
impl<T> HistogramCombine for HistogramFast<T>where
Self: HistogramVal<T>,
T: PrimInt + HasUnsignedVersion + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
source§impl<T> HistogramIntervalDistance<T> for HistogramFast<T>
impl<T> HistogramIntervalDistance<T> for HistogramFast<T>
source§fn interval_distance_overlap<V: Borrow<T>>(
&self,
val: V,
overlap: NonZeroUsize
) -> usize
fn interval_distance_overlap<V: Borrow<T>>( &self, val: V, overlap: NonZeroUsize ) -> usize
source§impl<T> HistogramPartition for HistogramFast<T>where
T: PrimInt + CheckedSub + ToPrimitive + CheckedAdd + One + FromPrimitive + HasUnsignedVersion + Bounded + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes, Unsigned = T::Unsigned> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned> + FromPrimitive + WrappingSub,
impl<T> HistogramPartition for HistogramFast<T>where
T: PrimInt + CheckedSub + ToPrimitive + CheckedAdd + One + FromPrimitive + HasUnsignedVersion + Bounded + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes, Unsigned = T::Unsigned> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned> + FromPrimitive + WrappingSub,
source§fn overlapping_partition(
&self,
n: usize,
overlap: usize
) -> Result<Vec<Self>, HistErrors>
fn overlapping_partition( &self, n: usize, overlap: usize ) -> Result<Vec<Self>, HistErrors>
source§impl<T> HistogramVal<T> for HistogramFast<T>where
T: PrimInt + HasUnsignedVersion + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
impl<T> HistogramVal<T> for HistogramFast<T>where
T: PrimInt + HasUnsignedVersion + WrappingAdd,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned>,
source§fn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>
fn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>
Iterator over the bins
- This iterator will always return SingleValued bins
- Consider using
self.bin_iter()
instead, its more efficient
source§fn first_border(&self) -> T
fn first_border(&self) -> T
source§fn last_border(&self) -> T
fn last_border(&self) -> T
source§fn last_border_is_inclusive(&self) -> bool
fn last_border_is_inclusive(&self) -> bool
source§fn distance<V: Borrow<T>>(&self, val: V) -> f64
fn distance<V: Borrow<T>>(&self, val: V) -> f64
source§fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>
fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>
source§fn not_inside<V: Borrow<T>>(&self, val: V) -> bool
fn not_inside<V: Borrow<T>>(&self, val: V) -> bool
is_inside