Struct sampling::histogram::HistogramInt
source · pub struct HistogramInt<T> { /* private fields */ }
Expand description
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>
Create a new histogram
right
: exclusive borderleft
: inclusive borderbins
: how many bins do you need?
Note
(right - left) % bins == 0
has to be true, otherwise the bins cannot all have the same length!
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> From<AtomicHistogramInt<T>> for HistogramInt<T>
impl<T> From<AtomicHistogramInt<T>> for HistogramInt<T>
source§fn from(other: AtomicHistogramInt<T>) -> Self
fn from(other: AtomicHistogramInt<T>) -> Self
source§impl<T> From<HistogramInt<T>> for AtomicHistogramInt<T>
impl<T> From<HistogramInt<T>> for AtomicHistogramInt<T>
source§fn from(other: HistogramInt<T>) -> Self
fn from(other: HistogramInt<T>) -> Self
source§impl<T> Histogram for HistogramInt<T>
impl<T> Histogram for HistogramInt<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> 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: 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 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 iterater 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