Skip to content

implement iter() and utility methods#12

Merged
nicolaskagami merged 3 commits into
mainfrom
nsk/iter_utils
Mar 9, 2026
Merged

implement iter() and utility methods#12
nicolaskagami merged 3 commits into
mainfrom
nsk/iter_utils

Conversation

@nicolaskagami

Copy link
Copy Markdown
Owner

What does this PR add?

  • IntoIter / Iter / IterMut
  • keys()
  • values() / values_mut()
  • len() and is_empty()
  • get() / get_mut()
  • retain()

closes #3

Details

  • In order to support iteration, each entries map now stores ((K, u8), ValueIndex) instead of just ValueIndex. 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 easy iter implementation.

  • The trie's internal structure guarantees lexicographic order of (len, key) for iterators basically for free.

  • Currently, IterMut requires unsafe to produce &'a mut V references. This is because values are stored in a contiguous Vec<V> for lookup cache locality, as opposed to keeping them in the BTreeMap where this would be trivial.

    • An alternative (I think) would be to collect &mut references into a Vec<Option<&mut V>> upfront and hand them out one by one, avoiding unsafe at the cost of an allocation and an extra indirection on every call to next(), which was judged not to be worth it.

@nicolaskagami nicolaskagami self-assigned this Mar 8, 2026
@nicolaskagami
nicolaskagami merged commit 47c9a74 into main Mar 9, 2026
1 check passed
@nicolaskagami
nicolaskagami deleted the nsk/iter_utils branch March 9, 2026 14:05
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.

implement iter() and its derivatives

1 participant