js/src/jit-test/tests/sunspider/check-access-binary-trees.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/sunspider/check-access-binary-trees.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +/* The Great Computer Language Shootout
     1.5 +   http://shootout.alioth.debian.org/
     1.6 +   contributed by Isaac Gouy */
     1.7 +
     1.8 +function TreeNode(left,right,item){
     1.9 +   this.left = left;
    1.10 +   this.right = right;
    1.11 +   this.item = item;
    1.12 +}
    1.13 +
    1.14 +TreeNode.prototype.itemCheck = function(){
    1.15 +   if (this.left==null) return this.item;
    1.16 +   else return this.item + this.left.itemCheck() - this.right.itemCheck();
    1.17 +}
    1.18 +
    1.19 +function bottomUpTree(item,depth){
    1.20 +   if (depth>0){
    1.21 +      return new TreeNode(
    1.22 +          bottomUpTree(2*item-1, depth-1)
    1.23 +         ,bottomUpTree(2*item, depth-1)
    1.24 +         ,item
    1.25 +      );
    1.26 +   }
    1.27 +   else {
    1.28 +      return new TreeNode(null,null,item);
    1.29 +   }
    1.30 +}
    1.31 +
    1.32 +var ret;
    1.33 +
    1.34 +for ( var n = 4; n <= 7; n += 1 ) {
    1.35 +    var minDepth = 4;
    1.36 +    var maxDepth = Math.max(minDepth + 2, n);
    1.37 +    var stretchDepth = maxDepth + 1;
    1.38 +    
    1.39 +    var check = bottomUpTree(0,stretchDepth).itemCheck();
    1.40 +    
    1.41 +    var longLivedTree = bottomUpTree(0,maxDepth);
    1.42 +    for (var depth=minDepth; depth<=maxDepth; depth+=2){
    1.43 +        var iterations = 1 << (maxDepth - depth + minDepth);
    1.44 +
    1.45 +        check = 0;
    1.46 +        for (var i=1; i<=iterations; i++){
    1.47 +            check += bottomUpTree(i,depth).itemCheck();
    1.48 +            check += bottomUpTree(-i,depth).itemCheck();
    1.49 +        }
    1.50 +    }
    1.51 +
    1.52 +    ret = longLivedTree.itemCheck();
    1.53 +}
    1.54 +
    1.55 +assertEq(ret, -1)

mercurial