algorithms/core

sourcealgorithms/core.sx

sort

pub fn sort[A: allocators.GeneralAllocator, T](ac: A, input: list[T]) list[T]

Generic sort (radix for numeric integers, insertion sort otherwise).

sort_numeric_radix

pub fn sort_numeric_radix[A: allocators.GeneralAllocator, T](ac: A, input: list[T]) list[T]

General numeric sort (radix)

radix_sort_i64_raw

private
fn radix_sort_i64_raw(src: ref void, n: usize, signed: bool) ref void = trust { ... }

Fast radix sort for signed i64 values (ascending). Sort a raw 64-bit integer buffer using a stable 16-bit LSD radix sort.

signed selects whether the sign bit is folded so that the result is in signed ascending order. The returned buffer is freshly allocated with @alloc and must be released by the caller. When all keys are non-negative only the significant 16-bit digits are processed.

sort_radix_i64

pub fn sort_radix_i64[A: allocators.GeneralAllocator](ac: A, input: list[i64]) list[i64]

Fast radix sort for signed i64 values (ascending).

This implementation works directly on the list backing buffer, avoiding the per-element boxing overhead of @get/@set in the generic path.

sort_radix_u64

pub fn sort_radix_u64[A: allocators.GeneralAllocator](ac: A, input: list[u64]) list[u64]

Fast radix sort for unsigned u64 values (ascending).

parse_leading_num

private
fn parse_leading_num(name: ref u8) i64

sort_by_num

pub fn sort_by_num[A: allocators.GeneralAllocator](ac: A, files: list[ref u8]) list[ref u8]

Insertion-sort a list of ref u8 by their leading number (ascending).

sort_i64

pub fn sort_i64[A: allocators.GeneralAllocator](ac: A, input: list[i64]) list[i64]

Fast radix sort for signed i64 values (ascending).

sort_f64

pub fn sort_f64[A: allocators.GeneralAllocator](ac: A, input: list[f64]) list[f64]

Insertion-sort a list of f64 (ascending).

intern_strcmp

private
fn intern_strcmp(a: ref u8, b: ref u8) i32

Internal string comparison function for algo purposes.

sort_alpha

pub fn sort_alpha[A: allocators.GeneralAllocator](ac: A, files: list[ref u8]) list[ref u8]

Sort some list of raw strings alphabetically.