mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
trie: improve comment
This commit is contained in:
parent
eb8f7ac0de
commit
bbc0c64074
1 changed files with 15 additions and 13 deletions
|
|
@ -145,7 +145,7 @@ type nodeIterator struct {
|
||||||
err error // Failure set in case of an internal error in the iterator
|
err error // Failure set in case of an internal error in the iterator
|
||||||
|
|
||||||
resolver NodeResolver // optional node resolver for avoiding disk hits
|
resolver NodeResolver // optional node resolver for avoiding disk hits
|
||||||
pool []*nodeIteratorState // local pool for iteratorstates
|
pool []*nodeIteratorState // local pool for iterator states
|
||||||
}
|
}
|
||||||
|
|
||||||
// errIteratorEnd is stored in nodeIterator.err when iteration is done.
|
// errIteratorEnd is stored in nodeIterator.err when iteration is done.
|
||||||
|
|
@ -550,13 +550,14 @@ func (it *nodeIterator) pop() {
|
||||||
it.path = it.path[:last.pathlen]
|
it.path = it.path[:last.pathlen]
|
||||||
it.stack[len(it.stack)-1] = nil
|
it.stack[len(it.stack)-1] = nil
|
||||||
it.stack = it.stack[:len(it.stack)-1]
|
it.stack = it.stack[:len(it.stack)-1]
|
||||||
// last is now unused
|
|
||||||
it.putInPool(last)
|
it.putInPool(last) // last is now unused
|
||||||
}
|
}
|
||||||
|
|
||||||
// reachedPath normalizes a path by truncating a terminator if present, and returns true if it is
|
// reachedPath normalizes a path by truncating a terminator if present, and
|
||||||
// greater than or equal to the target. Using this, the path of a value node embedded a full node
|
// returns true if it is greater than or equal to the target. Using this,
|
||||||
// will compare less than the full node's children.
|
// the path of a value node embedded a full node will compare less than the
|
||||||
|
// full node's children.
|
||||||
func reachedPath(path, target []byte) bool {
|
func reachedPath(path, target []byte) bool {
|
||||||
if hasTerm(path) {
|
if hasTerm(path) {
|
||||||
path = path[:len(path)-1]
|
path = path[:len(path)-1]
|
||||||
|
|
@ -564,12 +565,13 @@ func reachedPath(path, target []byte) bool {
|
||||||
return bytes.Compare(path, target) >= 0
|
return bytes.Compare(path, target) >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// A value embedded in a full node occupies the last slot (16) of the array of children. In order to
|
// A value embedded in a full node occupies the last slot (16) of the array of
|
||||||
// produce a pre-order traversal when iterating children, we jump to this last slot first, then go
|
// children. In order to produce a pre-order traversal when iterating children,
|
||||||
// back iterate the child nodes (and skip the last slot at the end):
|
// we jump to this last slot first, then go back iterate the child nodes (and
|
||||||
|
// skip the last slot at the end):
|
||||||
|
|
||||||
// prevChildIndex returns the index of a child in a full node which precedes the given index when
|
// prevChildIndex returns the index of a child in a full node which precedes
|
||||||
// performing a pre-order traversal.
|
// the given index when performing a pre-order traversal.
|
||||||
func prevChildIndex(index int) int {
|
func prevChildIndex(index int) int {
|
||||||
switch index {
|
switch index {
|
||||||
case 0: // We jumped back to iterate the children, from the value slot
|
case 0: // We jumped back to iterate the children, from the value slot
|
||||||
|
|
@ -583,8 +585,8 @@ func prevChildIndex(index int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nextChildIndex returns the index of a child in a full node which follows the given index when
|
// nextChildIndex returns the index of a child in a full node which follows
|
||||||
// performing a pre-order traversal.
|
// the given index when performing a pre-order traversal.
|
||||||
func nextChildIndex(index int) int {
|
func nextChildIndex(index int) int {
|
||||||
switch index {
|
switch index {
|
||||||
case -1: // Jump from the placeholder index to the embedded value slot
|
case -1: // Jump from the placeholder index to the embedded value slot
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue