Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (50 sloc) 1.4 KB
package mapreduce
import (
"fmt"
"strconv"
)
// Debugging enabled?
const debugEnabled = false
/* debug() will only print if debugEnabled is true
调用 debug("Reduce %s %v\n", key, e)
再举一个例子
func sum(nums ...int) {
fmt.Print(nums, " ")
total := 0
for _, num := range nums {
total += num
}
fmt.Println(total)
}
sum(1, 2) 这个函数可以传入任意数量的整型参数
sum(1, 2, 3)
nums := []int{1, 2, 3, 4} 传入切片
sum(nums...)
*/
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)
}