Documentation
¶
Overview ¶
Package stats provides helpers for simple stats
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CountSum ¶
type CountSum struct {
// contains filtered or unexported fields
}
CountSum holds sum and count values.
func (*CountSum) Add ¶
Add adds size to s and returns approximate values for the current count and total bytes.
func (*CountSum) Approximate ¶
Approximate returns an approximation of the current count and sum values. It is approximate because retrieving both values is not an atomic operation.
type CountersMap ¶ added in v0.22.0
type CountersMap[K comparable] struct { // contains filtered or unexported fields }
CountersMap is a concurrency-safe map from keys of type K to uint32 counters. It allows increments and retrievals of counts from concurrent go routines without additional concurrency coordination. Added counters cannot be removed.
func (*CountersMap[K]) CountMap ¶ added in v0.22.0
func (m *CountersMap[K]) CountMap() map[K]uint32
CountMap returns the current value of the counters. The counters do not correspond to a consistent snapshot of the map, the counters may change while the returned map is built.
func (*CountersMap[K]) Get ¶ added in v0.22.0
func (m *CountersMap[K]) Get(key K) (uint32, bool)
Get returns the current value of the counter for key, or 0 when key does not exist.
func (*CountersMap[K]) Increment ¶ added in v0.22.0
func (m *CountersMap[K]) Increment(key K) bool
Increment increases the counter for the specified key by 1. Returns true if the key already existed, false if it was newly created.
func (*CountersMap[K]) Length ¶ added in v0.22.0
func (m *CountersMap[K]) Length() uint
Length returns the approximate number of keys in the map. The actual number of keys can be equal or larger to the returned value, but not less.
func (*CountersMap[K]) Range ¶ added in v0.22.0
func (m *CountersMap[K]) Range(f func(key K, count uint32) bool)
Range iterates over all key/count pairs in the map, calling f for each item. If f returns false, iteration stops.