util

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: ISC Imports: 13 Imported by: 1

Documentation

Overview

Copyright (c) 2017-2020 The qitmeer developers license that can be found in the LICENSE file. Reference resources of rust bitVector

Copyright (c) 2017-2018 The qitmeer developers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func AppDir

func AppDir() string

func CleanAndExpandPath

func CleanAndExpandPath(path string) string

CleanAndExpandPath expands environment variables and leading ~ in the passed path, cleans the result, and returns it.

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

func FileExists

func FileExists(name string) bool

FilesExists reports whether the named file or directory exists.

func FromHex

func FromHex(hex string) *big.Int

func HasHexPrefix

func HasHexPrefix(str string) bool

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

func MustDecodeHexString

func MustDecodeHexString(hexStr string) []byte

MustDecodeHex wrap the calling to hex.DecodeString() method to return the bytes represented by the hexadecimal string. It panics if an error occurs. This is useful in the tests or some special cases.

func MustHex2Bytes

func MustHex2Bytes(str string) []byte

MustHex2Bytes returns the bytes represented by the hexadecimal string str. Must means panic when err

func PaddedAppend

func PaddedAppend(size uint, dst, src []byte) []byte

PaddedAppend appends the src byte slice to dst, returning the new slice. If the length of the source is smaller than the passed size, leading zero bytes are appended to the dst slice before appending src. Example : Bitcoin uncompressed pubkey

uncompressed := make([]byte, 0, 65)
uncompressed = append(uncompressed, 0x01)
uncompressed = PaddedAppend(32, uncompressed, p.X.Bytes())
uncompressed = PaddedAppend(32, uncompressed, p.Y.Bytes())

func PaddedBytes

func PaddedBytes(size uint, n *big.Int) []byte

PaddedBytes encodes a big integer as a big-endian byte slice, if the length of byte slice is smaller than the passed size, leading zero bytes will be added. Example : Ethereum privatekey

seckey := PaddedBigInt(32, prv.D)

Ethereum pubkey

func ReadSizedRand

func ReadSizedRand(rand io.Reader, size uint) []byte

ReadRand read size bytes from input rand if input rand is nil, use crypto/rand

func ReverseBytes

func ReverseBytes(b []byte)

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

Types

type BitVector

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

BitVector this is design for cuckoo hash bytes

func New

func New(l int) (bv *BitVector, err error)

init

func NewFromBytes

func NewFromBytes(b []byte, l int) (bv *BitVector, err error)

convert from bytes

func (*BitVector) Bytes

func (bv *BitVector) Bytes() []byte

return bytes

func (*BitVector) Get

func (bv *BitVector) Get(i int) bool

get BitVector

func (*BitVector) Set

func (bv *BitVector) Set(i int, v bool)

set BitVector

func (*BitVector) SetBitAt

func (bv *BitVector) SetBitAt(pos int)

set position

type IterativeQueue

type IterativeQueue []interface{}

func NewIterativeQueue

func NewIterativeQueue() IterativeQueue

func (*IterativeQueue) Dequeue

func (iq *IterativeQueue) Dequeue() interface{}

func (*IterativeQueue) Enqueue

func (iq *IterativeQueue) Enqueue(item interface{})

func (*IterativeQueue) Len

func (iq *IterativeQueue) Len() int

func (*IterativeQueue) Peek

func (iq *IterativeQueue) Peek() interface{}

type TimeSorter

type TimeSorter []int64

timeSorter implements sort.Interface to allow a slice of timestamps to be sorted.

func (TimeSorter) Len

func (s TimeSorter) Len() int

Len returns the number of timestamps in the slice. It is part of the sort.Interface implementation.

func (TimeSorter) Less

func (s TimeSorter) Less(i, j int) bool

Less returns whether the timstamp with index i should sort before the timestamp with index j. It is part of the sort.Interface implementation.

func (TimeSorter) Swap

func (s TimeSorter) Swap(i, j int)

Swap swaps the timestamps at the passed indices. It is part of the sort.Interface implementation.

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap

func (w *WaitGroupWrapper) Wrap(cb func())

Directories

Path Synopsis
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.

Jump to

Keyboard shortcuts

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