Skip to content

Commit

Permalink
Use L/R for Left/Right types
Browse files Browse the repository at this point in the history
Because I/J stand for iterators.
  • Loading branch information
Philippe-Cholet committed Jun 15, 2023
1 parent ac5c357 commit a74da09
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/merge_join.rs
Expand Up @@ -37,26 +37,26 @@ pub struct MergeJoinBy<I: Iterator, J: Iterator, F> {
cmp_fn: F,
}

pub trait OrderingOrBool<I, J> {
pub trait OrderingOrBool<L, R> {
type MergeResult;
fn left(left: I) -> Self::MergeResult;
fn right(right: J) -> Self::MergeResult;
fn left(left: L) -> Self::MergeResult;
fn right(right: R) -> Self::MergeResult;
// "merge" never returns (Some(...), Some(...), ...) so Option<Either<I::Item, J::Item>>
// is appealing but it is always followed by two put_backs, so we think the compiler is
// smart enough to optimize it. Or we could move put_backs into "merge".
fn merge(self, left: I, right: J) -> (Option<I>, Option<J>, Self::MergeResult);
fn merge(self, left: L, right: R) -> (Option<L>, Option<R>, Self::MergeResult);
fn size_hint(left: SizeHint, right: SizeHint) -> SizeHint;
}

impl<I, J> OrderingOrBool<I, J> for Ordering {
type MergeResult = EitherOrBoth<I, J>;
fn left(left: I) -> Self::MergeResult {
impl<L, R> OrderingOrBool<L, R> for Ordering {
type MergeResult = EitherOrBoth<L, R>;
fn left(left: L) -> Self::MergeResult {
EitherOrBoth::Left(left)
}
fn right(right: J) -> Self::MergeResult {
fn right(right: R) -> Self::MergeResult {
EitherOrBoth::Right(right)
}
fn merge(self, left: I, right: J) -> (Option<I>, Option<J>, Self::MergeResult) {
fn merge(self, left: L, right: R) -> (Option<L>, Option<R>, Self::MergeResult) {
match self {
Ordering::Equal => (None, None, EitherOrBoth::Both(left, right)),
Ordering::Less => (None, Some(right), EitherOrBoth::Left(left)),
Expand All @@ -75,15 +75,15 @@ impl<I, J> OrderingOrBool<I, J> for Ordering {
}
}

impl<I, J> OrderingOrBool<I, J> for bool {
type MergeResult = Either<I, J>;
fn left(left: I) -> Self::MergeResult {
impl<L, R> OrderingOrBool<L, R> for bool {
type MergeResult = Either<L, R>;
fn left(left: L) -> Self::MergeResult {
Either::Left(left)
}
fn right(right: J) -> Self::MergeResult {
fn right(right: R) -> Self::MergeResult {
Either::Right(right)
}
fn merge(self, left: I, right: J) -> (Option<I>, Option<J>, Self::MergeResult) {
fn merge(self, left: L, right: R) -> (Option<L>, Option<R>, Self::MergeResult) {
if self {
(None, Some(right), Either::Left(left))
} else {
Expand Down

0 comments on commit a74da09

Please sign in to comment.