Add iterators to various vector/collection types #232
Merged
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.
This adds a fairly full-featured, read-only iterator to the various packed/paged vector types.
The iterator implementation just carries a pointer to the container and an index within it. It is not meant to be able to be stored in a memory mapping; that might need a lot more templating.
It supports the less-than/greater-than comparisons that we want for the hub labeling distance index integration, on top of being a random access iterator.
So far it has tests for forward iterator functions, but not for the bidirectional iterator, random access iterator, or comparison logic.
Much of this code was generated by Anthropic Claude, which wrote 4 times as many iterators and 4 times as many tests as were really necessary, since all the test and iterator code was really the same. When I asked it to try and consolidate, it attempted SFINAE and went on strike for increased subscription fees.
Then I spent a couple hours removing the duplicated code myself, and implementing the more powerful iterator categories. To avoid the SFINAE nonsense, I made the vectors and the deques both use STL-style
push_back()/pop_back()instead ofappend()orappend_back()andpop()orpop_back(). I have deprecated stubs under the old names to call the new ones, so we don't have to immediately run around fixing vg.I haven't regenerated the Python bindings, but the old ones still build. We might want to exclude the iterators from being bound to avoid a profusion of types on the Python side that aren't really needed.
This also comes with the hints I gave to Anthropic Claude to teach it the project, although since it proceeded to generate 4 times as much code as it should have, they might not be very good.