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,
Sourcepub fn range_inclusive(&self) -> RangeInclusive<T>
pub fn range_inclusive(&self) -> RangeInclusive<T>
§Returns the range covered by the bins as a RangeInclusive<T>
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) -> Outcomewhere
T: Eq,
pub fn try_add(&mut self, other: &Self) -> Outcomewhere
T: Eq,
§Add other histogram to self
- will fail if the ranges are not equal, i.e., if equal_range returns false
- Otherwise the hit count of the bins of self will be increased by the corresponding hit count 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 increment_index_by(
&mut self,
index: usize,
count: usize,
) -> Result<(), HistErrors>
fn increment_index_by( &mut self, index: usize, count: usize, ) -> Result<(), HistErrors>
Source§fn increment_index(&mut self, index: usize) -> Result<(), HistErrors>
fn increment_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: NonZeroUsize,
overlap: usize,
) -> Result<Vec<Self>, HistErrors>
fn overlapping_partition( &self, n: NonZeroUsize, 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
Source§impl<T> IntervalOrder for HistogramFast<T>where
T: PrimInt,
impl<T> IntervalOrder for HistogramFast<T>where
T: PrimInt,
Source§fn left_compare(&self, other: &Self) -> Ordering
fn left_compare(&self, other: &Self) -> Ordering
Auto Trait Implementations§
impl<T> Freeze for HistogramFast<T>where
T: Freeze,
impl<T> RefUnwindSafe for HistogramFast<T>where
T: RefUnwindSafe,
impl<T> Send for HistogramFast<T>where
T: Send,
impl<T> Sync for HistogramFast<T>where
T: Sync,
impl<T> Unpin for HistogramFast<T>where
T: Unpin,
impl<T> UnwindSafe for HistogramFast<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more