Skip to content

Commit

Permalink
trie: simplify full/short-nodeEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Nov 21, 2024
1 parent b34643f commit fc0705f
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions trie/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,16 @@ type nodeFlag struct {
dirty bool // whether the node has changes that must be written to the database
}

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 *shortNodeEncoder) cache() (hashNode, bool) { return n.flags.hash, n.flags.dirty }
func (n hashNode) cache() (hashNode, bool) { return nil, true }
func (n valueNode) cache() (hashNode, bool) { return nil, true }
func (n *fullNode) 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 hashNode) cache() (hashNode, bool) { return nil, true }
func (n valueNode) cache() (hashNode, bool) { return nil, true }

// Pretty printing.
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 *shortNodeEncoder) String() string { return n.fstring("") }
func (n hashNode) String() string { return n.fstring("") }
func (n valueNode) String() string { return n.fstring("") }
func (n *fullNode) String() string { return n.fstring("") }
func (n *shortNode) String() string { return n.fstring("") }
func (n hashNode) String() string { return n.fstring("") }
func (n valueNode) String() string { return n.fstring("") }

func (n *fullNode) fstring(ind string) string {
resp := fmt.Sprintf("[\n%s ", ind)
Expand All @@ -111,23 +107,9 @@ func (n *fullNode) fstring(ind string) string {
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 {
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 {
return fmt.Sprintf("<%x> ", []byte(n))
}
Expand Down

0 comments on commit fc0705f

Please sign in to comment.