func (self *lossyCounter) Count(countable Countable) float64 {
	self.mu.Lock()
	defer self.mu.Unlock()
	self.total++
	count := 0
	for i, existing := range self.frequencies {
		if existing.countable.IsMatch(countable) {
			existing.count++
			count = existing.count
			self.frequencies[i].countable = countable
			self.distributionGauges[i].Set(float64(count))
			break
		}
	}
	if count == 0 {
		count = 1
		g := self.metrics.Distribution.WithLabelValues(strconv.Itoa(len(self.distributionGauges)))
		g.Set(float64(count))
		self.metrics.UniqueFingerprints.Inc()
		self.frequencies = append(self.frequencies, &entry{
			countable: countable,
			count:     count,
			delta:     self.bucket - 1,
		})
		self.distributionGauges = append(self.distributionGauges, g)
	}
	if self.total%self.width == 0 {
		self.prune()
		self.bucket++
	}
	return float64(count) / float64(self.total)
}
Count a countable and return the support for the countable.
package counter
import (
	"math"
	"strconv"
	"sync"
	"github.com/prometheus/client_golang/prometheus"
)
type lossyCounter struct {
	mu                 sync.RWMutex
	errorTolerance     float64
	frequencies        []*entry
	distributionGauges []prometheus.Gauge
	width              int
	total              int
	bucket             int
	metrics *Metrics
}
type entry struct {
	countable Countable
	count     int
	delta     int
}
func NewLossyCounter(metrics *Metrics, errorTolerance float64) *lossyCounter {
	return &lossyCounter{
		metrics:        metrics,
		errorTolerance: errorTolerance,
		width:          int(math.Ceil(1.0 / errorTolerance)),
		total:          0,
		bucket:         1,
	}
}