Type Alias sampling::histogram::FastBinningUSIZE
source · pub type FastBinningUSIZE = FastSingleIntBinning<usize>;
Expand description
Efficient binning for usize
with bins of width 1
Aliased Type§
struct FastBinningUSIZE { /* private fields */ }
Implementations§
source§impl FastBinningUSIZE
impl FastBinningUSIZE
sourcepub const fn new_inclusive(start: usize, end_inclusive: usize) -> Self
pub const fn new_inclusive(start: usize, end_inclusive: usize) -> Self
Create a new Binning
- both borders are inclusive
- each bin has width 1
Panics
- if
start
is smaller thanend_inclusive
TODO Think about if this should actually panic or return None
sourcepub const fn range_inclusive(&self) -> RangeInclusive<usize>
pub const fn range_inclusive(&self) -> RangeInclusive<usize>
sourcepub fn single_valued_bin_iter(&self) -> impl Iterator<Item = usize>
pub fn single_valued_bin_iter(&self) -> impl Iterator<Item = usize>
Iterator over all the bins
Since the bins have width 1, a bin can be defined by its corresponding value which we can iterate over.
Example
use sampling::histogram::FastBinningUSIZE;
let binning = FastBinningUSIZE::new_inclusive(2,5);
let vec: Vec<_> = binning.single_valued_bin_iter().collect();
assert_eq!(&vec, &[2, 3, 4, 5]);
sourcepub fn bins_m1(&self) -> <usize as HasUnsignedVersion>::Unsigned
pub fn bins_m1(&self) -> <usize as HasUnsignedVersion>::Unsigned
The amount of bins -1
- minus 1 because if the bins are going over the entire range of the type, then I 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
Trait Implementations§
source§impl Binning<usize> for FastBinningUSIZE
impl Binning<usize> for FastBinningUSIZE
source§fn get_bin_index<V: Borrow<usize>>(&self, val: V) -> Option<usize>
fn get_bin_index<V: Borrow<usize>>(&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 not_inside<V: Borrow<usize>>(&self, val: V) -> bool
fn not_inside<V: Borrow<usize>>(&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) -> usize
fn first_border(&self) -> usize
get the left most border (inclusive)
source§fn distance<V: Borrow<usize>>(&self, v: V) -> f64
fn distance<V: Borrow<usize>>(&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<usize>>>
fn bin_iter(&self) -> Box<dyn Iterator<Item = Bin<usize>>>
Iterates over all bins
- Note: This implementation use more efficient representations of the bins underneath, but are capable of returning the bins in this representation on request
- Note also that this
Binning
implements another method for the bin borders, i.e.,single_valued_bin_iter
. Consider using that instead, as it is more efficient
source§fn get_bin_len(&self) -> usize
fn get_bin_len(&self) -> usize
Get the number of underlying bins Read more
source§fn last_border(&self) -> usize
fn last_border(&self) -> usize
get last border from the rightNote: this border might be inclusive or exclusive Read more
source§fn last_border_is_inclusive(&self) -> bool
fn last_border_is_inclusive(&self) -> bool
True if last border is inclusive, false otherwise Read more