Struct counter::Counter [] [src]

pub struct Counter<T: Hash + Eq> {
    pub map: HashMap<T, usize>,
}

Fields

HashMap backing this Counter

Public to expose the HashMap API for direct manipulation. That said, this may change in the future to some other mapping type / trait.

Methods

impl<T> Counter<T> where
    T: Hash + Eq
[src]

Create a new, empty Counter

Create a new Counter initialized with the given iterable

Add the counts of the elements from the given iterable to this counter

Remove the counts of the elements from the given iterable to this counter

Non-positive counts are automatically removed

impl<T> Counter<T> where
    T: Hash + Eq + Clone
[src]

Create an iterator over (frequency, elem) pairs, sorted most to least common.

FIXME: This is pretty inefficient: it copies everything into a vector, sorts the vector, and returns an iterator over the vector. It would be much better to create some kind of MostCommon struct which implements Iterator which does all the necessary work on demand. PRs appreciated here!

Create an iterator over (frequency, elem) pairs, sorted most to least common.

In the event that two keys have an equal frequency, use the supplied ordering function to further arrange the results.

FIXME: This is pretty inefficient: it copies everything into a vector, sorts the vector, and returns an iterator over the vector. It would be much better to create some kind of MostCommon struct which implements Iterator which does all the necessary work on demand. PRs appreciated here!

impl<T> Counter<T> where
    T: Hash + Eq + Clone + Ord
[src]

Create an iterator over (frequency, elem) pairs, sorted most to least common.

In the event that two keys have an equal frequency, use the natural ordering of the keys to further sort the results.

FIXME: This is pretty inefficient: it copies everything into a vector, sorts the vector, and returns an iterator over the vector. It would be much better to create some kind of MostCommon struct which implements Iterator which does all the necessary work on demand. PRs appreciated here!

Trait Implementations

impl<T: Clone + Hash + Eq> Clone for Counter<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: PartialEq + Hash + Eq> PartialEq for Counter<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Eq + Hash + Eq> Eq for Counter<T>
[src]

impl<T> Add for Counter<T> where
    T: Clone + Hash + Eq
[src]

The resulting type after applying the + operator

Add two counters together.

out = c + d; -> out[x] == c[x] + d[x]

impl<T> Sub for Counter<T> where
    T: Clone + Hash + Eq
[src]

The resulting type after applying the - operator

Subtract (keeping only positive values).

out = c - d; -> out[x] == c[x] - d[x]

impl<T> BitAnd for Counter<T> where
    T: Clone + Hash + Eq
[src]

The resulting type after applying the & operator

Intersection

out = c & d; -> out[x] == min(c[x], d[x])

impl<T> BitOr for Counter<T> where
    T: Clone + Hash + Eq
[src]

The resulting type after applying the | operator

Union

out = c | d; -> out[x] == max(c[x], d[x])