But no good way to get a prefixed iterator with a given start position. As that was missing, a lot of code made one of two mistakes:
Use NewIteratorWithStart( prefix ++ start). This solution is wrong; consider the prefix 0x0a and start 0x00. The returned iterator would also return e.g 0x0b, as it is after a in the keyspace.
Use NewIteratorWithPrefix( prefix ++ start). This is also wrong. Consider the prefix 0x0a and start 0x01. This iterator would miss a key at 0x0a02, since 0x0a01 is not a prefix to 0x0a02.
@thientn @trinhdn97 The changes of Iterator in the PR #236 isn't necessary. This PR is an improvement of Iterator, please read description for more details.
This PR changes the way the Iteratee interface is defined. Previously, we had:
But no good way to get a prefixed iterator with a given start position. As that was missing, a lot of code made one of two mistakes:
NewIteratorWithStart( prefix ++ start)
. This solution is wrong; consider the prefix0x0a
and start0x00
. The returned iterator would also return e.g0x0b
, as it is aftera
in the keyspace.NewIteratorWithPrefix( prefix ++ start)
. This is also wrong. Consider the prefix0x0a
and start0x01
. This iterator would miss a key at0x0a02
, since0x0a01
is not a prefix to0x0a02
.I replaced both of these with