possibly do the correct comparison I hope

This commit is contained in:
jacekpoz 2024-04-10 13:03:34 +02:00
parent 95fc5a1e1d
commit b8ec6963be
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

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