Simple histogram for golang that avoids runtime memory allocations.




Package ghistogram provides a simple histogram of ints that avoids heap allocations (garbage creation) during data processing.



This section is empty.


This section is empty.


This section is empty.


type Histogram

type Histogram struct {
	Ranges []int // Lower bound of bin, so Ranges[0] == binStart.
	Counts []uint64

Histogram is a simple int histogram implementation that avoids heap allocations (garbage creation) during its processing of incoming data points.

The histogram bins are split across arrays of Ranges and Counts, where len(Ranges) == len(Counts). These arrays are public in case users wish to use reflection or JSON marhsallings.

Concurrent access (e.g., locking) on a Histogram is a responsibility of the user's application.

func NewHistogram

func NewHistogram(
	numBins int,
	binFirst int,
	binGrowthFactor float64) *Histogram

NewHistogram creates a new, ready to use Histogram. The numBins must be >= 2. The binFirst is the width of the first bin. The binGrowthFactor must be > 1.0.

func (*Histogram) Add

func (gh *Histogram) Add(dataPoint int, count uint64)

Add increases the count in the bin for the given dataPoint.

func (*Histogram) AddAll

func (gh *Histogram) AddAll(src *Histogram)

AddAll adds all the Counts from the src histogram into this histogram. The src and this histogram must either have the same exact creation parameters.

Source Files