implement iter() and utility methods#12
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR add?
IntoIter/Iter/IterMutkeys()values()/values_mut()len()andis_empty()get()/get_mut()retain()closes #3
Details
In order to support iteration, each
entriesmap now stores((K, u8), ValueIndex)instead of justValueIndex. This had an impact of roughly 1.5% extra time on insert benchmarks. This was deemed worthwhile since it did not affect the lookup time and enables a very easyiterimplementation.The trie's internal structure guarantees lexicographic order of
(len, key)for iterators basically for free.Currently,
IterMutrequiresunsafeto produce&'a mut Vreferences. This is because values are stored in a contiguousVec<V>for lookup cache locality, as opposed to keeping them in theBTreeMapwhere this would be trivial.&mutreferences into aVec<Option<&mut V>>upfront and hand them out one by one, avoidingunsafeat the cost of an allocation and an extra indirection on every call tonext(), which was judged not to be worth it.