Skip to content

Commit b46e281

Browse files
authored
Revert is_sorted removal, deprecate instead (#14388)
* Revert "removed (#14370)" This reverts commit 29e9a1c. * Restore/Deprecate is_sorted * Update datafusion/common/src/utils/mod.rs
1 parent 5113386 commit b46e281

File tree

1 file changed

+28
-0
lines changed
  • datafusion/common/src/utils

1 file changed

+28
-0
lines changed

datafusion/common/src/utils/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,21 @@ pub fn set_difference<T: Borrow<usize>, S: Borrow<usize>>(
769769
.collect()
770770
}
771771

772+
/// Checks whether the given index sequence is monotonically non-decreasing.
773+
#[deprecated(since = "45.0.0", note = "Use std::Iterator::is_sorted instead")]
774+
pub fn is_sorted<T: Borrow<usize>>(sequence: impl IntoIterator<Item = T>) -> bool {
775+
// TODO: Remove this function when `is_sorted` graduates from Rust nightly.
776+
let mut previous = 0;
777+
for item in sequence.into_iter() {
778+
let current = *item.borrow();
779+
if current < previous {
780+
return false;
781+
}
782+
previous = current;
783+
}
784+
true
785+
}
786+
772787
/// Find indices of each element in `targets` inside `items`. If one of the
773788
/// elements is absent in `items`, returns an error.
774789
pub fn find_indices<T: PartialEq, S: Borrow<T>>(
@@ -1157,6 +1172,19 @@ mod tests {
11571172
assert_eq!(set_difference([3, 4, 0], [4, 1, 2]), vec![3, 0]);
11581173
}
11591174

1175+
#[test]
1176+
#[expect(deprecated)]
1177+
fn test_is_sorted() {
1178+
assert!(is_sorted::<usize>([]));
1179+
assert!(is_sorted([0]));
1180+
assert!(is_sorted([0, 3, 4]));
1181+
assert!(is_sorted([0, 1, 2]));
1182+
assert!(is_sorted([0, 1, 4]));
1183+
assert!(is_sorted([0usize; 0]));
1184+
assert!(is_sorted([1, 2]));
1185+
assert!(!is_sorted([3, 2]));
1186+
}
1187+
11601188
#[test]
11611189
fn test_find_indices() -> Result<()> {
11621190
assert_eq!(find_indices(&[0, 3, 4], [0, 3, 4])?, vec![0, 1, 2]);

0 commit comments

Comments
 (0)