Commit 9e7d4553 authored by Irene Y Zhang's avatar Irene Y Zhang

adding some hints to lab 1 code

parent 712eaf09
...@@ -9,10 +9,21 @@ import "container/list" ...@@ -9,10 +9,21 @@ import "container/list"
// key to the Map function, as in the paper; only a value, // key to the Map function, as in the paper; only a value,
// which is a part of the input file contents // which is a part of the input file contents
func Map(value string) *list.List { func Map(value string) *list.List {
// Note: The value argument holds one line of text from the file.
// You need to:
// (1) Split up the string into words, discarding any punctuation
// (2) Add each word to the list with a mapreduce.KeyValue struct
} }
// iterate over list and add values // iterate over list and add values
func Reduce(key string, values *list.List) string { func Reduce(key string, values *list.List) string {
// Note:
// The key argument holds the key common too all values in the values argument
// The values argument is a list of mapreduce.KeyValue structs with the given key.
// You need to:
// (1) Reduce the all of the values in the values list
// (2) Return the reduced/summed up values as a string
} }
// Can be run in 3 ways: // Can be run in 3 ways:
...@@ -20,17 +31,17 @@ func Reduce(key string, values *list.List) string { ...@@ -20,17 +31,17 @@ func Reduce(key string, values *list.List) string {
// 2) Master (e.g., go run wc.go master x.txt localhost:7777) // 2) Master (e.g., go run wc.go master x.txt localhost:7777)
// 3) Worker (e.g., go run wc.go worker localhost:7777 localhost:7778 &) // 3) Worker (e.g., go run wc.go worker localhost:7777 localhost:7778 &)
func main() { func main() {
if len(os.Args) != 4 { if len(os.Args) != 4 {
fmt.Printf("%s: see usage comments in file\n", os.Args[0]) fmt.Printf("%s: see usage comments in file\n", os.Args[0])
} else if os.Args[1] == "master" { } else if os.Args[1] == "master" {
if os.Args[3] == "sequential" { if os.Args[3] == "sequential" {
mapreduce.RunSingle(5, 3, os.Args[2], Map, Reduce) mapreduce.RunSingle(5, 3, os.Args[2], Map, Reduce)
} else { } else {
mr := mapreduce.MakeMapReduce(5, 3, os.Args[2], os.Args[3]) mr := mapreduce.MakeMapReduce(5, 3, os.Args[2], os.Args[3])
// Wait until MR is done // Wait until MR is done
<- mr.DoneChannel <-mr.DoneChannel
} }
} else { } else {
mapreduce.RunWorker(os.Args[2], os.Args[3], Map, Reduce, 100) mapreduce.RunWorker(os.Args[2], os.Args[3], Map, Reduce, 100)
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment