Struct StandardHistogram

Source
pub struct StandardHistogram { /* private fields */ }
Expand description

StandardHistogram is a naive implementation of a histogram with no optimizations. It has optimal performance since it stores an exact count for exact labels, but it can take an arbitrary amount of space. It uses a library HashMap to store label-frequency pairs, and can be instantiated with one using the create_standard_histogram function. StandardHistogram is associated with NullParams.

§Example

To create, pass a HashMap to the constructor function:

let mut data = HashMap::new();
data.insert(1, 40);
data.insert(3, 15);
data.insert(50, 1);

let histogram :StandardHistogram = create_standard_histogram(data);

Implementations§

Source§

impl StandardHistogram

Source

pub fn to_compact(&self, cp: &CompactParams) -> Option<CompactHistogram>

If possible, creates a CompactHistogram of this histogram.

§Example
use c2_histograms::c2::{CompactHistogram, new_compact_params, CompactParams};

let histogram : StandardHistogram = create_standard_histogram(data);
let cp : CompactParams = new_compact_params(3.5, 8, 8).unwrap();

let compact_histogram : CompactHistogram = histogram.to_compact(&cp).unwrap();
Source

pub fn to_compressed( &self, cp: &CompressedParams, ) -> Option<CompressedHistogram>

If possible, creates a CompressedHistogram of this histogram.

§Example
use c2_histograms::c2::{CompressedHistogram, new_compressed_params, CompressedParams};

let histogram : StandardHistogram = create_standard_histogram(data);
let cp : CompressedParams = new_compressed_params(1.5, 255).unwrap();

let compact_histogram : CompressedHistogram = histogram.to_compressed(&cp).unwrap();
Source

pub fn to_c2(&self, c2p: &C2Params) -> Option<C2Histogram>

If possible, creates a C2Histogram of this histogram

§Example
use c2_histograms::c2::{CompactHistogram, new_compact_params, CompactParams, new_c2_params, C2Params, C2Histogram};
use c2_histograms::c2::{CompressedHistogram, new_compressed_params, CompressedParams};

let histogram : StandardHistogram = create_standard_histogram(data);

let cp1 : CompactParams = new_compact_params(3.5, 8, 8).unwrap();
let cp2 : CompressedParams = new_compressed_params(1.5, 255).unwrap();

let cp : C2Params = new_c2_params(cp1, cp2);

let compact_histogram : C2Histogram = histogram.to_c2(&cp).unwrap();

Trait Implementations§

Source§

impl Histogram<NullParams, usize, usize> for StandardHistogram

Source§

fn labels( &self, _params: &NullParams, ) -> Option<Box<dyn Iterator<Item = usize>>>

If possible, creates and returns an iterator for the labels for which the histogram has frequencies stored.
Source§

fn frequency(&self, label: usize, _params: &NullParams) -> Option<usize>

If possible, returns the frequency of a particular label. The behavior need only be defined if the label is in the set of values returned from labels.
Source§

fn total(&self) -> usize

the total number of data-points in the histogram

Auto Trait Implementations§

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.