1
- // xfail-test
2
-
3
- // Broken due to arena API problems.
4
-
5
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
6
2
// file at the top-level directory of this distribution and at
7
3
// http://rust-lang.org/COPYRIGHT.
8
4
//
15
11
extern mod extra;
16
12
use extra:: arena;
17
13
18
- enum tree < ' self > {
19
- nil ,
20
- node ( & ' self tree < ' self > , & ' self tree < ' self > , int ) ,
14
+ enum Tree < ' self > {
15
+ Nil ,
16
+ Node ( & ' self Tree < ' self > , & ' self Tree < ' self > , int ) ,
21
17
}
22
18
23
- fn item_check ( t : & tree ) -> int {
19
+ fn item_check ( t : & Tree ) -> int {
24
20
match * t {
25
- nil => { return 0 ; }
26
- node ( left, right, item) => {
21
+ Nil => { return 0 ; }
22
+ Node ( left, right, item) => {
27
23
return item + item_check ( left) - item_check ( right) ;
28
24
}
29
25
}
30
26
}
31
27
32
- fn bottom_up_tree < ' r > ( arena : & ' r mut arena:: Arena , item : int , depth : int )
33
- -> & ' r tree < ' r > {
28
+ fn bottom_up_tree < ' r > ( arena : & ' r arena:: Arena , item : int , depth : int )
29
+ -> & ' r Tree < ' r > {
34
30
if depth > 0 {
35
31
return arena. alloc (
36
- || node ( bottom_up_tree ( arena, 2 * item - 1 , depth - 1 ) ,
32
+ || Node ( bottom_up_tree ( arena, 2 * item - 1 , depth - 1 ) ,
37
33
bottom_up_tree ( arena, 2 * item, depth - 1 ) ,
38
34
item) ) ;
39
35
}
40
- return arena. alloc ( || nil ) ;
36
+ return arena. alloc ( || Nil ) ;
41
37
}
42
38
43
39
fn main ( ) {
@@ -61,25 +57,25 @@ fn main() {
61
57
max_depth = n;
62
58
}
63
59
64
- let mut stretch_arena = arena:: Arena ( ) ;
60
+ let stretch_arena = arena:: Arena ( ) ;
65
61
let stretch_depth = max_depth + 1 ;
66
- let stretch_tree = bottom_up_tree ( & mut stretch_arena, 0 , stretch_depth) ;
62
+ let stretch_tree = bottom_up_tree ( & stretch_arena, 0 , stretch_depth) ;
67
63
68
64
println ( fmt ! ( "stretch tree of depth %d\t check: %d" ,
69
65
stretch_depth,
70
66
item_check( stretch_tree) ) ) ;
71
67
72
- let mut long_lived_arena = arena:: Arena ( ) ;
73
- let long_lived_tree = bottom_up_tree ( & mut long_lived_arena, 0 , max_depth) ;
68
+ let long_lived_arena = arena:: Arena ( ) ;
69
+ let long_lived_tree = bottom_up_tree ( & long_lived_arena, 0 , max_depth) ;
74
70
let mut depth = min_depth;
75
71
while depth <= max_depth {
76
72
let iterations = int:: pow ( 2 , ( max_depth - depth + min_depth) as uint ) ;
77
73
let mut chk = 0 ;
78
74
let mut i = 1 ;
79
75
while i <= iterations {
80
- let mut temp_tree = bottom_up_tree ( & mut long_lived_arena, i, depth) ;
76
+ let mut temp_tree = bottom_up_tree ( & long_lived_arena, i, depth) ;
81
77
chk += item_check ( temp_tree) ;
82
- temp_tree = bottom_up_tree ( & mut long_lived_arena, -i, depth) ;
78
+ temp_tree = bottom_up_tree ( & long_lived_arena, -i, depth) ;
83
79
chk += item_check ( temp_tree) ;
84
80
i += 1 ;
85
81
}
0 commit comments