func main() { file, err := os.Create("output.txt") if err != nil { panic(err) } defer file.Close() count := make(map[string]int) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { switch index { case 0: num, _ := strconv.Atoi(tuple.Slice[1]) count[tuple.Slice[0]] += num case 1: num, _ := strconv.Atoi(tuple.Slice[1]) count[tuple.Slice[0]] += num case 2: num, _ := strconv.Atoi(tuple.Slice[1]) count[tuple.Slice[0]] -= num } }) stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") for key, value := range count { file.Write([]byte(key + ", " + strconv.Itoa(value) + "\n")) outTuple := worker.Tuple{[]string{key, strconv.Itoa(value)}} stdout.Write(outTuple.SerializeTuple(0)) stdout.Write([]byte{'\n'}) } }
func main() { // read from standard input to get the input tuples inputTuples := make([]worker.Tuple, 0) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { inputTuples = append(inputTuples, tuple) }) stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") counts := make(map[string]int) for _, tuple := range inputTuples { word := tuple.Slice[0] if count, ok := counts[word]; ok { counts[word] = count + 1 } else { counts[word] = 1 } } for word, count := range counts { outTuple := worker.Tuple{[]string{word, strconv.Itoa(count)}} stdout.Write(outTuple.SerializeTuple(0)) stdout.Write([]byte{'\n'}) } }
func main() { // read from standard input to get the input tuples newTuples := make([]worker.Tuple, 0) oldTuples := make([]worker.Tuple, 0) totalTuples := make([]worker.Tuple, 0) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { switch index { case 0: newTuples = append(newTuples, tuple) case 1: oldTuples = append(oldTuples, tuple) case 2: totalTuples = append(totalTuples, tuple) } }) stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") counts := make(map[string]int) for _, tuple := range totalTuples { word := tuple.Slice[0] prev, _ := strconv.Atoi(tuple.Slice[1]) if count, ok := counts[word]; ok { counts[word] = count + prev } else { counts[word] = prev } } for _, tuple := range newTuples { word := tuple.Slice[0] if count, ok := counts[word]; ok { counts[word] = count + 1 } else { counts[word] = 1 } } for _, tuple := range oldTuples { word := tuple.Slice[0] if count, ok := counts[word]; ok { counts[word] = count - 1 } } for word, count := range counts { outTuple := worker.Tuple{[]string{word, strconv.Itoa(count)}} stdout.Write(outTuple.SerializeTuple(2)) stdout.Write([]byte{'\n'}) } }
func main() { file, err := os.Create("output.txt") if err != nil { panic(err) } defer file.Close() worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { file.Write([]byte(tuple.Slice[0] + ", " + tuple.Slice[1] + "\n")) }) }
func main() { file, err := os.OpenFile("output2.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666) if err != nil { panic(err) } file.Write([]byte(time.Now().String() + "\n")) defer file.Close() worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { file.Write([]byte(tuple.Slice[0] + ", " + tuple.Slice[1] + "\n")) }) }
func main() { count := make(map[string]int) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { count[tuple.Slice[0]] += 1 }) stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") for key, value := range count { outTuple := worker.Tuple{[]string{key, strconv.Itoa(value)}} stdout.Write(outTuple.SerializeTuple(0)) stdout.Write([]byte{'\n'}) } }
func main() { // read from standard input to get the input tuples inputTuples := make([]worker.Tuple, 0) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { inputTuples = append(inputTuples, tuple) }) stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") count := 0 for _, _ = range inputTuples { // word := tuple.Slice[0] count += 1 } outTuple := worker.Tuple{[]string{"error", strconv.Itoa(count)}} stdout.Write(outTuple.SerializeTuple(0)) stdout.Write([]byte{'\n'}) }
func main() { // read input from standard input and create tuples inputTuples := make([]worker.Tuple, 0) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { inputTuples = append(inputTuples, tuple) }) // get standard output stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") // iterate over input tuples for _, tuple := range inputTuples { words := strings.Fields(tuple.Slice[0]) // iterate over words for _, word := range words { // emit each word in a new tuple outTuple := worker.Tuple{[]string{strings.ToLower(word), "1"}} stdout.Write(outTuple.SerializeTuple(0)) stdout.Write([]byte{'\n'}) } } }
func main() { // read from standard input to get the input tuples inputTuples := make([]worker.Tuple, 0) worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) { inputTuples = append(inputTuples, tuple) }) stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") for _, tuple := range inputTuples { words := strings.Fields(tuple.Slice[1]) for _, word := range words { word = strings.ToLower(word) if word == "error" { outTuple := worker.Tuple{[]string{word, "1"}} stdout.Write(outTuple.SerializeTuple(0)) stdout.Write([]byte{'\n'}) } } } }