Trait Binning

Source
pub trait Binning<T> {
    // Required methods
    fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Option<usize>;
    fn get_bin_len(&self) -> usize;
    fn bin_iter(&self) -> Box<dyn Iterator<Item = Bin<T>>>;
    fn is_inside<V: Borrow<T>>(&self, val: V) -> bool;
    fn not_inside<V: Borrow<T>>(&self, val: V) -> bool;
    fn first_border(&self) -> T;
    fn last_border(&self) -> T;
    fn last_border_is_inclusive(&self) -> bool;
    fn distance<V: Borrow<T>>(&self, val: V) -> f64;

    // Provided methods
    fn to_generic_hist(self) -> GenericHist<Self, T>
       where Self: Sized { ... }
    fn to_generic_atomic_hist(self) -> AtomicGenericHist<Self, T>
       where Self: Sized { ... }
}
Expand description

§Implements Binning

Part of a histogram, but without the capability of counting stuff, i.e., you can use this to iterate through the bins or to get the bin index that a certain value would correspond to, but it does not contain counters to track this.

You can use this to create histograms, see GenericHist or AtomicGenericHist

Required Methods§

Source

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

convert val to the respective binning index

Source

fn get_bin_len(&self) -> usize

§Get the number of underlying bins
  • note: if more than usize::MAX bins are there, usize::MAX is returned
Source

fn bin_iter(&self) -> Box<dyn Iterator<Item = Bin<T>>>

§Iterates over all bins

Note: Most (currently all) implementations use more efficient representations of the bins underneath, but are capable of returning the bins in this representation on request. So it’s better to use the native iterator instead, if you can.

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, so: is the value outside the valid range?

Source

fn first_border(&self) -> T

get the left most border (inclusive). This is the first value that lies inside the binning

Source

fn last_border(&self) -> T

  • If the last border is inclusive, this returns the largest value that is still inside the binning.
  • If the last border is exclusive, this is the first value which is not inside the binning.
Source

fn last_border_is_inclusive(&self) -> bool

§True if last border is inclusive, false otherwise

For most use cases this will return a constant value, as this is likely only dependent on the underlying type and not on something that changes dynamically

Source

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

§calculates some sort of absolute distance to the nearest valid bin
  • any invalid numbers (like NAN or INFINITY) should have the highest distance possible
  • if a value corresponds to a valid bin, the distance should be zero

Provided Methods§

Source

fn to_generic_hist(self) -> GenericHist<Self, T>
where Self: Sized,

§Convert binning into GenericHist

Useful histogram for single threaded context’s. Otherwise AtomicGenericHist might be more useful (see also Binning::to_generic_atomic_hist)

Source

fn to_generic_atomic_hist(self) -> AtomicGenericHist<Self, T>
where Self: Sized,

§Convert binning into a AtomicGenericHist

Useful histogram if you want to create the histogram in parallel, but otherwise has less functionality than GenericHist (see also Binning::to_generic_hist)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§