Documentation ¶
Index ¶
- Constants
- Variables
- type Buffer
- type CopySettings
- type Node
- func (n *Node) ChildrenBitmap() (bitmap uint16)
- func (n *Node) Copy(settings CopySettings) *Node
- func (n *Node) Encode(buffer Buffer) (err error)
- func (n *Node) EncodeAndHash(isRoot bool) (encoding, hash []byte, err error)
- func (n *Node) NumChildren() (count int)
- func (n *Node) SetDirty(dirty bool)
- func (n *Node) String() string
- func (n Node) StringNode() (stringNode *gotree.Node)
- func (n *Node) Type() Type
- type Type
Constants ¶
const (
// ChildrenCapacity is the maximum number of children in a branch node.
ChildrenCapacity = 16
)
Variables ¶
var ( // DefaultCopySettings contains the following copy settings: // - children are NOT deep copied recursively // - the HashDigest field is left empty on the copy // - the Encoding field is left empty on the copy // - the key field is deep copied // - the value field is deep copied DefaultCopySettings = CopySettings{ CopyKey: true, CopyValue: true, } // DeepCopySettings returns the following copy settings: // - children are deep copied recursively // - the HashDigest field is deep copied // - the Encoding field is deep copied // - the key field is deep copied // - the value field is deep copied DeepCopySettings = CopySettings{ CopyChildren: true, CopyCached: true, CopyKey: true, CopyValue: true, } )
var ( ErrReadHeaderByte = errors.New("cannot read header byte") ErrUnknownNodeType = errors.New("unknown node type") ErrDecodeValue = errors.New("cannot decode value") ErrReadChildrenBitmap = errors.New("cannot read children bitmap") ErrDecodeChildHash = errors.New("cannot decode child hash") )
Functions ¶
This section is empty.
Types ¶
type CopySettings ¶
type CopySettings struct { // CopyChildren can be set to true to recursively deep copy the eventual // children of the node. This is false by default and should only be used // in tests since it is quite inefficient. CopyChildren bool // CopyCached can be set to true to deep copy the cached digest // and encoding fields on the current node copied. // This is false by default because in production, a node is copied // when it is about to be mutated, hence making its cached fields // no longer valid. CopyCached bool // CopyKey can be set to true to deep copy the key field of // the node. This is useful when false if the key is about to // be assigned after the Copy operation, to save a memory operation. CopyKey bool // CopyValue can be set to true to deep copy the value field of // the node. This is useful when false if the value is about to // be assigned after the Copy operation, to save a memory operation. CopyValue bool }
CopySettings contains settings to configure the deep copy of a node.
type Node ¶
type Node struct { // Key is the partial key bytes in nibbles (0 to f in hexadecimal) Key []byte Value []byte // Generation is incremented on every trie Snapshot() call. // Each node also contain a certain Generation number, // which is updated to match the trie Generation once they are // inserted, moved or iterated over. Generation uint64 // Children is a slice of length 16 for branches. // It is left to nil for leaves to reduce memory usage. Children []*Node // Dirty is true when the branch differs // from the node stored in the database. Dirty bool // HashDigest is the cached hash digest of the // node encoding. HashDigest []byte // Encoding is the cached encoding of the node. Encoding []byte // Descendants is the number of descendant nodes for // this particular node. Descendants uint32 }
Node is a node in the trie and can be a leaf or a branch.
func Decode ¶
Decode decodes a node from a reader. For branch decoding, see the comments on decodeBranch. For leaf decoding, see the comments on decodeLeaf.
func (*Node) ChildrenBitmap ¶
ChildrenBitmap returns the 16 bit bitmap of the children in the branch node.
func (*Node) Copy ¶
func (n *Node) Copy(settings CopySettings) *Node
Copy deep copies the node. Setting copyChildren to true will deep copy children as well.
func (*Node) Encode ¶
Encode encodes the node to the buffer given. The encoding format is documented in encode_doc.go.
func (*Node) EncodeAndHash ¶
EncodeAndHash returns the encoding of the node and the blake2b hash digest of the encoding of the node. If the encoding is less than 32 bytes, the hash returned is the encoding and not the hash of the encoding.
func (*Node) NumChildren ¶
NumChildren returns the total number of children in the branch node.
func (Node) StringNode ¶
StringNode returns a gotree compatible node for String methods.