Skip to content
FutureBlitz

    Install

    Import std.collections.counter

    std.collections.counter

    Counter<T>: how many times each value was added, in the order the values were added. A value's count is never 0: one whose count goes down to 0 goes, so it comes back last, and counter[value] of one that isn't there is 0.

    std/collections/counter.fb

    Types

    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.

    std/collections/counter.fb, line 10

    • Public New() constructor #

      A new, empty Counter.

    • Public Property Count: Int property #

      How many values it counts, each once.

    • Public Property Total: Int64 property #

      All the counts added up, which can be more than an Int holds.

    • @PanicsAtCaller Public Method Add(value: T) method #

      Counts the value once more.

    • @PanicsAtCaller Public Method Add(value: T, times: Int) method #

      Counts the value times more times. A negative times panics, and so does a count past what an Int holds, which only Total can be.

    • @PanicsAtCaller Public Method AddAll(values: Iterable<T>) method #

      Counts each of the values once more, all read first.

    • Public Method Remove(value: T): Bool method #

      Counts the value once less, and tells whether it was there.

    • @PanicsAtCaller Public Method Remove(value: T, times: Int): Int method #

      Counts the value up to times less, and gives how many it took away. A negative times panics.

    • Operator [](value: T): Int operator #

      How many times the value was counted, or 0.

    • @PanicsAtCaller Operator []=(value: T, count: Int) operator #

      Gives the value a count, and a count of 0 removes it. A negative count panics.

    • Public Method Contains(value: T): Bool method #

      Whether value has a count.

    • Public Method Clear() method #

      Takes every count out.

    • @PanicsAtCaller Public Method MostCommon(count: Int): (T, Int)[] method #

      The count most counted values and their counts, most first, and values counted the same number of times in the Counter's order. A negative count panics.

    • Public Method Values(): T[] method #

      The values, each once, in the order they were added, one that came back last.

    • Public Static Method DefaultValue(): Counter<T> static method #

      A new, empty Counter.

    • Public Method Clone(): Counter<T> method #

      A new Counter with the same counts.

    • Operator ==(a: Counter<T>, b: Counter<T>): Bool operator #

      Two Counters are equal when they count the same values the same number of times, in any order.

    • Public Method Hash(): UInt64 method #

      Its hash, the same for values that are equal.

      Doc from std.core.interfaces.Hashable.Hash.

    • Public Method Iterate(): MapIterator<T, Int> method #

      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.

    Extends

    Counter extend

    Extend Counter<T> Implements Printable

    No doc comment.

    std/collections/counter.fb, line 143

    Report an issue with this page or with FutureBlitz on GitHub.