-
Notifications
You must be signed in to change notification settings - Fork 69
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
Implements DoubleEndedIterator
for trie iterators
#208
Implements DoubleEndedIterator
for trie iterators
#208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Co-authored-by: cheme <[email protected]>
…n methods, remove back_trail & back_key_nibbles, remove clone from OwnedNode
However, I believe adding this behaviour in a standard iterator is unintuitive for library users.
IMHO I don't think it does. I believe having separate structs for explicit iteration in both directions enhances code clarity. It also provides a better understanding of the behavior of standard iterator structs compared to double ended iterator structs. I've implemented modifications based on our discussion (the unit test demonstrates this):
Still need to add a bunch of tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, into_double_ended_iter
api looks good to me.
… add double ended iterator test mod
Small note (not something that needs change right now), I think that the raw node iter can return on a status At, then if iterating in different direction we may not have the right next node : eg entering a branch backward then state is At then calling iterator forward and then state become AtChild(0) when we should have exit. |
Closes #164
Enables bidirectional iteration by implementing the
DoubleEndedIterator
for all iterator types.New double ended iterator structs:
TrieDBDoubleEndedIterator
TrieDBNodeDoubleEndedIterator
TrieDBKeyDoubleEndedIterator
FatDBDoubleEndedIterator
Internal iteration methods now accept a
fwd
bool flag to conditionally traverse a trie backwards or forwards (non exhaustive list).TrieDBRawIterator::next_raw_item
TrieDBRawIterator::seek
Crumb::increment
(renamed toCrumb::step
to better convey its behaviour)Modifies
next_raw_item
to return middle node (i.e. a node containing child nodes) in reverse order based on iteration direction. Middle node is returned last when iterating backwards, mirroring forward iteration behaviour.Adds new
AftExiting
status to pop crumb after returning it inExiting
status for backward iteration.Library users can create one of these iterators from a
TrieDB
instance by calling the publicTrieDB::into_*
methods.