freq

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package freq implements a frequency counter for periodic events.

Index

Constants

View Source
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.

Jump to

Keyboard shortcuts

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