util

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUint64

func AddUint64(ns ...uint64) (sum uint64, overflow bool, err error)

AddUint64 adds a list of uint64s together, returning an error and a boolean indicator if the sum overflows uint64.

func BytesToUint32

func BytesToUint32(b []byte) uint32

func BytesToUint64

func BytesToUint64(b []byte) uint64

func FileExists

func FileExists(path string) bool

func IsValidURI

func IsValidURI(u string) bool

func ReadJsonFile

func ReadJsonFile[T any](path string, res *T) (*T, error)

func SafeAdd

func SafeAdd(a, b uint64) (uint64, bool)

SafeAdd returns a+b and checks for overflow

func SafeSub

func SafeSub(a, b uint64) (uint64, bool)

SafeSub returns a-b and checks for underflow

func ShuffleSliceCopy

func ShuffleSliceCopy[T any](src []T) []T

func TransformSlice

func TransformSlice[S ~[]E, E any, V any](s S, mapper func(E) V) []V

TransformSlice processes input slice s by calling the mapper callback for each element and returning the slice of values returned by the callback.

Could be used for extracting single field values from slice of structs etc.

func Uint32ToBytes

func Uint32ToBytes(i uint32) []byte

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

func WriteJsonFile

func WriteJsonFile[T any](path string, obj *T) error

Types

type Stack

type Stack[T any] []T

A simple stack implementation. Not thread safe.

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop pops an item from the stack and panics if the stack is empty. IsEmpty method can be used to check if the following Pop would be successful.

func (*Stack[T]) Push

func (s *Stack[T]) Push(item T)

Jump to

Keyboard shortcuts

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