pub struct FrequencyDistribution<K, S = RandomState> { /* private fields */ }
Implementations§
Source§impl<K, H, S> FrequencyDistribution<K, S>
impl<K, H, S> FrequencyDistribution<K, S>
Sourcepub fn with_capacity_and_hasher(
size: usize,
state: S,
) -> FrequencyDistribution<K, S>
pub fn with_capacity_and_hasher( size: usize, state: S, ) -> FrequencyDistribution<K, S>
Creates a new FrequencyDistrbution with a hasher and size, where the size is known or can be estimated.
Sourcepub fn with_hasher(state: S) -> FrequencyDistribution<K, S>
pub fn with_hasher(state: S) -> FrequencyDistribution<K, S>
Creates a new FrequencyDistribution with a hasher and default size.
Sourcepub fn iter_non_zero(&self) -> NonZeroKeysIter<'_, K> ⓘ
pub fn iter_non_zero(&self) -> NonZeroKeysIter<'_, K> ⓘ
Iterator over the non-zero frequency keys.
§Example
let existing = vec![
("shoes", 1),
("scarf", 0),
("shirt", 13),
("pants", 4)
];
let fdist: FrequencyDistribution<&str> =
FromIterator::from_iter(existing.into_iter());
let mut iter = fdist.iter_non_zero();
assert!(iter.next().is_some());
assert!(iter.next().is_some());
assert!(iter.next().is_some());
assert!(iter.next().is_none());
Sourcepub fn sum_counts(&self) -> usize
pub fn sum_counts(&self) -> usize
Sum of the total number of items counted thus far.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the counts of all keys and clears all keys from the distribution.
Source§impl<K, H, S> FrequencyDistribution<K, S>
impl<K, H, S> FrequencyDistribution<K, S>
Sourcepub fn new() -> FrequencyDistribution<K, S>
pub fn new() -> FrequencyDistribution<K, S>
Creates a new FrequencyDistribution where the size of the HashMap is unknown.
Sourcepub fn with_capacity(size: usize) -> FrequencyDistribution<K, S>
pub fn with_capacity(size: usize) -> FrequencyDistribution<K, S>
Creates a new FrequencyDistribution where the size of the HashMap is known, or a estimate can be made.
Trait Implementations§
Source§impl<K, H, S> Default for FrequencyDistribution<K, S>
impl<K, H, S> Default for FrequencyDistribution<K, S>
Source§fn default() -> FrequencyDistribution<K, S>
fn default() -> FrequencyDistribution<K, S>
Creates a default FrequencyDistribution.
Source§impl<K, H, S> Extend<(K, usize)> for FrequencyDistribution<K, S>
impl<K, H, S> Extend<(K, usize)> for FrequencyDistribution<K, S>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, usize)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, usize)>,
Extends the hashmap by adding the keys or updating the frequencies of the keys.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<K, H, S> FromIterator<(K, usize)> for FrequencyDistribution<K, S>
impl<K, H, S> FromIterator<(K, usize)> for FrequencyDistribution<K, S>
Source§fn from_iter<T>(iter: T) -> FrequencyDistribution<K, S>where
T: IntoIterator<Item = (K, usize)>,
fn from_iter<T>(iter: T) -> FrequencyDistribution<K, S>where
T: IntoIterator<Item = (K, usize)>,
Iterates through an iterator, and creates a new FrequencyDistribution from
it. The iterator should be an iterator over keys and frequencies. If a
upper bounded size_hsize
is available, then it is used, otherwise the lower
bounded size_hsize
is used.
§Example
let existing = vec![
("apples", 3),
("oranges", 4),
("bannana", 7)
];
let fdist: FrequencyDistribution<&str> =
FromIterator::from_iter(existing.into_iter());
assert_eq!(fdist.get(&"apples"), 3);
assert_eq!(fdist.get(&"oranges"), 4);
assert_eq!(fdist.get(&"bannana"), 7);