Skip to content

Commit

Permalink
std::slices: add the SortFunc function
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Sep 2, 2024
1 parent a50176d commit a1a2d1f
Show file tree
Hide file tree
Showing 5 changed files with 795 additions and 348 deletions.
21 changes: 0 additions & 21 deletions std/slices/slices.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

use bits for std::math::bits
use cmp for std::internal::cmp

// Sorts a slice of any ordered type in ascending order.
// When sorting floating-point numbers, NaNs are ordered before other values.
fn Sort[S: []E, E: ordered](mut s: S) {
n := len(s)
pdqsort(s, 0, n, bits::Len(uint(n)))
}

// Reports whether x is sorted in ascending order.
fn IsSorted[S: []E, E: ordered](mut s: S): bool {
mut i := len(s) - 1
for i > 0; i-- {
if cmp::Less(s[i], s[i-1]) {
ret false
}
}
ret true
}

// Reports whether slices are the same length and contains same elements.
// The nil slices considered as zero-length slices.
// The floating-point NaNs are not considered equal.
Expand Down
Loading

0 comments on commit a1a2d1f

Please sign in to comment.