pub struct AtomicHistogramInt<T> { /* private fields */ }
Expand description

Implementations§

source§

impl<T> AtomicHistogramInt<T>

source

pub fn borders(&self) -> &[T]

similar to self.borders_clone but does not allocate memory

source

pub fn bin_iter(&self) -> impl Iterator<Item = &[T; 2]>

Iterator over all the bins

In AtomicHistogramInt 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 = AtomicHistI8::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);
source

pub fn bin_hits_iter(&mut self) -> impl Iterator<Item = (&[T; 2], usize)>

Iterate over all bins

In AtomicHistogramInt 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)

Note

Since I am using atomics here it is possible that the hit-count changes during the iteration, if another thread writes to the histogram for example.

Item of Iterator

(&[left_border, right_border], number_of_hits)

Example
use sampling::histogram::*;
 
let mut hist = AtomicHistUsize::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> AtomicHistogramInt<T>
where T: Sub<T, Output = T> + Add<T, Output = T> + Ord + One + Copy + NumCast,

source

pub fn increment<V: Borrow<T>>(&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
source

pub fn increment_quiet<V: Borrow<T>>(&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

Note
  • Uses atomic operations for the counters, so this is thread safe
source§

impl<T> AtomicHistogramInt<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>,

source

pub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>

Create a new histogram
  • right: exclusive border
  • left: inclusive border
  • bins: how many bins do you need?
Note
  • (right - left) % bins == 0 has to be true, otherwise the bins cannot all have the same length!
source

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

Create a new histogram
Note:
  • Due to implementation details, right cannot be T::MAX - if you try, you will get Err(HistErrors::Overflow)

Trait Implementations§

source§

impl<T> AtomicHistogram for AtomicHistogramInt<T>

source§

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

Uses SeqCst

source§

fn bin_count(&self) -> usize

How many bins the histogram contains Read more
source§

fn hist(&self) -> &[AtomicUsize]

the created histogram Read more
source§

fn reset(&mut self)

reset the histogram to zero
source§

fn count_index(&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 Read more
source§

impl<T> AtomicHistogramVal<T> for AtomicHistogramInt<T>
where T: Ord + Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy,

source§

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

None if not inside Hist covered zone

source§

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

count val. Ok(index), if inside of hist, Err(_) if val is invalid
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 first_border(&self) -> T

get the left most border (inclusive)
source§

fn last_border(&self) -> T

Get border on the right Read more
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 borders_clone(&self) -> Result<Vec<T>, HistErrors>

binning borders Read more
source§

impl<T: Debug> Debug for AtomicHistogramInt<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 AtomicHistogramInt<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> From<AtomicHistogramInt<T>> for HistogramInt<T>

source§

fn from(other: AtomicHistogramInt<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<HistogramInt<T>> for AtomicHistogramInt<T>

source§

fn from(other: HistogramInt<T>) -> Self

Converts to this type from the input type.
source§

impl<T> HistogramIntervalDistance<T> for AtomicHistogramInt<T>
where T: Ord + Sub<T, Output = T> + Add<T, Output = T> + One + 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 AtomicHistogramInt<T>
where T: Clone + Debug,

source§

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

partition the interval Read more
source§

impl<T> IntervalOrder for AtomicHistogramInt<T>
where T: Ord,

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 AtomicHistogramInt<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 AtomicHistogramInt<T>
where T: RefUnwindSafe,

§

impl<T> Send for AtomicHistogramInt<T>
where T: Send,

§

impl<T> Sync for AtomicHistogramInt<T>
where T: Sync,

§

impl<T> Unpin for AtomicHistogramInt<T>
where T: Unpin,

§

impl<T> UnwindSafe for AtomicHistogramInt<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, 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>,