partV

创建文档反向索引。word -> document
与 前面做的 单词统计类似,这个是单词与文档位置的映射关系。
mapF 文档解析相同,返回信息不同而已。
reduceF 返回归约都的字符串,返回document 切片 转成 string 使用 strings.join 。
 
master@master:~/study/6.824/src/main$ go run ii.go master sequential pg-*.txt
ii.go:9:8: cannot find package "mapreduce" in any of:
/usr/local/go/src/mapreduce (from $GOROOT)
/home/master/go/src/mapreduce (from $GOPATH)

找不到 mapReduce 包,把mapReduce 添加到 path
$ cd 6.824
$ export "GOPATH=$PWD" # go needs $GOPATH to be set to the project's working directory
 

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的更多相关文章

  1. 6.828 lab1 bootload

    MIT6.828 lab1地址:http://pdos.csail.mit.edu/6.828/2014/labs/lab1/ 第一个练习,主要是让我们熟悉汇编,嗯,没什么好说的. Part 1: P ...

  2. Machine Learning #Lab1# Linear Regression

    Machine Learning Lab1 打算把Andrew Ng教授的#Machine Learning#相关的6个实验一一实现了贴出来- 预计时间长度战线会拉的比較长(毕竟JOS的7级浮屠还没搞 ...

  3. ucore lab1 bootloader学习笔记

    ---恢复内容开始--- 开机流程回忆 以Intel 80386为例,计算机加电后,CPU从物理地址0xFFFFFFF0(由初始化的CS:EIP确定,此时CS和IP的值分别是0xF000和0xFFF0 ...

  4. 6.824 LAB1 环境搭建

    MIT 6.824 LAB1 环境搭建 vmware 虚拟机 linux ubuntu server   安装 go 官方安装步骤: 下载此压缩包并提取到 /usr/local 目录,在 /usr/l ...

  5. 软件测试:lab1.Junit and Eclemma

    软件测试:lab1.Junit and Eclemma Task: Install Junit(4.12), Hamcrest(1.3) with Eclipse Install Eclemma wi ...

  6. MIT 6.824 lab1:mapreduce

    这是 MIT 6.824 课程 lab1 的学习总结,记录我在学习过程中的收获和踩的坑. 我的实验环境是 windows 10,所以对lab的code 做了一些环境上的修改,如果你仅仅对code 感兴 ...

  7. 清华大学OS操作系统实验lab1练习知识点汇总

    lab1知识点汇总 还是有很多问题,但是我觉得我需要在查看更多资料后回来再理解,学这个也学了一周了,看了大量的资料...还是它们自己的80386手册和lab的指导手册觉得最准确,现在我就把这部分知识做 ...

  8. JOS lab1 part2 分析

    lab1的Exercise 2就是让我们熟悉gdb的si操作,并知道BIOS的几条指令在做什么就够了,所以我们也会尽可能的去分析每一行代码. 首先进入到6.8282/lab这个目录下,输入指令make ...

  9. MIT 操作系统实验 MIT JOS lab1

    JOS lab1 首先向MIT还有K&R致敬! 没有非常好的开源环境我不可能拿到这么好的东西. 向每个与我一起交流讨论的programmer致谢!没有道友一起死磕.我也可能会中途放弃. 跟丫死 ...

随机推荐

  1. windows 环境下mysql 重置密码解决方案

    1.打开本地安装MySQL的安装目录,如:D:\software\mysql-5.7.20-winx64 进入bin目录,执行如下命令: mysqld -nt --skip-grant-tables ...

  2. keil折叠代码

    在代码页面右键 Outlining->Start All Outlining

  3. Web服务器软件 (Tomcat)

    1.什么是服务器? 安装了服务器的软件的计算机 服务器软件:接收用户的请求(request),处理请求,做出响应. Web服务器软件:接收用户的请求(request),处理请求,做出响应,再Web服务 ...

  4. Minimum Spanning Trees

    Kruskal’s algorithm always union the lightest link if two sets haven't been linked typedef struct { ...

  5. 禁用ViewPager的滑动事件

    public class NoScrollViewPager extends ViewPager { private boolean noScroll = false; public NoScroll ...

  6. Matlab_ eval 批量定义变量

    本文备忘 Matlab 中批量定义变量的方法. 参考: [1] matlab中批量赋值与声明变量(eval函数) [2] MathWorks eval 缘起与说明 当变量名称多到一定程度时,变量名的管 ...

  7. pycharm介绍

      PyCharm是一种Python IDE(集成开发软件),带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具. 1.1 PyCharm主界面 PyCharm包含4个主要区分,分别为 ...

  8. ES5数组、对象常用方法总结

    数组方法: Array.isArray(items);判断判断一个变量是否包含数组数据: forEach(function(value, index, fullArray){ }); every(fu ...

  9. Tecplot: 多截面云图显示

    [原创]禁止转载,需要转载请联系作者 想要使用Tecplot显示图1中这样一张云图,即删除掉接近0的一些正负的压力值,尝试了多种方法后成功实现: 图1 多截面云图显示 问题:如何去掉 -0.3< ...

  10. VS2010与Matlab2010b混合编程

    环境: 1.VS2010 2.MATLAB 2010b 3.WINDOW 7 (X64) 1.Matlab环境设置 要建立独立运行的C应用程序,系统中需要安装Matlab.Matlab编译器.C/C+ ...