trie

package
v0.0.0-...-84d53aa Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNodeType = errors.New("invalid node type")
	ErrPbMsg           = errors.New("pb Message cannot be converted into Node")
	ErrNotFound        = storage.ErrKeyNotFound
)

Errors

View Source
var (
	ErrCannotPerformInBatch    = errors.New("cannot perform in batch")
	ErrNotBatching             = errors.New("not batching")
	ErrAlreadyPreparedTrie     = errors.New("cannot prepare again")
	ErrNotPrepared             = errors.New("not preparing")
	ErrCannotClonePreparedTrie = errors.New("cannot clone prepared trie")
)

Trie errors string representation

Functions

func BeginBatchCall

func BeginBatchCall(batch Batcher) error

BeginBatchCall is a begin batch call.

func CommitCall

func CommitCall(batch Batcher) error

CommitCall is a commit call.

func FlushCall

func FlushCall(batch Batcher) error

FlushCall is a flush call.

func KeyToRoute

func KeyToRoute(key []byte) []byte

KeyToRoute 256 => 16 * 16

func PrepareCall

func PrepareCall(batch Batcher) error

PrepareCall is a prepare call.

func ResetCall

func ResetCall(batch Batcher) error

ResetCall is a reset call.

func RollbackCall

func RollbackCall(batch Batcher) error

RollbackCall is a rollback call.

func RouteToKey

func RouteToKey(route []byte) []byte

RouteToKey convert route to key

Types

type Batch

type Batch struct {
	*Trie
	// contains filtered or unexported fields
}

Batch batch implementation for trie

func NewBatch

func NewBatch(rootHash []byte, stor storage.Storage) (*Batch, error)

NewBatch return new Batch instance

func (*Batch) BeginBatch

func (tb *Batch) BeginBatch() error

BeginBatch begin batch

func (*Batch) Clone

func (tb *Batch) Clone() (*Batch, error)

Clone clone Batch

func (*Batch) Commit

func (tb *Batch) Commit() error

Commit commit batch WARNING: not thread-safe

func (*Batch) Delete

func (tb *Batch) Delete(key []byte) error

Delete delete in trie

func (*Batch) Get

func (tb *Batch) Get(key []byte) ([]byte, error)

Get get from trie

func (*Batch) GetData

func (tb *Batch) GetData(key []byte, data Serializable) error

GetData get value from trie and set on serializable data

func (*Batch) Put

func (tb *Batch) Put(key []byte, value []byte) error

Put put to trie

func (*Batch) PutData

func (tb *Batch) PutData(key []byte, data Serializable) error

PutData put serializable data to trie

func (*Batch) RollBack

func (tb *Batch) RollBack() error

RollBack rollback batch WARNING: not thread-safe

func (*Batch) RootHash

func (tb *Batch) RootHash() ([]byte, error)

RootHash getter for rootHash

type BatchCallType

type BatchCallType func(batch Batcher) error

BatchCallType is a type of batch call function.

type Batcher

type Batcher interface {
	Prepare() error
	BeginBatch() error
	Commit() error
	RollBack() error
	Flush() error
	Reset() error
}

Batcher is an interface for batch commands.

type Iterator

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

Iterator to traverse leaf node in a trie

func (*Iterator) Key

func (it *Iterator) Key() []byte

Key return current leaf node's key

func (*Iterator) Next

func (it *Iterator) Next() (bool, error)

Next return if there is next leaf node

func (*Iterator) Value

func (it *Iterator) Value() []byte

Value return current leaf node's value

type IteratorState

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

IteratorState represents the intermediate statue in iterator

type Serializable

type Serializable interface {
	ToBytes() ([]byte, error)
	FromBytes([]byte) error
}

Serializable interface for serializing/deserializing

type Trie

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

Trie is a Merkle Patricia Trie, consists of three kinds of nodes, Branch Node: 16-elements array, value is [hash_0, hash_1, ..., hash_f, hash] Extension Node: 3-elements array, value is [ext flag, prefix path, next hash] Leaf Node: 3-elements array, value is [leaf flag, suffix path, value]

func NewTrie

func NewTrie(rootHash []byte, storage storage.Storage) (*Trie, error)

NewTrie create and return new Trie instance

func (*Trie) Clone

func (t *Trie) Clone() (*Trie, error)

Clone clone trie

func (*Trie) Delete

func (t *Trie) Delete(key []byte) error

Delete delete value from Trie

func (*Trie) Flush

func (t *Trie) Flush() error

Flush save temp nodes to storage

func (*Trie) Get

func (t *Trie) Get(key []byte) ([]byte, error)

Get get value from Trie

func (*Trie) Iterator

func (t *Trie) Iterator(prefix []byte) (*Iterator, error)

Iterator return an iterator

func (*Trie) Keys

func (t *Trie) Keys(prefix []byte) ([][]byte, error)

Keys returns all keys starting with the given prefix.

func (*Trie) Prepare

func (t *Trie) Prepare() error

Prepare prepare trie

func (*Trie) Put

func (t *Trie) Put(key []byte, value []byte) error

Put put value to Trie

func (*Trie) Reset

func (t *Trie) Reset() error

Reset reset temp nodes

func (*Trie) RootHash

func (t *Trie) RootHash() []byte

RootHash getter for rootHash

func (*Trie) SetRootHash

func (t *Trie) SetRootHash(rootHash []byte)

SetRootHash setter for rootHash

func (*Trie) ShowPath

func (t *Trie) ShowPath(key []byte) []string

ShowPath return node's info in path

Directories

Path Synopsis
Package triepb is a generated protocol buffer package.
Package triepb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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