track prev. path

This commit is contained in:
2024-07-07 13:06:15 +08:00
parent 115ead1d02
commit c64d49d040
+6 -3
View File
@@ -25,6 +25,7 @@
package tracker
import (
"bytes"
"encoding/csv"
"fmt"
"os"
@@ -106,11 +107,12 @@ type TrackerImpl struct {
type Iterator struct {
trie.NodeIterator
tracker *TrackerImpl
tracker *TrackerImpl
prevPath []byte
}
func (tr *TrackerImpl) Tracked(it trie.NodeIterator) *Iterator {
ret := &Iterator{it, tr}
ret := &Iterator{it, tr, nil}
tr.startChan <- ret
return ret
}
@@ -128,7 +130,7 @@ func (tr *TrackerImpl) Save() error {
for it := range tr.started {
_, endPath := it.Bounds()
rows = append(rows, []string{
fmt.Sprintf("%x", it.Path()),
fmt.Sprintf("%x", it.prevPath),
fmt.Sprintf("%x", endPath),
})
}
@@ -232,6 +234,7 @@ func (tr *TrackerImpl) CloseAndSave() error {
// Next advances the iterator, notifying its owning tracker when it finishes.
func (it *Iterator) Next(descend bool) bool {
it.prevPath = bytes.Clone(it.Path())
ret := it.NodeIterator.Next(descend)
if !ret {