kardiachain / go-kardia

Golang implementation of KardiaChain Decentralize Network
https://kardiachain.io
GNU Lesser General Public License v3.0
33 stars 18 forks source link

Simplify-iterator #242

Closed yadsendew closed 1 year ago

yadsendew commented 1 year ago

This PR changes the way the Iteratee interface is defined. Previously, we had:

NewIteratorWithPrefix(prefix []byte)
NewIteratorWithStart(start []byte)

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:

  1. 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.
  2. 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.

I replaced both of these with

NewIterator(prefix, start []byte)
yadsendew commented 1 year ago

@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.