util

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0, BSD-2-Clause Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

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 added in v0.3.0

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

func AllDifferentStrings added in v0.2.0

func AllDifferentStrings(lst ...string) bool

func Bytes

func Bytes(obj interface{ Write(io.Writer) error }) ([]byte, error)

func ExistsFilePath added in v0.1.0

func ExistsFilePath(filePath string) (bool, error)

ExistsFilePath returns whether the given file or directory exists.

func GentleTruncate added in v0.1.0

func GentleTruncate(s string, length int) string

func GetHashValue

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

func Int32To4Bytes added in v0.2.0

func Int32To4Bytes(val int32) []byte

func Int64From8Bytes added in v0.1.0

func Int64From8Bytes(b []byte) (int64, error)

func Int64To8Bytes added in v0.2.0

func Int64To8Bytes(val int64) []byte

func IsSubset added in v0.2.0

func IsSubset(sub, super []string) bool

func IsZeroBigInt added in v0.3.0

func IsZeroBigInt(bi *big.Int) bool

func LocateFile added in v0.1.0

func LocateFile(fileName string, relativePath ...string) string

func MakeRange added in v0.2.0

func MakeRange(from, to int) []int

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

func MinUint64 added in v0.3.0

func MinUint64(a, b uint64) uint64

func MustBytes

func MustBytes(obj interface{ Write(io.Writer) error }) []byte

func MustTokenScheme added in v0.3.0

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

func MustUint16From2Bytes added in v0.1.0

func MustUint16From2Bytes(b []byte) uint16

func MustUint32From4Bytes added in v0.1.0

func MustUint32From4Bytes(b []byte) uint32

func MustUint64From8Bytes added in v0.1.0

func MustUint64From8Bytes(b []byte) uint64

func MustUint8From1Bytes added in v0.2.3

func MustUint8From1Bytes(b []byte) uint8

func NFTIDFromNFTOutput added in v0.3.0

func NFTIDFromNFTOutput(out *iotago.NFTOutput, outID iotago.OutputID) iotago.NFTID

func ReadBoolByte

func ReadBoolByte(r io.Reader, cond *bool) error

func ReadByte

func ReadByte(r io.Reader) (byte, error)

func ReadBytes16

func ReadBytes16(r io.Reader) ([]byte, error)

func ReadBytes16FromMarshalUtil added in v0.3.0

func ReadBytes16FromMarshalUtil(mu *marshalutil.MarshalUtil) ([]byte, error)

func ReadBytes32

func ReadBytes32(r io.Reader) ([]byte, error)

func ReadBytes8 added in v0.3.0

func ReadBytes8(r io.Reader) ([]byte, error)

func ReadBytes8FromMarshalUtil added in v0.3.0

func ReadBytes8FromMarshalUtil(mu *marshalutil.MarshalUtil) ([]byte, error)

func ReadHashValue

func ReadHashValue(r io.Reader, h *hashing.HashValue) error

func ReadInt32 added in v0.2.0

func ReadInt32(r io.Reader, pval *int32) error

func ReadInt64

func ReadInt64(r io.Reader, pval *int64) error

func ReadIntsAsBits added in v0.3.0

func ReadIntsAsBits(r io.Reader) ([]int, error)

func ReadMarshaled added in v0.1.0

func ReadMarshaled(r io.Reader, val encoding.BinaryUnmarshaler) error

ReadMarshaled supports kyber.Point, kyber.Scalar and similar.

func ReadOutputID added in v0.2.0

func ReadOutputID(r io.Reader) (*iotago.UTXOInput, error)

func ReadString16

func ReadString16(r io.Reader) (string, error)

func ReadStrings16

func ReadStrings16(r io.Reader) ([]string, error)

func ReadTime

func ReadTime(r io.Reader, ts *time.Time) error

func ReadTransactionID added in v0.3.0

func ReadTransactionID(r io.Reader, txid *iotago.TransactionID) error

func ReadUint16

func ReadUint16(r io.Reader, pval *uint16) error

func ReadUint32

func ReadUint32(r io.Reader, pval *uint32) error

func ReadUint64

func ReadUint64(r io.Reader, pval *uint64) error

func ReadUint8 added in v0.2.3

func ReadUint8(r io.Reader, pval *uint8) error

func SelectDeterministicRandomUint16 added in v0.2.0

func SelectDeterministicRandomUint16(selectFrom []uint16, seed int64) uint16

func StringInList added in v0.2.0

func StringInList(s string, lst []string) bool

func TerminateCmdWhenTestStops added in v0.3.0

func TerminateCmdWhenTestStops(cmd *exec.Cmd)

func ToBigInt added in v0.3.0

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

func Uint16From2Bytes

func Uint16From2Bytes(b []byte) (uint16, error)

func Uint16To2Bytes

func Uint16To2Bytes(val uint16) []byte

func Uint32From4Bytes

func Uint32From4Bytes(b []byte) (uint32, error)

func Uint32To4Bytes

func Uint32To4Bytes(val uint32) []byte

func Uint64From8Bytes

func Uint64From8Bytes(b []byte) (uint64, error)

func Uint64To8Bytes

func Uint64To8Bytes(val uint64) []byte

func Uint8From1Bytes added in v0.2.3

func Uint8From1Bytes(b []byte) (uint8, error)

func Uint8To1Bytes added in v0.2.3

func Uint8To1Bytes(val uint8) []byte

func ValidPermutation

func ValidPermutation(perm []uint16) bool

func WriteBoolByte

func WriteBoolByte(w io.Writer, cond bool) error

func WriteByte

func WriteByte(w io.Writer, val byte) error

func WriteBytes16

func WriteBytes16(w io.Writer, data []byte) error

func WriteBytes16ToMarshalUtil added in v0.3.0

func WriteBytes16ToMarshalUtil(data []byte, mu *marshalutil.MarshalUtil)

func WriteBytes32

func WriteBytes32(w io.Writer, data []byte) error

func WriteBytes8 added in v0.3.0

func WriteBytes8(w io.Writer, data []byte) error

func WriteBytes8ToMarshalUtil added in v0.3.0

func WriteBytes8ToMarshalUtil(data []byte, mu *marshalutil.MarshalUtil)

func WriteInt64

func WriteInt64(w io.Writer, val int64) error

func WriteIntsAsBits added in v0.3.0

func WriteIntsAsBits(w io.Writer, ints []int) error

func WriteMarshaled added in v0.1.0

func WriteMarshaled(w io.Writer, val encoding.BinaryMarshaler) error

WriteMarshaled supports kyber.Point, kyber.Scalar and similar.

func WriteOutputID added in v0.3.0

func WriteOutputID(w io.Writer, oid *iotago.UTXOInput) error

func WriteString16

func WriteString16(w io.Writer, str string) error

func WriteStrings16

func WriteStrings16(w io.Writer, strs []string) error

func WriteTime

func WriteTime(w io.Writer, ts time.Time) error

func WriteUint16

func WriteUint16(w io.Writer, val uint16) error

func WriteUint32

func WriteUint32(w io.Writer, val uint32) error

func WriteUint64

func WriteUint64(w io.Writer, val uint64) error

func WriteUint8 added in v0.2.3

func WriteUint8(w io.Writer, val uint8) error

Types

type BitVector added in v0.3.0

type BitVector interface {
	SetBits(positions []int) BitVector
	AsInts() []int
	Bytes() []byte
}

func NewFixedSizeBitVector added in v0.3.0

func NewFixedSizeBitVector(size int) BitVector

func NewFixedSizeBitVectorFromMarshalUtil added in v0.3.0

func NewFixedSizeBitVectorFromMarshalUtil(mu *marshalutil.MarshalUtil) (BitVector, error)

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)

Seed should be provided in tests only 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. 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 allways 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 added in v0.3.0

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 added in v0.3.0

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 added in v0.3.0

type Ratio32 struct {
	A uint32
	B uint32
}

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

func Ratio32FromBytes added in v0.3.0

func Ratio32FromBytes(bytes []byte) (Ratio32, error)

func (Ratio32) Bytes added in v0.3.0

func (r Ratio32) Bytes() []byte

func (*Ratio32) Set added in v0.3.0

func (r *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 added in v0.3.0

func (r Ratio32) String() string

func (Ratio32) Type added in v0.3.0

func (r Ratio32) Type() string

Type is part of the pflag.Value interface.

func (Ratio32) XCeil64 added in v0.3.0

func (r Ratio32) XCeil64(y uint64) uint64

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

func (Ratio32) XFloor64 added in v0.3.0

func (r Ratio32) XFloor64(y uint64) uint64

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

func (Ratio32) YCeil64 added in v0.3.0

func (r Ratio32) YCeil64(x uint64) uint64

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

func (Ratio32) YFloor64 added in v0.3.0

func (r Ratio32) YFloor64(x uint64) uint64

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

type Timer added in v0.3.0

type Timer time.Time

func NewTimer added in v0.3.0

func NewTimer() Timer

func (Timer) Duration added in v0.3.0

func (t Timer) Duration() time.Duration

type WaitChan added in v0.1.0

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

WaitChan is something similar to sync.WaitGroup, just is based on channels and supports waiting with timeout.

func NewWaitChan added in v0.1.0

func NewWaitChan() *WaitChan

func (*WaitChan) Done added in v0.1.0

func (c *WaitChan) Done()

func (*WaitChan) Reset added in v0.1.0

func (c *WaitChan) Reset()

func (*WaitChan) Wait added in v0.1.0

func (c *WaitChan) Wait()

func (*WaitChan) WaitTimeout added in v0.1.0

func (c *WaitChan) WaitTimeout(timeout time.Duration) bool

Directories

Path Synopsis
package implement a simple primitive to wait for readiness of concurrent modules
package implement a simple primitive to wait for readiness of concurrent modules
package implements simple semaphore with timeout
package implements simple semaphore with timeout

Jump to

Keyboard shortcuts

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