@@ -2737,7 +2737,7 @@ pub trait Itertools : Iterator {
2737
2737
Self : Sized ,
2738
2738
Self :: Item : Ord ,
2739
2739
{
2740
- crate :: k_smallest:: k_smallest ( self , k)
2740
+ crate :: k_smallest:: k_smallest_general ( self , k, Self :: Item :: cmp )
2741
2741
}
2742
2742
2743
2743
/// Sort the k smallest elements into a new iterator using the provided comparison.
@@ -2751,7 +2751,7 @@ pub trait Itertools : Iterator {
2751
2751
Self : Sized ,
2752
2752
F : Fn ( & Self :: Item , & Self :: Item ) -> Ordering ,
2753
2753
{
2754
- crate :: k_smallest:: k_smallest_by ( self , k, cmp)
2754
+ crate :: k_smallest:: k_smallest_general ( self , k, cmp)
2755
2755
}
2756
2756
2757
2757
/// Return the elements producing the k smallest outputs of the provided function
@@ -2766,7 +2766,13 @@ pub trait Itertools : Iterator {
2766
2766
F : Fn ( & Self :: Item ) -> K ,
2767
2767
K : Ord ,
2768
2768
{
2769
- crate :: k_smallest:: k_smallest_by_key ( self , k, key)
2769
+ let iter = self . map ( |v| ( key ( & v) , v) ) ;
2770
+
2771
+ let results: Vec < _ > =
2772
+ crate :: k_smallest:: k_smallest_general ( iter, k, |( k, _) , ( l, _) | k. cmp ( & l) )
2773
+ . map ( |( _, t) | t)
2774
+ . collect ( ) ;
2775
+ results. into_iter ( )
2770
2776
}
2771
2777
2772
2778
/// Sort the k largest elements into a new iterator, in descending order.
@@ -2789,7 +2795,7 @@ pub trait Itertools : Iterator {
2789
2795
Self : Sized ,
2790
2796
Self :: Item : Ord ,
2791
2797
{
2792
- crate :: k_smallest :: k_smallest_by ( self , k, k_smallest:: reverse_cmp ( Self :: Item :: cmp) )
2798
+ self . k_smallest_by ( k, k_smallest:: reverse_cmp ( Self :: Item :: cmp) )
2793
2799
}
2794
2800
2795
2801
/// Sort the k largest elements into a new iterator using the provided comparison.
@@ -2800,7 +2806,7 @@ pub trait Itertools : Iterator {
2800
2806
Self : Sized ,
2801
2807
F : Fn ( & Self :: Item , & Self :: Item ) -> Ordering ,
2802
2808
{
2803
- crate :: k_smallest :: k_smallest_by ( self , k, k_smallest:: reverse_cmp ( cmp) )
2809
+ self . k_smallest_by ( k, k_smallest:: reverse_cmp ( cmp) )
2804
2810
}
2805
2811
2806
2812
/// Return the elements producing the k largest outputs of the provided function
@@ -2812,7 +2818,7 @@ pub trait Itertools : Iterator {
2812
2818
K : Ord ,
2813
2819
{
2814
2820
let key = crate :: k_smallest:: reverse_key ( key) ;
2815
- crate :: k_smallest :: k_smallest_by_key ( self , k, key)
2821
+ self . k_smallest_by_key ( k, key)
2816
2822
}
2817
2823
2818
2824
/// Collect all iterator elements into one of two
0 commit comments