histogram

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 7 Imported by: 0

README

go-histogram

a go package to calculate and histograms and print them to a console

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print[T constraints.Float | constraints.Integer](w io.Writer, h Histogram[T], opt PrintOptions[T])

Print prints a histogram to a writer

Types

type Bucket

type Bucket[T constraints.Float | constraints.Integer] struct {
	Low   T   // Low is the low edge of this Bucket
	High  T   // High is the high edge of this Bucket
	Min   T   // Min is the minimum of values in this Bucket, if Count > 0
	Max   T   // Max is the maximum of values in this Bucket, if Count > 0
	Count int // Count is the number of values in this bucket
	Sum   T   // Sum is the summation of all values in this bucket
	// contains filtered or unexported fields
}

Bucket is one element of a Histogram

type Histogram

type Histogram[T constraints.Float | constraints.Integer] []Bucket[T]

Histogram is an ordered slice of Buckets

func CreateLinear

func CreateLinear[T constraints.Float | constraints.Integer](slice []T, binCount int) Histogram[T]

CreateLinear creates a Histogram on a linear scale

Example
hist := histogram.CreateLinear([]float32{0, 0, 1, 2, 8}, 4)
fmt.Printf("Edges: %v\n", hist.Edges())
histogram.Print(os.Stdout, hist, histogram.PrintOptions[float32]{
	Width:     20,
	Prefix:    "  ",
	Symbol:    '>',
	PadSymbol: '-',
})
Output:

Edges: [0 2 4 6 8]
    8
  > 6: ------>              (1)
  > 4: >                    (0)
  > 2: ------>              (1)
  > 0: -------------------> (3)

func CreateLog

func CreateLog[T constraints.Float | constraints.Integer](slice []T, binCount int) Histogram[T]

CreateLog creates a Histogram on a log scale

func (Histogram[T]) Edges

func (h Histogram[T]) Edges() []T

Edges returns a slice of edge values of the Buckets

type PrintOptions

type PrintOptions[T constraints.Float | constraints.Integer] struct {
	Prefix    string
	Width     int
	Symbol    rune
	PadSymbol rune
	Format    func(T) string
	// SumSymbol is used, if not zero, for plotting the sum of a bin
	SumSymbol rune
	// CombinedSymbol is used, if not zero, for plotting the sum and count
	// of a bin, when they appear at the same position in the plot
	CombinedSymbol rune
}

PrintOptions specifies options for the Print function

func GetBytesOptions

func GetBytesOptions[T constraints.Integer](width int, printSum bool) PrintOptions[T]

GetBytesOptions returns a PrintOptions for printout out byte sizes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL