tree

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SafeTree

type SafeTree struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

SafeTree is a wrapper around Tendermint's IAVL that provides thread-safe operations

func NewSafeTree

func NewSafeTree(db tmdb.DB, cacheSize int) (*SafeTree, error)

NewSafeTree creates an instance of SafeTree

func (*SafeTree) Get

func (s *SafeTree) Get(key []byte) (index int64, value []byte)

Get returns the index and value of the specified key if it exists, or nil and the next index, if it doesn't.

func (*SafeTree) GetVersioned

func (s *SafeTree) GetVersioned(key []byte, version int64) (index int64, value []byte)

GetVersioned gets the value at the specified key and version.

func (*SafeTree) Hash

func (s *SafeTree) Hash() []byte

Hash returns the hash of the latest saved version of the tree, as returned by SaveVersion. If no versions have been saved, Hash returns nil.

func (*SafeTree) Load

func (s *SafeTree) Load() (int64, error)

Load the latest versioned tree from disk.

func (*SafeTree) Raw

func (s *SafeTree) Raw() interface{}

Raw returns the underlying tree

func (*SafeTree) Remove

func (s *SafeTree) Remove(key []byte) bool

Remove removes a key and returns 'true' if successful

func (*SafeTree) Rollback

func (s *SafeTree) Rollback()

Rollback rolls back the tree to the latest version, discarding unsaved changes.

func (*SafeTree) SaveVersion

func (s *SafeTree) SaveVersion() ([]byte, int64, error)

SaveVersion saves a new tree version to disk, based on the current state of the tree. Returns the hash and new version number.

func (*SafeTree) Set

func (s *SafeTree) Set(key, value []byte) bool

Set sets a key in the working tree. Nil values are not supported. Returns true if the key existed and was updated.

func (*SafeTree) Version

func (s *SafeTree) Version() int64

Version returns the version of the tree.

func (*SafeTree) WorkingHash

func (s *SafeTree) WorkingHash() []byte

WorkingHash returns the hash of the current working tree.

type Tree

type Tree interface {
	Version() int64
	GetVersioned(key []byte, version int64) (index int64, value []byte)
	Get(key []byte) (index int64, value []byte)
	Set(key, value []byte) bool
	Remove(key []byte) bool
	SaveVersion() ([]byte, int64, error)
	Load() (int64, error)
	WorkingHash() []byte
	Hash() []byte
}

Tree represents a merkle tree

Jump to

Keyboard shortcuts

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