diff --git a/go.mod b/go.mod index 247fa01..89609a0 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,5 @@ module github.com/vulcanize/go-eth-state-node-iterator go 1.13 -require github.com/ethereum/go-ethereum v1.10.9 - -replace github.com/ethereum/go-ethereum v1.10.9 => github.com/vulcanize/go-ethereum v1.10.9-statediff-0.0.27 +require github.com/ethereum/go-ethereum v1.9.14 +replace github.com/ethereum/go-ethereum v1.9.14 => github.com/vulcanize/go-ethereum v1.10.14-statediff-0.0.29 diff --git a/iterator.go b/iterator.go index 407ad24..80115de 100644 --- a/iterator.go +++ b/iterator.go @@ -112,14 +112,16 @@ func (gen *prefixGenerator) HasNext() bool { } func (gen *prefixGenerator) Next() { + // increment the cursor, and gen.current[gen.stepIndex] += gen.step overflow := false for ix := 0; ix < len(gen.current); ix++ { - rix := len(gen.current) - 1 - ix // reverse - if overflow { + rix := len(gen.current) - 1 - ix // index in prefix is reverse + if overflow { // apply overflow gen.current[rix]++ overflow = false } + // detect overflow at this index if rix != 0 && gen.current[rix] > 0xf { gen.current[rix] = 0 overflow = true diff --git a/iterator_test.go b/iterator_test.go new file mode 100644 index 0000000..3a26f64 --- /dev/null +++ b/iterator_test.go @@ -0,0 +1,20 @@ +package iterator_test + +import ( + "testing" + + iter "github.com/vulcanize/go-eth-state-node-iterator" +) + +func TestMakePaths(t *testing.T) { + var prefix []byte + for i := 0; i < 4; i++ { + nbins := uint(1) << i + paths := iter.MakePaths(prefix, nbins) + t.Log(paths) + if len(paths) != int(nbins) { + t.Logf("failed: TestMakePaths") + t.Error("wrong number of paths", len(paths)) + } + } +}