Files
scriptc/tests/corpus/2702-uint8array-to-sorted.ts
T
Chris Tate 4b241f77d7 Replace quadratic array sorting with stable merge sort (#296)
* Fix Sandbox command transport and pinned native setup

Build the Linux LLVM helper and runtime pack before running both test lanes, and align native cache contracts with the current target policy. Full managed Sandbox gate passed.

* Replace quadratic array sorting with stable merge sort

Cover sort snapshots, consistent-comparator results, stable ties, and comparator complexity with Node differential fixtures. Document differences from V8 TimSort.
2026-09-12 16:05:16 -05:00

17 lines
628 B
TypeScript

const source = new Uint8Array(256);
for (let i = 0; i < source.length; i++) source[i] = 255 - i;
let comparisons = 0;
const sorted = source.toSorted((a, b) => {
comparisons++;
if (comparisons > 5000) throw new Error("Uint8Array sort exceeded comparison budget");
return a - b;
});
console.log(sorted[0], sorted[255], source[0], source[255]);
const descending = source.toSorted((a, b) => b - a);
console.log(descending[0], descending[255], source[0], source[255]);
const defaults = new Uint8Array([9, 1, 7, 1, 5, 2]).toSorted();
console.log(defaults[0], defaults[1], defaults[2], defaults[3], defaults[4], defaults[5]);