Type Alias BinningI16

Source
pub type BinningI16 = BinningWithWidth<i16>;
Expand description

Efficient binning for i16 with arbitrary width

Aliased Type§

struct BinningI16 { /* private fields */ }

Implementations§

Source§

impl BinningI16

Source

pub fn new_inclusive( start: i16, end_inclusive: i16, bin_width: i16, ) -> Result<Self, <i16 as HasUnsignedVersion>::Unsigned>

§Create a new Binning
  • both borders are inclusive
  • each bin has width bin_width
§Panics
  • if start is smaller than end_inclusive
  • if bin_width <= 0
§Err

Result is Err if start and end are mismatched with the bin_width, i.e., it is impossible to create the binning due to the integer nature of our types

Source

pub const fn left(&self) -> i16

Get left border, inclusive

Source

pub const fn right(&self) -> i16

Get right border, inclusive

Source

pub const fn range_inclusive(&self) -> RangeInclusive<i16>

§Returns the range covered by the bins as a RangeInclusive<i16>
Source

pub fn native_bin_iter(&self) -> impl Iterator<Item = RangeInclusive<i16>>

§Iterator over all the bins

Here the bins are represented as RangeInclusive<i16>

§Example:
use sampling::histogram::BinningI16;
let binning = BinningI16::new_inclusive(2,7,2).unwrap();
let vec: Vec<_> = binning.native_bin_iter().collect();
assert_eq!(&vec, &[(2..=3), (4..=5), (6..=7)]);
Source

pub fn bins_m1(&self) -> <i16 as HasUnsignedVersion>::Unsigned

§The amount of bins -1
  • minus 1 because if the bins are of width 1 and are going over the entire range of the type, then we cannot represent the number of bins as this type
§Example

If we look at an u8 and the range from 0 to 255, then this is 256 bins, which cannot be represented as u8. To combat this, I return bins - 1. This works, because we always have at least 1 bin

Source

pub fn get_bin_index_native<V: Borrow<i16>>( &self, val: V, ) -> Option<<i16 as HasUnsignedVersion>::Unsigned>

§Get the respective bin in native unsigned

Trait Implementations§

Source§

impl Binning<i16> for BinningI16

Source§

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

§Get the respective bin index
  • Note: Obviously this breaks when the bin index cannot be represented as usize
Source§

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

Does a value correspond to a valid bin?

Source§

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

§Opposite of is_inside
  • I could also have called this is_outside, but I didn’t
Source§

fn first_border(&self) -> i16

get the left most border (inclusive)

Source§

fn distance<V: Borrow<i16>>(&self, v: V) -> f64

§calculates some sort of absolute distance to the nearest valid bin
  • if a value corresponds to a valid bin, the distance is zero
Source§

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

§Iterates over all bins
  • Note: This implementation uses a more efficient representations of the bins underneath, but is capable of returning the bins in this representation on request
  • Note also that this Binning implements another method for the bin borders, i.e., native_bin_iter. Consider using that instead, as it is more efficient
Source§

fn get_bin_len(&self) -> usize

Get the number of underlying bins Read more
Source§

fn last_border(&self) -> i16

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. Read more
Source§

fn last_border_is_inclusive(&self) -> bool

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

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

Convert binning into GenericHist Read more
Source§

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

Convert binning into a AtomicGenericHist Read more