Patches, test, comments
This commit is contained in:
parent
89b3064c00
commit
6bba614243
5
go.mod
5
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
|
||||
|
@ -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
|
||||
|
20
iterator_test.go
Normal file
20
iterator_test.go
Normal file
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user