code wiki / (root) / nx_qsort.nx

nx_qsort.nx

buildroot/runtime/nx_qsort.nx

5704 B184 linesdepth 3pulls 3 transitivereach 34 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_qsort.nx -- in-place quicksort for i64 arrays + a generic indirect variant that takes a comparator function pointer. Used by: - nx_link / nx_objdump / nx_nm: sort symbols by address or name. - nx_dwarf_line: sort PC ranges before emitting the line program. - nx_audit / nx_metrics: sort scores for top-N reporting. Today most NishiLang call sites do bubble-sort or insertion-sort inline, which is fine for tiny arrays but quadratic above ~50 elements. This module gives O(n log n) average + O(log n) stack. Implementation notes: - Lomuto partition (simpler than Hoare; the constant-factor difference doesn't matter when symbol counts are < 100k). - Recursion bound = log2(n) + small constant; for n = 1M, that is ~20 frames -- fits even a tiny call stack. - When n <= 16 we fall back to insertion sort (lower overhead for small arrays; classic optimisation).

dependencies 1 imports · 1 importers

syscalls.nx nx_qsort.nx nx_infill.nx

imports: syscalls.nx

imported by: nx_infill.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_qsort_i64 nx_qsort_i64_range nx_qsort_insertion_i64 nx_qsort_partition_i64 nx_qsort_swap_i64 nx_qsort_i64_range ↻

structs

none

consts

30const NX_QSORT_INSERTION_CUTOFF: i64 = 16

functions

34func nx_qsort_swap_i64(a: *i64, i: i64, j: i64) -> i64
41func nx_qsort_insertion_i64(a: *i64, lo: i64, hi: i64) -> i64
called by 1: nx_qsort_i64_range
62func nx_qsort_partition_i64(a: *i64, lo: i64, hi: i64) -> i64
93func nx_qsort_i64_range(a: *i64, lo: i64, hi: i64) -> i64
105func nx_qsort_i64(a: *i64, n: i64) -> i64
116func main() -> i64
calls 1: nx_qsort_i64