Skip to content

Commit

Permalink
Inclusive range
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Mar 29, 2024
1 parent b76e076 commit d22a620
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions neqo-common/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl<T> Timer<T> {
}
}

for i in self.cursor..(self.cursor + self.delta(until)) {
let i = i % self.items.len();
let items_len = self.items.len();
for i in (self.cursor..=(self.cursor + self.delta(until))).map(|i| i % items_len) {
let res = maybe_take(&mut self.items[i], until);
if res.is_some() {
return res;
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<T> Timer<T> {

#[cfg(test)]
mod test {
use std::sync::OnceLock;
use std::{iter, sync::OnceLock};

use super::{Duration, Instant, Timer};

Expand Down Expand Up @@ -411,4 +411,18 @@ mod test {

assert_eq!(None, t.remove(too_far_future, |candidate| *candidate == v));
}

#[test]
fn take_next() {
const TIMES: &[u64] = &[1, 2, 3, 5, 8, 13, 21, 34];
let mut t = Timer::new(now(), GRANULARITY, CAPACITY);
for &time in TIMES {
t.add(now() + Duration::from_millis(time), time);
}

assert_eq!(
TIMES,
iter::from_fn(|| t.next_time().and_then(|time| t.take_next(time))).collect::<Vec<_>>()
);
}
}

0 comments on commit d22a620

Please sign in to comment.