std::sortSorting utilities for vectors.
Provides type-specific sort and reverse functions. Each returns a new vector โ the original is never modified. Integer and string sorting use iterative merge passes with O(n log n) comparisons.
import std.sort;
fn main() {
var nums: Vec<i64> = Vec.new();
nums.push(3);
nums.push(1);
nums.push(2);
let sorted = sort.sort_ints(nums);
// sorted is [1, 2, 3]
}
sort_bySort any Vec<T> in the order less defines, where less(a, b) returns
true when a belongs strictly before b. Stable: elements for which
neither is less than the other keep their relative order.
Returns a new sorted vector; the original is unchanged.
There is no generic sort() alongside this: it would need an ordering
trait bound (T: Ord or similar), and std.builtins does not declare
one yet. sort_ints/sort_strings/sort_floats remain the built-in
orderings for those concrete types.
There is also no v.sort_by(less) fluent method form: the checker
reserves inherent impl Vec<T> { ... } blocks for std/builtins.hew
(E_HIR: impl-block shape not yet lowered) and, even there, Vec's
method dispatch only forwards runtime-backed (#[extern_symbol])
methods, panicking on a pure-Hew one (hew-types/src/check/methods.rs,
"Vec method signature was present immediately before dispatch"). Both are
compiler gaps outside this module's reach; see the stdlib-packages lane
report for hew-lang/hew#2933.
import std.sort;
fn main() {
var nums: Vec<i64> = Vec.new();
nums.push(3);
nums.push(1);
nums.push(2);
let sorted = sort.sort_by(nums, |a: i64, b: i64| a < b);
println(sorted[0]); // 1
println(sorted[1]); // 2
println(sorted[2]); // 3
}
sort_intsSort a vector of integers in ascending order.
Returns a new sorted vector; the original is unchanged.
sort_ints_countedSort integers and return the production merge core's comparison count.
This diagnostic form exists for deterministic complexity regression tests.
sort_stringsSort a vector of strings in alphabetical order.
Returns a new sorted vector; the original is unchanged.
sort_strings_countedSort strings and return the production merge core's comparison count.
This diagnostic form exists for deterministic complexity regression tests.
sort_floatsSort a vector of floats in ascending order.
Returns a new sorted vector; the original is unchanged.
reverse_intsReverse a vector of integers.
Returns a new reversed vector; the original is unchanged.
reverse_stringsReverse a vector of strings.
Returns a new reversed vector; the original is unchanged.
reverse_floatsReverse a vector of floats.
Returns a new reversed vector; the original is unchanged.