Пример #1
0
package main

import (
	"fmt"
	"github.com/xiexiao/gopark"
	"strings"
)

var (
	fn = gopark.NewFlatMapperFunc("fn", func(x interface{}) []interface{} {
		vals := strings.Fields(x.(string))
		results := make([]interface{}, len(vals))
		for idx, v := range vals {
			results[idx] = v
		}
		return results
	})
	fnMap = gopark.NewMapperFunc("fnMap", func(x interface{}) interface{} {
		return &gopark.KeyValue{x, 1}
	})

	fnReduce = gopark.NewReducerFunc("fnReduce", func(x, y interface{}) interface{} {
		return x.(int) + y.(int)
	})
)

func init() {
	gopark.RegisterFunc(fn)
	gopark.RegisterFunc(fnMap)
	gopark.RegisterFunc(fnReduce)
}
Пример #2
0
	fmt.Println("Pi =", (4.0 * count.Value().(float64) / float64(N)))
}

func main() {
	testTextFile()
}

var flatmap_func = gopark.NewFlatMapperFunc("flatmap_func",
	func(line interface{}) []interface{} {
		vs := strings.Fields(line.(string))
		set := make(map[string]bool)
		for _, v := range vs {
			if _, ok := set[v]; !ok {
				set[v] = true
			}
		}
		words := make([]interface{}, len(set))
		idx := 0
		for k, _ := range set {
			words[idx] = k
			idx += 1
		}
		return words
	})
var reducer_func = gopark.NewReducerFunc("reducer_func",
	func(x, y interface{}) interface{} {
		return x.(int) + y.(int)
	})

func init() {
	gopark.RegisterFunc(random_once)