mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +00:00
trie: simplify summary generation
This commit is contained in:
parent
b4f7b076a5
commit
9b4495b9a8
1 changed files with 19 additions and 52 deletions
|
|
@ -19,6 +19,7 @@ package trie
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"cmp"
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -464,64 +465,30 @@ func (t *topStorage) Sorted() []*storageSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareStorageByDepth(a, b *storageSnapshot) int {
|
func compareStorageByDepth(a, b *storageSnapshot) int {
|
||||||
if cmp := compareInt(a.MaxDepth, b.MaxDepth); cmp != 0 {
|
return cmp.Or(
|
||||||
return cmp
|
cmp.Compare(a.MaxDepth, b.MaxDepth),
|
||||||
}
|
cmp.Compare(a.TotalNodes, b.TotalNodes),
|
||||||
if cmp := compareUint64(a.TotalNodes, b.TotalNodes); cmp != 0 {
|
cmp.Compare(a.Summary.Value, b.Summary.Value),
|
||||||
return cmp
|
bytes.Compare(a.Owner[:], b.Owner[:]),
|
||||||
}
|
)
|
||||||
if cmp := compareUint64(a.Summary.Value, b.Summary.Value); cmp != 0 {
|
|
||||||
return cmp
|
|
||||||
}
|
|
||||||
return bytes.Compare(a.Owner[:], b.Owner[:])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareStorageByTotal(a, b *storageSnapshot) int {
|
func compareStorageByTotal(a, b *storageSnapshot) int {
|
||||||
if cmp := compareUint64(a.TotalNodes, b.TotalNodes); cmp != 0 {
|
return cmp.Or(
|
||||||
return cmp
|
cmp.Compare(a.TotalNodes, b.TotalNodes),
|
||||||
}
|
cmp.Compare(a.MaxDepth, b.MaxDepth),
|
||||||
if cmp := compareInt(a.MaxDepth, b.MaxDepth); cmp != 0 {
|
cmp.Compare(a.Summary.Value, b.Summary.Value),
|
||||||
return cmp
|
bytes.Compare(a.Owner[:], b.Owner[:]),
|
||||||
}
|
)
|
||||||
if cmp := compareUint64(a.Summary.Value, b.Summary.Value); cmp != 0 {
|
|
||||||
return cmp
|
|
||||||
}
|
|
||||||
return bytes.Compare(a.Owner[:], b.Owner[:])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareStorageByValue(a, b *storageSnapshot) int {
|
func compareStorageByValue(a, b *storageSnapshot) int {
|
||||||
if cmp := compareUint64(a.Summary.Value, b.Summary.Value); cmp != 0 {
|
return cmp.Or(
|
||||||
return cmp
|
cmp.Compare(a.Summary.Value, b.Summary.Value),
|
||||||
}
|
cmp.Compare(a.MaxDepth, b.MaxDepth),
|
||||||
if cmp := compareInt(a.MaxDepth, b.MaxDepth); cmp != 0 {
|
cmp.Compare(a.TotalNodes, b.TotalNodes),
|
||||||
return cmp
|
bytes.Compare(a.Owner[:], b.Owner[:]),
|
||||||
}
|
)
|
||||||
if cmp := compareUint64(a.TotalNodes, b.TotalNodes); cmp != 0 {
|
|
||||||
return cmp
|
|
||||||
}
|
|
||||||
return bytes.Compare(a.Owner[:], b.Owner[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func compareInt(a, b int) int {
|
|
||||||
switch {
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func compareUint64(a, b uint64) int {
|
|
||||||
switch {
|
|
||||||
case a > b:
|
|
||||||
return 1
|
|
||||||
case a < b:
|
|
||||||
return -1
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type inspectSummary struct {
|
type inspectSummary struct {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue