Skip to content
This repository
Newer
Older
100644 370 lines (303 sloc) 9.673 kb
640886ce »
2011-08-25 Polymorphic MapReduce!
1 /**
2 A parallel word-frequency counting program.
3
4 This is meant primarily to demonstrate Rust's MapReduce framework.
5
6 It takes a list of files on the command line and outputs a list of
7 words along with how many times each word is used.
8
9 */
10
05543fd0 »
2012-07-12 Make tests pass
11 // xfail-pretty
12
640886ce »
2011-08-25 Polymorphic MapReduce!
13 use std;
14
f686896f »
2012-09-05 test: "import" -> "use"
15 use option = option;
16 use option::Some;
17 use option::None;
18 use std::map;
19 use std::map::hashmap;
20 use io::WriterUtil;
21
22 use std::time;
23
24 use comm::Chan;
25 use comm::Port;
26 use comm::recv;
27 use comm::send;
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
28
38891b91 »
2012-08-22 Update invocation syntax for `macro_rules!`
29 macro_rules! move_out (
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
30 { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
38891b91 »
2012-08-22 Update invocation syntax for `macro_rules!`
31 )
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
32
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
33 trait word_reader {
8337fa1a »
2012-08-20 Camel case the option type
34 fn read_word() -> Option<~str>;
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
35 }
36
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
37 trait hash_key {
97452c0c »
2012-08-02 Remove modes from map API and replace with regions.
38 pure fn hash() -> uint;
39 pure fn eq(&&k: self) -> bool;
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
40 }
41
42 fn mk_hash<K: const hash_key, V: copy>() -> map::hashmap<K, V> {
97452c0c »
2012-08-02 Remove modes from map API and replace with regions.
43 pure fn hashfn<K: const hash_key>(k: &K) -> uint { k.hash() }
44 pure fn hasheq<K: const hash_key>(k1: &K, k2: &K) -> bool { k1.eq(*k2) }
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
45
97452c0c »
2012-08-02 Remove modes from map API and replace with regions.
46 map::hashmap(hashfn, hasheq)
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
47 }
48
6a0720b4 »
2012-08-07 Convert impls to new syntax
49 impl ~str: hash_key {
97452c0c »
2012-08-02 Remove modes from map API and replace with regions.
50 pure fn hash() -> uint { str::hash(&self) }
51 pure fn eq(&&x: ~str) -> bool { self == x }
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
52 }
53
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
54 // These used to be in task, but they disappeard.
9c6890f4 »
2012-08-15 Convert more core types to camel case
55 type joinable_task = Port<()>;
d1fc2b59 »
2012-06-30 Convert to new closure syntax
56 fn spawn_joinable(+f: fn~()) -> joinable_task {
161a82e4 »
2012-08-27 Camel case various core constructors
57 let p = Port();
58 let c = Chan(p);
d1fc2b59 »
2012-06-30 Convert to new closure syntax
59 do task::spawn() |move f| {
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
60 f();
61 c.send(());
62 }
63 p
64 }
65
66 fn join(t: joinable_task) {
67 t.recv()
68 }
640886ce »
2011-08-25 Polymorphic MapReduce!
69
11258310 »
2012-08-14 Convert more core types to camel case
70 impl io::Reader: word_reader {
8337fa1a »
2012-08-20 Camel case the option type
71 fn read_word() -> Option<~str> { read_word(self) }
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
72 }
73
92743dc2 »
2012-07-13 Move the world over to using the new style string literals and types.…
74 fn file_word_reader(filename: ~str) -> word_reader {
c284b8b1 »
2012-08-24 Start using core::path2::Path in a lot of places.
75 match io::file_reader(&Path(filename)) {
0c6e470a »
2012-08-26 Convert core::result to camel case
76 result::Ok(f) => { f as word_reader }
77 result::Err(e) => { fail fmt!("%?", e) }
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
78 }
79 }
640886ce »
2011-08-25 Polymorphic MapReduce!
80
92743dc2 »
2012-07-13 Move the world over to using the new style string literals and types.…
81 fn map(f: fn~() -> word_reader, emit: map_reduce::putter<~str, int>) {
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
82 let f = f();
321fd802 »
2012-03-09 Add an infinite loop construct
83 loop {
ecaf9e39 »
2012-08-06 Convert alt to match. Stop parsing alt
84 match f.read_word() {
8337fa1a »
2012-08-20 Camel case the option type
85 Some(w) => { emit(w, 1); }
86 None => { break; }
640886ce »
2011-08-25 Polymorphic MapReduce!
87 }
88 }
89 }
90
92743dc2 »
2012-07-13 Move the world over to using the new style string literals and types.…
91 fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
92 let mut count = 0;
640886ce »
2011-08-25 Polymorphic MapReduce!
93
8337fa1a »
2012-08-20 Camel case the option type
94 loop { match get() { Some(_) => { count += 1; } None => { break; } } }
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
95
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
96 io::println(fmt!("%s\t%?", word, count));
640886ce »
2011-08-25 Polymorphic MapReduce!
97 }
98
3ab4b014 »
2012-08-15 Remove the class keyword
99 struct box<T> {
2572e803 »
2012-09-06 Remove 'let' syntax for struct fields
100 mut contents: Option<T>,
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
101
102 fn swap(f: fn(+T) -> T) {
8337fa1a »
2012-08-20 Camel case the option type
103 let mut tmp = None;
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
104 self.contents <-> tmp;
8337fa1a »
2012-08-20 Camel case the option type
105 self.contents = Some(f(option::unwrap(tmp)));
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
106 }
107
108 fn unwrap() -> T {
8337fa1a »
2012-08-20 Camel case the option type
109 let mut tmp = None;
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
110 self.contents <-> tmp;
111 option::unwrap(tmp)
112 }
113 }
114
b4e547d7 »
2012-09-05 Remove struct ctors
115 fn box<T>(+x: T) -> box<T> {
116 box {
117 contents: Some(x)
118 }
119 }
120
640886ce »
2011-08-25 Polymorphic MapReduce!
121 mod map_reduce {
122 export putter;
123 export getter;
124 export mapper;
125 export reducer;
126 export map_reduce;
127
60ae1590 »
2012-01-05 Switch to new param kind bound syntax
128 type putter<K: send, V: send> = fn(K, V);
640886ce »
2011-08-25 Polymorphic MapReduce!
129
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
130 type mapper<K1: send, K2: send, V: send> = fn~(K1, putter<K2, V>);
640886ce »
2011-08-25 Polymorphic MapReduce!
131
8337fa1a »
2012-08-20 Camel case the option type
132 type getter<V: send> = fn() -> Option<V>;
640886ce »
2011-08-25 Polymorphic MapReduce!
133
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
134 type reducer<K: copy send, V: copy send> = fn~(K, getter<V>);
640886ce »
2011-08-25 Polymorphic MapReduce!
135
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
136 enum ctrl_proto<K: copy send, V: copy send> {
9c6890f4 »
2012-08-15 Convert more core types to camel case
137 find_reducer(K, Chan<Chan<reduce_proto<V>>>),
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
138 mapper_done
640886ce »
2011-08-25 Polymorphic MapReduce!
139 }
140
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
141
77e83d83 »
2012-08-22 Change calls of `proto!` to use parens.
142 proto! ctrl_proto (
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
143 open: send<K: copy send, V: copy send> {
144 find_reducer(K) -> reducer_response<K, V>,
6748f78c »
2012-07-25 Polymorphic protocols work well enough to do MapReduce.
145 mapper_done -> !
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
146 }
147
148 reducer_response: recv<K: copy send, V: copy send> {
9c6890f4 »
2012-08-15 Convert more core types to camel case
149 reducer(Chan<reduce_proto<V>>) -> open<K, V>
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
150 }
77e83d83 »
2012-08-22 Change calls of `proto!` to use parens.
151 )
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
152
c5437c0b »
2012-07-31 Fix failing tests
153 enum reduce_proto<V: copy send> { emit_val(V), done, addref, release }
640886ce »
2011-08-25 Polymorphic MapReduce!
154
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
155 fn start_mappers<K1: copy send, K2: const copy send hash_key,
156 V: copy send>(
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
157 map: mapper<K1, K2, V>,
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
158 &ctrls: ~[ctrl_proto::server::open<K2, V>],
159 inputs: ~[K1])
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
160 -> ~[joinable_task]
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
161 {
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
162 let mut tasks = ~[];
d1fc2b59 »
2012-06-30 Convert to new closure syntax
163 for inputs.each |i| {
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
164 let (ctrl, ctrl_server) = ctrl_proto::init();
165 let ctrl = box(ctrl);
bf88ff52 »
2012-07-11 Remove slow vec+=, and make word-count difficulty harder.
166 vec::push(tasks, spawn_joinable(|| map_task(map, ctrl, i) ));
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
167 vec::push(ctrls, ctrl_server);
640886ce »
2011-08-25 Polymorphic MapReduce!
168 }
b355936b »
2012-08-01 Convert ret to return
169 return tasks;
640886ce »
2011-08-25 Polymorphic MapReduce!
170 }
171
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
172 fn map_task<K1: copy send, K2: const copy send hash_key, V: copy send>(
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
173 map: mapper<K1, K2, V>,
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
174 ctrl: box<ctrl_proto::client::open<K2, V>>,
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
175 input: K1)
176 {
f0dfbe7b »
2011-12-22 Register new snapshots, purge log_err and log_full in favour of log(.…
177 // log(error, "map_task " + input);
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
178 let intermediates = mk_hash();
640886ce »
2011-08-25 Polymorphic MapReduce!
179
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
180 do map(input) |key, val| {
8337fa1a »
2012-08-20 Camel case the option type
181 let mut c = None;
ecaf9e39 »
2012-08-06 Convert alt to match. Stop parsing alt
182 match intermediates.find(key) {
8337fa1a »
2012-08-20 Camel case the option type
183 Some(_c) => { c = Some(_c); }
184 None => {
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
185 do ctrl.swap |ctrl| {
186 let ctrl = ctrl_proto::client::find_reducer(ctrl, key);
ecaf9e39 »
2012-08-06 Convert alt to match. Stop parsing alt
187 match pipes::recv(ctrl) {
025d8662 »
2012-08-03 Switch alts to use arrows
188 ctrl_proto::reducer(c_, ctrl) => {
8337fa1a »
2012-08-20 Camel case the option type
189 c = Some(c_);
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
190 move_out!(ctrl)
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
191 }
192 }
193 }
194 intermediates.insert(key, c.get());
c5437c0b »
2012-07-31 Fix failing tests
195 send(c.get(), addref);
640886ce »
2011-08-25 Polymorphic MapReduce!
196 }
197 }
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
198 send(c.get(), emit_val(val));
640886ce »
2011-08-25 Polymorphic MapReduce!
199 }
200
9c6890f4 »
2012-08-15 Convert more core types to camel case
201 fn finish<K: copy send, V: copy send>(_k: K, v: Chan<reduce_proto<V>>)
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
202 {
640886ce »
2011-08-25 Polymorphic MapReduce!
203 send(v, release);
204 }
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
205 for intermediates.each_value |v| { send(v, release) }
206 ctrl_proto::client::mapper_done(ctrl.unwrap());
640886ce »
2011-08-25 Polymorphic MapReduce!
207 }
208
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
209 fn reduce_task<K: copy send, V: copy send>(
210 reduce: reducer<K, V>,
211 key: K,
9c6890f4 »
2012-08-15 Convert more core types to camel case
212 out: Chan<Chan<reduce_proto<V>>>)
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
213 {
161a82e4 »
2012-08-27 Camel case various core constructors
214 let p = Port();
640886ce »
2011-08-25 Polymorphic MapReduce!
215
161a82e4 »
2012-08-27 Camel case various core constructors
216 send(out, Chan(p));
640886ce »
2011-08-25 Polymorphic MapReduce!
217
4dcf84e4 »
2012-06-19 Remove bind. Issue #2189
218 let mut ref_count = 0;
219 let mut is_done = false;
640886ce »
2011-08-25 Polymorphic MapReduce!
220
9c6890f4 »
2012-08-15 Convert more core types to camel case
221 fn get<V: copy send>(p: Port<reduce_proto<V>>,
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
222 &ref_count: int, &is_done: bool)
8337fa1a »
2012-08-20 Camel case the option type
223 -> Option<V> {
640886ce »
2011-08-25 Polymorphic MapReduce!
224 while !is_done || ref_count > 0 {
ecaf9e39 »
2012-08-06 Convert alt to match. Stop parsing alt
225 match recv(p) {
025d8662 »
2012-08-03 Switch alts to use arrows
226 emit_val(v) => {
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
227 // error!("received %d", v);
8337fa1a »
2012-08-20 Camel case the option type
228 return Some(v);
640886ce »
2011-08-25 Polymorphic MapReduce!
229 }
025d8662 »
2012-08-03 Switch alts to use arrows
230 done => {
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
231 // error!("all done");
640886ce »
2011-08-25 Polymorphic MapReduce!
232 is_done = true;
233 }
025d8662 »
2012-08-03 Switch alts to use arrows
234 addref => { ref_count += 1; }
235 release => { ref_count -= 1; }
640886ce »
2011-08-25 Polymorphic MapReduce!
236 }
237 }
8337fa1a »
2012-08-20 Camel case the option type
238 return None;
640886ce »
2011-08-25 Polymorphic MapReduce!
239 }
240
d1fc2b59 »
2012-06-30 Convert to new closure syntax
241 reduce(key, || get(p, ref_count, is_done) );
640886ce »
2011-08-25 Polymorphic MapReduce!
242 }
243
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
244 fn map_reduce<K1: copy send, K2: const copy send hash_key, V: copy send>(
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
245 map: mapper<K1, K2, V>,
246 reduce: reducer<K2, V>,
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
247 inputs: ~[K1])
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
248 {
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
249 let mut ctrl = ~[];
640886ce »
2011-08-25 Polymorphic MapReduce!
250
251 // This task becomes the master control task. It task::_spawns
252 // to do the rest.
253
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
254 let reducers = mk_hash();
255 let mut tasks = start_mappers(map, ctrl, inputs);
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
256 let mut num_mappers = vec::len(inputs) as int;
640886ce »
2011-08-25 Polymorphic MapReduce!
257
258 while num_mappers > 0 {
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
259 let (_ready, message, ctrls) = pipes::select(ctrl);
ecaf9e39 »
2012-08-06 Convert alt to match. Stop parsing alt
260 match option::unwrap(message) {
025d8662 »
2012-08-03 Switch alts to use arrows
261 ctrl_proto::mapper_done => {
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
262 // error!("received mapper terminated.");
640886ce »
2011-08-25 Polymorphic MapReduce!
263 num_mappers -= 1;
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
264 ctrl = ctrls;
640886ce »
2011-08-25 Polymorphic MapReduce!
265 }
025d8662 »
2012-08-03 Switch alts to use arrows
266 ctrl_proto::find_reducer(k, cc) => {
640886ce »
2011-08-25 Polymorphic MapReduce!
267 let c;
f0dfbe7b »
2011-12-22 Register new snapshots, purge log_err and log_full in favour of log(.…
268 // log(error, "finding reducer for " + k);
ecaf9e39 »
2012-08-06 Convert alt to match. Stop parsing alt
269 match reducers.find(k) {
8337fa1a »
2012-08-20 Camel case the option type
270 Some(_c) => {
f0dfbe7b »
2011-12-22 Register new snapshots, purge log_err and log_full in favour of log(.…
271 // log(error,
8b580954 »
2011-12-22 Register snapshots and switch logging over to use of log_full or #err…
272 // "reusing existing reducer for " + k);
640886ce »
2011-08-25 Polymorphic MapReduce!
273 c = _c;
274 }
8337fa1a »
2012-08-20 Camel case the option type
275 None => {
f0dfbe7b »
2011-12-22 Register new snapshots, purge log_err and log_full in favour of log(.…
276 // log(error, "creating new reducer for " + k);
161a82e4 »
2012-08-27 Camel case various core constructors
277 let p = Port();
278 let ch = Chan(p);
640886ce »
2011-08-25 Polymorphic MapReduce!
279 let r = reduce, kk = k;
bf88ff52 »
2012-07-11 Remove slow vec+=, and make word-count difficulty harder.
280 vec::push(tasks,
281 spawn_joinable(|| reduce_task(r, kk, ch) ));
640886ce »
2011-08-25 Polymorphic MapReduce!
282 c = recv(p);
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
283 reducers.insert(k, c);
640886ce »
2011-08-25 Polymorphic MapReduce!
284 }
285 }
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
286 ctrl = vec::append_one(
287 ctrls,
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
288 ctrl_proto::server::reducer(move_out!(cc), c));
640886ce »
2011-08-25 Polymorphic MapReduce!
289 }
290 }
291 }
292
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
293 for reducers.each_value |v| { send(v, done) }
640886ce »
2011-08-25 Polymorphic MapReduce!
294
d1fc2b59 »
2012-06-30 Convert to new closure syntax
295 for tasks.each |t| { join(t); }
640886ce »
2011-08-25 Polymorphic MapReduce!
296 }
297 }
298
92743dc2 »
2012-07-13 Move the world over to using the new style string literals and types.…
299 fn main(argv: ~[~str]) {
300 if vec::len(argv) < 2u && !os::getenv(~"RUST_BENCH").is_some() {
640886ce »
2011-08-25 Polymorphic MapReduce!
301 let out = io::stdout();
302
29f32b4a »
2012-08-22 `m1!{...}` -> `m1!(...)`
303 out.write_line(fmt!("Usage: %s <filename> ...", argv[0]));
640886ce »
2011-08-25 Polymorphic MapReduce!
304
b355936b »
2012-08-01 Convert ret to return
305 return;
640886ce »
2011-08-25 Polymorphic MapReduce!
306 }
307
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
308 let readers: ~[fn~() -> word_reader] = if argv.len() >= 2 {
65beca4e »
2012-07-26 Use iteration protocol for ebml, use vec::view in more places (issue #…
309 vec::view(argv, 1u, argv.len()).map(
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
310 |f| fn~() -> word_reader { file_word_reader(f) } )
311 }
312 else {
313 let num_readers = 50;
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
314 let words_per_reader = 600;
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
315 vec::from_fn(
316 num_readers,
317 |_i| fn~() -> word_reader {
318 random_word_reader(words_per_reader) as word_reader
319 })
320 };
321
640886ce »
2011-08-25 Polymorphic MapReduce!
322 let start = time::precise_time_ns();
323
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
324 map_reduce::map_reduce(map, reduce, readers);
640886ce »
2011-08-25 Polymorphic MapReduce!
325 let stop = time::precise_time_ns();
326
0c3a1284 »
2012-05-25 Update word-count-generic to latest syntax and un-xfail it. Closes #1740
327 let elapsed = (stop - start) / 1000000u64;
640886ce »
2011-08-25 Polymorphic MapReduce!
328
92743dc2 »
2012-07-13 Move the world over to using the new style string literals and types.…
329 log(error, ~"MapReduce completed in "
330 + u64::str(elapsed) + ~"ms");
640886ce »
2011-08-25 Polymorphic MapReduce!
331 }
332
8337fa1a »
2012-08-20 Camel case the option type
333 fn read_word(r: io::Reader) -> Option<~str> {
92743dc2 »
2012-07-13 Move the world over to using the new style string literals and types.…
334 let mut w = ~"";
640886ce »
2011-08-25 Polymorphic MapReduce!
335
336 while !r.eof() {
337 let c = r.read_char();
338
339 if is_word_char(c) {
ab6bb035 »
2011-09-01 Rename std::istr to std::str. Issue #855
340 w += str::from_char(c);
8337fa1a »
2012-08-20 Camel case the option type
341 } else { if w != ~"" { return Some(w); } }
640886ce »
2011-08-25 Polymorphic MapReduce!
342 }
8337fa1a »
2012-08-20 Camel case the option type
343 return None;
640886ce »
2011-08-25 Polymorphic MapReduce!
344 }
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
345
df83a793 »
2012-05-25 In generic word count, use str instead of [u8], and use built in is_a…
346 fn is_word_char(c: char) -> bool {
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
347 char::is_alphabetic(c) || char::is_digit(c) || c == '_'
348 }
349
3ab4b014 »
2012-08-15 Remove the class keyword
350 struct random_word_reader: word_reader {
2572e803 »
2012-09-06 Remove 'let' syntax for struct fields
351 mut remaining: uint,
352 rng: rand::Rng,
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
353
8337fa1a »
2012-08-20 Camel case the option type
354 fn read_word() -> Option<~str> {
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
355 if self.remaining > 0 {
356 self.remaining -= 1;
1a276dba »
2012-07-11 Switch map-reduce control protocol to use pipes. This exposed a bug i…
357 let len = self.rng.gen_uint_range(1, 4);
8337fa1a »
2012-08-20 Camel case the option type
358 Some(self.rng.gen_str(len))
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
359 }
8337fa1a »
2012-08-20 Camel case the option type
360 else { None }
a00478b7 »
2012-07-11 word-count-generic now generates random words in benchmark mode.
361 }
362 }
b4e547d7 »
2012-09-05 Remove struct ctors
363
364 fn random_word_reader(count: uint) -> random_word_reader {
365 random_word_reader {
366 remaining: count,
367 rng: rand::Rng()
368 }
369 }
Something went wrong with that request. Please try again.