Skip to content

Commit f18901f

Browse files
committed
Don't need a Pair type for keyed ordering
1 parent 88395e7 commit f18901f

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/k_smallest.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ where
7979
F: Fn(&T) -> K,
8080
K: Ord,
8181
{
82-
let iter = iter.map(|v| Pair(key(&v), v));
82+
let iter = iter.map(|v| (key(&v), v));
8383

84-
let results: Vec<_> = k_smallest_general(iter, k, Ord::cmp)
85-
.map(|Pair(_, t)| t)
84+
let results: Vec<_> = k_smallest_general(iter, k, |(k, _), (l, _)| k.cmp(&l))
85+
.map(|(_, t)| t)
8686
.collect();
8787
results.into_iter()
8888
}
@@ -120,21 +120,3 @@ fn sift_down<T>(
120120
}
121121
}
122122
}
123-
124-
struct Pair<K, T>(K, T);
125-
impl<K: Ord, T> PartialEq for Pair<K, T> {
126-
fn eq(&self, other: &Self) -> bool {
127-
self.0 == other.0
128-
}
129-
}
130-
impl<K: Ord, T> Eq for Pair<K, T> {}
131-
impl<K: Ord, T> PartialOrd for Pair<K, T> {
132-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
133-
self.0.partial_cmp(&other.0)
134-
}
135-
}
136-
impl<K: Ord, T> Ord for Pair<K, T> {
137-
fn cmp(&self, other: &Self) -> Ordering {
138-
self.0.cmp(&other.0)
139-
}
140-
}

0 commit comments

Comments
 (0)