Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

More efficient interval algorithms #1191

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

Open
Lucretiel wants to merge 8 commits into rust-lang:master
base: master
Choose a base branch
Loading
from Lucretiel:more-efficient-intervals

Conversation

@Lucretiel
Copy link
Contributor

@Lucretiel Lucretiel commented May 7, 2024
edited
Loading

This PR implements linear time and constant space algorithms for a few of the interval operations:

  • canonicalize: track the current "merge target", and merge each interval into the target if they overlap. The merge target is always shifted left as appropriate, so that we can simply truncate the list afterwards.
  • negate: replace each interval with the negated interval to its left, then finally add the trailing interval on the right. Take care to avoid the leftmost and rightmost intervals if they're empty.
  • union: two possible algorithms:
    • If the current vector has enough extra space: merge the two lists, in-place, into the vec, then perform a canonicalization.
    • If the current vector needs to be reallocated: merge the two lists of ranges with an iterator that outputs them all in sorted order. Merge them as they come, if they're adjacent, and construct a new vec out of them.
  • push: use a binary search to insert the interval, the use the in-place sorted union.

Copy link
Member

Because of #1104 and specifically #1051 (comment), I can't accept these sorts of changes without first improving the testing strategy to ensure we don't ship regressions.

I haven't thought much about how to improve tests, but that's the first step here.

Lucretiel reacted with thumbs up emoji

Copy link
Contributor Author

Lucretiel commented Aug 28, 2025
edited
Loading

Understood, that's reasonable. Were the violations detected by the fuzzer added as regression tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /