Skip to content

Commit

Permalink
refactor: key range aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Sep 26, 2024
1 parent 41cbc45 commit f9d1b5b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/key_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,23 @@ impl KeyRange {
}

pub fn aggregate<'a>(mut iter: impl Iterator<Item = &'a Self>) -> Self {
let mut key_range = iter.next().cloned().expect("should not be empty");
let first = iter.next().expect("should not be empty");
let mut min = first.min();
let mut max = first.max();

for other in iter {
let min = other.min();
if min < key_range.min() {
key_range.0 .0 = min.clone();
let x = other.min();
if x < min {
min = x;
}

let max = other.min();
if other.max() > key_range.max() {
key_range.0 .1 = max.clone();
let x = other.max();
if x > max {
max = x;
}
}

key_range
Self((min.clone(), max.clone()))
}
}

Expand Down

0 comments on commit f9d1b5b

Please sign in to comment.