nx_qsort.nx
buildroot/runtime/nx_qsort.nx
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
imports: syscalls.nx
imported by: nx_infill.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 30 | const NX_QSORT_INSERTION_CUTOFF: i64 = 16 |
functions
| 34 | func nx_qsort_swap_i64(a: *i64, i: i64, j: i64) -> i64 called by 1: nx_qsort_partition_i64 |
| 41 | func nx_qsort_insertion_i64(a: *i64, lo: i64, hi: i64) -> i64 called by 1: nx_qsort_i64_range |
| 62 | func nx_qsort_partition_i64(a: *i64, lo: i64, hi: i64) -> i64 |
| 93 | func nx_qsort_i64_range(a: *i64, lo: i64, hi: i64) -> i64 called by 2: nx_qsort_i64_rangenx_qsort_i64 calls 3: nx_qsort_insertion_i64nx_qsort_partition_i64nx_qsort_i64_range |
| 105 | func nx_qsort_i64(a: *i64, n: i64) -> i64 |
| 116 | func main() -> i64 calls 1: nx_qsort_i64 |