Last active
August 29, 2015 14:14
-
-
Save sagivo/2b8b81e9cf1b3d48ce51 to your computer and use it in GitHub Desktop.
mergesort async with limit
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
func merge_sort_async(l []int, c chan []int) { | |
if len(l) < 2 { | |
c <- l | |
return | |
} | |
if len(l) < 500 { //TUNE THIS NUMER AND DONT CREATE EXTRA WORK UNLESS IT'S BIGGER | |
c <- merge_sort(l) | |
return | |
} | |
mid := len(l) / 2 | |
c1 := make(chan []int, 1) | |
c2 := make(chan []int, 1) | |
go merge_sort_async(l[:mid], c1) | |
go merge_sort_async(l[mid:], c2) | |
go func() { c <- merge(<-c1, <-c2) }() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment