utils

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MAXUINT64 = uint64(18446744073709551615)

Variables

This section is empty.

Functions

func CanonicalPathsEqual

func CanonicalPathsEqual(filePath1, filePath2 string) (isEqual bool, err error)

func CollectGarbage

func CollectGarbage()

CollectGarbage runs the Go GC and times it

func CopyFile

func CopyFile(fromFile, toFile string) error

func CopyFromFileName2Writer

func CopyFromFileName2Writer(fromFileName string, toFile *os.File) error

func CreatePrefixedZip

func CreatePrefixedZip(pathToZipUp, zipFilePath, prefixToReplace, newPrefix string) error
 CreatePrefixedZip creates a zip file of a directory (pathToZip). As it puts each file in the zip,
 if the path of the file starts with prefixToReplace it will be changed to newPrefix.
 Note: this is not a full-featured zip creation function, only what we need. Specifically, it doesn't
		follow sym links during its recursion (because filepath.Walk() doesn't), and it doesn't add the
		dirs as their own entries like the zip cmd does (SPC can't handle that).

func GlobalUniqueIntFactory

func GlobalUniqueIntFactory()

UniqueIntFactory creates the global instance of UniqueInt todo: verify this is ok for multiple populations!!!!!!!!!!!!!!

func MaxFloat64

func MaxFloat64(a, b float64) float64

func MaxUint32

func MaxUint32(a, b uint32) uint32

func MaxUint64

func MaxUint64(a, b uint64) uint64

func MeasurerFactory

func MeasurerFactory(verbosity uint32)

MeasurerFactory creates an instance of Measurer

func MinFloat64

func MinFloat64(a, b float64) float64

func MinInt

func MinInt(a, b int) int

func MinUint32

func MinUint32(a, b uint32) uint32

func NotImplementedYet

func NotImplementedYet(what string)

func RandomSlug

func RandomSlug(byteLen uint) string

RandomSlug returns a random 6 char id

func RoundInt

func RoundInt(f float64) int

RoundInt returns the nearest int result. To get more exact, look at https://github.com/a-h/round

func RoundIntDiv

func RoundIntDiv(a, b float64) int

RoundIntDiv divides a/b and returns the nearest int result.

func RoundToEven

func RoundToEven(f float64) int

RoundToEven returns the nearest even integer. Note: only works for positive numbers

func RoundUpInt

func RoundUpInt(f float64) int

RoundUpInt returns the nearest int that is >= f.

Types

type Measurer

type Measurer struct {
	DeltaTime      map[string]time.Time // holds the start time for 1 duration measurement
	TotalTime      map[string]int64
	MaxTotalMemory uint64 // the amount of memory this program used
	Track          bool
}

Measure keeps track of how much execution time was spent in various parts of the code, and the maximum amount of memory

var Measure *Measurer

Measure is a singleton instance of Measure to track execution time

func (*Measurer) CheckAmountMemoryUsed

func (m *Measurer) CheckAmountMemoryUsed()

func (*Measurer) GetAmountMemoryUsed

func (m *Measurer) GetAmountMemoryUsed() float32

GetAmountMemoryUsed returns the max memory used so far in MB

func (*Measurer) GetInterimTime

func (m *Measurer) GetInterimTime(codeName string) float64

GetInterimTime returns the total number of seconds (as a float64) so far for this codeName.

func (*Measurer) LogSummary

func (m *Measurer) LogSummary()

LogSummary prints to the log all of the total times.

func (*Measurer) Start

func (m *Measurer) Start(codeName string) *Measurer

Start starts the time measuring of a section of code. Returns the Measurer instance to Start and Stop can be chained in a defer statement.

func (*Measurer) Stop

func (m *Measurer) Stop(codeName string) (delta float64)

Stop stops the time measuring of a section of code and adds this amount to the total for the run

type ResDivide

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

ResDivide splits a resource quantity among a number of recipient objects, handling the remainder for the last object.

func ResDivideFactory

func ResDivideFactory(numResources, numObjects uint64) *ResDivide

ResDivideFactory creates an instance of ResDivide

func (*ResDivide) NextAmount

func (r *ResDivide) NextAmount() (nextAmount uint64)

NextAmount returns the number of resources the next object in the iteration should receive

type UniqueInt

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

UniqueInt hands out unique integer numbers, with the ability to also give a range to another object

var GlobalUniqueInt *UniqueInt

GlobalUniqueInt is a singleton instance of UniqueInt to hand out integers. It is *not* thread safe.

func (*UniqueInt) DonateRange

func (u *UniqueInt) DonateRange(rangeSize uint64) (newU *UniqueInt)

DonateRange create a new instance of UniqueInt, donating a range of int's from the existing object.

func (*UniqueInt) NextInt

func (u *UniqueInt) NextInt() uint64

Start starts the time measuring of a section of code. Returns the UniqueInt instance to Start and Stop can be chained in a defer statement.

Jump to

Keyboard shortcuts

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