trie

package
v0.0.0-...-ad1a03f Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilValueNode = ValueNode(nil)

nilValueNode is used when collapsing internal trie nodes for hashing, since unset children need to serialize correctly.

Functions

func HexToKey

func HexToKey(hex []byte) []byte

hexToKeybytes turns hex nibbles into key bytes. This can only be used for keys of even length.

func hexToKeybytes(hex []byte) []byte {
	if hasTerm(hex) {
		hex = hex[:len(hex)-1]
	}
	if len(hex)&1 != 0 {
		panic("can't convert hex key of odd length")
	}
	key := make([]byte, len(hex)/2)
	decodeNibbles(hex, key)
	return key
}

Types

type FullNode

type FullNode struct {
	Children [17]Node // Actual trie node data to encode/decode (needs custom encoder)
	Self     HashNode
}

func (*FullNode) DeepTravel

func (n *FullNode) DeepTravel(fn func(Node, []byte), args []byte)

func (*FullNode) Find

func (n *FullNode) Find(hash []byte) (Node, error)

func (*FullNode) String

func (n *FullNode) String() string

func (*FullNode) Travel

func (n *FullNode) Travel(fn func(Node))

type HashNode

type HashNode []byte

func (HashNode) DeepTravel

func (n HashNode) DeepTravel(fn func(Node, []byte), args []byte)

func (HashNode) String

func (n HashNode) String() string

func (HashNode) Travel

func (n HashNode) Travel(fn func(Node))

type Node

type Node interface {
	String() string
	Travel(fn func(Node))
	DeepTravel(func(Node, []byte), []byte)
	// contains filtered or unexported methods
}

func DecodeNode

func DecodeNode(hash, buf []byte) (Node, error)

type ShortNode

type ShortNode struct {
	Key  []byte
	Val  Node
	Self HashNode
}

func (*ShortNode) DeepTravel

func (n *ShortNode) DeepTravel(fn func(Node, []byte), args []byte)

func (*ShortNode) HashKey

func (n *ShortNode) HashKey() []byte

func (*ShortNode) String

func (n *ShortNode) String() string

func (*ShortNode) Travel

func (n *ShortNode) Travel(fn func(Node))

type ValueNode

type ValueNode []byte

func (ValueNode) DeepTravel

func (n ValueNode) DeepTravel(fn func(Node, []byte), args []byte)

func (ValueNode) String

func (n ValueNode) String() string

func (ValueNode) Travel

func (n ValueNode) Travel(fn func(Node))

Jump to

Keyboard shortcuts

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