export end path field
This commit is contained in:
parent
f25ee8319c
commit
c532c17b05
24
iterator.go
24
iterator.go
@ -25,8 +25,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PrefixBoundIterator struct {
|
type PrefixBoundIterator struct {
|
||||||
endKey []byte
|
|
||||||
trie.NodeIterator
|
trie.NodeIterator
|
||||||
|
EndPath []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *PrefixBoundIterator) Next(descend bool) bool {
|
func (it *PrefixBoundIterator) Next(descend bool) bool {
|
||||||
@ -37,13 +37,13 @@ func (it *PrefixBoundIterator) Next(descend bool) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// stop if underlying iterator went past endKey
|
// stop if underlying iterator went past endKey
|
||||||
cmp := bytes.Compare(it.Path(), it.endKey)
|
cmp := bytes.Compare(it.Path(), it.EndPath)
|
||||||
return cmp <= 0
|
return cmp <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterator with an upper bound value (hex path prefix)
|
// Iterator with an upper bound value (hex path prefix)
|
||||||
func NewPrefixBoundIterator(it trie.NodeIterator, to []byte) *PrefixBoundIterator {
|
func NewPrefixBoundIterator(it trie.NodeIterator, to []byte) *PrefixBoundIterator {
|
||||||
return &PrefixBoundIterator{NodeIterator: it, endKey: to}
|
return &PrefixBoundIterator{NodeIterator: it, EndPath: to}
|
||||||
}
|
}
|
||||||
|
|
||||||
type prefixGenerator struct {
|
type prefixGenerator struct {
|
||||||
@ -129,24 +129,24 @@ func eachPrefixRange(prefix []byte, nbins uint, callback func([]byte, []byte)) {
|
|||||||
// Cut a trie by path prefix, returning `nbins` iterators covering its subtries
|
// Cut a trie by path prefix, returning `nbins` iterators covering its subtries
|
||||||
func SubtrieIterators(tree state.Trie, nbins uint) []trie.NodeIterator {
|
func SubtrieIterators(tree state.Trie, nbins uint) []trie.NodeIterator {
|
||||||
var iters []trie.NodeIterator
|
var iters []trie.NodeIterator
|
||||||
eachPrefixRange(nil, nbins, func(key []byte, endKey []byte) {
|
eachPrefixRange(nil, nbins, func(from []byte, to []byte) {
|
||||||
it := tree.NodeIterator(HexToKeyBytes(key))
|
it := tree.NodeIterator(HexToKeyBytes(from))
|
||||||
iters = append(iters, NewPrefixBoundIterator(it, endKey))
|
iters = append(iters, NewPrefixBoundIterator(it, to))
|
||||||
})
|
})
|
||||||
return iters
|
return iters
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factory for per-bin subtrie iterators
|
// Factory for per-bin subtrie iterators
|
||||||
type SubtrieIteratorFactory struct {
|
type SubtrieIteratorFactory struct {
|
||||||
tree state.Trie
|
tree state.Trie
|
||||||
startKeys, endKeys [][]byte
|
startPaths, endPaths [][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fac *SubtrieIteratorFactory) Length() int { return len(fac.startKeys) }
|
func (fac *SubtrieIteratorFactory) Length() int { return len(fac.startPaths) }
|
||||||
|
|
||||||
func (fac *SubtrieIteratorFactory) IteratorAt(bin uint) *PrefixBoundIterator {
|
func (fac *SubtrieIteratorFactory) IteratorAt(bin uint) *PrefixBoundIterator {
|
||||||
it := fac.tree.NodeIterator(HexToKeyBytes(fac.startKeys[bin]))
|
it := fac.tree.NodeIterator(HexToKeyBytes(fac.startPaths[bin]))
|
||||||
return NewPrefixBoundIterator(it, fac.endKeys[bin])
|
return NewPrefixBoundIterator(it, fac.endPaths[bin])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cut a trie by path prefix, returning `nbins` iterators covering its subtries
|
// Cut a trie by path prefix, returning `nbins` iterators covering its subtries
|
||||||
@ -157,5 +157,5 @@ func NewSubtrieIteratorFactory(tree state.Trie, nbins uint) SubtrieIteratorFacto
|
|||||||
starts = append(starts, key)
|
starts = append(starts, key)
|
||||||
ends = append(ends, endKey)
|
ends = append(ends, endKey)
|
||||||
})
|
})
|
||||||
return SubtrieIteratorFactory{tree: tree, startKeys: starts, endKeys: ends}
|
return SubtrieIteratorFactory{tree: tree, startPaths: starts, endPaths: ends}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user