JuliaLang/julia — pull request #3702 by johnmyleswhite (2013-07-13 04:43:43+00:00)
Title: RFC: Implement a Counter type for Base.Collections

This is a first pass at implementing a Counter type like the one provided by Python's collections module: http://docs.python.org/2/library/collections.html

Counters provide a useful abstraction around Dict's that default to 0 for new keys. With some additions, they provide a natural mechanism for describing multisets. I would prefer that we implement a Multiset type in terms of Counter, so I have not implemented methods like `union` or `intersect` so far.

One complication with this PR is that I've implemented an `elements` function based on the equivalently named function in Python: `elements` allows one to iterate through a Counter while ignoring an keys that have zero counts. We could easily call this method `nonzeros`, but I went with `elements` for now even though that function name is deprecated in lieu of `collect` for normal Dict's.