public snapshot · system/tools/nib/bench/xlang/ · system@main · commit a92f56ab098e · shared 2026-11-22T22:43:57Z· frozen: this page does not change when the repository does
1 struct Node {
2 left : Option < Box < Node >> ,
3 right : Option < Box < Node >> ,
4 }
5
6 fn make ( d : u32 ) -> Box < Node > {
7 if d > 0 {
8 Box :: new ( Node {
9 left : Some ( make ( d - 1 )) ,
10 right : Some ( make ( d - 1 )) ,
11 })
12 } else {
13 Box :: new ( Node {
14 left : None ,
15 right : None ,
16 })
17 }
18 }
19
20 fn check ( t : & Node ) -> u64 {
21 let mut n = 1 ;
22 if let Some ( l) = & t. left {
23 n += check ( l) ;
24 }
25 if let Some ( r) = & t. right {
26 n += check ( r) ;
27 }
28 n
29 }
30
31 fn main () {
32 let max_depth = 21u32 ;
33 let min_depth = 4u32 ;
34 let stretch = max_depth + 1 ;
35 println! (
36 "stretch tree of depth {} \t check: {}" ,
37 stretch,
38 check( & make( stretch))
39 ) ;
40 let long_lived = make ( max_depth) ;
41 let mut d = min_depth;
42 while d <= max_depth - 1 {
43 let iters = 1u64 << ( max_depth - d + min_depth) ;
44 let mut sum = 0 ;
45 for _ in 0 ..iters {
46 sum += check ( & make ( d)) ;
47 }
48 println! ( "{} \t trees of depth {} \t check: {}" , iters, d, sum) ;
49 d += 2 ;
50 }
51 println! (
52 "long lived tree of depth {} \t check: {}" ,
53 max_depth,
54 check( & long_lived)
55 ) ;
56 }
snapshot of a92f56ab098e · 2858 files · browse