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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug in MergeIter::size_hint
  • Loading branch information
Lucretiel committed Feb 20, 2025
commit 04e73e54e54e273186938be1d5f425afcfae4d1e
18 changes: 16 additions & 2 deletions regex-syntax/src/hir/interval.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ impl Bound for char {
}
}

/// Iterator that, given a pair of sorted iterators, merges their items into
/// a single sorted sequence
struct MergeIter<I: Iterator> {
left: I,
right: I,
Expand Down Expand Up @@ -692,12 +694,24 @@ where
}

fn size_hint(&self) -> (usize, Option<usize>) {
use MergeIterState::*;

// Fundamentally this is a spicy concatenation, so add the sizes together
let extra_element = match self.state {
LeftExhausted => 0,
RightExhausted => 0,
LeftItem(_) => 1,
RightItem(_) => 1,
};

let (min1, max1) = self.left.size_hint();
let (min2, max2) = self.right.size_hint();

let min = min1.saturating_add(min2);
let max = max1.and_then(|max| max.checked_add(max2?));
let min = min1.saturating_add(min2).saturating_add(extra_element);

let max = max1
.and_then(|max| max.checked_add(max2?))
.and_then(|max| max.checked_add(extra_element));

(min, max)
}
Expand Down

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