Struct FrequencyDistribution

Source
pub struct FrequencyDistribution<K, S = RandomState> { /* private fields */ }

Implementations§

Source§

impl<K, H, S> FrequencyDistribution<K, S>
where K: Eq + Hash, H: Hasher, S: BuildHasher<Hasher = H>,

Source

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.

Source

pub fn with_hasher(state: S) -> FrequencyDistribution<K, S>

Creates a new FrequencyDistribution with a hasher and default size.

Source

pub fn keys(&self) -> Keys<'_, K, usize>

Iterator over the keys.

Source

pub fn iter(&self) -> Iter<'_, K, usize>

Iterator over the key, frequency pairs.

Source

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

pub fn sum_counts(&self) -> usize

Sum of the total number of items counted thus far.

Source

pub fn len(&self) -> usize

Returns the number of entries in the distribution

Source

pub fn get<Q>(&self, k: &Q) -> usize
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Gets the frequency in which the key occurs.

Source

pub fn clear(&mut self)

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

Source

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

Source

pub fn remove<Q>(&mut self, k: &Q)
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes an item and its associated counts.

Source§

impl<K, H, S> FrequencyDistribution<K, S>
where K: Eq + Hash, H: Hasher + Default, S: BuildHasher<Hasher = H> + Default,

Source

pub fn new() -> FrequencyDistribution<K, S>

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

Source

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>
where K: Eq + Hash, H: Hasher + Default, S: BuildHasher<Hasher = H> + Default,

Source§

fn default() -> FrequencyDistribution<K, S>

Creates a default FrequencyDistribution.

Source§

impl<K, H, S> Extend<(K, usize)> for FrequencyDistribution<K, S>
where K: Eq + Hash, H: Hasher, S: BuildHasher<Hasher = H>,

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K, H, S> FromIterator<(K, usize)> for FrequencyDistribution<K, S>
where K: Eq + Hash, H: Hasher, S: BuildHasher<Hasher = H> + Default,

Source§

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);
Source§

impl<'a, K, H, S, Q> Index<&'a Q> for FrequencyDistribution<K, S>
where K: Eq + Hash + Borrow<Q>, H: Hasher, S: BuildHasher<Hasher = H>, Q: Eq + Hash + ?Sized,

Source§

type Output = usize

The returned type after indexing.
Source§

fn index<'b>(&'b self, index: &Q) -> &'b usize

Performs the indexing (container[index]) operation. Read more
Source§

impl<K, H, S> IntoIterator for FrequencyDistribution<K, S>
where K: Eq + Hash, H: Hasher, S: BuildHasher<Hasher = H>,

Source§

fn into_iter(self) -> IntoIter<K, usize>

Consumes the distribution, and creates an iterator over the (Key, Quantity: usize) pairs.

Source§

type Item = (K, usize)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, usize>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<K, S> Freeze for FrequencyDistribution<K, S>
where S: Freeze,

§

impl<K, S> RefUnwindSafe for FrequencyDistribution<K, S>

§

impl<K, S> Send for FrequencyDistribution<K, S>
where S: Send, K: Send,

§

impl<K, S> Sync for FrequencyDistribution<K, S>
where S: Sync, K: Sync,

§

impl<K, S> Unpin for FrequencyDistribution<K, S>
where S: Unpin, K: Unpin,

§

impl<K, S> UnwindSafe for FrequencyDistribution<K, S>
where K: UnwindSafe, S: UnwindSafe,

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.