Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Doug Woos
452-labs
Commits
9e7d4553
Commit
9e7d4553
authored
Jan 02, 2015
by
Irene Y Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding some hints to lab 1 code
parent
712eaf09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
src/main/wc.go
src/main/wc.go
+24
-13
No files found.
src/main/wc.go
View file @
9e7d4553
...
...
@@ -9,10 +9,21 @@ import "container/list"
// key to the Map function, as in the paper; only a value,
// which is a part of the input file contents
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
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:
...
...
@@ -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)
// 3) Worker (e.g., go run wc.go worker localhost:7777 localhost:7778 &)
func
main
()
{
if
len
(
os
.
Args
)
!=
4
{
fmt
.
Printf
(
"%s: see usage comments in file
\n
"
,
os
.
Args
[
0
])
}
else
if
os
.
Args
[
1
]
==
"master"
{
if
os
.
Args
[
3
]
==
"sequential"
{
mapreduce
.
RunSingle
(
5
,
3
,
os
.
Args
[
2
],
Map
,
Reduce
)
}
else
{
mr
:=
mapreduce
.
MakeMapReduce
(
5
,
3
,
os
.
Args
[
2
],
os
.
Args
[
3
])
// Wait until MR is done
<-
mr
.
DoneChannel
}
}
else
{
mapreduce
.
RunWorker
(
os
.
Args
[
2
],
os
.
Args
[
3
],
Map
,
Reduce
,
100
)
}
if
len
(
os
.
Args
)
!=
4
{
fmt
.
Printf
(
"%s: see usage comments in file
\n
"
,
os
.
Args
[
0
])
}
else
if
os
.
Args
[
1
]
==
"master"
{
if
os
.
Args
[
3
]
==
"sequential"
{
mapreduce
.
RunSingle
(
5
,
3
,
os
.
Args
[
2
],
Map
,
Reduce
)
}
else
{
mr
:=
mapreduce
.
MakeMapReduce
(
5
,
3
,
os
.
Args
[
2
],
os
.
Args
[
3
])
// Wait until MR is done
<-
mr
.
DoneChannel
}
}
else
{
mapreduce
.
RunWorker
(
os
.
Args
[
2
],
os
.
Args
[
3
],
Map
,
Reduce
,
100
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment