From 33c7e18ac86afdb914cc9d7d30ee39a1c75ee5d3 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 20 Feb 2024 13:19:02 +0900 Subject: [PATCH] revset: flip ordering of generic combination iterators As a general-purpose iterator combinator, ascending order makes more sense. --- lib/src/default_index/revset_engine.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index 240c6cbea..d33e3f449 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -341,7 +341,7 @@ where Box::new(union_by( self.set1.iter(index), self.set2.iter(index), - |entry1, entry2| entry1.position().cmp(&entry2.position()), + |entry1, entry2| entry1.position().cmp(&entry2.position()).reverse(), )) } @@ -370,7 +370,7 @@ where /// Iterator that merges two sorted iterators. /// -/// The input items should be sorted in descending order by the `cmp` function. +/// The input items should be sorted in ascending order by the `cmp` function. struct UnionByIterator { iter1: Peekable, iter2: Peekable, @@ -390,12 +390,12 @@ where (None, _) => self.iter2.next(), (_, None) => self.iter1.next(), (Some(item1), Some(item2)) => match (self.cmp)(item1, item2) { - Ordering::Less => self.iter2.next(), + Ordering::Less => self.iter1.next(), Ordering::Equal => { self.iter2.next(); self.iter1.next() } - Ordering::Greater => self.iter1.next(), + Ordering::Greater => self.iter2.next(), }, } } @@ -436,7 +436,7 @@ where Box::new(intersection_by( self.set1.iter(index), self.set2.iter(index), - |entry1, entry2| entry1.position().cmp(&entry2.position()), + |entry1, entry2| entry1.position().cmp(&entry2.position()).reverse(), )) } @@ -465,7 +465,7 @@ where /// Iterator that intersects two sorted iterators. /// -/// The input items should be sorted in descending order by the `cmp` function. +/// The input items should be sorted in ascending order by the `cmp` function. struct IntersectionByIterator { iter1: Peekable, iter2: Peekable, @@ -491,14 +491,14 @@ where } (Some(item1), Some(item2)) => match (self.cmp)(item1, item2) { Ordering::Less => { - self.iter2.next(); + self.iter1.next(); } Ordering::Equal => { self.iter2.next(); return self.iter1.next(); } Ordering::Greater => { - self.iter1.next(); + self.iter2.next(); } }, } @@ -543,7 +543,7 @@ where Box::new(difference_by( self.set1.iter(index), self.set2.iter(index), - |entry1, entry2| entry1.position().cmp(&entry2.position()), + |entry1, entry2| entry1.position().cmp(&entry2.position()).reverse(), )) } @@ -572,7 +572,7 @@ where /// Iterator that subtracts `iter2` items from `iter1`. /// -/// The input items should be sorted in descending order by the `cmp` function. +/// The input items should be sorted in ascending order by the `cmp` function. struct DifferenceByIterator { iter1: Peekable, iter2: Peekable, @@ -598,14 +598,14 @@ where } (Some(item1), Some(item2)) => match (self.cmp)(item1, item2) { Ordering::Less => { - self.iter2.next(); + return self.iter1.next(); } Ordering::Equal => { self.iter2.next(); self.iter1.next(); } Ordering::Greater => { - return self.iter1.next(); + self.iter2.next(); } }, }