util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CommandSize is the fixed size of all commands (MessageHeader.Code) in the common message
	// header.  Shorter commands must be zero padded.
	CommandSize = 4
)

Variables

View Source
var (
	ErrKeyNotFound  = errors.New("key not found in dag")
	ErrKeyIsExisted = errors.New("key is exist in dag")
)

error

View Source
var ReadByte func(io.Reader) (byte, error)

ReadByte reads single byte.

View Source
var WriteByte func(io.Writer, byte) error

WriteByte wtires single byte.

Functions

func ANDBytes added in v0.5.0

func ANDBytes(a, b []byte) []byte

ANDBytes ands one by one. It works on all architectures, independent if it supports unaligned read/writes or not.

func BitIndexes added in v0.5.0

func BitIndexes(data []byte) []uint32

BitIndexes return marked bit indexes.

func BuildMerkleRoot

func BuildMerkleRoot(hashs []*crypto.HashType) []*crypto.HashType

BuildMerkleRoot build transaction merkle tree

         root = h1234 = h(h12 + h34)
        /                           \
  h12 = h(h1 + h2)            h34 = h(h3 + h4)
   /            \              /            \
h1 = h(tx1)  h2 = h(tx2)    h3 = h(tx3)  h4 = h(tx4)

The above stored as a linear array is as follows:

[h1 h2 h3 h4 h12 h34 root]

func Equal

func Equal(a []byte, b []byte) bool

Equal checks whether byte slice a and b are equal.

func FromHex

func FromHex(data string) ([]byte, error)

FromHex decodes string from Hex.

func FromInt16

func FromInt16(v int16) []byte

FromInt16 decodes int16 v.

func FromInt32

func FromInt32(v int32) []byte

FromInt32 decodes int32 v.

func FromInt64

func FromInt64(v int64) []byte

FromInt64 decodes int64 v.

func FromUint16

func FromUint16(v uint16) []byte

FromUint16 decodes uint16.

func FromUint32

func FromUint32(v uint32) []byte

FromUint32 decodes uint32.

func FromUint64

func FromUint64(v uint64) []byte

FromUint64 decodes unit64 value.

func HashBytes

func HashBytes(a []byte) uint32

HashBytes return bytes hash

func Hex

func Hex(data []byte) string

Hex encodes []byte to Hex.

func HomeDir

func HomeDir() string

HomeDir returns home directory of current user

func InArray

func InArray(obj interface{}, array interface{}) bool

InArray return if there is an element in the array

func Int16

func Int16(data []byte) int16

Int16 encode []byte.

func Int32

func Int32(data []byte) int32

Int32 encodes []byte.

func Int64

func Int64(data []byte) int64

Int64 encodes []byte.

func IsPrefixed

func IsPrefixed(s, prefix []byte) bool

IsPrefixed returns if s has the passed prefix

func Less

func Less(a []byte, b []byte) bool

Less return if a < b

func ORBytes added in v0.5.0

func ORBytes(a, b []byte) []byte

ORBytes ors one by one. It works on all architectures, independent if it supports unaligned read/writes or not.

func PrettyPrint

func PrettyPrint(obj interface{}) string

PrettyPrint prints all types with pretty ident and format

func ReadBytes

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

ReadBytes reads fix length of []byte via reader.

func ReadBytesOfLength

func ReadBytesOfLength(r io.Reader, l uint32) ([]byte, error)

ReadBytesOfLength reads specified length of []byte via reader.

func ReadHex

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

ReadHex reads Hex string.

func ReadInt16

func ReadInt16(r io.Reader) (int16, error)

ReadInt16 reads int16 value.

func ReadInt32

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

ReadInt32 reads int32.

func ReadInt64

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

ReadInt64 reads int64.

func ReadInt8

func ReadInt8(r io.Reader) (int8, error)

ReadInt8 reads int8 value.

func ReadUint16

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

ReadUint16 reads uint16.

func ReadUint32

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

ReadUint32 reads uint32.

func ReadUint64

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

ReadUint64 read uint64.

func ReadUint8

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

ReadUint8 reads uint8.

func ReadUvarint

func ReadUvarint(r io.Reader) (uint64, error)

ReadUvarint read uint64.

func ReadVarBytes

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

ReadVarBytes reads variable length of []byte via reader.

func ReadVarint

func ReadVarint(r io.Reader) (int64, error)

ReadVarint read uint64.

func Uint16

func Uint16(data []byte) uint16

Uint16 encodes []byte.

func Uint32

func Uint32(data []byte) uint32

Uint32 encodes []byte.

func Uint64

func Uint64(data []byte) uint64

Uint64 encodes []byte.

func WriteBytes

func WriteBytes(w io.Writer, v []byte) error

WriteBytes writes fix length of bytes.

func WriteElements

func WriteElements(w io.Writer, elements ...interface{}) error

WriteElements writes multiple items to w. It is equivalent to multiple calls to writeElement.

func WriteHex

func WriteHex(w io.Writer, s string) error

WriteHex writes Hex string.

func WriteInt16

func WriteInt16(w io.Writer, v int16) error

WriteInt16 writes int16 v.

func WriteInt32

func WriteInt32(w io.Writer, v int32) error

WriteInt32 writes int32 v.

func WriteInt64

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

WriteInt64 writes int64 v.

func WriteInt8

func WriteInt8(w io.Writer, v int8) error

WriteInt8 writes int8 v.

func WriteUint16

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

WriteUint16 wtires uint16 v.

func WriteUint32

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

WriteUint32 writes uint32.

func WriteUint64

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

WriteUint64 writes unit64 value.

func WriteUint8

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

WriteUint8 wtires uint8 v.

func WriteUvarint

func WriteUvarint(w io.Writer, v uint64) error

WriteUvarint writes unit64 value.

func WriteVarBytes

func WriteVarBytes(w io.Writer, v []byte) error

WriteVarBytes writes variable length of bytes.

func WriteVarint

func WriteVarint(w io.Writer, v int64) error

WriteVarint writes unit64 value.

Types

type Dag added in v0.5.0

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

Dag define a dag struct

func NewDag added in v0.5.0

func NewDag() *Dag

NewDag new dag

func (*Dag) AddEdge added in v0.5.0

func (dag *Dag) AddEdge(fkey, tkey interface{}) error

AddEdge add edge for dag

func (*Dag) AddNode added in v0.5.0

func (dag *Dag) AddNode(key interface{}, weight int) error

AddNode add node for dag

func (*Dag) GetRootNodes added in v0.5.0

func (dag *Dag) GetRootNodes() []*Node

GetRootNodes get root nodes in dag

func (*Dag) Index added in v0.5.0

func (dag *Dag) Index() int

Index return current index in dag

func (*Dag) IsCirclular added in v0.5.0

func (dag *Dag) IsCirclular() bool

IsCirclular check if circlular in dag

func (*Dag) TopoSort added in v0.5.0

func (dag *Dag) TopoSort() []*Node

TopoSort topo_sort in dag

type Hash

type Hash []byte

Hash by Sha3-256

func (Hash) Base58

func (h Hash) Base58() string

Base58 return base58 encodes string

func (Hash) Equals

func (h Hash) Equals(b Hash) bool

Equals compare two Hash. True is equal, otherwise false.

func (Hash) Hex

func (h Hash) Hex() HexHash

Hex return hex encoded hash.

func (Hash) String

func (h Hash) String() string

type HexHash

type HexHash string

HexHash is the hex string of a hash

func (HexHash) Hash

func (hh HexHash) Hash() (Hash, error)

Hash return hex decoded hash.

type LessFunc

type LessFunc func(*PriorityQueue, int, int) bool

LessFunc define less function.

type Node added in v0.5.0

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

Node define a node struct

func NewNode added in v0.5.0

func NewNode(key interface{}, index int, weight int) *Node

NewNode new node

func (*Node) Key added in v0.5.0

func (node *Node) Key() interface{}

Key return node key

type PriorityQueue

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

PriorityQueue define a priority queue.

func NewPriorityQueue

func NewPriorityQueue(lessFunc LessFunc) *PriorityQueue

NewPriorityQueue create a new PriorityQueue

func (*PriorityQueue) Items

func (pq *PriorityQueue) Items(i int) interface{}

Items return item in queue at index i.

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

Len returns the length of items. It implemented heap.Interface.

func (*PriorityQueue) Less

func (pq *PriorityQueue) Less(i, j int) bool

Less implemented the heap.Interface.

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

Pop removes the highest priority item from the priority

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

Push pushes the passed item onto the priority queue.

func (*PriorityQueue) SetLessFunc

func (pq *PriorityQueue) SetLessFunc(lessFunc LessFunc)

SetLessFunc sets the compare function for the priority queue

func (*PriorityQueue) Swap

func (pq *PriorityQueue) Swap(i, j int)

Swap swaps the items in the priority queue. It implemented heap.Interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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