Caller can specify source counts and quantities

This commit is contained in:
Stephen McQuay 2018-05-05 09:23:42 -07:00
parent 39d849b955
commit c41e28fdd5
Signed by: sm
GPG Key ID: C383C74875475AC8

21
main.go
View File

@ -4,12 +4,31 @@ import (
"container/heap"
"fmt"
"math/rand"
"os"
"sort"
"strconv"
"time"
)
const usage = "smerge [count, count, ... count]"
func main() {
for i := range merge(source(500), source(100), source(200)) {
args := os.Args[1:]
if len(args) < 1 {
fmt.Fprintf(os.Stderr, "usage: %v\n", usage)
os.Exit(1)
}
srcs := []<-chan int{}
for _, arg := range args {
i, err := strconv.Atoi(arg)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
srcs = append(srcs, source(i))
}
for i := range merge(srcs...) {
fmt.Printf("%20d\n", i)
}
}