MPTPlus

package
v0.0.0-...-7ede18c Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrefixLength

func PrefixLength(a, b []byte) int

返回公共前缀的长度

Types

type MTP

type MTP struct {
	Root types.HexBytes
	DB   db.IKVDatabase
}

func MTP_Tree

func MTP_Tree(db db.IKVDatabase, root []byte) *MTP

func NewMTP

func NewMTP(db db.IKVDatabase) *MTP

func (*MTP) ContainsKey

func (mtp *MTP) ContainsKey(key []byte) bool

func (*MTP) FindParents

func (mtp *MTP) FindParents(key []byte) (parentHashes [][]byte, prefixs [][]byte, err error)

func (*MTP) GetInterfaceValue

func (mtp *MTP) GetInterfaceValue(key []byte, v interface{}) error

func (*MTP) GetNode

func (mtp *MTP) GetNode(hash []byte) (*TrieNode, error)

func (*MTP) GetValue

func (mtp *MTP) GetValue(key []byte) (value []byte, err error)

func (*MTP) GetValueByKey

func (mtp *MTP) GetValueByKey(key []byte) (value []byte, err error)

func (MTP) MarshalJSON

func (mtp MTP) MarshalJSON() ([]byte, error)

func (*MTP) MustInsert

func (mtp *MTP) MustInsert(key, value []byte) error

* *把Key和Value插入到root对应的树上 * *首先搜索到要插入的节点,插入之后向上回溯寻找自己的Parent节点更新,直至root节点

func (*MTP) SaveNode

func (mtp *MTP) SaveNode(node TrieNode) (nodeHash []byte, err error)

func (*MTP) SaveValue

func (mtp *MTP) SaveValue(value []byte) ([]byte, error)

func (*MTP) TryInsert

func (mtp *MTP) TryInsert(key, value []byte, parentHashes, prefixs [][]byte) error

func (*MTP) UnmarshalJSON

func (mtp *MTP) UnmarshalJSON(data []byte) error

func (*MTP) Update

func (mtp *MTP) Update(key, value []byte, parentHashes [][]byte, prefixs [][]byte) error

type SortedSon

type SortedSon []TrieSonInfo

func (SortedSon) Len

func (sonInfo SortedSon) Len() int

func (SortedSon) Less

func (sonInfo SortedSon) Less(i, j int) bool

func (SortedSon) Swap

func (sonInfo SortedSon) Swap(i, j int)

type TrieNode

type TrieNode struct {
	Sons      SortedSon      `json:"sons"`
	Leaf      bool           `json:"leaf"`
	Root      bool           `json:"root"`
	PathValue types.HexBytes `json:"pathValue"`
}

*TrieNode存储的是当前节点的一些信息,包括PathValue 是否是叶子节点,子节点信息等等 *strings.Join(pathValue,"")就是用户要存储的key

func (*TrieNode) AddSon

func (node *TrieNode) AddSon(hash, pathValue []byte)

func (*TrieNode) DeleteSon

func (node *TrieNode) DeleteSon(pathValue []byte)

type TrieSonInfo

type TrieSonInfo struct {
	Hash      types.HexBytes `json:"hash"`
	PathValue types.HexBytes `json:"pathValue"`
}

*TrieSonInfo存储的是当前节点的下一个节点的信息 *如果当前节点是叶子节点,则Sons的长度为1,且TrieSonInfo.Hash是当前路径key的Value值的hash *如果当前节点不是叶子节点,则Sons的长度大于等于1,存储的是子节点的Hash值和PathValue

Jump to

Keyboard shortcuts

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