Sort output before it goes out

Fixes #1
This commit is contained in:
Stephen McQuay 2017-10-18 17:43:26 -07:00
parent 717f195cf7
commit 98d5dd7033
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
1 changed files with 21 additions and 1 deletions

22
hash.go
View File

@ -9,6 +9,7 @@ import (
"hash"
"io"
"os"
"sort"
"sync"
)
@ -19,6 +20,13 @@ type result struct {
err error
}
// results exists to sort a slice of result
type results []result
func (r results) Len() int { return len(r) }
func (r results) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r results) Less(i, j int) bool { return r[i].f < r[j].f }
// hashr exists so that we can make a thing that can return valid hash.Hash
// interfaces.
type hashr func() hash.Hash
@ -72,7 +80,19 @@ func hsh(files []string) chan result {
res = append(res, compute(h, jobs))
}
return rmerge(res)
o := make(chan result)
go func() {
rs := results{}
for r := range rmerge(res) {
rs = append(rs, r)
}
sort.Sort(rs)
for _, r := range rs {
o <- r
}
close(o)
}()
return o
}
// compute is the checksumming workhorse