Struct russell_stat::Histogram
source · pub struct Histogram<T>{ /* private fields */ }
Expand description
Implements a Histogram to count frequencies
The stations/bins are set as follows:
[ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] )[ bin[4] )
---|---------|---------|---------|---------|---------|--- x
s[0] s[1] s[2] s[3] s[4] s[5]
bin_i corresponds to station_i <= x < station_(i+1)
§Examples
use russell_stat::{Histogram, StrError};
fn main() -> Result<(), StrError> {
let data = [
-1.0, // outside
10.0, 10.1, // outside
9.0, // count = 1
8.1, 8.2, // count = 2
7.1, 7.2, 7.2, // count = 3
6.0, 6.1, 6.1, 6.2, 6.99, // count = 5
5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, // count = 9
4.0, 4.1, 4.1, 4.2, 4.99, // count = 5
3.1, 3.2, 3.2, // count = 3
2.1, // count = 1
];
let stations: [f64; 11] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
let mut hist = Histogram::new(&stations)?;
hist.count(&data);
assert_eq!(hist.get_counts(), &[0, 0, 1, 3, 5, 9, 5, 3, 2, 1]);
hist.set_bar_max_len(10);
assert_eq!(
format!("{}", hist),
"[ 0, 1) | 0 \n\
[ 1, 2) | 0 \n\
[ 2, 3) | 1 🟦\n\
[ 3, 4) | 3 🟦🟦🟦\n\
[ 4, 5) | 5 🟦🟦🟦🟦🟦\n\
[ 5, 6) | 9 🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦\n\
[ 6, 7) | 5 🟦🟦🟦🟦🟦\n\
[ 7, 8) | 3 🟦🟦🟦\n\
[ 8, 9) | 2 🟦🟦\n\
[ 9,10) | 1 🟦\n\
\x20\x20\x20sum = 29\n"
);
Ok(())
}
Implementations§
source§impl<T> Histogram<T>
impl<T> Histogram<T>
sourcepub fn get_counts(&self) -> &Vec<usize>
pub fn get_counts(&self) -> &Vec<usize>
Returns a read-only access to the counts (frequencies)
sourcepub fn set_bar_char(&mut self, bar_char: char) -> &mut Self
pub fn set_bar_char(&mut self, bar_char: char) -> &mut Self
Sets the character used in histogram drawn by Display
sourcepub fn set_bar_max_len(&mut self, bar_max_len: usize) -> &mut Self
pub fn set_bar_max_len(&mut self, bar_max_len: usize) -> &mut Self
Sets the maximum length (number of characters) used in histogram draw by Display
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Histogram<T>
impl<T> RefUnwindSafe for Histogram<T>where
T: RefUnwindSafe,
impl<T> Send for Histogram<T>where
T: Send,
impl<T> Sync for Histogram<T>where
T: Sync,
impl<T> Unpin for Histogram<T>where
T: Unpin,
impl<T> UnwindSafe for Histogram<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more