github.com/project-88388/tendermint-v0.34.14-terra.2@v1.0.0/crypto/merkle/types.go (about)

     1  package merkle
     2  
     3  import (
     4  	"encoding/binary"
     5  	"io"
     6  )
     7  
     8  // Tree is a Merkle tree interface.
     9  type Tree interface {
    10  	Size() (size int)
    11  	Height() (height int8)
    12  	Has(key []byte) (has bool)
    13  	Proof(key []byte) (value []byte, proof []byte, exists bool) // TODO make it return an index
    14  	Get(key []byte) (index int, value []byte, exists bool)
    15  	GetByIndex(index int) (key []byte, value []byte)
    16  	Set(key []byte, value []byte) (updated bool)
    17  	Remove(key []byte) (value []byte, removed bool)
    18  	HashWithCount() (hash []byte, count int)
    19  	Hash() (hash []byte)
    20  	Save() (hash []byte)
    21  	Load(hash []byte)
    22  	Copy() Tree
    23  	Iterate(func(key []byte, value []byte) (stop bool)) (stopped bool)
    24  	IterateRange(start []byte, end []byte, ascending bool, fx func(key []byte, value []byte) (stop bool)) (stopped bool)
    25  }
    26  
    27  //-----------------------------------------------------------------------
    28  
    29  // Uvarint length prefixed byteslice
    30  func encodeByteSlice(w io.Writer, bz []byte) (err error) {
    31  	var buf [binary.MaxVarintLen64]byte
    32  	n := binary.PutUvarint(buf[:], uint64(len(bz)))
    33  	_, err = w.Write(buf[0:n])
    34  	if err != nil {
    35  		return
    36  	}
    37  	_, err = w.Write(bz)
    38  	return
    39  }