-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
43 lines (35 loc) · 1.09 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package mapreduce
import (
"fmt"
"strconv"
)
// Debugging enabled?
const debugEnabled = false
// DPrintf will only print if the debugEnabled const has been set to true
func debug(format string, a ...interface{}) (n int, err error) {
if debugEnabled {
n, err = fmt.Printf(format, a...)
}
return
}
// jobPhase indicates whether a task is scheduled as a map or reduce task.
type jobPhase string
const (
mapPhase jobPhase = "Map"
reducePhase = "Reduce"
)
// KeyValue is a type used to hold the key/value pairs passed to the map and
// reduce functions.
type KeyValue struct {
Key string
Value string
}
// reduceName constructs the name of the intermediate file which map task
// <mapTask> produces for reduce task <reduceTask>.
func reduceName(jobName string, mapTask int, reduceTask int) string {
return "mrtmp." + jobName + "-" + strconv.Itoa(mapTask) + "-" + strconv.Itoa(reduceTask)
}
// mergeName constructs the name of the output file of reduce task <reduceTask>
func mergeName(jobName string, reduceTask int) string {
return "mrtmp." + jobName + "-res-" + strconv.Itoa(reduceTask)
}