Skip to content

Commit

Permalink
Simplified quicksort with $switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jul 8, 2023
1 parent 9543fbb commit 053f788
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions lib/std/sort/quicksort.c3
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ fn isz partition(Type list, isz low, isz high, Comparer cmp) @inline @local
isz i = low - 1;
for (isz j = low; j < high; j++)
{
$if $checks(cmp(list[0], list[0])):
int res = cmp(list[j], pivot);
$else
$if $checks(cmp(&list[0], &list[0])):
int res = cmp(&list[j], &pivot);
$else
int res;
$switch
$case $checks(cmp(list[0], list[0])):
if (cmp(list[j], pivot) > 0) continue;
$case $checks(cmp(&list[0], &list[0])):
if (cmp(&list[j], &pivot) > 0) continue;
$default:
if (greater(list[j], pivot)) continue;
$endif
$endif
if (res <= 0)
{
i++;
@swap(list[i], list[j]);
}
$endswitch
i++;
@swap(list[i], list[j]);
}
i++;
@swap(list[i], list[high]);
Expand Down

0 comments on commit 053f788

Please sign in to comment.