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]

Creates a new FrequencyDistrbution with a hasher and size, where the size is known or can be estimated.

Creates a new FrequencyDistribution with a hasher and default size.

Iterator over the keys.

Iterator over the key, frequency pairs.

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());

Sum of the total number of items counted thus far.

Returns the number of entries in the distribution

Gets the frequency in which the key occurs.

Clears the counts of all keys and clears all keys from the distribution.

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.

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]

Creates a new FrequencyDistribution where the size of the HashMap is unknown.

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]

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]

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]

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]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

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]

The returned type after indexing

The method for the indexing (container[index]) operation