Skip to content

Commit 58029c9

Browse files
committed
---
yaml --- r: 12198 b: refs/heads/master c: 8774493 h: refs/heads/master v: v3
1 parent 5f515a1 commit 58029c9

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
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: 166d14e42de0d29ba88fa5a88551a76f7a12418e
2+
refs/heads/master: 8774493dd33c0028ac7e543a88657d00c34e5eeb
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/test/bench/shootout-binarytrees.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std;
2+
import std::arena;
3+
import std::arena::arena;
24

3-
enum tree { nil, node(~tree, ~tree, int), }
5+
enum tree { nil, node(&tree, &tree, int), }
46

5-
fn item_check(t: ~tree) -> int {
7+
fn item_check(t: &tree) -> int {
68
alt *t {
79
nil { ret 0; }
810
node(left, right, item) {
@@ -11,11 +13,13 @@ fn item_check(t: ~tree) -> int {
1113
}
1214
}
1315

14-
fn bottom_up_tree(item: int, depth: int) -> ~tree {
16+
fn bottom_up_tree(arena: &a.arena::arena, item: int, depth: int) -> &a.tree {
1517
if depth > 0 {
16-
ret ~node(bottom_up_tree(2 * item - 1, depth - 1),
17-
bottom_up_tree(2 * item, depth - 1), item);
18-
} else { ret ~nil; }
18+
ret new(*arena) node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
19+
bottom_up_tree(arena, 2 * item, depth - 1),
20+
item);
21+
}
22+
ret new(*arena) nil;
1923
}
2024

2125
fn main(args: [str]) {
@@ -28,22 +32,29 @@ fn main(args: [str]) {
2832
let mut max_depth;
2933
if min_depth + 2 > n {
3034
max_depth = min_depth + 2;
31-
} else { max_depth = n; }
35+
} else {
36+
max_depth = n;
37+
}
38+
39+
let stretch_arena = arena::arena();
3240
let stretch_depth = max_depth + 1;
33-
let stretch_tree = bottom_up_tree(0, stretch_depth);
41+
let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
42+
3443
io::println(#fmt("stretch tree of depth %d\t check: %d",
3544
stretch_depth,
3645
item_check(stretch_tree)));
37-
let long_lived_tree = bottom_up_tree(0, max_depth);
46+
47+
let long_lived_arena = arena::arena();
48+
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
3849
let mut depth = min_depth;
3950
while depth <= max_depth {
4051
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
4152
let mut chk = 0;
4253
let mut i = 1;
4354
while i <= iterations {
44-
let mut temp_tree = bottom_up_tree(i, depth);
55+
let mut temp_tree = bottom_up_tree(&long_lived_arena, i, depth);
4556
chk += item_check(temp_tree);
46-
temp_tree = bottom_up_tree(-i, depth);
57+
temp_tree = bottom_up_tree(&long_lived_arena, -i, depth);
4758
chk += item_check(temp_tree);
4859
i += 1;
4960
}

0 commit comments

Comments
 (0)