 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Variables
- func AbsDiff[T constraints.Unsigned](a, b T) T
- func Add64(a, b uint64) (uint64, error)
- func Max[T constraints.Ordered](max T, nums ...T) T
- func Min[T constraints.Ordered](min T, nums ...T) T
- func Mul64(a, b uint64) (uint64, error)
- func Sub[T constraints.Unsigned](a, b T) (T, error)
- type Averager
- type AveragerHeap
Constants ¶
This section is empty.
Variables ¶
var ( ErrOverflow = errors.New("overflow") ErrUnderflow = errors.New("underflow") )
Functions ¶
func AbsDiff ¶ added in v1.9.1
func AbsDiff[T constraints.Unsigned](a, b T) T
func Add64 ¶
Add64 returns: 1) a + b 2) If there is overflow, an error
Note that we don't have a generic Add function because checking for an overflow requires knowing the max size of a given type, which we don't know if we're adding generic types.
func Max ¶ added in v1.9.1
func Max[T constraints.Ordered](max T, nums ...T) T
func Min ¶ added in v1.7.11
func Min[T constraints.Ordered](min T, nums ...T) T
func Mul64 ¶
Mul64 returns: 1) a * b 2) If there is overflow, an error
Note that we don't have a generic Mul function because checking for an overflow requires knowing the max size of a given type, which we don't know if we're adding generic types.
func Sub ¶ added in v1.9.1
func Sub[T constraints.Unsigned](a, b T) (T, error)
Sub returns: 1) a - b 2) If there is underflow, an error
Types ¶
type Averager ¶ added in v1.0.4
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 ¶ added in v1.0.4
func NewSyncAverager ¶ added in v1.2.4
func NewUninitializedAverager ¶ added in v1.7.15
NewUninitializedAverager creates a new averager with the given halflife. If [Read] is called before [Observe], the zero value will be returned. When [Observe] is called the first time, the averager will be initialized with [value] at that time.
type AveragerHeap ¶ added in v1.7.13
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 ¶ added in v1.7.13
func NewMaxAveragerHeap() AveragerHeap
NewMaxAveragerHeap returns a new empty max heap. The returned heap is not thread safe.
func NewMinAveragerHeap ¶ added in v1.7.13
func NewMinAveragerHeap() AveragerHeap
NewMinAveragerHeap returns a new empty min heap. The returned heap is not thread safe.