Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
imported>Rcmlz |
imported>Rcmlz |
||
Line 8,241: | Line 8,241: | ||
flat quicksort($before), $pivot, $equiv, quicksort($after) |
flat quicksort($before), $pivot, $equiv, quicksort($after) |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
Note that <code>$before</code> and <code>$after</code> are bound to lazy lists |
Note that <code>$before</code> and <code>$after</code> are bound to lazy lists. The partitions can be sorted in parallel. |
||
<syntaxhighlight lang="raku" line> |
<syntaxhighlight lang="raku" line> |
||
#|« Recursive, |
#|« Recursive, concurrent quicksort implementation. |
||
* in partitioning/classifying step by .race or .hyper |
|||
concurrency applied |
|||
* in |
* in recursion step on Less partition by start {} |
||
* in recursion steps by start {} |
|||
» |
» |
||
sub quicksort-recursive-parallel(@input) { |
sub quicksort-recursive-parallel(@input) { |
||
Line 8,258: | Line 8,257: | ||
my %partiton = $_; |
my %partiton = $_; |
||
my $less = start { %partiton{Less}:exists ?? samewith(%partiton{Less}) !! [] }; |
my $less = start { %partiton{Less}:exists ?? samewith(%partiton{Less}) !! [] }; |
||
my $more = |
my $more = %partiton{More}:exists ?? samewith(%partiton{More}) !! []; |
||
await $less, $more |
await $less andthen |$less.result, |%partiton{Same}, |$more |
||
|$less.result, |%partiton{Same}, |$more.result |
|||
} |
} |
||
} |
} |
||
#=« Implementation |
#=« Implementation Notes: |
||
* samewith() refactors out the actual name of the routine. |
* samewith() refactors out the actual name of the routine. |
||
* andthen passes |
* andthen passes the result of the previous block as $_ to the next block. |
||
* no need to start a new thread for More partition - as we better use current thread. |
|||
» |
» |
||
</syntaxhighlight> |
</syntaxhighlight> |