Created
April 14, 2019 02:53
-
-
Save imrenagi/0639819b99b809baa8ce0030d82f6698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func mapF(filename string, contents string) []mapreduce.KeyValue { | |
tokens := strings.FieldsFunc(contents, func(r rune) bool { | |
return !unicode.IsLetter(r) | |
}) | |
kvs := make([]mapreduce.KeyValue, 0) | |
for _, val := range tokens { | |
kvs = append(kvs, mapreduce.KeyValue{Key: val, Value: "1"}) | |
} | |
return kvs | |
} | |
func reduceF(key string, values []string) string { | |
var sum int64 | |
for _, s := range values { | |
val, _ := strconv.ParseInt(s, 10, 64) | |
sum = sum + val | |
} | |
return fmt.Sprintf("%d", sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment