Skip to content

Commit 74ca4af

Browse files
committed
---
yaml --- r: 81743 b: refs/heads/master c: 02b27b2 h: refs/heads/master i: 81741: 973304d 81739: 8a15cbc 81735: 2e3966e 81727: 4184bfd v: v3
1 parent 5d6bafc commit 74ca4af

File tree

5 files changed

+668
-7
lines changed

5 files changed

+668
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 44dc3fba8b10e066056a03f5444729d2e38596dc
2+
refs/heads/master: 02b27b2998d5722860f0c15e6b464edd517f0842
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729

trunk/mk/docs.mk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ doc/$(1)/rust.css: rust.css
231231
DOCS += doc/$(1)/index.html
232232
endef
233233

234-
# The library documenting macro
235-
# $(1) - The output directory
234+
# The "next generation" library documenting macro
235+
# $(1) - The crate name (std/extra)
236236
# $(2) - The crate file
237-
# $(3) - The crate soruce files
237+
# $(3) - The relevant host build triple (to depend on libstd)
238238
define libdocng
239-
doc/ng/$(1)/index.html: $(2) $(3) $$(RUSTDOC_NG)
239+
doc/ng/$(1)/index.html: $$(RUSTDOC_NG) $$(TLIB2_T_$(3)_H_$(3))/$(CFG_STDLIB_$(3))
240240
@$$(call E, rustdoc_ng: $$@)
241241
$(Q)$(RUSTDOC_NG) html $(2) -o doc/ng
242242

@@ -245,8 +245,8 @@ endef
245245

246246
$(eval $(call libdoc,std,$(STDLIB_CRATE),$(STDLIB_INPUTS)))
247247
$(eval $(call libdoc,extra,$(EXTRALIB_CRATE),$(EXTRALIB_INPUTS)))
248-
$(eval $(call libdocng,std,$(STDLIB_CRATE),$(STDLIB_INPUTS)))
249-
$(eval $(call libdocng,extra,$(EXTRALIB_CRATE),$(EXTRALIB_INPUTS)))
248+
$(eval $(call libdocng,std,$(STDLIB_CRATE),$(CFG_BUILD_TRIPLE)))
249+
$(eval $(call libdocng,extra,$(EXTRALIB_CRATE),$(CFG_BUILD_TRIPLE)))
250250
endif
251251

252252

trunk/src/libextra/extra.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub mod glob;
9393
pub mod term;
9494
pub mod time;
9595
pub mod arena;
96+
pub mod par;
9697
pub mod base64;
9798
pub mod rl;
9899
pub mod workcache;

trunk/src/libextra/par.rs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
use std::cast;
13+
use std::num;
14+
use std::ptr;
15+
use std::sys;
16+
use std::vec;
17+
use future::Future;
18+
19+
/**
20+
* The maximum number of tasks this module will spawn for a single
21+
* operation.
22+
*/
23+
static MAX_TASKS : uint = 32u;
24+
25+
/// The minimum number of elements each task will process.
26+
static MIN_GRANULARITY : uint = 1024u;
27+
28+
/**
29+
* An internal helper to map a function over a large vector and
30+
* return the intermediate results.
31+
*
32+
* This is used to build most of the other parallel vector functions,
33+
* like map or alli.
34+
*/
35+
fn map_slices<A:Clone + Send,B:Clone + Send>(
36+
xs: &[A],
37+
f: &fn() -> ~fn(uint, v: &[A]) -> B)
38+
-> ~[B] {
39+
40+
let len = xs.len();
41+
if len < MIN_GRANULARITY {
42+
info!("small slice");
43+
// This is a small vector, fall back on the normal map.
44+
~[f()(0u, xs)]
45+
} else {
46+
let num_tasks = num::min(MAX_TASKS, len / MIN_GRANULARITY);
47+
48+
let items_per_task = len / num_tasks;
49+
50+
let mut futures = ~[];
51+
let mut base = 0u;
52+
info!("spawning tasks");
53+
while base < len {
54+
let end = num::min(len, base + items_per_task);
55+
do xs.as_imm_buf |p, _len| {
56+
let f = f();
57+
let base = base;
58+
let f = do Future::spawn() || {
59+
unsafe {
60+
let len = end - base;
61+
let slice = (ptr::offset(p, base as int),
62+
len * sys::size_of::<A>());
63+
info!("pre-slice: %?", (base, slice));
64+
let slice : &[A] =
65+
cast::transmute(slice);
66+
info!("slice: %?", (base, slice.len(), end - base));
67+
assert_eq!(slice.len(), end - base);
68+
f(base, slice)
69+
}
70+
};
71+
futures.push(f);
72+
};
73+
base += items_per_task;
74+
}
75+
info!("tasks spawned");
76+
77+
info!("num_tasks: %?", (num_tasks, futures.len()));
78+
assert_eq!(num_tasks, futures.len());
79+
80+
do futures.move_iter().map |ys| {
81+
let mut ys = ys;
82+
ys.get()
83+
}.collect()
84+
}
85+
}
86+
87+
/// A parallel version of map.
88+
pub fn map<A:Clone + Send,B:Clone + Send>(
89+
xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] {
90+
vec::concat(map_slices(xs, || {
91+
let f = fn_factory();
92+
let result: ~fn(uint, &[A]) -> ~[B] =
93+
|_, slice| slice.iter().map(|x| f(x)).collect();
94+
result
95+
}))
96+
}
97+
98+
/// A parallel version of mapi.
99+
pub fn mapi<A:Clone + Send,B:Clone + Send>(
100+
xs: &[A],
101+
fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] {
102+
let slices = map_slices(xs, || {
103+
let f = fn_factory();
104+
let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| {
105+
slice.iter().enumerate().map(|(i, x)| {
106+
f(i + base, x)
107+
}).collect()
108+
};
109+
result
110+
});
111+
let r = vec::concat(slices);
112+
info!("%?", (r.len(), xs.len()));
113+
assert_eq!(r.len(), xs.len());
114+
r
115+
}
116+
117+
/// Returns true if the function holds for all elements in the vector.
118+
pub fn alli<A:Clone + Send>(
119+
xs: &[A],
120+
fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
121+
{
122+
let mapped = map_slices(xs, || {
123+
let f = fn_factory();
124+
let result: ~fn(uint, &[A]) -> bool = |base, slice| {
125+
slice.iter().enumerate().all(|(i, x)| f(i + base, x))
126+
};
127+
result
128+
});
129+
mapped.iter().all(|&x| x)
130+
}
131+
132+
/// Returns true if the function holds for any elements in the vector.
133+
pub fn any<A:Clone + Send>(
134+
xs: &[A],
135+
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
136+
let mapped = map_slices(xs, || {
137+
let f = fn_factory();
138+
let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f);
139+
result
140+
});
141+
mapped.iter().any(|&x| x)
142+
}

0 commit comments

Comments
 (0)