LAB1 partII


wc.go
package main import (
"fmt"
"mapreduce"
"os"
"strings"
"unicode"
"strconv"
) //
// The map function is called once for each file of input. The first
// argument is the name of the input file, and the second is the
// file's complete contents. You should ignore the input file name,
// and look only at the contents argument. The return value is a slice
// of key/value pairs.
//
func mapF(filename string, contents string) []mapreduce.KeyValue {
// Your code here (Part II). f := func(c rune) bool {
return !unicode.IsLetter(c)
}
rst := make([]mapreduce.KeyValue, ) keys := strings.FieldsFunc(contents, f)
for _, key := range keys {
kv := mapreduce.KeyValue{ Key: key, Value:""}
rst = append(rst, kv)
}
return rst
} //
// The reduce function is called once for each key generated by the
// map tasks, with a list of all the values created for that key by
// any map task.
//
func reduceF(key string, values []string) string {
// Your code here (Part II).
cnt := for _ , val := range values { i , err := strconv.Atoi(val);
if err != nil {
panic(err)
}
cnt += i
} rst := strconv.Itoa(cnt)
return rst
} // Can be run in 3 ways:
// 1) Sequential (e.g., go run wc.go master sequential x1.txt .. xN.txt)
// 2) Master (e.g., go run wc.go master localhost:7777 x1.txt .. xN.txt)
// 3) Worker (e.g., go run wc.go worker localhost:7777 localhost:7778 &)
func main() {
if len(os.Args) < {
fmt.Printf("%s: see usage comments in file\n", os.Args[])
} else if os.Args[] == "master" {
var mr *mapreduce.Master
if os.Args[] == "sequential" {
mr = mapreduce.Sequential("wcseq", os.Args[:], , mapF, reduceF)
} else {
mr = mapreduce.Distributed("wcseq", os.Args[:], , os.Args[])
}
mr.Wait()
} else {
mapreduce.RunWorker(os.Args[], os.Args[], mapF, reduceF, , nil)
}
}
LAB1 partII的更多相关文章
- MIT 6.824学习笔记4 Lab1
现在我们准备做第一个作业Lab1啦 wjk大神也在做6.824,可以参考大神的笔记https://github.com/zzzyyyxxxmmm/MIT6824_Distribute_System P ...
- 6.828 lab1 bootload
MIT6.828 lab1地址:http://pdos.csail.mit.edu/6.828/2014/labs/lab1/ 第一个练习,主要是让我们熟悉汇编,嗯,没什么好说的. Part 1: P ...
- Machine Learning #Lab1# Linear Regression
Machine Learning Lab1 打算把Andrew Ng教授的#Machine Learning#相关的6个实验一一实现了贴出来- 预计时间长度战线会拉的比較长(毕竟JOS的7级浮屠还没搞 ...
- ucore lab1 bootloader学习笔记
---恢复内容开始--- 开机流程回忆 以Intel 80386为例,计算机加电后,CPU从物理地址0xFFFFFFF0(由初始化的CS:EIP确定,此时CS和IP的值分别是0xF000和0xFFF0 ...
- LAB1 partV
partV 创建文档反向索引.word -> document 与 前面做的 单词统计类似,这个是单词与文档位置的映射关系. mapF 文档解析相同,返回信息不同而已. reduceF 返回归约 ...
- 6.824 LAB1 环境搭建
MIT 6.824 LAB1 环境搭建 vmware 虚拟机 linux ubuntu server 安装 go 官方安装步骤: 下载此压缩包并提取到 /usr/local 目录,在 /usr/l ...
- 软件测试:lab1.Junit and Eclemma
软件测试:lab1.Junit and Eclemma Task: Install Junit(4.12), Hamcrest(1.3) with Eclipse Install Eclemma wi ...
- MIT 6.824 lab1:mapreduce
这是 MIT 6.824 课程 lab1 的学习总结,记录我在学习过程中的收获和踩的坑. 我的实验环境是 windows 10,所以对lab的code 做了一些环境上的修改,如果你仅仅对code 感兴 ...
- 清华大学OS操作系统实验lab1练习知识点汇总
lab1知识点汇总 还是有很多问题,但是我觉得我需要在查看更多资料后回来再理解,学这个也学了一周了,看了大量的资料...还是它们自己的80386手册和lab的指导手册觉得最准确,现在我就把这部分知识做 ...
随机推荐
- key单片机按键抖动
//write by:cyt //Time:2017-2-10 //Porject Name:key shake_destory #include<reg51.h> #define GPI ...
- 西门子SCL读写DB数据
数据块间接寻址方式,仅供参考. STATUS_1:= DB11.DW[COUNTER]; //字节间接寻址STATUS_2:= DB12.DX[WNO, BITNO]; //位间接寻址,用户改变WNO ...
- Ubuntu如何使用Vscode写C++代码
(一). 下载Vscode (1). 打开Ubuntu软件 (2). 搜索Vscode,下载并运行. (二). 安装C++ (1). 看到右边的列表,点击最下面的 (2). 然后我们搜索和下载 C++ ...
- 前段时间碰到的一些问题(免费WiFi设置+fiddler对手机进行抓包+fiddler抓不到https的请求)
这段时间转入移动端测试,对这块比较陌生,工作开展起来比较困难,所以好多东西都只是以解决问题为第一目标,没有去细细推敲其中原理,可能会有些语无伦次之感,但还是记一下当时解决问题的大致思路,供以后参考. ...
- Vue基础之内部指令(上)
v-if.v-else-if.v-else以及v-show 条件指令v-if.v-else-if.v-else 类似于JavaScript里的if.else-if.else,这三个指令根据表达式的值对 ...
- Bartender标签传参与打印
在VS中添加bartender的COM组件引用后(一定要添加,否则会提示找不到BarTender.Application): /// <summary> /// Bartender模板打印 ...
- Spring Boot 定时任务使用
详情参考文章https://blog.csdn.net/qq_31001665/article/details/76408929
- 软件开发者路线图梗概&书摘chapter6
安排你的课程:靠自己去寻求建议,安排课程 1.阅读列表:维护一张列表,更新未读和已读 保存在公共空间 得出模式.趋势.缺口,决定下一步,得到建议 参考书目形成优先级队列 从宽泛的读起,指导者推荐 能使 ...
- Thread.yield( )通俗理解
一. Thread.yield( )方法: 使当前线程从执行状态(运行状态)变为可执行态(就绪状态).cpu会从众多的可执行态里选择,也就是说,当前也就是刚刚的那个线程还是有可能会被再次执行到的,并不 ...
- 将 windows 目录结构 复制到 linux 上
思路:生成目录结构文件,复制到linux上,然后建立每个文件即可 借助unix_utils( https://sourceforge.net/projects/unxutils/) 1. window ...