-
Notifications
You must be signed in to change notification settings - Fork 0
/
crosscheck.go
53 lines (41 loc) · 1.02 KB
/
crosscheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
)
// send all of my codes to one of my friends
// I don't need to wait on him to answer
// if there is a problem, he will tell mom
func sendToFriends(w *worker, fname string, c codeMap) {
var rq request
rq.fname = fname
rq.codes = c
w.inp <- rq
}
func listenForFriends(w *worker, keys codeMap) {
fmt.Printf("%s listening for %d friends\n", w.fname, w.listenCount)
for {
if w.listenCount == 0 {
break // I've heard from all my friends, so I'm done.
}
chk := <-w.inp
fmt.Printf("asked to check %d codes from file %s\n", len(chk.codes), chk.fname)
w.listenCount--
go checkFriend(w, chk, keys)
}
}
func checkFriend(w *worker, chk request, keys codeMap) {
var res results
for k := range chk.codes {
_, ok := keys[k]
if ok {
res.codesSeen = -1
res.resultsDescription = fmt.Sprintf("key value %s found in both %s and %s\n", k, w.fname, chk.fname)
w.outp <- res
return
}
}
res.codesSeen = len(chk.codes)
res.resultsDescription = checkOp
w.outp <- res
return
}