• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang worker.Tuple类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中worker.Tuple的典型用法代码示例。如果您正苦于以下问题:Golang Tuple类的具体用法?Golang Tuple怎么用?Golang Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Tuple类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {

	file, err := os.Create("output.txt")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	count := make(map[string]int)

	worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) {
		switch index {
		case 0:
			num, _ := strconv.Atoi(tuple.Slice[1])
			count[tuple.Slice[0]] += num
		case 1:
			num, _ := strconv.Atoi(tuple.Slice[1])
			count[tuple.Slice[0]] += num
		case 2:
			num, _ := strconv.Atoi(tuple.Slice[1])
			count[tuple.Slice[0]] -= num
		}
	})

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	for key, value := range count {
		file.Write([]byte(key + ", " + strconv.Itoa(value) + "\n"))
		outTuple := worker.Tuple{[]string{key, strconv.Itoa(value)}}
		stdout.Write(outTuple.SerializeTuple(0))
		stdout.Write([]byte{'\n'})
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:33,代码来源:output.go


示例2: main

func main() {

	// read from standard input to get the input tuples
	inputTuples := make([]worker.Tuple, 0)
	worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) {
		inputTuples = append(inputTuples, tuple)
	})

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	counts := make(map[string]int)
	for _, tuple := range inputTuples {
		word := tuple.Slice[0]

		if count, ok := counts[word]; ok {
			counts[word] = count + 1
		} else {
			counts[word] = 1
		}
	}

	for word, count := range counts {
		outTuple := worker.Tuple{[]string{word, strconv.Itoa(count)}}
		stdout.Write(outTuple.SerializeTuple(0))
		stdout.Write([]byte{'\n'})
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:27,代码来源:wordcount_reduce.go


示例3: main

// go run input.go start_time duration number_of_log random_seed
// go run input.go now 60 2000 5
func main() {
	d, _ := strconv.Atoi(os.Args[2])
	duration := time.Second * time.Duration(d)

	startTime := time.Now() // os.Args[1]

	num, _ := strconv.Atoi(os.Args[3])

	seed, _ := strconv.ParseInt(os.Args[4], 10, 64)

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	r := rand.New(rand.NewSource(seed))

	step := duration / time.Duration(num)

	for st := startTime; st.Before(startTime.Add(duration)); st = st.Add(step) {
		s := []string{"[" + st.String() + "]"}

		if r.Float32() < 0.1 {
			s = append(s, "error")
		} else {
			s = append(s, "pass")
		}

		tuple := worker.Tuple{s}
		stdout.Write(tuple.SerializeTuple(0))
		stdout.Write([]byte{'\n'})
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:32,代码来源:input.go


示例4: main

func main() {

	// read from standard input to get the input tuples
	newTuples := make([]worker.Tuple, 0)
	oldTuples := make([]worker.Tuple, 0)
	totalTuples := make([]worker.Tuple, 0)

	worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) {
		switch index {
		case 0:
			newTuples = append(newTuples, tuple)
		case 1:
			oldTuples = append(oldTuples, tuple)
		case 2:
			totalTuples = append(totalTuples, tuple)
		}
	})

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	counts := make(map[string]int)
	for _, tuple := range totalTuples {
		word := tuple.Slice[0]
		prev, _ := strconv.Atoi(tuple.Slice[1])

		if count, ok := counts[word]; ok {
			counts[word] = count + prev
		} else {
			counts[word] = prev
		}
	}

	for _, tuple := range newTuples {
		word := tuple.Slice[0]

		if count, ok := counts[word]; ok {
			counts[word] = count + 1
		} else {
			counts[word] = 1
		}
	}

	for _, tuple := range oldTuples {
		word := tuple.Slice[0]

		if count, ok := counts[word]; ok {
			counts[word] = count - 1
		}
	}

	for word, count := range counts {
		outTuple := worker.Tuple{[]string{word, strconv.Itoa(count)}}

		stdout.Write(outTuple.SerializeTuple(2))
		stdout.Write([]byte{'\n'})
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:57,代码来源:combine.go


示例5: main

func main() {

	// read from standard input to get the input tuples
	inputTuples := make([]worker.Tuple, 0)
	worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) {
		inputTuples = append(inputTuples, tuple)
	})

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	for _, tuple := range inputTuples {
		words := strings.Fields(tuple.Slice[1])

		for _, word := range words {
			word = strings.ToLower(word)
			if word == "error" {
				outTuple := worker.Tuple{[]string{word, "1"}}
				stdout.Write(outTuple.SerializeTuple(0))
				stdout.Write([]byte{'\n'})
			}
		}
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:23,代码来源:map.go


示例6: main

func main() {
	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	t := time.Now()
	strings := []string{"Zack", "Jeff", "Vedha", "Vikas", "Zack"}

	for i := 0; i < 1000; i++ {
		for _, str := range strings {
			tuple := worker.Tuple{[]string{str, t.String()}}
			stdout.Write(tuple.SerializeTuple(0))
			stdout.Write([]byte{'\n'})
		}
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:14,代码来源:mock_log_reader.go


示例7: main

func main() {

	count := make(map[string]int)

	worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) {
		count[tuple.Slice[0]] += 1
	})

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	for key, value := range count {
		outTuple := worker.Tuple{[]string{key, strconv.Itoa(value)}}
		stdout.Write(outTuple.SerializeTuple(0))
		stdout.Write([]byte{'\n'})
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:16,代码来源:reduce.go


示例8: main

func main() {
	gopath := os.Getenv("GOPATH")
	path := path.Join(gopath, "/src/demo/wordcount_go/input_file.txt")

	file, err := os.Open(path)
	if err != nil {
		log.Panic(err)
	}
	defer file.Close()

	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		tuple := worker.Tuple{[]string{scanner.Text()}}

		stdout.Write(tuple.SerializeTuple(0))
		stdout.Write([]byte{'\n'})
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:20,代码来源:wordcount_input.go


示例9: main

func main() {

	// read input from standard input and create tuples
	inputTuples := make([]worker.Tuple, 0)
	worker.ReadTupleStream(os.Stdin, func(tuple worker.Tuple, index int) {
		inputTuples = append(inputTuples, tuple)
	})

	// get standard output
	stdout := os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")

	// iterate over input tuples
	for _, tuple := range inputTuples {
		words := strings.Fields(tuple.Slice[0])
		// iterate over words
		for _, word := range words {
			// emit each word in a new tuple
			outTuple := worker.Tuple{[]string{strings.ToLower(word), "1"}}
			stdout.Write(outTuple.SerializeTuple(0))
			stdout.Write([]byte{'\n'})
		}
	}
}
开发者ID:jtwarren,项目名称:Hurricane,代码行数:23,代码来源:wordcount_map.go



注:本文中的worker.Tuple类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang module_state2.State类代码示例发布时间:2022-05-28
下一篇:
Golang db.Env类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap