Files
LNXSDK/lib/radix/README.md
2026-10-15 02:41:03 -07:00

869 B

Radix

Haxe port: in-place MSD radix sort (American flag sort) with an insertion sort fallback for small sub-ranges implemented in the Leenkx SDK by Riccardo Mazzucco

Original reference source Malte Skarupke's ska_sort - https://github.com/skarupke/ska_sort

Usage

import radix.Radix;

// Stable sort: counting-sort scatter between `a` and `buffer`.
// Equal keys keep input order - matches haxe Array.sort semantics.
Radix.sortCopyKeyed(meshes, keys, meshesBuf, keysBuf);

// In-place MSD sort on the same (element, keys) arrays.
// No scratch buffer needed, but NOT stable - equal keys may reorder.
Radix.sortKeyed(meshes, keys);

// Or let the sorter build keys from an extractor
Radix.sort(meshes, function(m) {
    return (m.depthRead ? 0x80000000 : 0) | (FPHelper.floatToI32(m.cameraDistance) >>> 1);
});