std.sort
in-place sorts (introsort, not stable; stable_* merge) and binary search
pub Asc :: struct($T: type) { marker: u8,}smallest first
Asc.less
Section titled “Asc.less”pub less :: fn(self: *Self, a: T, b: T) -> boolpub Desc :: struct($T: type) { marker: u8,}largest first
Desc.less
Section titled “Desc.less”pub less :: fn(self: *Self, a: T, b: T) -> boolpub By :: struct($T: type) { f: fn(T, T) -> bool,}f(a, b) true when a goes before b
By.less
Section titled “By.less”pub less :: fn(self: *Self, a: T, b: T) -> boolpub asc :: fn($T: type, xs: []T)in place, smallest first; not stable
pub desc :: fn($T: type, xs: []T)in place, largest first; not stable
pub by :: fn($T: type, xs: []T, less: fn(T, T) -> bool)in place by less; not stable
stable_asc
Section titled “stable_asc”pub stable_asc :: fn($T: type, xs: []T, scratch: *Arena)stable, smallest first; allocates an xs.len buffer in scratch
stable_by
Section titled “stable_by”pub stable_by :: fn($T: type, xs: []T, less: fn(T, T) -> bool, scratch: *Arena)stable by less; allocates an xs.len buffer in scratch
is_sorted
Section titled “is_sorted”pub is_sorted :: fn($T: type, xs: []const T) -> booltrue when ascending
is_sorted_by
Section titled “is_sorted_by”pub is_sorted_by :: fn($T: type, xs: []const T, less: fn(T, T) -> bool) -> booltrue when sorted by less
lower_bound
Section titled “lower_bound”pub lower_bound :: fn($T: type, xs: []const T, key: T) -> usizefirst index with xs[i] >= key; xs.len if none
lower_bound_by
Section titled “lower_bound_by”pub lower_bound_by :: fn($T: type, xs: []const T, key: T, less: fn(T, T) -> bool) -> usizelower_bound by less
upper_bound
Section titled “upper_bound”pub upper_bound :: fn($T: type, xs: []const T, key: T) -> usizefirst index with xs[i] > key; xs.len if none
upper_bound_by
Section titled “upper_bound_by”pub upper_bound_by :: fn($T: type, xs: []const T, key: T, less: fn(T, T) -> bool) -> usizeupper_bound by less
search
Section titled “search”pub search :: fn($T: type, xs: []const T, key: T) -> ?usizeindex of the first element equal to key, or null
search_by
Section titled “search_by”pub search_by :: fn($T: type, xs: []const T, key: T, less: fn(T, T) -> bool) -> ?usizesearch by less; equal means neither is less