Struct freqdist::FrequencyDistribution
[−]
[src]
pub struct FrequencyDistribution<K, S = RandomState> { /* fields omitted */ }
Methods
impl<K, H, S> FrequencyDistribution<K, S> where
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H>,
[src]
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H>,
fn with_capacity_and_hasher(
size: usize,
state: S
) -> FrequencyDistribution<K, S>
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.
fn with_hasher(state: S) -> FrequencyDistribution<K, S>
Creates a new FrequencyDistribution with a hasher and default size.
fn keys(&self) -> Keys<K, usize>
Iterator over the keys.
fn iter(&self) -> Iter<K, usize>
Iterator over the key, frequency pairs.
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());
fn sum_counts(&self) -> usize
Sum of the total number of items counted thus far.
fn len(&self) -> usize
Returns the number of entries in the distribution
fn get<Q: ?Sized>(&self, k: &Q) -> usize where
K: Borrow<Q>,
Q: Hash + Eq,
K: Borrow<Q>,
Q: Hash + Eq,
Gets the frequency in which the key occurs.
fn clear(&mut self)
Clears the counts of all keys and clears all keys from the distribution.
fn insert(&mut self, k: K)
Updates the frequency of the value found with the key if it already exists. Otherwise, inserts the key sizeo the hashmap, and sets its frequency to 1.
fn remove<Q: ?Sized>(&mut self, k: &Q) where
K: Borrow<Q>,
Q: Hash + Eq,
K: Borrow<Q>,
Q: Hash + Eq,
Removes an item and its associated counts.
impl<K, H, S> FrequencyDistribution<K, S> where
K: Eq + Hash,
H: Hasher + Default,
S: BuildHasher<Hasher = H> + Default,
[src]
K: Eq + Hash,
H: Hasher + Default,
S: BuildHasher<Hasher = H> + Default,
fn new() -> FrequencyDistribution<K, S>
Creates a new FrequencyDistribution where the size of the HashMap is unknown.
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
impl<K, H, S> Default for FrequencyDistribution<K, S> where
K: Eq + Hash,
H: Hasher + Default,
S: BuildHasher<Hasher = H> + Default,
[src]
K: Eq + Hash,
H: Hasher + Default,
S: BuildHasher<Hasher = H> + Default,
fn default() -> FrequencyDistribution<K, S>
Creates a default FrequencyDistribution.
impl<K, H, S> FromIterator<(K, usize)> for FrequencyDistribution<K, S> where
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H> + Default,
[src]
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H> + Default,
fn from_iter<T>(iter: T) -> FrequencyDistribution<K, S> where
T: IntoIterator<Item = (K, usize)>,
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);
impl<K, H, S> Extend<(K, usize)> for FrequencyDistribution<K, S> where
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H>,
[src]
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H>,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, usize)>,
T: IntoIterator<Item = (K, usize)>,
Extends the hashmap by adding the keys or updating the frequencies of the keys.
impl<K, H, S> IntoIterator for FrequencyDistribution<K, S> where
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H>,
[src]
K: Eq + Hash,
H: Hasher,
S: BuildHasher<Hasher = H>,
type Item = (K, usize)
The type of the elements being iterated over.
type IntoIter = IntoIter<K, usize>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<K, usize>
Consumes the distribution, and creates an iterator over the (Key, Quantity: usize) pairs.
impl<'a, K, H, S, Q: ?Sized> Index<&'a Q> for FrequencyDistribution<K, S> where
K: Eq + Hash + Borrow<Q>,
H: Hasher,
S: BuildHasher<Hasher = H>,
Q: Eq + Hash,
[src]
K: Eq + Hash + Borrow<Q>,
H: Hasher,
S: BuildHasher<Hasher = H>,
Q: Eq + Hash,