Esempio n. 1
0
	"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)
}
func WC() {
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
Esempio n. 2
0
	if x*x+y*y < 1 {
		count.Add(float64(1))
	}
})

func init() {
	gopark.RegisterFunc(random_once)
	gopark.RegisterFunc(map_func)
	gopark.RegisterFunc(reducer_func)
}

var map_func = gopark.NewMapperFunc("map_func",
	func(_ interface{}) interface{} {
		x := rand.Float32()
		y := rand.Float32()
		if x*x+y*y < 1 {
			return 1
		} else {
			return 0
		}
	})

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

func main() {
	go func() {
		var m runtime.MemStats
		for {
			runtime.ReadMemStats(&m)
Esempio n. 3
0
var reducer_func = gopark.NewReducerFunc("reducer_func",
	func(x, y interface{}) interface{} {
		return x.(int) + y.(int)
	})

func init() {
	gopark.RegisterFunc(random_once)
	gopark.RegisterFunc(map_func)
	gopark.RegisterFunc(flatmap_func)
	gopark.RegisterFunc(reducer_func)
	gopark.RegisterFunc(filter_func)
	gopark.RegisterFunc(less_func)
}

var map_func = gopark.NewMapperFunc("map_func",
	func(x interface{}) interface{} {
		return &gopark.KeyValue{x, 1}
	})

var filter_func = gopark.NewFilterFunc("filter_func",
	func(x interface{}) bool {
		result := x.(*gopark.KeyValue).Value.(int) > 30
		return result
	})
var less_func = gopark.NewLessFunc("less_func",
	func(x, y interface{}) bool {
		a := x.(*gopark.KeyValue).Value.(int)
		b := y.(*gopark.KeyValue).Value.(int)
		return a < b
	})

func testTextFile() {