math

package
v0.0.0-...-cb9e034 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: BSD-3-Clause Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add64

func Add64(a, b uint64) (uint64, error)

Add64 returns: 1) a + b 2) If there is overflow, an error

func Diff64

func Diff64(a, b uint64) uint64

func Max64

func Max64(max uint64, nums ...uint64) uint64

Max64 returns the maximum of the values provided

func Min

func Min(min int, nums ...int) int

Min returns the minimum of the values provided

func Min64

func Min64(min uint64, nums ...uint64) uint64

Min64 returns the minimum of the values provided

func Mul64

func Mul64(a, b uint64) (uint64, error)

Mul64 returns: 1) a * b 2) If there is overflow, an error

func Sub64

func Sub64(a, b uint64) (uint64, error)

Sub64 returns: 1) a - b 2) If there is underflow, an error

Types

type Averager

type Averager interface {
	// Observe the value at the given time
	Observe(value float64, currentTime time.Time)

	// Read returns the average of the provided values.
	Read() float64
}

Averager tracks a continuous time exponential moving average of the provided values.

func NewAverager

func NewAverager(
	initialPrediction float64,
	halflife time.Duration,
	currentTime time.Time,
) Averager

func NewSyncAverager

func NewSyncAverager(averager Averager) Averager

type AveragerHeap

type AveragerHeap interface {
	// Add the average to the heap. If [nodeID] is already in the heap, the
	// average will be replaced and the old average will be returned. If there
	// was not an old average, false will be returned.
	Add(nodeID ids.NodeID, averager Averager) (Averager, bool)
	// Remove attempts to remove the average that was added with the provided
	// [nodeID], if none is contained in the heap, [false] will be returned.
	Remove(nodeID ids.NodeID) (Averager, bool)
	// Pop attempts to remove the node with either the largest or smallest
	// average, depending on if this is a max heap or a min heap, respectively.
	Pop() (ids.NodeID, Averager, bool)
	// Peek attempts to return the node with either the largest or smallest
	// average, depending on if this is a max heap or a min heap, respectively.
	Peek() (ids.NodeID, Averager, bool)
	// Len returns the number of nodes that are currently in the heap.
	Len() int
}

AveragerHeap maintains a heap of the averagers.

func NewMaxAveragerHeap

func NewMaxAveragerHeap() AveragerHeap

NewMaxAveragerHeap returns a new empty max heap. The returned heap is not thread safe.

func NewMinAveragerHeap

func NewMinAveragerHeap() AveragerHeap

NewMinAveragerHeap returns a new empty min heap. The returned heap is not thread safe.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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