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
|
go 1.13
|
||||||
|
|
||||||
require github.com/ethereum/go-ethereum v1.10.9
|
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
|
||||||
replace github.com/ethereum/go-ethereum v1.10.9 => github.com/vulcanize/go-ethereum v1.10.9-statediff-0.0.27
|
|
||||||
|
@ -112,14 +112,16 @@ func (gen *prefixGenerator) HasNext() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gen *prefixGenerator) Next() {
|
func (gen *prefixGenerator) Next() {
|
||||||
|
// increment the cursor, and
|
||||||
gen.current[gen.stepIndex] += gen.step
|
gen.current[gen.stepIndex] += gen.step
|
||||||
overflow := false
|
overflow := false
|
||||||
for ix := 0; ix < len(gen.current); ix++ {
|
for ix := 0; ix < len(gen.current); ix++ {
|
||||||
rix := len(gen.current) - 1 - ix // reverse
|
rix := len(gen.current) - 1 - ix // index in prefix is reverse
|
||||||
if overflow {
|
if overflow { // apply overflow
|
||||||
gen.current[rix]++
|
gen.current[rix]++
|
||||||
overflow = false
|
overflow = false
|
||||||
}
|
}
|
||||||
|
// detect overflow at this index
|
||||||
if rix != 0 && gen.current[rix] > 0xf {
|
if rix != 0 && gen.current[rix] > 0xf {
|
||||||
gen.current[rix] = 0
|
gen.current[rix] = 0
|
||||||
overflow = true
|
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