Documentation
¶
Overview ¶
Library that provides to collect and display the quantity of occurrences of values in given spans.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrItemsQuantityNegative = errors.New("items quantity is negative") ErrItemsQuantityZero = errors.New("items quantity is zero") ErrLowerGreaterUpper = errors.New("lower value is greater than upper") ErrSpansListEmpty = errors.New("an empty list of spans was specified") ErrSpansSequenceUnsorted = errors.New("spans sequence is not sorted") )
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item[Type constraints.Integer] struct { // Kind (purpose) of item Kind ItemKind // Quantity of occurrences of a value belonging to a Span Quantity uint64 // Span of values for which the Quantity of occurrences is collected Span span.Span[Type] }
Item of statistics.
type Predictor ¶ added in v0.1.0
type Predictor[Type constraints.Integer] func(value Type) uint64
A function used to determine (at least approximately) the index of a span in a list of spans to which a value belongs.
type Stat ¶
type Stat[Type constraints.Integer] struct { // contains filtered or unexported fields }
Statistics.
Example ¶
package main
import (
"fmt"
"os"
"github.com/akramarenkov/stat"
)
func main() {
sts, err := stat.NewLinear(1, 100, 20)
if err != nil {
panic(err)
}
sts.Inc(0)
sts.Inc(1)
sts.Inc(20)
sts.Inc(21)
sts.Inc(22)
sts.Inc(40)
sts.Inc(41)
sts.Inc(42)
sts.Inc(59)
sts.Inc(60)
sts.Inc(61)
sts.Inc(62)
sts.Inc(80)
sts.Inc(81)
sts.Inc(100)
sts.Inc(101)
fmt.Println(sts.Graph(os.Stderr))
}
Output: <nil>
func New ¶
func New[Type constraints.Integer](spans []span.Span[Type], predictor Predictor[Type]) (*Stat[Type], error)
Creates an instance of statistics for the specified spans of values.
Spans sequence must be increasing and sorted. Spans must not intersect.
Prediction function may not be specified, but then the value's correspondence to the span will be determined by searching the list of spans, which is slower.
func NewLinear ¶
func NewLinear[Type constraints.Integer](lower, upper, width Type) (*Stat[Type], error)
Creates a linear statistics whose items have the specified width.
func NewLinearQ ¶ added in v0.2.0
func NewLinearQ[Type constraints.Integer](lower, upper, quantity Type) (*Stat[Type], error)
Creates a linear statistics with the specified quantity of items.
func (*Stat[Type]) Graph ¶
Writes statistics as a bar chart to the specified writers.
If no writer is specified, the bar chart will be written to standard output.