util

package
v0.0.0-...-cf74617 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const RatioByteSize = serializer.UInt32ByteSize + serializer.UInt32ByteSize

A + B

View Source
const WindowsOS = "windows"

Variables

View Source
var (
	Big0       = big.NewInt(0)
	Big1       = big.NewInt(1)
	MaxUint256 = new(big.Int).Sub(new(big.Int).Lsh(Big1, 256), Big1)
)

Functions

func AliasIDFromAliasOutput

func AliasIDFromAliasOutput(out *iotago.AliasOutput, outID iotago.OutputID) iotago.AliasID

func BaseTokensDecimalsToEthereumDecimals

func BaseTokensDecimalsToEthereumDecimals(value uint64, baseTokenDecimals uint32) (result *big.Int)

base tokens => wei

func CloneMap

func CloneMap[K comparable, T Cloneable[T]](base map[K]T) map[K]T

CloneMap clones every element in the the map into cloned and returns the cloned map.

func CloneSlice

func CloneSlice[T Cloneable[T]](base []T) []T

CloneSlice clones every element in the the slice into cloned and returns the cloned slice.

func CreateDirectoryForFilePath

func CreateDirectoryForFilePath(filePath string, perm os.FileMode) error

func DecodeHexBinaryMarshaled

func DecodeHexBinaryMarshaled(dataHex string, value encoding.BinaryUnmarshaler) error

func DecodeSliceHexBinaryMarshaled

func DecodeSliceHexBinaryMarshaled[M encoding.BinaryUnmarshaler](dataHex []string, values []M) error

func EncodeHexBinaryMarshaled

func EncodeHexBinaryMarshaled(value encoding.BinaryMarshaler) (string, error)

func EncodeSliceHexBinaryMarshaled

func EncodeSliceHexBinaryMarshaled[M encoding.BinaryMarshaler](values []M) ([]string, error)

func EthereumDecimalsToBaseTokenDecimals

func EthereumDecimalsToBaseTokenDecimals(value *big.Int, baseTokenDecimals uint32) (result uint64, remainder *big.Int)

wei => base tokens

func ExecuteIfNotNil

func ExecuteIfNotNil(function func())

func ExistsFilePath

func ExistsFilePath(filePath string) (bool, error)

ExistsFilePath returns whether the given file or directory exists.

func GentleTruncate

func GentleTruncate(s string, length int) string

func GetHashValue

func GetHashValue(obj interface{ Bytes() []byte }) hashing.HashValue

func IsPositiveBigInt

func IsPositiveBigInt(n *big.Int) bool

func IsSlug

func IsSlug(s string) bool

func IsZeroBigInt

func IsZeroBigInt(bi *big.Int) bool

func MakeRange

func MakeRange(from, to int) []int

MakeRange returns slice with a range of elements starting from to up to-1, inclusive

func MustEthereumDecimalsToBaseTokenDecimalsExact

func MustEthereumDecimalsToBaseTokenDecimalsExact(value *big.Int, baseTokenDecimals uint32) (result uint64)

func MustTokenScheme

func MustTokenScheme(tokenScheme iotago.TokenScheme) *iotago.SimpleTokenScheme

func NFTIDFromNFTOutput

func NFTIDFromNFTOutput(nftOutput *iotago.NFTOutput, outputID iotago.OutputID) iotago.NFTID

func NewPseudoRand

func NewPseudoRand(seed ...int64) *rand.Rand

func OutputFromBytes

func OutputFromBytes(data []byte) (iotago.Output, error)

func PrefixHex

func PrefixHex(data []byte, prefixLen int) string

Mostly for logging.

func Same

func Same[V Equated[V]](a, b []V) bool

Checks two slices, if they represent the same sets (same elements, maybe a different order).

func SliceShortString

func SliceShortString[E ShortStringable](slice []E) string

func TerminateCmdWhenTestStops

func TerminateCmdWhenTestStops(cmd *exec.Cmd)

func TimeOrNever

func TimeOrNever(t time.Time) string

func TimeOrNever2

func TimeOrNever2(t time.Time, never string) string

func ToBigInt

func ToBigInt(i interface{}) *big.Int

func ValidPermutation

func ValidPermutation(perm []uint16) bool

Types

type BitVector

type BitVector interface {
	SetBits(positions []int) BitVector
	AsInts() []int
	Bytes() []byte
	Read(r io.Reader) error
	Write(w io.Writer) error
}

func FixedSizeBitVectorFromBytes

func FixedSizeBitVectorFromBytes(data []byte) (BitVector, error)

func NewFixedSizeBitVector

func NewFixedSizeBitVector(size uint16) BitVector

type Cloneable

type Cloneable[T any] interface {
	Clone() T
}

type ComparableAddress

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

func NewComparableAddress

func NewComparableAddress(address iotago.Address) *ComparableAddress

func (*ComparableAddress) Address

func (c *ComparableAddress) Address() iotago.Address

func (*ComparableAddress) Key

func (c *ComparableAddress) Key() string

func (*ComparableAddress) String

func (c *ComparableAddress) String() string

type ComparableString

type ComparableString string

func (ComparableString) Key

func (c ComparableString) Key() string

func (ComparableString) String

func (c ComparableString) String() string

type Equated

type Equated[V any] interface {
	Equals(other V) bool
}

type Permutation16

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

Permutation16 deterministic permutation of integers from 0 to size-1

func NewPermutation16

func NewPermutation16(size uint16, seedOptional ...int64) (*Permutation16, error)

HINT: Seed should only be provided in tests to obtain predicted test results. If used in production, the seed should not be set, because it will be generated using cryptographically secure random number generator. The seed itself will be used to initialize a pseudo random number generator which is used to shuffle the permutations. Unless the permutations must be exactly the same between different calls (probable from different nodes). In the latter case, the seed should be the same for all the calls which expect the same permutation. This function always returns a permutation; error should be considered as a warning that permutation was seeded incorrectly.

func (*Permutation16) Current

func (perm *Permutation16) Current() uint16

func (*Permutation16) ForEach

func (perm *Permutation16) ForEach(f func(i uint16) bool)

func (*Permutation16) GetArray

func (perm *Permutation16) GetArray() []uint16

func (*Permutation16) Next

func (perm *Permutation16) Next() uint16

func (*Permutation16) NextNoCycles

func (perm *Permutation16) NextNoCycles() uint16

If the whole permutation is obtained, reshuffles it to avoid cycles

func (*Permutation16) Shuffle

func (perm *Permutation16) Shuffle() *Permutation16

type Ratio32

type Ratio32 struct {
	A uint32 `json:"a" swagger:"min(0),required"`
	B uint32 `json:"b" swagger:"min(0),required"`
}

Ratio32 represents a ratio (a:b) between two quantities, expressed as two uint32 values.

func Ratio32FromBytes

func Ratio32FromBytes(data []byte) (ret Ratio32, err error)

func Ratio32FromString

func Ratio32FromString(s string) (ret Ratio32, err error)

func (Ratio32) Bytes

func (ratio Ratio32) Bytes() []byte

func (Ratio32) HasZeroComponent

func (ratio Ratio32) HasZeroComponent() bool

func (Ratio32) IsEmpty

func (ratio Ratio32) IsEmpty() bool

func (Ratio32) IsValid

func (ratio Ratio32) IsValid() bool

func (*Ratio32) Read

func (ratio *Ratio32) Read(r io.Reader) error

func (*Ratio32) Set

func (ratio *Ratio32) Set(s string) error

Set is part of the pflag.Value interface. It accepts a string in the form "a:b".

func (Ratio32) String

func (ratio Ratio32) String() string

func (Ratio32) Type

func (ratio Ratio32) Type() string

Type is part of the pflag.Value interface.

func (*Ratio32) Write

func (ratio *Ratio32) Write(w io.Writer) error

func (Ratio32) XCeil64

func (ratio Ratio32) XCeil64(y uint64) uint64

XCeil64 computes x = ceil(y * a / b)

func (Ratio32) XFloor64

func (ratio Ratio32) XFloor64(y uint64) uint64

XFloor64 computes x = floor(y * a / b)

func (Ratio32) YCeil64

func (ratio Ratio32) YCeil64(x uint64) uint64

YCeil64 computes y = ceil(x * b / a)

func (Ratio32) YFloor64

func (ratio Ratio32) YFloor64(x uint64) uint64

YFloor64 computes y = floor(x * b / a)

type ShortStringable

type ShortStringable interface {
	ShortString() string
}

type SliceStruct

type SliceStruct[E any] struct {
	// contains filtered or unexported fields
}

Putting slice into a map is not acceptable as if you want to append to slice, you'll have to re-include the appended slice into the map.

func NewSliceStruct

func NewSliceStruct[E any](elems ...E) *SliceStruct[E]

func NewSliceStructLength

func NewSliceStructLength[E any](length int) *SliceStruct[E]

func NewSliceStructLengthCapacity

func NewSliceStructLengthCapacity[E any](length, capacity int) *SliceStruct[E]

func (*SliceStruct[E]) Add

func (s *SliceStruct[E]) Add(elem E)

func (*SliceStruct[E]) Clone

func (s *SliceStruct[E]) Clone() *SliceStruct[E]

Returns a reference to new SliceStruct with exactly the same elements

func (*SliceStruct[E]) CloneDeep

func (s *SliceStruct[E]) CloneDeep(cloneFun func(E) E) *SliceStruct[E]

Returns a reference to new SliceStruct with every element of the old SliceStruct cloned using provided function

func (*SliceStruct[E]) ContainsBy

func (s *SliceStruct[E]) ContainsBy(fun func(E) bool) bool

func (*SliceStruct[E]) Find

func (s *SliceStruct[E]) Find(fun func(E) bool) (E, bool)

func (*SliceStruct[E]) ForEach

func (s *SliceStruct[E]) ForEach(forEachFun func(int, E) bool) bool

func (*SliceStruct[E]) Get

func (s *SliceStruct[E]) Get(index int) E

func (*SliceStruct[E]) Length

func (s *SliceStruct[E]) Length() int

func (*SliceStruct[E]) Set

func (s *SliceStruct[E]) Set(index int, elem E)

type Timer

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

func NewTimer

func NewTimer() *Timer

func (*Timer) Done

func (t *Timer) Done(name string)

func (*Timer) Duration

func (t *Timer) Duration() time.Duration

func (*Timer) Step

func (t *Timer) Step(name string)

func (*Timer) String

func (t *Timer) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳