LAB1 partV
partV


bash ./test-ii.sh 直接测试程序结果。
ii.go
package main import (
"os"
"strings"
"unicode"
"strconv"
)
import "fmt"
import "mapreduce" // The mapping function is called once for each piece of the input.
// In this framework, the key is the name of the file that is being processed,
// and the value is the file's contents. The return value should be a slice of
// key/value pairs, each represented by a mapreduce.KeyValue.
func mapF(document string, value string) (res []mapreduce.KeyValue) {
// Your code here (Part V).
f := func(c rune) bool {
return !unicode.IsLetter(c)
}
rst := make([]mapreduce.KeyValue, ) keys := strings.FieldsFunc(value, f)
for _, key := range keys {
kv := mapreduce.KeyValue{ Key: key, Value:document}
rst = append(rst, kv)
}
return rst
} // The reduce function is called once for each key generated by Map, with a
// list of that key's string value (merged across all inputs). The return value
// should be a single output value for that key.
func reduceF(key string, values []string) string {
// Your code here (Part V).
vm := make(map[string]string)
var rst []string
for _, value := range values {
if _, ok := vm[value]; !ok {
rst = append(rst, value)
vm[value] = value
}
} vl := strings.Join(rst, ",")
return strconv.Itoa(len(rst)) + " " + vl
} // 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("iiseq", os.Args[:], , mapF, reduceF)
} else {
mr = mapreduce.Distributed("iiseq", os.Args[:], , os.Args[])
}
mr.Wait()
} else {
mapreduce.RunWorker(os.Args[], os.Args[], mapF, reduceF, , nil)
}
}
上面LAB1 五部分一起测试。
LABI 完成。
LAB1 partV的更多相关文章
- 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 ...
- 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的指导手册觉得最准确,现在我就把这部分知识做 ...
- JOS lab1 part2 分析
lab1的Exercise 2就是让我们熟悉gdb的si操作,并知道BIOS的几条指令在做什么就够了,所以我们也会尽可能的去分析每一行代码. 首先进入到6.8282/lab这个目录下,输入指令make ...
- MIT 操作系统实验 MIT JOS lab1
JOS lab1 首先向MIT还有K&R致敬! 没有非常好的开源环境我不可能拿到这么好的东西. 向每个与我一起交流讨论的programmer致谢!没有道友一起死磕.我也可能会中途放弃. 跟丫死 ...
随机推荐
- web后台工作流程
浏览器的主要功能是将用户选择的web资源呈现出来,它需要从服务器请求资源,并将其显示在浏览器窗口中,资源的格式通常是HTML,也包括PDF.image及其他格式.用户用URI(Uniform Reso ...
- redis学习步骤
Redis简介 redis全称REmote DIctionary Server,是一个由Salvatore Sanfilippo写的高性能key-value存储系统,其完全开源免费,遵守BSD协议.R ...
- entrySet用法 以及遍历map的用法
entrySet用法 以及遍历map的用法 keySet是键的集合,Set里面的类型即key的类型entrySet是 键-值 对的集合,Set里面的类型是Map.Entry 1.keySet( ...
- outlook2010设置失败后重新设置
1.WIN+R ,然后在弹出框中输入outlook /importprf .\.prf 2.重新设置.
- MYSQL HA 部署手册
1 MySQL启用主主双写复制 1.1 卸载系统默认的数据库mariadb 安装mysql出现安装包不兼容问题,首先卸载掉系统自带mariadb 查看已经安装的mariadb rpm -qa|grep ...
- NSTimer应用
NSTimer应用 在参与项目开发中遇到了NSTimer的应用,虽然我负责的模块内只用到了一小部分,但我觉得还是有必要拿出来好好琢磨一下. 一.概念(来自官方描述) 官网上最新的定义是“A timer ...
- angular js 初学
1 angularJS的一些概念 AngularJS 通过新的属性和表达式扩展了 HTML. AngularJS 是一个 JavaScript 框架,它是一个以Javascript编写的库,它可通过 ...
- MHA-Atlas-MySQL高可用集群
主机名映射 [root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 loca ...
- python批量下载微信好友头像,微信头像批量下载
#!/usr/bin/python #coding=utf8 # 自行下载微信模块 itchat 小和QQ496631085 import itchat,os itchat.auto_login() ...
- introduce of servlet and filter
servlet简介: Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中 ...