db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: GPL-3.0 Imports: 3 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found")

ErrNotFound is used by the implementations of the interface db.Storage for when a key is not found in the storage

Functions

func Clone

func Clone(b0 []byte) []byte

Clone clones a byte array into a new byte array

func Concat

func Concat(vs ...[]byte) []byte

Concat concatenates arrays of bytes

Types

type KV

type KV struct {
	K []byte
	V []byte
}

KV contains a key (K) and a value (V)

type KvMap

type KvMap map[[sha256.Size]byte]KV

KvMap is a key-value map between a sha256 byte array hash, and a KV struct

func (KvMap) Get

func (m KvMap) Get(k []byte) ([]byte, bool)

Get retreives the value respective to a key from the KvMap

func (KvMap) Put

func (m KvMap) Put(k, v []byte)

Put stores a key and a value in the KvMap

type Storage

type Storage interface {
	NewTx() (Tx, error)
	WithPrefix(prefix []byte) Storage
	Get([]byte) ([]byte, error)
	List(int) ([]KV, error)
	Close()
	Iterate(func([]byte, []byte) (bool, error)) error
}

Storage is the interface that defines the methods for the storage used in the merkletree. Examples of the interface implementation can be found at db/memory and db/leveldb directories.

type Tx

type Tx interface {
	// Get retreives the value for the given key
	// looking first in the content of the Tx, and
	// then into the content of the Storage
	Get([]byte) ([]byte, error)
	// Put sets the key & value into the Tx
	Put(k, v []byte) error
	// Add adds the given Tx into the Tx
	Add(Tx) error
	Commit() error
	Close()
}

Tx is the interface that defines the methods for the db transaction used in the merkletree storage. Examples of the interface implementation can be found at db/memory and db/leveldb directories.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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