generated from Gophing-Around/hashcode-golang-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_main.go
51 lines (45 loc) · 1.1 KB
/
new_main.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
package main
import (
"fmt"
)
func new_main() {
files := []string{
"a",
"b",
"c",
"d",
"e",
}
for _, fileName := range files {
fmt.Printf("Processing input: %s\n", fileName)
config := buildNewInput(fmt.Sprintf("./inputFiles/%s.in", fileName))
fmt.Printf("CONFIG %+v\n", config)
for _, photo := range config.photoList {
fmt.Printf("PHOTO %+v\n", *photo)
}
break
}
}
func buildNewInput(file string) *Config {
config := Config{}
ReadInput(file, 8000, 1000, func(lineReady <-chan bool, wordChannel <-chan string, readNextLine chan<- bool, doneChannel chan<- bool) {
<-lineReady
config.nPhotos = toint(<-wordChannel)
readNextLine <- true
config.photoList = make([]*Photo, 0)
for id := 0; id < config.nPhotos; id++ {
<-lineReady
photo := Photo{ID: id}
photo.Layout = <-wordChannel
photo.NTags = toint(<-wordChannel)
photo.Tags = make([]string, 0)
for j := 0; j < photo.NTags; j++ {
photo.Tags = append(photo.Tags, <-wordChannel)
}
config.photoList = append(config.photoList, &photo)
readNextLine <- true
}
doneChannel <- true
})
return &config
}