slowcounter

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Offset affects how much the count is increased on the first
	// increment.
	Offset *big.Int
	// Rate controls how fast the offset increases after each increment.
	Rate float64
	// Interval is the amount of time to wait before each time the counter is
	// incremented.
	Interval time.Duration
	// MaxCount is the maximum value for the counter. After reaching MaxCount, the
	// counter will stop incrementing until reset.
	MaxCount *big.Int
	// contains filtered or unexported fields
}

Config is a set of configuration options for SlowCounter.

type SlowCounter

type SlowCounter struct {
	// contains filtered or unexported fields
}

SlowCounter is an exponentially increasing counter that is slowly incremented after a certain time interval, unless reset. It has a few configuration options to control the rate of increase. SlowCounter uses the following exponential growth formula:

currentCount = startingCount + offset * (rate ^ n)

where n is the number of increments that have occurred. And the number of increments is calculated as:

n = math.Floor(time.Since(startTime) / interval)

func New

func New(config Config, startingCount *big.Int) (*SlowCounter, error)

New returns a new SlowCounter with the given starting count.

func (*SlowCounter) Count

func (sc *SlowCounter) Count() *big.Int

Count returns the current count.

func (*SlowCounter) Reset

func (sc *SlowCounter) Reset(count *big.Int)

Reset resets the counter to the given count.

Jump to

Keyboard shortcuts

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