3 <script src=
"../htmlrunner.js"></script>
5 /* The Great Computer Language Shootout
6 http://shootout.alioth.debian.org/
7 contributed by Isaac Gouy */
9 function TreeNode(left
,right
,item
){
15 TreeNode
.prototype.itemCheck = function(){
16 if (this.left
==null) return this.item
;
17 else return this.item
+ this.left
.itemCheck() - this.right
.itemCheck();
20 function bottomUpTree(item
,depth
){
23 bottomUpTree(2*item
-1, depth
-1)
24 ,bottomUpTree(2*item
, depth
-1)
29 return new TreeNode(null,null,item
);
33 window
.onload = function(){ startTest("sunspider-access-binary-trees", 'c1dfeea3');
37 test( "Binary Trees", function(){
38 for ( var n
= 4; n
<= 5; n
+= 1 ) {
40 var maxDepth
= Math
.max(minDepth
+ 2, n
);
41 var stretchDepth
= maxDepth
+ 1;
43 var check
= bottomUpTree(0,stretchDepth
).itemCheck();
45 var longLivedTree
= bottomUpTree(0,maxDepth
);
46 for (var depth
=minDepth
; depth
<=maxDepth
; depth
+=2){
47 var iterations
= 1 << (maxDepth
- depth
+ minDepth
);
50 for (var i
=1; i
<=iterations
; i
++){
51 check
+= bottomUpTree(i
,depth
).itemCheck();
52 check
+= bottomUpTree(-i
,depth
).itemCheck();
56 ret
= longLivedTree
.itemCheck();