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

Implement DoubleEndedIterator for some iterator structs #107

Merged
merged 6 commits into from
Jun 25, 2024

Conversation

alexmozaidze
Copy link
Contributor

@alexmozaidze alexmozaidze commented Jun 21, 2024

Note

This PR is a semi-draft; I want to hear some feedback before I start refining the code.

Changes:

  1. Implemented DoubleEndedIterator for some of the iterator structs
  2. Reduced repetitiveness in traverse.rs using a new macro that replaces impl_node_iterator! completely
  3. Removed FusedIterator for everything using the new macro, just to be safe (may be re-implemented if the current changes adhere to FusedIterator's contract)
  4. Deprecated ReverseChildren since Children::rev() is more idiomatic.

There is an edge-case for when I need to get first/last root node from the arena, in which case I resorted to iter().next() and iter().last(), which I don't think is efficient. If you have any suggestions, I'd be happy to hear them.

@alexmozaidze
Copy link
Contributor Author

I may be able to ensure FusedIterator's contract by bringing back old behaviour for iterators that don't implement DoubleEndedIterator. I'll make some adjustments to the macro.

This allows us to implement `FusedIterator` for one way iterators, bringing back the simple way to iterate. This also means that there are now 2 separate underlying iterator structs, but that is merely an implementation detail that is unlikely to affect performance.
@alexmozaidze
Copy link
Contributor Author

Yep, I think it's all done now.

Macro is convenient, code duplication is close to none, and there are no feature regressions for one way iterators (FusedIterator implementation).

Unless there are optimizations I've missed that can make some iterators faster, there is nothing else to add.

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.3%. Comparing base (cd3d680) to head (9d054f7).

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #107     +/-   ##
=======================================
- Coverage   66.0%   65.3%   -0.8%     
=======================================
  Files          8       8             
  Lines        474     467      -7     
  Branches     145     142      -3     
=======================================
- Hits         313     305      -8     
- Misses        42      44      +2     
+ Partials     119     118      -1     

@saschagrunert
Copy link
Owner

May I ask you to fix the CI issues? :)

@alexmozaidze
Copy link
Contributor Author

alexmozaidze commented Jun 25, 2024

The clippy one should be simple to fix (#[allow(deprecated)]), but I am not sure about how to fix the code coverage. How do I fix it? Do I add tests?

@saschagrunert
Copy link
Owner

The clippy one should be simple to fix (#[allow(deprecated)]), but I am not sure about how to fix the code coverage. How do I fix it? Do I add tests?

The coverage is no concern, I'm mostly speaking about the clippy ones.

Copy link
Owner

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, code LGTM!

@saschagrunert saschagrunert merged commit 822960f into saschagrunert:main Jun 25, 2024
7 checks passed
@saschagrunert
Copy link
Owner

A bunch of tests would be nice, but I don't see it as a must here.

@alexmozaidze
Copy link
Contributor Author

I will add some tests in a future PR, along with other improvements.

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.

None yet

2 participants