Created
August 24, 2022 08:21
-
-
Save teivah/c65fcbae3a9431903bf4fafaf09a85e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| func parallelMergesortV1(s []int) { | |
| if len(s) <= 1 { | |
| return | |
| } | |
| middle := len(s) / 2 | |
| var wg sync.WaitGroup | |
| wg.Add(2) | |
| go func() { // Spins up the first half of the work in a goroutine | |
| defer wg.Done() | |
| parallelMergesortV1(s[:middle]) | |
| }() | |
| go func() { // Spins up the second half of the work in a goroutine | |
| defer wg.Done() | |
| parallelMergesortV1(s[middle:]) | |
| }() | |
| wg.Wait() | |
| merge(s, middle) // Merges the halves | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment