freq

package
v1.7.1 Latest Latest
Warning

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

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

Documentation

Overview

Package freq keeps track of last X seen events. The events themselves are not stored here. So the Freq type should be added next to the thing it is tracking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Freq

type Freq struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Freq tracks the frequencies of things.

func New

func New(t time.Time) *Freq

New returns a new initialized Freq.

func (*Freq) Hits

func (f *Freq) Hits() int

Hits returns the number of hits that we have seen, according to the updates we have done to f.

func (*Freq) Reset

func (f *Freq) Reset(t time.Time, hits int)

Reset resets f to time t and hits to hits.

func (*Freq) Update

func (f *Freq) Update(d time.Duration, now time.Time) int

Update updates the number of hits. Last time seen will be set to now. If the last time we've seen this entity is within now - d, we increment hits, otherwise we reset hits to 1. It returns the number of hits.

Jump to

Keyboard shortcuts

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