Skip to content

Commit

Permalink
cleaning, minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian83 committed Dec 6, 2016
1 parent 970a421 commit 3b9e289
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 62 deletions.
23 changes: 0 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
Binary file removed go_mapreduce/bin/mapper
Binary file not shown.
Binary file removed go_mapreduce/bin/reducer
Binary file not shown.
53 changes: 23 additions & 30 deletions go_mapreduce/src/mapreduce/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,36 @@ package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
"io"
)

func main() {

bio := bufio.NewReader(os.Stdin)

for true {

line, err := bio.ReadString('\n')

if err != nil {
if err != io.EOF {
fmt.Fprintf(os.Stderr, "error: can't read - %s\n", err)
}
// io.EOF
break


}

line = strings.TrimSpace(line)


if len(line) > 0 {
words := strings.Split(line, " ")

for _, word := range words {
word = strings.TrimSpace(word)
if len(word) > 0 {
fmt.Println(fmt.Sprintf("%s\t1", word))
}
}
}
}

for true {

line, err := bio.ReadString('\n')

if err != nil {
if err != io.EOF {
fmt.Fprintf(os.Stderr, "Error while reading from Stdin. Error: %v\n", err)
}
break
}

if line = strings.TrimSpace(line); line != "" {
words := strings.Split(line, " ")

for _, word := range words {
word = strings.TrimSpace(word)
if word != "" {
fmt.Println(fmt.Sprintf("%s\t1", word))
}
}
}
}

}
13 changes: 4 additions & 9 deletions go_mapreduce/src/mapreduce/reducer/reducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,27 @@ func main() {

if err != nil {
if err != io.EOF {
fmt.Fprintf(os.Stderr, "error: can't read - %s\n", err)
fmt.Fprintf(os.Stderr, "Error while reading from Stdin. Error: %v\n", err)
}
// io.EOF
break

}

line = strings.TrimSpace(line)
if len(line) > 0 {
if line = strings.TrimSpace(line); line != "" {
parts := strings.Split(line, "\t")

word := parts[0]
countStr := parts[1]

count, err := strconv.Atoi(countStr)
if err != nil {
fmt.Fprintf(os.Stderr, "not a number! ", err)

fmt.Fprintf(os.Stderr, "Error while processing data. Cannot convert string to number. Error: %v/n", err)
break
}
counts[word] = counts[word] + count

}
}

for word, count := range counts {
fmt.Printf("%s\t%d\n", word, count)
}
//fmt.Printf("%s\t%d\n", "test", 8)
}

0 comments on commit 3b9e289

Please sign in to comment.