diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-05-01 16:42:10 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-05-01 16:42:10 -0700 |
commit | 558363cceda60c12b8fd22cda399e2e39dc11bac (patch) | |
tree | 75b1f4d714d2e0ef0d4c13cd4dba32a2fa91cb98 /stdlib/struct.tl | |
parent | cb9b5f6e8ffbec96b5c22ab89bc6852f27dd29b8 (diff) | |
download | txr-558363cceda60c12b8fd22cda399e2e39dc11bac.tar.gz txr-558363cceda60c12b8fd22cda399e2e39dc11bac.tar.bz2 txr-558363cceda60c12b8fd22cda399e2e39dc11bac.zip |
sort: replace Lomuto partitioning with Hoare
I'm seeing numbers aobut the same performance on a
sorted vector of integers, and 21% faster on vector of N
random integers in the range [0, N).
Also, this original algorithm handles well the case
of an array consisting of a repeated value.
The code we are replacing degrates to quadratic time.
* lib.c (med_of_three, middle_pivot): We don't use
the return value, so don't calculate and return one.
(quicksort): Revise to Hoare: scanning from both ends
of the array, exchanging elements.
* tests/010/sort.tl: New file. We test sort with
lists and vectors from length zero to eight, all
permutations.
Diffstat (limited to 'stdlib/struct.tl')
0 files changed, 0 insertions, 0 deletions