trie: update func ForEachWithOrder #27496 #27909 (#1163)

Co-authored-by: Dan Laine <daniel.laine@avalabs.org>
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Daniel Liu 2026-01-29 13:58:36 +08:00 committed by GitHub
parent a74b7e2466
commit 222d180a6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -100,12 +100,12 @@ func NewNodeSet(owner common.Hash) *NodeSet {
// ForEachWithOrder iterates the nodes with the order from bottom to top,
// right to left, nodes with the longest path will be iterated first.
func (set *NodeSet) ForEachWithOrder(callback func(path string, n *Node)) {
var paths sort.StringSlice
paths := make([]string, 0, len(set.Nodes))
for path := range set.Nodes {
paths = append(paths, path)
}
// Bottom-up, longest path first
sort.Sort(sort.Reverse(paths))
sort.Sort(sort.Reverse(sort.StringSlice(paths)))
for _, path := range paths {
callback(path, set.Nodes[path].Unwrap())
}