nx_seed_sort.nx
buildroot/runtime/nx_seed_sort.nx
about
nx_seed_sort.nx -- in-place sort of seed-pair arrays by (r, q).
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/knuth-volume-3-insertion-sort
G1.2b of NISHI_GENOMICS_SUBSTRATE_ROADMAP.md. Closes the
composability gap between nx_align_match (G1.2) and nx_align_chain
(G1.3): match outputs seed pairs in (outer-q, inner-r) order;
chain DP requires pre-sorted-by-r input. This primitive bridges
them so the seed-and-extend pipeline composes without test-time
hand-sorting.
Algorithm: classic insertion sort over paired (q, r) arrays, kept
in lock-step. Sort key is (r_pos, q_pos) ascending lexicographic
-- r is the primary axis (chain DP precondition) and q breaks ties
deterministically so the leftmost-tie chain rule remains stable.
Why insertion sort: O(n^2) reference impl is fine for short-read
seed counts (n ~ 50-500); long-read or chromosome-scale needs a
non-comparison sort (G1.5 nx_seed_sort_radix, 8-bit r-byte buckets).
API:
sort_seeds_by_r(seeds_q, seeds_r, n) -> i64 always 0; in-place
nx_safety_envelope: (schema: nishi-library/seeds/safety-critical-standards.toml)
intended_use: "Seed-pair sort bridging match -> chain;
substrate primitive that removes the
'caller pre-sort' precondition from the
chain DP"
sil_target: SIL2
asil_target: QM
dal_target: DAL C
iec_62304_class: B
evidence: [no_floating_point, deterministic,
bit_equal_reproducible,
insertion_sort_textbook,
lex_tiebreak_stable,
end_to_end_KAT_matcher_output_validates,
license_tier_INDEPENDENT_REDERIVE]
hazard_register: [bug-tape-paired-array-desync-on-swap,
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_seed_sort_test.nx
structs
| none |
consts
| none |
functions
| 53 | func sort_seeds_by_r(seeds_q: *i64, seeds_r: *i64, n: i64) -> i64 called by 1: main |