window

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WindowSize      = 10
	WindowSliceSize = WindowSize * consts.Uint64Len
)

Variables

This section is empty.

Functions

func Last

func Last(w *Window) uint64

func Sum

func Sum(w Window) uint64

Sum sums [numUint64s] encoded in window. Assumes that the length of window is sufficient to contain [numUint64s] or else this function panics. If an overflow occurs, while summing the contents, the maximum uint64 value is returned.

func Update

func Update(w *Window, start int, unitsConsumed uint64)

Update adds [unitsConsumed] in at index within window. Assumes that [index] has already been validated. If an overflow occurs, the maximum uint64 value is used.

Types

type Window

type Window [WindowSliceSize]byte

func Roll

func Roll(w Window, roll int) (Window, error)

Roll rolls the uint64s within [consumptionWindow] over by [roll] places. For example, if there are 4 uint64 encoded in a 32 byte slice, rollWindow would have the following effect: Original: [1, 2, 3, 4] Roll = 0 [1, 2, 3, 4] Roll = 1 [2, 3, 4, 0] Roll = 2 [3, 4, 0, 0] Roll = 3 [4, 0, 0, 0] Roll >= 4 [0, 0, 0, 0] Assumes that [roll] is greater than or equal to 0

Jump to

Keyboard shortcuts

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