Import std.collections.counter
Counter
class
@DebugEntries Public Class Counter<T: Hashable> Implements Iterable<(T, Int)>, Cloneable, Defaultable, Hashable
How many times each value was added, for tallies and histograms.
Examples
Local words = Counter<String>()
words.AddAll(["the", "cat", "the", "hat", "the"])
Expect(words["the"] == 3)
Expect(words["dog"] == 0)
Expect(words.Count == 3)
Expect(words.Total == 5)std/collections/counter.fb, line 23
-
A new, empty Counter.
-
How many values it counts, each once.
-
All the counts added up, which can be more than an Int holds.
-
Counts the
valueonce more. -
Counts the
valuetimesmore times. A negativetimespanics, and so does a count past what an Int holds, which only Total can be. -
Counts each of the
valuesonce more, all read first. -
Counts the
valueonce less, and tells whether it was there. -
Counts the
valueup totimesless, and gives how many it took away. A negativetimespanics. -
How many times the value was counted, or 0.
-
Gives the value a count, and a count of 0 removes it. A negative count panics.
-
Whether
valuehas a count. -
Takes every count out.
-
The
countmost counted values and their counts, most first, and values counted the same number of times in the Counter's order. A negativecountpanics.Examples
Local letters = Counter<String>() letters.AddAll(["b", "a", "b", "c", "a", "b"]) Expect(letters.MostCommon(2) == [("b", 3), ("a", 2)]) -
The values, each once, in the order they were added, one that came back last.
-
A new, empty Counter.
-
A new Counter with the same counts.
-
Two Counters are equal when they count the same values the same number of times, in any order.
-
A hash of its values and their counts, which Counters that are equal share.
-
Each value and its count, for 'For value, count In counter'. Changing a count while going over them is fine, but adding or removing a value panics.
Report an issue with this page or with FutureBlitz on GitHub.