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,

source

pub fn left(&self) -> T

Get left border, inclusive

source

pub fn right(&self) -> T

Get right border, inclusive

source

pub fn range_inclusive(&self) -> RangeInclusive<T>

source§

impl<T> HistogramFast<T>

source

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 and right an exclusive border
source

pub fn new_inclusive(left: T, right: T) -> Result<Self, HistErrors>

Create new histogram with inclusive borders
  • Err if left > right
  • left is inclusive border
  • right is inclusive border
source

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]);
source

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)]);
source

pub fn equal_range(&self, other: &Self) -> bool
where T: Eq,

checks if the range of two Histograms is equal, i.e., if they have the same bin borders

source

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
source

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

source

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>

§

type BinEntry = T

source§

fn display_bin_iter(&self) -> Box<dyn Iterator<Item = Self::BinEntry> + '_>

Iterator over all the bins Read more
source§

fn write_bin<W: Write>(entry: &Self::BinEntry, writer: W) -> Result<()>

For writing a bin Read more
source§

fn write_header<W: Write>(&self, writer: W) -> Result<()>

Writing the header of the bin Read more
source§

impl<T: Clone> Clone for HistogramFast<T>

source§

fn clone(&self) -> HistogramFast<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for HistogramFast<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Histogram for HistogramFast<T>

source§

fn count_multiple_index( &mut self, index: usize, count: usize ) -> Result<(), HistErrors>

self.hist[index] += count, Err() if index out of bounds Read more
source§

fn hist(&self) -> &Vec<usize>

the created histogram Read more
source§

fn bin_count(&self) -> usize

How many bins the histogram contains Read more
source§

fn reset(&mut self)

reset the histogram to zero
source§

fn count_index(&mut self, index: usize) -> Result<(), HistErrors>

self.hist[index] += 1, Err() if index out of bounds Read more
source§

fn any_bin_zero(&self) -> bool

check if any bin was not hit yet
source§

impl<T> HistogramCombine for HistogramFast<T>

source§

fn encapsulating_hist<S>(hists: &[S]) -> Result<Self, HistErrors>
where S: Borrow<Self>,

Create a histogram, which encapsulates the histograms passed Read more
source§

fn align<S>(&self, right: S) -> Result<usize, HistErrors>
where S: Borrow<Self>,

Get bin difference between histograms Read more
source§

impl<T> HistogramIntervalDistance<T> for HistogramFast<T>
where Self: HistogramVal<T>, T: PartialOrd + Sub<Output = T> + NumCast + Copy,

source§

fn interval_distance_overlap<V: Borrow<T>>( &self, val: V, overlap: NonZeroUsize ) -> usize

Distance metric for how far a value is from a valid interval Read more
source§

impl<T> HistogramPartition for HistogramFast<T>

source§

fn overlapping_partition( &self, n: usize, overlap: usize ) -> Result<Vec<Self>, HistErrors>

partition the interval Read more
source§

impl<T> HistogramVal<T> for HistogramFast<T>

source§

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

get the left most border (inclusive)
source§

fn last_border(&self) -> T

get last border from the right Read more
source§

fn last_border_is_inclusive(&self) -> bool

True if last border is inclusive, false otherwise Read more
source§

fn distance<V: Borrow<T>>(&self, val: V) -> f64

calculates some sort of absolute distance to the nearest valid bin Read more
source§

fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>

convert val to the respective histogram index
source§

fn is_inside<V: Borrow<T>>(&self, val: V) -> bool

does a value correspond to a valid bin?
source§

fn not_inside<V: Borrow<T>>(&self, val: V) -> bool

opposite of is_inside
source§

fn count_val<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>

count val. Ok(index), if inside of hist, Err(_) if val is invalid
source§

impl<T> IntervalOrder for HistogramFast<T>
where T: PrimInt,

source§

fn left_compare(&self, other: &Self) -> Ordering

Will compare leftest bin first. if they are equal: will compare right bin
source§

impl<T> Serialize for HistogramFast<T>
where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<S, T> Cast<T> for S
where T: Conv<S>,

§

fn cast(self) -> T

Cast from Self to T Read more
§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,