Skip to content

Commit b3d9cc3

Browse files
committed
Use the primitive slice's is_sorted methods
1 parent 09db3cc commit b3d9cc3

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

src/map/slice.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ impl<K, V> Slice<K, V> {
264264
where
265265
K: PartialOrd,
266266
{
267-
// TODO(MSRV 1.82): self.entries.is_sorted_by(|a, b| a.key <= b.key)
268-
self.is_sorted_by_key(|k, _| k)
267+
self.entries.is_sorted_by(|a, b| a.key <= b.key)
269268
}
270269

271270
/// Checks if this slice is sorted using the given comparator function.
@@ -274,17 +273,8 @@ impl<K, V> Slice<K, V> {
274273
where
275274
F: FnMut(&'a K, &'a V, &'a K, &'a V) -> bool,
276275
{
277-
// TODO(MSRV 1.82): self.entries
278-
// .is_sorted_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value))
279-
let mut iter = self.entries.iter();
280-
match iter.next() {
281-
Some(mut prev) => iter.all(move |next| {
282-
let sorted = cmp(&prev.key, &prev.value, &next.key, &next.value);
283-
prev = next;
284-
sorted
285-
}),
286-
None => true,
287-
}
276+
self.entries
277+
.is_sorted_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value))
288278
}
289279

290280
/// Checks if this slice is sorted using the given sort-key function.
@@ -294,17 +284,8 @@ impl<K, V> Slice<K, V> {
294284
F: FnMut(&'a K, &'a V) -> T,
295285
T: PartialOrd,
296286
{
297-
// TODO(MSRV 1.82): self.entries
298-
// .is_sorted_by_key(move |a| sort_key(&a.key, &a.value))
299-
let mut iter = self.entries.iter().map(move |a| sort_key(&a.key, &a.value));
300-
match iter.next() {
301-
Some(mut prev) => iter.all(move |next| {
302-
let sorted = prev <= next;
303-
prev = next;
304-
sorted
305-
}),
306-
None => true,
307-
}
287+
self.entries
288+
.is_sorted_by_key(move |a| sort_key(&a.key, &a.value))
308289
}
309290

310291
/// Returns the index of the partition point of a sorted map according to the given predicate

src/set/slice.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ impl<T> Slice<T> {
166166
where
167167
T: PartialOrd,
168168
{
169-
// TODO(MSRV 1.82): self.entries.is_sorted_by(|a, b| a.key <= b.key)
170-
self.is_sorted_by(T::le)
169+
self.entries.is_sorted_by(|a, b| a.key <= b.key)
171170
}
172171

173172
/// Checks if this slice is sorted using the given comparator function.
@@ -176,16 +175,7 @@ impl<T> Slice<T> {
176175
where
177176
F: FnMut(&'a T, &'a T) -> bool,
178177
{
179-
// TODO(MSRV 1.82): self.entries.is_sorted_by(move |a, b| cmp(&a.key, &b.key))
180-
let mut iter = self.entries.iter();
181-
match iter.next() {
182-
Some(mut prev) => iter.all(move |next| {
183-
let sorted = cmp(&prev.key, &next.key);
184-
prev = next;
185-
sorted
186-
}),
187-
None => true,
188-
}
178+
self.entries.is_sorted_by(move |a, b| cmp(&a.key, &b.key))
189179
}
190180

191181
/// Checks if this slice is sorted using the given sort-key function.
@@ -195,16 +185,7 @@ impl<T> Slice<T> {
195185
F: FnMut(&'a T) -> K,
196186
K: PartialOrd,
197187
{
198-
// TODO(MSRV 1.82): self.entries.is_sorted_by_key(move |a| sort_key(&a.key))
199-
let mut iter = self.entries.iter().map(move |a| sort_key(&a.key));
200-
match iter.next() {
201-
Some(mut prev) => iter.all(move |next| {
202-
let sorted = prev <= next;
203-
prev = next;
204-
sorted
205-
}),
206-
None => true,
207-
}
188+
self.entries.is_sorted_by_key(move |a| sort_key(&a.key))
208189
}
209190

210191
/// Returns the index of the partition point of a sorted set according to the given predicate

0 commit comments

Comments
 (0)