Skip to content

Commit 9f017a3

Browse files
committed
---
yaml --- r: 13122 b: refs/heads/master c: ad292a8 h: refs/heads/master v: v3
1 parent 8071774 commit 9f017a3

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
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: 09a32aedb5ae56cabac371ba9af7cce631becf51
2+
refs/heads/master: ad292a8c73a0cceddfa9618a4d6eea577897bae8
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/rand.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[doc = "Random number generation"];
22

33
export rng, seed, seeded_rng, weighted, extensions;
4+
export xorshift, seeded_xorshift;
45

56
enum rctx {}
67

@@ -253,6 +254,35 @@ fn seeded_rng(seed: [u8]) -> rng {
253254
@rand_res(rustrt::rand_new_seeded(seed)) as rng
254255
}
255256

257+
type xorshift_state = {
258+
mut x: u32,
259+
mut y: u32,
260+
mut z: u32,
261+
mut w: u32
262+
};
263+
264+
impl of rng for xorshift_state {
265+
fn next() -> u32 {
266+
let x = self.x;
267+
let mut t = x ^ (x << 11);
268+
self.x = self.y;
269+
self.y = self.z;
270+
self.z = self.w;
271+
let w = self.w;
272+
self.w = w ^ (w >> 19) ^ (t ^ (t >> 8));
273+
self.w
274+
}
275+
}
276+
277+
fn xorshift() -> rng {
278+
// constants taken from http://en.wikipedia.org/wiki/Xorshift
279+
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
280+
}
281+
282+
fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> rng {
283+
{mut x: x, mut y: y, mut z: z, mut w: w} as rng
284+
}
285+
256286
#[cfg(test)]
257287
mod tests {
258288

trunk/src/libstd/par.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn alli<A: copy send>(xs: [A], f: fn~(uint, A) -> bool) -> bool {
129129

130130
#[doc="Returns true if the function holds for any elements in the vector."]
131131
fn any<A: copy send>(xs: [A], f: fn~(A) -> bool) -> bool {
132-
vec::any(map_slices(xs) {||
132+
vec::any(map_slices(xs) {||
133133
fn~(_base : uint, slice: [const A]/&, copy f) -> bool {
134134
vec::any(slice, f)
135135
}

trunk/src/test/bench/graph500-bfs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type graph = [[node_id]];
2121
type bfs_result = [node_id];
2222

2323
fn make_edges(scale: uint, edgefactor: uint) -> [(node_id, node_id)] {
24-
let r = rand::rng();
24+
let r = rand::xorshift();
2525

2626
fn choose_edge(i: node_id, j: node_id, scale: uint, r: rand::rng)
2727
-> (node_id, node_id) {
@@ -247,12 +247,12 @@ fn pbfs(&&graph: arc::arc<graph>, key: node_id) -> bfs_result {
247247
white {
248248
let i = i as node_id;
249249

250-
let neighbors = (*graph)[i];
250+
let neighbors = graph[i];
251251

252252
let mut color = white;
253253

254254
neighbors.each() {|k|
255-
if is_gray((*colors)[k]) {
255+
if is_gray(colors[k]) {
256256
color = gray(k);
257257
false
258258
}

0 commit comments

Comments
 (0)