Documentation ¶
Index ¶
- Constants
- func EncodeBytes(w io.Writer, bz []byte) error
- func HashNode(node Node) []byte
- func Mmap(f *os.File) ([]byte, *[mmap.MaxMapSize]byte, error)
- func VerifyHash(node Node) bool
- type MemNode
- func (node *MemNode) Hash() []byte
- func (node *MemNode) Height() int8
- func (node *MemNode) Key() []byte
- func (node *MemNode) Left() Node
- func (node *MemNode) Mutate(version int64) *MemNode
- func (node *MemNode) Right() Node
- func (node *MemNode) Size() int64
- func (node *MemNode) Value() []byte
- func (node *MemNode) Version() int64
- type MmapFile
- type Node
- type PersistedNode
- func (node PersistedNode) Hash() []byte
- func (node PersistedNode) Height() int8
- func (node PersistedNode) Key() []byte
- func (node PersistedNode) Left() Node
- func (node PersistedNode) Mutate(version int64) *MemNode
- func (node PersistedNode) Right() Node
- func (node PersistedNode) Size() int64
- func (node PersistedNode) Value() []byte
- func (node PersistedNode) Version() int64
- type Snapshot
- func (snapshot *Snapshot) Close() error
- func (snapshot *Snapshot) IsEmpty() bool
- func (snapshot *Snapshot) Node(index uint32) PersistedNode
- func (snapshot *Snapshot) RootNode() PersistedNode
- func (snapshot *Snapshot) ScanNodes(callback func(node PersistedNode) error) error
- func (snapshot *Snapshot) Version() uint64
- type Tree
Constants ¶
const ( OffsetHeight = 0 OffsetVersion = OffsetHeight + 4 OffsetSize = OffsetVersion + 4 OffsetKey = OffsetSize + 8 OffsetRight = OffsetKey + 8 OffsetLeft = OffsetRight + 4 OffsetValue = OffsetKey + 8 OffsetHash = OffsetValue + 8 SizeHash = sha256.Size SizeNodeWithoutHash = OffsetHash SizeNode = SizeNodeWithoutHash + SizeHash // encoding key/value length as 4 bytes with little endianness. SizeKeyLen = 4 SizeValueLen = 4 )
const ( // SnapshotFileMagic is little endian encoded b"IAVL" SnapshotFileMagic = 1280721225 // the initial snapshot format SnapshotFormat = 0 // magic: uint32, format: uint32, version: uint64, root node index: uint32 SizeMetadata = 20 // EmptyRootNodeIndex is a special value of root node index to represent empty tree EmptyRootNodeIndex = math.MaxUint32 )
Variables ¶
This section is empty.
Functions ¶
func EncodeBytes ¶
EncodeBytes writes a varint length-prefixed byte slice to the writer, it's used for hash computation, must be compactible with the official IAVL implementation.
func VerifyHash ¶
VerifyHash compare node's cached hash with computed one
Types ¶
type MemNode ¶
type MemNode struct {
// contains filtered or unexported fields
}
func (*MemNode) Hash ¶
Computes the hash of the node without computing its descendants. Must be called on nodes which have descendant node hashes already computed.
type MmapFile ¶
type MmapFile struct {
// contains filtered or unexported fields
}
MmapFile manage the resources of a mmap-ed file
type Node ¶
type Node interface { Height() int8 Size() int64 Version() int64 Key() []byte Value() []byte Left() Node Right() Node Hash() []byte // PersistedNode clone a new node, MemNode modify in place Mutate(version int64) *MemNode }
Node interface encapsulate the interface of both PersistedNode and MemNode.
type PersistedNode ¶
type PersistedNode struct {
// contains filtered or unexported fields
}
PersistedNode is backed by serialized byte array, usually mmap-ed from disk file. Encoding format (all integers are encoded in little endian): - height : int8 // padded to 4bytes - version : int32 - size : int64 - key : int64 - left : int32 // node index, inner node only - right : int32 // node index, inner node only - value : int64 offset // leaf node only - hash : [32]byte
func (PersistedNode) Hash ¶
func (node PersistedNode) Hash() []byte
func (PersistedNode) Height ¶
func (node PersistedNode) Height() int8
func (PersistedNode) Key ¶
func (node PersistedNode) Key() []byte
func (PersistedNode) Left ¶
func (node PersistedNode) Left() Node
Left result is not defined for leaf nodes.
func (PersistedNode) Mutate ¶
func (node PersistedNode) Mutate(version int64) *MemNode
func (PersistedNode) Right ¶
func (node PersistedNode) Right() Node
Right result is not defined for leaf nodes.
func (PersistedNode) Size ¶
func (node PersistedNode) Size() int64
func (PersistedNode) Value ¶
func (node PersistedNode) Value() []byte
Value result is not defined for non-leaf node.
func (PersistedNode) Version ¶
func (node PersistedNode) Version() int64
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot manage the lifecycle of mmap-ed files for the snapshot, it must out live the objects that derived from it.
func NewEmptySnapshot ¶ added in v0.0.4
func OpenSnapshot ¶
OpenSnapshot parse the version number and the root node index from metadata file, and mmap the other files.
func (*Snapshot) Node ¶
func (snapshot *Snapshot) Node(index uint32) PersistedNode
Node returns the node by index
func (*Snapshot) RootNode ¶
func (snapshot *Snapshot) RootNode() PersistedNode
RootNode returns the root node
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
verify change sets by replay them to rebuild iavl tree and verify the root hashes
func NewEmptyTree ¶
NewEmptyTree creates an empty tree at an arbitrary version.
func NewFromSnapshot ¶ added in v0.0.4
NewFromSnapshot mmap the blob files and create the root node.
func NewWithInitialVersion ¶
New creates a empty tree with initial-version, it happens when a new store created at the middle of the chain.
func (*Tree) SaveVersion ¶
SaveVersion increases the version number and optionally updates the hashes
func (*Tree) WriteSnapshot ¶
WriteSnapshot save the IAVL tree to a new snapshot directory.