Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify-iterator #242

Merged
merged 1 commit into from Jan 5, 2023
Merged

Conversation

rameight
Copy link
Contributor

@rameight rameight commented Dec 29, 2022

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)

@rameight
Copy link
Contributor Author

rameight commented Dec 29, 2022

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

@rameight rameight marked this pull request as ready for review December 29, 2022 10:01
@rameight rameight merged commit 89f45f6 into kardiachain:master Jan 5, 2023
@rameight rameight deleted the simplify-iterator branch January 5, 2023 06:33
@rameight rameight linked an issue Jun 20, 2023 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize & Improve Trie, Preparing for state trie pruner
2 participants