Documentation ¶
Overview ¶
Package freq implements a frequency counter for periodic events.
Index ¶
Constants ¶
const DefaultWindowSize = 10
DefaultWindowSize is the size of a zero-valued EventCount window.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventCount ¶
type EventCount struct {
// contains filtered or unexported fields
}
EventCount keeps track of timestamps and event counts. The zero value is safe to use, but will have the DefaultWindowSize.
func Init ¶
func Init(windowsize int) *EventCount
Init creates an EventCount with the given windowsize. Init will not return nil.
func (*EventCount) Event ¶
func (ec *EventCount) Event() float64
Event adds one event at the current time to the window and expires the oldest item. Returns the frequency of the EventCount.
func (*EventCount) EventMulti ¶
func (ec *EventCount) EventMulti(count int) float64
EventMulti adds count events at the current time to the window and expires the oldest item. Returns the frequency of the EventCount.
func (*EventCount) Frequency ¶
func (ec *EventCount) Frequency() float64
Frequency returns the current frequency of the events without modifying the window.
func (*EventCount) NoEvent ¶
func (ec *EventCount) NoEvent() float64
NoEvent expires the oldest item in the window, same as EventMulti(0). Returns the frequency of the EventCount.