Documentation ¶
Overview ¶
Package counter implements various counter types, analagous to Python's collections.Counter
Index ¶
- type Pair
- type Pairs
- type String
- func (counter String) Add(items ...string)
- func (counter String) Combine(counters ...String) String
- func (counter String) Copy() String
- func (counter String) Count(k string) int
- func (counter String) Equal(other String) bool
- func (counter String) Keys() []string
- func (counter String) MostCommon() (string, int)
- func (counter String) MostCommonN(n int) (pairs Pairs, err error)
- func (counter String) Neg() String
- func (counter String) NonZeroElements() String
- func (counter String) Pairs() Pairs
- func (counter String) PositiveElements() String
- func (counter String) Sorted() Pairs
- func (counter String) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pairs ¶
type Pairs []Pair
Pairs is a slice of Pairs. It is sortable lexigraphically by count, then key.
type String ¶
String counts the occurence of strings.
func FromStrings ¶
FromStrings creates a counter of strings from a slice, counting each member once.
func (String) Combine ¶
Combine one or more counters, where the count of each element is the sum of the count of each
func (String) Equal ¶
Equal returns true if two counters are equal. Two counters are equal if they have the same length and share all keys and values.
func (String) MostCommon ¶
func (String) MostCommonN ¶
MostCommonN returns the N most common keys. In the case of a tie, it prioritizes the lexigraphically lowest, so that the keys contained in counter.MostCommonN(n) will be identical for two equivalent counters.
func (String) Neg ¶
Neg returns a copy of the counter with inverted counts: i.e, {k: -v for k, v in counter}
func (String) NonZeroElements ¶
NonZeroElements returns a copy of the counter with all dummy elements(count zero) removed.
func (String) PositiveElements ¶
PositiveElements returns a copy of counter containing all the elements where the counter[x] > 0