packages
The Louise packages, each released on its own
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#31 · main · 4 min 11 s
0Étoiles
0Forks
3Issues
std/array: sort and sort_by, a driftsort-style stable sort (#380)
A driftsort-style stable sort (Bergdoll and Peters, 2024; Rust's slice::sort), in pure Louise over the array's own storage — set on a unique array updates in place, so the TL_SCAN_LARGE layout is untouched and no runtime or interpreter change is needed: - natural runs: ascending, or strictly descending reversed in place (sorted and reversed input cost O(n) comparisons); - runs under sqrt(n) are left unsorted until their first merge, then sorted by a stable quicksort: median-of-~sqrt(n) pivot selection, a stable partition through the scratch array that splits off the elements equal to a repeated pivot (pdqsort-style; O(n log k) expected on k distinct values), and a merge-sort fallback past 2*log2(n) bad partitions (O(n log n) worst case); - runs merge in powersort order (Munro and Wild, 2018) through the scratch array, galloping (exponential, then binary, search) while one side keeps winning, timsort-style; - the scratch is n elements up to a million (8 MB of words, so one quicksort can take the whole input — driftsort's full-buffer policy), n / 2 past it. Two bugs found by the differential and property tests, for the record: the partition's backwards-written right side came back unreversed, and the up-gallop searched the left run twice where timsort alternates (right key into the left run, then left key into the right run) — the latter is an instability only long equal runs reach. Correctness: tests/run/sort.lse (edge cases, the algorithm's thresholds, the detected patterns, stability, an effectful comparator; differential interp/native), and packages/gen property tests against an insertion-sort oracle (sorted, stable, permutation), interp and native. Measurements (tests/bench/sorts.lse patterns, 100k elements, user instructions on one core, generation included, the merge sort of std/list vs the array roundtrip from_list + sort + to_list): random 730.7M -> 717.3M, sorted 342.3M -> 43.7M, reverse 340.7M -> 51.3M, low-cardinality 721.4M -> 392.0M, organ-pipe 361.4M -> 77.8M. Co-Authored-By: Ember-1 <noreply@fireworks.ai>
Parents bd0a0fc
1 fichiers modifiés, 142 ajouts, 0 suppressions
gen/test/sort_test.lse+142−0