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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* The Great Computer Language Shootout
     2    http://shootout.alioth.debian.org/
     3    contributed by Isaac Gouy */
     5 function TreeNode(left,right,item){
     6    this.left = left;
     7    this.right = right;
     8    this.item = item;
     9 }
    11 TreeNode.prototype.itemCheck = function(){
    12    if (this.left==null) return this.item;
    13    else return this.item + this.left.itemCheck() - this.right.itemCheck();
    14 }
    16 function bottomUpTree(item,depth){
    17    if (depth>0){
    18       return new TreeNode(
    19           bottomUpTree(2*item-1, depth-1)
    20          ,bottomUpTree(2*item, depth-1)
    21          ,item
    22       );
    23    }
    24    else {
    25       return new TreeNode(null,null,item);
    26    }
    27 }
    29 var ret;
    31 for ( var n = 4; n <= 7; n += 1 ) {
    32     var minDepth = 4;
    33     var maxDepth = Math.max(minDepth + 2, n);
    34     var stretchDepth = maxDepth + 1;
    36     var check = bottomUpTree(0,stretchDepth).itemCheck();
    38     var longLivedTree = bottomUpTree(0,maxDepth);
    39     for (var depth=minDepth; depth<=maxDepth; depth+=2){
    40         var iterations = 1 << (maxDepth - depth + minDepth);
    42         check = 0;
    43         for (var i=1; i<=iterations; i++){
    44             check += bottomUpTree(i,depth).itemCheck();
    45             check += bottomUpTree(-i,depth).itemCheck();
    46         }
    47     }
    49     ret = longLivedTree.itemCheck();
    50 }
    52 assertEq(ret, -1)

mercurial