Created
September 30, 2023 08:52
-
-
Save gfldex/7d76fa95f620b9352e0687140da65699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my atomicint $spawn-limit = 8; | |
sub spawn(&c, |args) { | |
# dd ⚛$spawn-limit; | |
⚛$spawn-limit > 0 | |
?? ($spawn-limit⚛-- ;start { LEAVE $spawn-limit⚛++; c(|args) }) | |
!! c(|args) | |
} | |
sub collect(*@things) { | |
slip @things.map: -> $thing { $thing ~~ Promise ?? await $thing !! $thing } | |
} | |
multi quicksort([]) { () } | |
multi quicksort([$pivot, *@rest]) { | |
my @before = @rest.grep(* before $pivot); | |
my @after = @rest.grep(* !before $pivot); | |
flat collect spawn(&?ROUTINE.dispatcher, @before), $pivot, spawn(&?ROUTINE.dispatcher, @after) | |
} | |
my @a = ('a'..'z').roll(12).join xx 60000; | |
# dd @a; | |
quicksort @a; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment