utils

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateRemainingTime added in v0.5.0

func EstimateRemainingTime(timeStart time.Time, current int64, total int64) (percentage float64, remaining time.Duration)

EstimateRemainingTime estimates the remaining time for a running operation and returns the finished percentage.

func GetUint32Diff

func GetUint32Diff(newCount uint32, oldCount uint32) uint32

GetUint32Diff returns the difference between newCount and oldCount and catches overflows

func RandomInsecure

func RandomInsecure(min int, max int) int

RandomInsecure returns a random int in the range of min to max. the result is not cryptographically secure. RandomInsecure is inclusive max value.

func RandomKerlHashTrytesInsecure added in v0.5.4

func RandomKerlHashTrytesInsecure() trinary.Hash

RandomKerlHashTrytesInsecure returns random hash trytes. Since the result mimics a Kerl hash, the last trit will be zero.

func RandomTrytesInsecure

func RandomTrytesInsecure(length int) trinary.Trytes

RandomTrytesInsecure returns random Trytes with the given length. the result is not cryptographically secure. DO NOT USE this function to generate a seed.

Types

type TimeHeap

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

TimeHeap implements a heap sorted by time, where older elements are popped during GetAveragePerSecond call.

func NewTimeHeap

func NewTimeHeap() *TimeHeap

NewTimeHeap creates a new TimeHeap object.

func (*TimeHeap) Add

func (h *TimeHeap) Add(count uint64)

Add a new entry to the container with a count for the average calculation.

func (*TimeHeap) GetAveragePerSecond

func (h *TimeHeap) GetAveragePerSecond(timeBefore time.Duration) float32

GetAveragePerSecond calculates the average per second of all entries in the given duration. older elements are removed from the container.

func (TimeHeap) Len

func (h TimeHeap) Len() int

/////////////// heap interface /////////////////

func (TimeHeap) Less

func (h TimeHeap) Less(i, j int) bool

func (*TimeHeap) Pop

func (h *TimeHeap) Pop() interface{}

func (*TimeHeap) Push

func (h *TimeHeap) Push(x interface{})

func (TimeHeap) Swap

func (h TimeHeap) Swap(i, j int)

Jump to

Keyboard shortcuts

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