@@ -150,11 +150,11 @@ type nodeIterator struct {
150
150
// Fields for subtree iteration (original byte keys)
151
151
startKey []byte // Start key for subtree iteration (nil for full trie)
152
152
stopKey []byte // Stop key for subtree iteration (nil for full trie)
153
-
153
+
154
154
// Precomputed nibble paths for efficient comparison
155
155
startPath []byte // Precomputed hex path for startKey (without terminator)
156
156
stopPath []byte // Precomputed hex path for stopKey (without terminator)
157
-
157
+
158
158
// Iteration mode
159
159
prefixMode bool // True if this is prefix iteration (use HasPrefix check)
160
160
}
@@ -309,30 +309,30 @@ func (it *nodeIterator) Next(descend bool) bool {
309
309
}
310
310
311
311
// Check if we're still within the subtree boundaries using precomputed paths
312
- if it .startPath != nil && len (path ) > 0 {
313
- if it .prefixMode {
314
- // For prefix iteration, use HasPrefix to ensure we stay within the prefix
315
- if ! bytes .HasPrefix (path , it .startPath ) {
316
- it .err = errIteratorEnd
317
- return false
318
- }
319
- } else {
320
- // For range iteration, ensure we don't return nodes before the lower bound.
321
- // Advance the iterator until we reach a node at or after startPath.
322
- for bytes .Compare (path , it .startPath ) < 0 {
323
- // Progress the iterator by pushing the current candidate, then peeking again.
324
- it .push (state , parentIndex , path )
325
- state , parentIndex , path , err = it .peek (descend )
326
- it .err = err
327
- if it .err != nil {
328
- return false
329
- }
330
- if len (path ) == 0 {
331
- break
332
- }
333
- }
334
- }
335
- }
312
+ if it .startPath != nil && len (path ) > 0 {
313
+ if it .prefixMode {
314
+ // For prefix iteration, use HasPrefix to ensure we stay within the prefix
315
+ if ! bytes .HasPrefix (path , it .startPath ) {
316
+ it .err = errIteratorEnd
317
+ return false
318
+ }
319
+ } else {
320
+ // For range iteration, ensure we don't return nodes before the lower bound.
321
+ // Advance the iterator until we reach a node at or after startPath.
322
+ for bytes .Compare (path , it .startPath ) < 0 {
323
+ // Progress the iterator by pushing the current candidate, then peeking again.
324
+ it .push (state , parentIndex , path )
325
+ state , parentIndex , path , err = it .peek (descend )
326
+ it .err = err
327
+ if it .err != nil {
328
+ return false
329
+ }
330
+ if len (path ) == 0 {
331
+ break
332
+ }
333
+ }
334
+ }
335
+ }
336
336
if it .stopPath != nil && len (path ) > 0 {
337
337
if bytes .Compare (path , it .stopPath ) >= 0 {
338
338
it .err = errIteratorEnd
@@ -883,13 +883,13 @@ func (it *unionIterator) Error() error {
883
883
884
884
// NewSubtreeIterator creates an iterator that only traverses nodes within a subtree
885
885
// defined by the given startKey and stopKey. This supports general range iteration
886
- // where startKey is inclusive and stopKey is exclusive.
886
+ // where startKey is inclusive and stopKey is exclusive.
887
887
//
888
888
// The iterator will only visit nodes whose keys k satisfy: startKey <= k < stopKey,
889
889
// where comparisons are performed in lexicographic order of byte keys (internally
890
890
// implemented via hex-nibble path comparisons for efficiency).
891
891
//
892
- // If startKey is nil, iteration starts from the beginning. If stopKey is nil,
892
+ // If startKey is nil, iteration starts from the beginning. If stopKey is nil,
893
893
// iteration continues to the end of the trie. For prefix iteration, use the
894
894
// Trie.NodeIteratorWithPrefix method which handles prefix semantics correctly.
895
895
func NewSubtreeIterator (trie * Trie , startKey , stopKey []byte ) NodeIterator {
@@ -912,7 +912,7 @@ func nextKey(prefix []byte) []byte {
912
912
// Make a copy to avoid modifying the original
913
913
next := make ([]byte , len (prefix ))
914
914
copy (next , prefix )
915
-
915
+
916
916
// Increment the last byte that isn't 0xff
917
917
for i := len (next ) - 1 ; i >= 0 ; i -- {
918
918
if next [i ] < 0xff {
@@ -942,7 +942,7 @@ func newSubtreeIterator(trie *Trie, startKey, stopKey []byte, prefixMode bool) N
942
942
stopPath = stopPath [:len (stopPath )- 1 ]
943
943
}
944
944
}
945
-
945
+
946
946
if trie .Hash () == types .EmptyRootHash {
947
947
return & nodeIterator {
948
948
trie : trie ,
0 commit comments