Documentation ¶
Index ¶
- func PrintIAVLNode(node *IAVLNode)
- func SimpleHashFromBinaries(items []interface{}) []byte
- func SimpleHashFromBinary(item interface{}) []byte
- func SimpleHashFromHashables(items []Hashable) []byte
- func SimpleHashFromHashes(hashes [][]byte) []byte
- func SimpleHashFromMap(m map[string]interface{}) []byte
- func SimpleHashFromTwoHashes(left []byte, right []byte) []byte
- type Hashable
- type IAVLNode
- type IAVLProof
- type IAVLProofInnerNode
- type IAVLProofLeafNode
- type IAVLTree
- func (t *IAVLTree) ConstructProof(key interface{}) *IAVLProof
- func (t *IAVLTree) Copy() Tree
- func (t *IAVLTree) Get(key interface{}) (index int, value interface{})
- func (t *IAVLTree) GetByIndex(index int) (key interface{}, value interface{})
- func (t *IAVLTree) Has(key interface{}) bool
- func (t *IAVLTree) Hash() []byte
- func (t *IAVLTree) HashWithCount() ([]byte, int)
- func (t *IAVLTree) Height() int8
- func (t *IAVLTree) Iterate(fn func(key interface{}, value interface{}) bool) (stopped bool)
- func (t *IAVLTree) Load(hash []byte)
- func (t *IAVLTree) Remove(key interface{}) (value interface{}, removed bool)
- func (t *IAVLTree) Save() []byte
- func (t *IAVLTree) Set(key interface{}, value interface{}) (updated bool)
- func (t *IAVLTree) Size() int
- type KVPair
- type KVPairs
- type SimpleProof
- type SimpleProofNode
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SimpleHashFromBinaries ¶
func SimpleHashFromBinaries(items []interface{}) []byte
Convenience for SimpleHashFromHashes.
func SimpleHashFromHashables ¶
Convenience for SimpleHashFromHashes.
func SimpleHashFromHashes ¶
func SimpleHashFromMap ¶
Convenience for SimpleHashFromHashes.
func SimpleHashFromTwoHashes ¶
Types ¶
type IAVLNode ¶
type IAVLNode struct {
// contains filtered or unexported fields
}
func NewIAVLNode ¶
func NewIAVLNode(key interface{}, value interface{}) *IAVLNode
type IAVLProof ¶
type IAVLProof struct { LeafNode IAVLProofLeafNode InnerNodes []IAVLProofInnerNode RootHash []byte }
type IAVLProofInnerNode ¶
func (IAVLProofInnerNode) Hash ¶
func (branch IAVLProofInnerNode) Hash(childHash []byte) []byte
type IAVLProofLeafNode ¶
func (IAVLProofLeafNode) Hash ¶
func (leaf IAVLProofLeafNode) Hash() []byte
type IAVLTree ¶
type IAVLTree struct {
// contains filtered or unexported fields
}
Immutable AVL Tree (wraps the Node root) This tree is not goroutine safe.
func NewIAVLTree ¶
func (*IAVLTree) ConstructProof ¶
Returns nil if key is not in tree.
func (*IAVLTree) Copy ¶
The returned tree and the original tree are goroutine independent. That is, they can each run in their own goroutine.
func (*IAVLTree) GetByIndex ¶
func (*IAVLTree) HashWithCount ¶
func (*IAVLTree) Load ¶
Sets the root node by reading from db. If the hash is empty, then sets root to nil.
type KVPair ¶
type KVPair struct { Key string Value interface{} }
Convenience struct for key-value pairs.
A list of KVPairs is hashed via `SimpleHashFromHashables`. NOTE: Each `Value` is encoded for hashing without extra type information, so the user is presumed to be aware of the Value types.
type SimpleProof ¶
type SimpleProof struct { Index int `json:"index"` Total int `json:"total"` LeafHash []byte `json:"leaf_hash"` InnerHashes [][]byte `json:"inner_hashes"` // Hashes from leaf's sibling to a root's child. RootHash []byte `json:"root_hash"` }
func SimpleProofsFromHashables ¶
func SimpleProofsFromHashables(items []Hashable) (proofs []*SimpleProof)
proofs[0] is the proof for items[0].
func (*SimpleProof) String ¶
func (sp *SimpleProof) String() string
func (*SimpleProof) StringIndented ¶
func (sp *SimpleProof) StringIndented(indent string) string
type SimpleProofNode ¶
type SimpleProofNode struct { Hash []byte Parent *SimpleProofNode Left *SimpleProofNode // Left sibling (only one of Left,Right is set) Right *SimpleProofNode // Right sibling (only one of Left,Right is set) }
Helper structure to construct merkle proof. The node and the tree is thrown away afterwards. Exactly one of node.Left and node.Right is nil, unless node is the root, in which case both are nil. node.Parent.Hash = hash(node.Hash, node.Right.Hash) or
hash(node.Left.Hash, node.Hash), depending on whether node is a left/right child.
func (*SimpleProofNode) FlattenInnerHashes ¶
func (spn *SimpleProofNode) FlattenInnerHashes() [][]byte
Starting from a leaf SimpleProofNode, FlattenInnerHashes() will return the inner hashes for the item corresponding to the leaf.
type Tree ¶
type Tree interface { Size() (size int) Height() (height int8) Has(key interface{}) (has bool) Get(key interface{}) (index int, value interface{}) GetByIndex(index int) (key interface{}, value interface{}) Set(key interface{}, value interface{}) (updated bool) Remove(key interface{}) (value interface{}, removed bool) HashWithCount() (hash []byte, count int) Hash() (hash []byte) Save() (hash []byte) Load(hash []byte) Copy() Tree Iterate(func(key interface{}, value interface{}) (stop bool)) (stopped bool) }