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

Implementations

similar to self.borders_clone but does not allocate memory

Iterator over all the bins

In HistogramInt 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 = HistI8::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);
Iterate over all bins

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

Item of Iterator

(&[left_border, right_border], number_of_hits)

Example
use sampling::histogram::*;
 
let mut hist = HistUsize::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);
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

Increment hit count

Increments the hit count of the bin corresponding to val. If no bin corresponding to val exists, nothing happens

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
How many bins the histogram contains
the created histogram
self.hist[index] += count, Err() if index out of bounds
reset the histogram to zero
self.hist[index] += 1, Err() if index out of bounds
check if any bin was not hit yet
Distance metric for how far a value is from a valid interval Read more
partition the interval Read more

None if not inside Hist covered zone

count val. Ok(index), if inside of hist, Err(_) if val is invalid
calculates some sort of absolute distance to the nearest valid bin Read more
get the left most border (inclusive)
  • get second last border from the right
  • should be the same as let b = self.borders_clone().expect("overflow"); assert_eq!(self.second_last_border(), b[b.len()-2])
  • Read more
    does a value correspond to a valid bin?
    opposite of is_inside
    binning borders Read more
    Will compare leftest bin first. if they are equal: will compare right bin Read more
    Serialize this value into the given Serde serializer. Read more

    Auto Trait Implementations

    Blanket Implementations

    Gets the TypeId of self. Read more
    Immutably borrows from an owned value. Read more
    Mutably borrows from an owned value. Read more
    Cast from Self to T
    Try converting from Self to T
    Cast to integer, truncating Read more
    Cast to the nearest integer Read more
    Cast the floor to an integer Read more
    Cast the ceiling to an integer Read more
    Try converting to integer with truncation Read more
    Try converting to the nearest integer Read more
    Try converting the floor to an integer Read more
    Try convert the ceiling to an integer Read more
    Convert from T to Self
    Try converting from T to Self

    Returns the argument unchanged.

    Calls U::from(self).

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

    The alignment of pointer.
    The type for initializers.
    Initializes a with the given initializer. Read more
    Dereferences the given pointer. Read more
    Mutably dereferences the given pointer. Read more
    Drops the object pointed to by the given pointer. Read more
    The resulting type after obtaining ownership.
    Creates owned data from borrowed data, usually by cloning. Read more
    Uses borrowed data to replace owned data, usually by cloning. Read more
    The type returned in the event of a conversion error.
    Performs the conversion.
    The type returned in the event of a conversion error.
    Performs the conversion.