30 lines
1.2 KiB
Markdown
30 lines
1.2 KiB
Markdown
# Magyar-sort
|
|
|
|
Header-only library for my take on radix sorting in-place.
|
|
|
|
Had this idea yesterday after watching "Creed"s video on youtube
|
|
first on cache locality and stuff and then just normal radix sort
|
|
(that I already know) in a recreational way.
|
|
|
|
It struck me when watching the videos in this order that his counting
|
|
sort variant of course needs a separate array. He even says it would
|
|
be good if could be done in place... I was like... but hey! I can do
|
|
it in place!
|
|
|
|
Biggest relevation was realizing that prefix sums will already tell
|
|
me from-to areas of sets in coded that were already sorted by its
|
|
first (radix-loop choosen) digit. I just need to keep the prefix sum
|
|
around in an untouched copy.
|
|
|
|
Maybe better to do it on nibbles for better cache usage and do all
|
|
"digits" at once in a single big loop. Then algorithm is recursive:
|
|
first do biggest digit, then prefix sum1-2 will tell where digits
|
|
"areas" start and end. Between them we either recurse and do a small
|
|
radix on second char OR if the thing is small enough just do regular
|
|
sort on it and that is all...
|
|
|
|
Also might be helpful to know starting digits are unused - small num
|
|
support?
|
|
|
|
Will need to code it, has it on paper. Should be fast and cache-friendly!
|