From c64d49d040641e49a2535ee66a739bb2a23c6aec Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Sat, 6 Jul 2024 22:35:35 +0800 Subject: [PATCH] track prev. path --- tracker/tracker.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tracker/tracker.go b/tracker/tracker.go index 1176c29..f878348 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -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 {