Documentation
¶
Overview ¶
Package counter provides functions to generate a frequency histogram of values.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
Counter is used for calculating a frequency histogram of strings.
Example (All) ¶
This example shows you can setup a counter and get all the values that have occured.
c := New() for i := 0; i < 10; i++ { c.Increment("foo") } for i := 0; i < 5; i++ { c.Increment("bar") } values := c.All(true) // get all values fmt.Println(values)
Output: [bar foo]
Example (Bar) ¶
This example shows you can setup a counter and find the value with the least number of occurences.
c := New() for i := 0; i < 10; i++ { c.Increment("foo") } for i := 0; i < 5; i++ { c.Increment("bar") } values := c.Bottom(1, -1, true) // get bottom value, no maximum, and in sorted order if len(values) > 0 { fmt.Println(values[0]) }
Output: bar
Example (Top) ¶
This example shows you can setup a counter and find the value with the most number of occurences.
c := New() for i := 0; i < 10; i++ { c.Increment("foo") } for i := 0; i < 5; i++ { c.Increment("bar") } values := c.Top(1, 0, true) // get top value, greater than zero, and in sorted order if len(values) > 0 { fmt.Println(values[0]) }
Output: foo
func CountFiles ¶
CountFiles generates a frequency distribution for the tokens found in the files files is a list of paths to files. splitFunc is a bufio.SplitFunc, which can be bufio.ScanBytes, bufio.ScanWords, bufio.ScanLines, or a custom function. If skipErrors is set to true, then errors opening or reading files are skipped and not returned.
func (Counter) All ¶
All returns all the values as a slice of strings. If s is set to true, then the values are sorted in alphabetical order.
func (Counter) Bottom ¶
Top returns at most "n" values that have occured at most "max" times as a slice of strings. If max is less than zero, then ignore "max" as a threshold. If max is set to zero, then the function will return an empty slice of strings. If s is set to true, then the values are sorted in ascending order before the "n" values are chosen.
func (Counter) Count ¶
Count returns the current count for a given value. Returns 0 if the value has not occured.
func (Counter) Top ¶
Top returns at most "n" values that have occured at least "min" times as a slice of strings. If s is set to true, then the values are sorted in descending order before the "n" values are chosen. If you would want to get the single most frequent value then use Top(1, 0, true). If you want 2 values that occured at least ten times, but do not care if they are the 2 most frequent values, then use Top(2, 10, false).