trie: simplify full/short-nodeEncoder

This commit is contained in:
Martin Holst Swende 2024-11-21 08:51:43 +01:00
parent 649a329cec
commit bfc3aaee4c
No known key found for this signature in database
GPG Key ID: 683B438C05A5DDF0
1 changed files with 10 additions and 30 deletions

View File

@ -51,7 +51,6 @@ type (
// intense than using the fullNode type. // intense than using the fullNode type.
fullnodeEncoder struct { fullnodeEncoder struct {
Children [17][]byte Children [17][]byte
flags nodeFlag
} }
//shortNodeEncoder is a type used exclusively for encoding. Briefly instantiating //shortNodeEncoder is a type used exclusively for encoding. Briefly instantiating
@ -60,7 +59,6 @@ type (
shortNodeEncoder struct { shortNodeEncoder struct {
Key []byte Key []byte
Val []byte Val []byte
flags nodeFlag
} }
) )
@ -85,17 +83,13 @@ type nodeFlag struct {
} }
func (n *fullNode) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty } func (n *fullNode) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty }
func (n *fullnodeEncoder) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty }
func (n *shortNode) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty } func (n *shortNode) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty }
func (n *shortNodeEncoder) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty }
func (n hashNode) cache() (hashNode, bool) { return nil, true } func (n hashNode) cache() (hashNode, bool) { return nil, true }
func (n valueNode) cache() (hashNode, bool) { return nil, true } func (n valueNode) cache() (hashNode, bool) { return nil, true }
// Pretty printing. // Pretty printing.
func (n *fullNode) String() string { return n.fstring("") } func (n *fullNode) String() string { return n.fstring("") }
func (n *fullnodeEncoder) String() string { return n.fstring("") }
func (n *shortNode) String() string { return n.fstring("") } func (n *shortNode) String() string { return n.fstring("") }
func (n *shortNodeEncoder) String() string { return n.fstring("") }
func (n hashNode) String() string { return n.fstring("") } func (n hashNode) String() string { return n.fstring("") }
func (n valueNode) String() string { return n.fstring("") } func (n valueNode) String() string { return n.fstring("") }
@ -111,23 +105,9 @@ func (n *fullNode) fstring(ind string) string {
return resp + fmt.Sprintf("\n%s] ", ind) return resp + fmt.Sprintf("\n%s] ", ind)
} }
func (n *fullnodeEncoder) fstring(ind string) string {
resp := fmt.Sprintf("[\n%s ", ind)
for i, node := range &n.Children {
if node == nil {
resp += fmt.Sprintf("%s: <nil> ", indices[i])
} else {
resp += fmt.Sprintf("%s: %x", indices[i], node)
}
}
return resp + fmt.Sprintf("\n%s] ", ind)
}
func (n *shortNode) fstring(ind string) string { func (n *shortNode) fstring(ind string) string {
return fmt.Sprintf("{%x: %v} ", n.Key, n.Val.fstring(ind+" ")) return fmt.Sprintf("{%x: %v} ", n.Key, n.Val.fstring(ind+" "))
} }
func (n *shortNodeEncoder) fstring(ind string) string {
return fmt.Sprintf("{%x: %x} ", n.Key, n.Val)
}
func (n hashNode) fstring(ind string) string { func (n hashNode) fstring(ind string) string {
return fmt.Sprintf("<%x> ", []byte(n)) return fmt.Sprintf("<%x> ", []byte(n))
} }