pub struct HistogramInt<T> { /* private fields */ }
Expand description
ยงGeneric Histogram for integer types
If possible, consider using GenericHist with FastSingleIntBinning or,
if your bin width is not 1, with BinningWithWidth instead (see Binning::to_generic_hist).
This will likely be faster than using HistogramInt<T>
Implementationsยง
Sourceยงimpl<T> HistogramInt<T>
impl<T> HistogramInt<T>
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 HistogramInt 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 = HistI8::new(0, 8, 4).unwrap();
let mut bin_iter = hist.bin_iter();
assert_eq!(bin_iter.next(), Some(&[0_i8, 2]));
assert_eq!(bin_iter.next(), Some(&[2, 4]));
assert_eq!(bin_iter.next(), Some(&[4, 6]));
assert_eq!(bin_iter.next(), Some(&[6, 8]));
assert_eq!(bin_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 HistogramInt a bin is defined by two values: The left border (inclusive) and the right border (exclusive)
This iterates over these values as well as the corresponding hit count (i.e. how often the corresponding bin was hit)
ยงItem of Iterator
(&[left_border, right_border], number_of_hits)
ยงExample
use sampling::histogram::*;
let mut hist = HistUsize::new(0, 6, 3).unwrap();
hist.increment(0).unwrap();
hist.increment(5).unwrap();
hist.increment(4).unwrap();
let mut iter = hist.bin_hits_iter();
assert_eq!(
iter.next(),
Some(
(&[0, 2], 1)
)
);
assert_eq!(
iter.next(),
Some(
(&[2, 4], 0)
)
);
assert_eq!(
iter.next(),
Some(
(&[4, 6], 2)
)
);
assert_eq!(iter.next(), None);
Sourceยงimpl<T> HistogramInt<T>
impl<T> HistogramInt<T>
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
Sourceยงimpl<T> HistogramInt<T>where
T: PartialOrd + ToPrimitive + FromPrimitive + CheckedAdd + One + HasUnsignedVersion + Bounded + Sub<T, Output = T> + Mul<T, Output = T> + Zero + Copy,
RangeInclusive<T>: Iterator<Item = T>,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes, Unsigned = T::Unsigned> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned> + Rem<Output = T::Unsigned> + FromPrimitive + Zero + Eq + Div<Output = T::Unsigned> + Ord + Mul<Output = T::Unsigned> + WrappingSub + Copy,
RangeInclusive<T::Unsigned>: Iterator<Item = T::Unsigned>,
impl<T> HistogramInt<T>where
T: PartialOrd + ToPrimitive + FromPrimitive + CheckedAdd + One + HasUnsignedVersion + Bounded + Sub<T, Output = T> + Mul<T, Output = T> + Zero + Copy,
RangeInclusive<T>: Iterator<Item = T>,
T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes, Unsigned = T::Unsigned> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned> + Rem<Output = T::Unsigned> + FromPrimitive + Zero + Eq + Div<Output = T::Unsigned> + Ord + Mul<Output = T::Unsigned> + WrappingSub + Copy,
RangeInclusive<T::Unsigned>: Iterator<Item = T::Unsigned>,
Sourcepub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
pub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
Sourcepub fn new_inclusive(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
pub fn new_inclusive(left: T, right: T, bins: usize) -> Result<Self, HistErrors>
ยงCreate a new histogram
- equivalent to
Self::new(left, right + 1, bins)
(except that this method checks for possible overflow)
ยงNote:
- Due to implementation details,
right
cannot beT::MAX
- if you try, you will getErr(HistErrors::Overflow)
Trait Implementationsยง
Sourceยงimpl<T: Clone> Clone for HistogramInt<T>
impl<T: Clone> Clone for HistogramInt<T>
Sourceยงfn clone(&self) -> HistogramInt<T>
fn clone(&self) -> HistogramInt<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 HistogramInt<T>
impl<T: Debug> Debug for HistogramInt<T>
Sourceยงimpl<'de, T> Deserialize<'de> for HistogramInt<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for HistogramInt<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 HistogramInt<T>
impl<T> Histogram for HistogramInt<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> HistogramIntervalDistance<T> for HistogramInt<T>
impl<T> HistogramIntervalDistance<T> for HistogramInt<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 HistogramInt<T>
impl<T> HistogramPartition for HistogramInt<T>
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 HistogramInt<T>
impl<T> HistogramVal<T> for HistogramInt<T>
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>
None if not inside Hist covered zone
Sourceยงfn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>
fn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>
ยงconsider using self.bin_iter()
instead
- this will return an iterator over the bins for displaying purposes
- all bins are defined via an inclusive and an exclusive border
- It is more efficient to use
self.bin_iter()
instead
Sourceยงfn count_val<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>
fn count_val<V: Borrow<T>>(&mut 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 last_border_is_inclusive(&self) -> bool
fn last_border_is_inclusive(&self) -> bool
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 HistogramInt<T>where
T: Ord,
impl<T> IntervalOrder for HistogramInt<T>where
T: Ord,
Sourceยงfn left_compare(&self, other: &Self) -> Ordering
fn left_compare(&self, other: &Self) -> Ordering
Auto Trait Implementationsยง
impl<T> Freeze for HistogramInt<T>
impl<T> RefUnwindSafe for HistogramInt<T>where
T: RefUnwindSafe,
impl<T> Send for HistogramInt<T>where
T: Send,
impl<T> Sync for HistogramInt<T>where
T: Sync,
impl<T> Unpin for HistogramInt<T>where
T: Unpin,
impl<T> UnwindSafe for HistogramInt<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