Sorting algorithms/Quicksort: Difference between revisions

imported>Rcmlz
imported>Rcmlz
Line 8,241:
flat quicksort($before), $pivot, $equiv, quicksort($after)
}</syntaxhighlight>
Note that <code>$before</code> and <code>$after</code> are bound to lazy lists,. so theThe partitions can (at least in theory) be sorted in parallel.
 
<syntaxhighlight lang="raku" line>
#|« Recursive, parallelconcurrent quicksort implementation.
 
* in partitioning/classifying step by .race or .hyper
concurrency applied
* in partitioningrecursion step byon .hyperLess partition by orstart .race{}
* in recursion steps by start {}
»
sub quicksort-recursive-parallel(@input) {
Line 8,258 ⟶ 8,257:
my %partiton = $_;
my $less = start { %partiton{Less}:exists ?? samewith(%partiton{Less}) !! [] };
my $more = start { %partiton{More}:exists ?? samewith(%partiton{More}) !! [] };
await $less andthen |$less.result, |%partiton{Same}, |$more;
 
|$less.result, |%partiton{Same}, |$more.result
}
}
#=« Implementation notesNotes:
* samewith() refactors out the actual name of the routine.
* andthen passes outputthe result of the previous block as $_ to the next block, alternatively use ==>.
* no need to start a new thread for More partition - as we better use current thread.
»
</syntaxhighlight>
Anonymous user