示例#1
0
// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file content. the return
// value should be a list of key/value pairs, each represented
// by a mapreduce.KeyValue.
func Map(value string) *list.List {
	f := func(c rune) bool {
		return !unicode.IsLetter(c)
	}
	tks := strings.FieldsFunc(value, f)
	lst := list.New()
	for i := range tks {
		var kv mapreduce.KeyValue
		kv.Key = tks[i]
		kv.Value = "1"
		lst.PushBack(kv)
	}
	return lst
}
示例#2
0
// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file content. the return
// value should be a list of key/value pairs, each represented
// by a mapreduce.KeyValue.
func Map(value string) *list.List {
	// By Yan
	l := list.New()
	f := func(c rune) bool {
		return !unicode.IsLetter(c)
	}
	substrs := strings.FieldsFunc(value, f)
	for _, v := range substrs {
		var kv mapreduce.KeyValue
		kv.Key = v
		kv.Value = "1"
		l.PushBack(kv)
	}

	return l
}
示例#3
0
// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file content. the return
// value should be a list of key/value pairs, each represented
// by a mapreduce.KeyValue.
func Map(value string) *list.List {

	filter := func(c rune) bool {
		return !unicode.IsLetter(c)
	}

	items := list.New()

	for _, v := range strings.FieldsFunc(value, filter) {
		var kv mapreduce.KeyValue
		kv.Key = v
		kv.Value = "1"
		items.PushBack(kv)
	}

	return items
}
示例#4
0
文件: wc.go 项目: simplehpt/lecture
// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file content. the return
// value should be a list of key/value pairs, each represented
// by a mapreduce.KeyValue.
func Map(value string) *list.List {
	list := list.New()

	f := func(c rune) bool {
		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
	}

	array_str := strings.FieldsFunc(value, f)
	for i := 0; i < len(array_str); i++ {
		var kv mapreduce.KeyValue
		kv.Key = array_str[i]
		kv.Value = "1"
		list.PushBack(kv)
	}

	return list
}
示例#5
0
文件: wc.go 项目: samfu1994/6.824
func mapF(document string, value string) (res []mapreduce.KeyValue) {
	// TODO: you have to write this function

	res = make([]mapreduce.KeyValue, 0)
	myMap := make(map[string]int)
	words := strings.FieldsFunc(value, judgeFunc)
	length := len(words)

	for i := 0; i < length; i++ {
		myMap[words[i]]++
	}
	count := 0
	var tmp mapreduce.KeyValue
	for k, v := range myMap {
		tmp.Key = k
		tmp.Value = strconv.Itoa(v)
		res = append(res, tmp)
		count++
	}
	return res
}
示例#6
0
文件: wc.go 项目: tpwow/goMR
// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file content. the return
// value should be a list of key/value pairs, each represented
// by a mapreduce.KeyValue.
func Map(value string) *list.List {
	wordmap := make(map[string]int)
	vals := strings.Split(value, " ")
	for i := 0; i < len(vals); i++ {
		s := vals[i]
		if len(s) > 0 {
			cnt, ok := wordmap[s]
			if ok {
				wordmap[s] = cnt + 1
			} else {
				wordmap[s] = 0
			}
		}
	}
	wordcnt := list.New()
	for word := range wordmap {
		kv := new(mapreduce.KeyValue)
		kv.Key = word
		kv.Value = strconv.Itoa(wordmap[word])
		wordcnt.PushBack(*kv)
	}
	return wordcnt
}