add comments to dual pivot quicksort

This commit is contained in:
jacekpoz 2024-04-10 13:25:45 +02:00
parent 9bc0a4e198
commit c8d54ab6c1
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -41,7 +41,9 @@ fn dual_pivot_partition(list: &mut [u64], res: &mut SortResult) -> (usize, usize
let q = list[list.len() - 1];
while k <= g {
// l > s
if ((list.len() - 1) - g) > (l - 1) {
// list[k] >= q
if compare(list[k], q, &mut comps) != LESS {
while compare(list[g], q, &mut comps) == GREATER && k < g {
g -= 1;
@ -52,14 +54,18 @@ fn dual_pivot_partition(list: &mut [u64], res: &mut SortResult) -> (usize, usize
swap(list, k, l, &mut swaps);
l += 1;
}
// list[k] < p
} else if compare(list[k], p, &mut comps) == LESS {
swap(list, k, l, &mut swaps);
l += 1;
}
// l < s
} else {
// list[k] < p
if compare(list[k], p, &mut comps) == LESS {
swap(list, k, l, &mut swaps);
l += 1;
// list[k] >= q
} else if compare(list[k], q, &mut comps) != LESS {
while compare(list[g], q, &mut comps) == GREATER && k < g {
g -= 1;