From c622606fa4c9d6ca85b485e6bd7cc8004a249e24 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Sun, 2 Jul 2023 15:20:43 +0200 Subject: [PATCH] Add `InternalMergeJoinBy` --- src/lib.rs | 2 +- src/merge_join.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c6a62b652..940067931 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1065,7 +1065,7 @@ pub trait Itertools : Iterator { /// ); /// ``` #[inline] - fn merge_join_by(self, other: J, cmp_fn: F) -> MergeJoinBy> + fn merge_join_by(self, other: J, cmp_fn: F) -> MergeJoinBy where J: IntoIterator, F: FnMut(&Self::Item, &J::Item) -> T, Self: Sized diff --git a/src/merge_join.rs b/src/merge_join.rs index 81b204ec4..34b1f6e7e 100644 --- a/src/merge_join.rs +++ b/src/merge_join.rs @@ -44,7 +44,7 @@ pub fn merge(i: I, j: J) -> Merge<::IntoIter, , I::Item: PartialOrd { - MergeJoinBy { + InternalMergeJoinBy { left: put_back(i.into_iter().fuse()), right: put_back(j.into_iter().fuse()), cmp_fn: MergeFuncT(MergeLte), @@ -57,7 +57,7 @@ pub fn merge(i: I, j: J) -> Merge<::IntoIter, = MergeJoinBy>; +pub type MergeBy = InternalMergeJoinBy>; /// Create a `MergeBy` iterator. pub fn merge_by_new(a: I, b: J, cmp: F) -> MergeBy @@ -65,7 +65,7 @@ pub fn merge_by_new(a: I, b: J, cmp: F) -> MergeBy, F: FnMut(&I::Item, &I::Item) -> bool, { - MergeJoinBy { + InternalMergeJoinBy { left: put_back(a.into_iter().fuse()), right: put_back(b.into_iter().fuse()), cmp_fn: MergeFuncT(cmp), @@ -76,12 +76,12 @@ pub fn merge_by_new(a: I, b: J, cmp: F) -> MergeBy(left: I, right: J, cmp_fn: F) - -> MergeJoinBy> + -> MergeJoinBy where I: IntoIterator, J: IntoIterator, F: FnMut(&I::Item, &J::Item) -> T, { - MergeJoinBy { + InternalMergeJoinBy { left: put_back(left.into_iter().fuse()), right: put_back(right.into_iter().fuse()), cmp_fn: MergeFuncLR(cmp_fn, PhantomData), @@ -91,8 +91,10 @@ pub fn merge_join_by(left: I, right: J, cmp_fn: F) /// An iterator adaptor that merge-joins items from the two base iterators in ascending order. /// /// See [`.merge_join_by()`](crate::Itertools::merge_join_by) for more information. +pub type MergeJoinBy = InternalMergeJoinBy>; + #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] -pub struct MergeJoinBy { +pub struct InternalMergeJoinBy { left: PutBack>, right: PutBack>, cmp_fn: F, @@ -204,7 +206,7 @@ impl MergePredicate for MergeFuncT { } } -impl Clone for MergeJoinBy +impl Clone for InternalMergeJoinBy where I: Iterator, J: Iterator, PutBack>: Clone, @@ -214,16 +216,16 @@ impl Clone for MergeJoinBy clone_fields!(left, right, cmp_fn); } -impl fmt::Debug for MergeJoinBy +impl fmt::Debug for InternalMergeJoinBy where I: Iterator + fmt::Debug, I::Item: fmt::Debug, J: Iterator + fmt::Debug, J::Item: fmt::Debug, { - debug_fmt_fields!(MergeJoinBy, left, right); + debug_fmt_fields!(InternalMergeJoinBy, left, right); } -impl Iterator for MergeJoinBy +impl Iterator for InternalMergeJoinBy where I: Iterator, J: Iterator, F: MergePredicate, @@ -326,7 +328,7 @@ impl Iterator for MergeJoinBy } } -impl FusedIterator for MergeJoinBy +impl FusedIterator for InternalMergeJoinBy where I: Iterator, J: Iterator, F: MergePredicate,