/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['collections/AnderssonTree.js']) {
  _$jscoverage['collections/AnderssonTree.js'] = [];
  _$jscoverage['collections/AnderssonTree.js'][1] = 0;
  _$jscoverage['collections/AnderssonTree.js'][6] = 0;
  _$jscoverage['collections/AnderssonTree.js'][9] = 0;
  _$jscoverage['collections/AnderssonTree.js'][11] = 0;
  _$jscoverage['collections/AnderssonTree.js'][12] = 0;
  _$jscoverage['collections/AnderssonTree.js'][20] = 0;
  _$jscoverage['collections/AnderssonTree.js'][21] = 0;
  _$jscoverage['collections/AnderssonTree.js'][22] = 0;
  _$jscoverage['collections/AnderssonTree.js'][23] = 0;
  _$jscoverage['collections/AnderssonTree.js'][24] = 0;
  _$jscoverage['collections/AnderssonTree.js'][25] = 0;
  _$jscoverage['collections/AnderssonTree.js'][27] = 0;
  _$jscoverage['collections/AnderssonTree.js'][30] = 0;
  _$jscoverage['collections/AnderssonTree.js'][31] = 0;
  _$jscoverage['collections/AnderssonTree.js'][32] = 0;
  _$jscoverage['collections/AnderssonTree.js'][33] = 0;
  _$jscoverage['collections/AnderssonTree.js'][34] = 0;
  _$jscoverage['collections/AnderssonTree.js'][35] = 0;
  _$jscoverage['collections/AnderssonTree.js'][36] = 0;
  _$jscoverage['collections/AnderssonTree.js'][38] = 0;
  _$jscoverage['collections/AnderssonTree.js'][41] = 0;
  _$jscoverage['collections/AnderssonTree.js'][42] = 0;
  _$jscoverage['collections/AnderssonTree.js'][43] = 0;
  _$jscoverage['collections/AnderssonTree.js'][46] = 0;
  _$jscoverage['collections/AnderssonTree.js'][47] = 0;
  _$jscoverage['collections/AnderssonTree.js'][48] = 0;
  _$jscoverage['collections/AnderssonTree.js'][49] = 0;
  _$jscoverage['collections/AnderssonTree.js'][51] = 0;
  _$jscoverage['collections/AnderssonTree.js'][54] = 0;
  _$jscoverage['collections/AnderssonTree.js'][55] = 0;
  _$jscoverage['collections/AnderssonTree.js'][56] = 0;
  _$jscoverage['collections/AnderssonTree.js'][57] = 0;
  _$jscoverage['collections/AnderssonTree.js'][58] = 0;
  _$jscoverage['collections/AnderssonTree.js'][59] = 0;
  _$jscoverage['collections/AnderssonTree.js'][60] = 0;
  _$jscoverage['collections/AnderssonTree.js'][61] = 0;
  _$jscoverage['collections/AnderssonTree.js'][62] = 0;
  _$jscoverage['collections/AnderssonTree.js'][63] = 0;
  _$jscoverage['collections/AnderssonTree.js'][64] = 0;
  _$jscoverage['collections/AnderssonTree.js'][65] = 0;
  _$jscoverage['collections/AnderssonTree.js'][67] = 0;
  _$jscoverage['collections/AnderssonTree.js'][70] = 0;
  _$jscoverage['collections/AnderssonTree.js'][71] = 0;
  _$jscoverage['collections/AnderssonTree.js'][74] = 0;
  _$jscoverage['collections/AnderssonTree.js'][75] = 0;
  _$jscoverage['collections/AnderssonTree.js'][76] = 0;
  _$jscoverage['collections/AnderssonTree.js'][77] = 0;
  _$jscoverage['collections/AnderssonTree.js'][78] = 0;
  _$jscoverage['collections/AnderssonTree.js'][79] = 0;
  _$jscoverage['collections/AnderssonTree.js'][81] = 0;
  _$jscoverage['collections/AnderssonTree.js'][82] = 0;
  _$jscoverage['collections/AnderssonTree.js'][85] = 0;
  _$jscoverage['collections/AnderssonTree.js'][104] = 0;
  _$jscoverage['collections/AnderssonTree.js'][110] = 0;
  _$jscoverage['collections/AnderssonTree.js'][114] = 0;
  _$jscoverage['collections/AnderssonTree.js'][115] = 0;
  _$jscoverage['collections/AnderssonTree.js'][119] = 0;
  _$jscoverage['collections/AnderssonTree.js'][124] = 0;
  _$jscoverage['collections/AnderssonTree.js'][125] = 0;
  _$jscoverage['collections/AnderssonTree.js'][126] = 0;
  _$jscoverage['collections/AnderssonTree.js'][128] = 0;
  _$jscoverage['collections/AnderssonTree.js'][133] = 0;
  _$jscoverage['collections/AnderssonTree.js'][134] = 0;
  _$jscoverage['collections/AnderssonTree.js'][139] = 0;
  _$jscoverage['collections/AnderssonTree.js'][140] = 0;
  _$jscoverage['collections/AnderssonTree.js'][142] = 0;
  _$jscoverage['collections/AnderssonTree.js'][146] = 0;
  _$jscoverage['collections/AnderssonTree.js'][147] = 0;
  _$jscoverage['collections/AnderssonTree.js'][148] = 0;
  _$jscoverage['collections/AnderssonTree.js'][149] = 0;
  _$jscoverage['collections/AnderssonTree.js'][150] = 0;
  _$jscoverage['collections/AnderssonTree.js'][152] = 0;
  _$jscoverage['collections/AnderssonTree.js'][153] = 0;
  _$jscoverage['collections/AnderssonTree.js'][154] = 0;
  _$jscoverage['collections/AnderssonTree.js'][155] = 0;
  _$jscoverage['collections/AnderssonTree.js'][156] = 0;
}
_$jscoverage['collections/AnderssonTree.js'][1]++;
var define = require("../define").define, Tree = require("./Tree"), base = require("../base"), multiply = base.string.multiply;
_$jscoverage['collections/AnderssonTree.js'][6]++;
var RED = "red", BLACK = "black";
_$jscoverage['collections/AnderssonTree.js'][9]++;
var nil = {level: 0, data: null};
_$jscoverage['collections/AnderssonTree.js'][11]++;
var makeNode = (function (data, level) {
  _$jscoverage['collections/AnderssonTree.js'][12]++;
  return ({data: data, level: level, left: nil, right: nil});
});
_$jscoverage['collections/AnderssonTree.js'][20]++;
var skew = (function (root) {
  _$jscoverage['collections/AnderssonTree.js'][21]++;
  if (root.level != 0 && root.left.level == root.level) {
    _$jscoverage['collections/AnderssonTree.js'][22]++;
    var save = root.left;
    _$jscoverage['collections/AnderssonTree.js'][23]++;
    root.left = save.right;
    _$jscoverage['collections/AnderssonTree.js'][24]++;
    save.right = root;
    _$jscoverage['collections/AnderssonTree.js'][25]++;
    root = save;
  }
  _$jscoverage['collections/AnderssonTree.js'][27]++;
  return root;
});
_$jscoverage['collections/AnderssonTree.js'][30]++;
var split = (function (root) {
  _$jscoverage['collections/AnderssonTree.js'][31]++;
  if (root.level != 0 && root.right.right.level == root.level) {
    _$jscoverage['collections/AnderssonTree.js'][32]++;
    var save = root.right;
    _$jscoverage['collections/AnderssonTree.js'][33]++;
    root.right = save.left;
    _$jscoverage['collections/AnderssonTree.js'][34]++;
    save.left = root;
    _$jscoverage['collections/AnderssonTree.js'][35]++;
    root = save;
    _$jscoverage['collections/AnderssonTree.js'][36]++;
    ++root.level;
  }
  _$jscoverage['collections/AnderssonTree.js'][38]++;
  return root;
});
_$jscoverage['collections/AnderssonTree.js'][41]++;
var insert = (function (root, data, compare) {
  _$jscoverage['collections/AnderssonTree.js'][42]++;
  if (root == nil) {
    _$jscoverage['collections/AnderssonTree.js'][43]++;
    root = makeNode(data, 1);
  }
  else {
    _$jscoverage['collections/AnderssonTree.js'][46]++;
    var dir = compare(data, root.data) == -1? "left": "right";
    _$jscoverage['collections/AnderssonTree.js'][47]++;
    root[dir] = insert(root[dir], data, compare);
    _$jscoverage['collections/AnderssonTree.js'][48]++;
    root = skew(root);
    _$jscoverage['collections/AnderssonTree.js'][49]++;
    root = split(root);
  }
  _$jscoverage['collections/AnderssonTree.js'][51]++;
  return root;
});
_$jscoverage['collections/AnderssonTree.js'][54]++;
var remove = (function (root, data, compare) {
  _$jscoverage['collections/AnderssonTree.js'][55]++;
  var rLeft, rRight;
  _$jscoverage['collections/AnderssonTree.js'][56]++;
  if (root != nil) {
    _$jscoverage['collections/AnderssonTree.js'][57]++;
    var cmp = compare(data, root.data);
    _$jscoverage['collections/AnderssonTree.js'][58]++;
    if (cmp == 0) {
      _$jscoverage['collections/AnderssonTree.js'][59]++;
      rLeft = root.left, rRight = root.right;
      _$jscoverage['collections/AnderssonTree.js'][60]++;
      if (rLeft != nil && rRight != nil) {
        _$jscoverage['collections/AnderssonTree.js'][61]++;
        var heir = rLeft;
        _$jscoverage['collections/AnderssonTree.js'][62]++;
        while (heir.right != nil) {
          _$jscoverage['collections/AnderssonTree.js'][63]++;
          heir = heir.right;
}
        _$jscoverage['collections/AnderssonTree.js'][64]++;
        root.data = heir.data;
        _$jscoverage['collections/AnderssonTree.js'][65]++;
        root.left = remove(rLeft, heir.data, compare);
      }
      else {
        _$jscoverage['collections/AnderssonTree.js'][67]++;
        root = root[rLeft == nil? "right": "left"];
      }
    }
    else {
      _$jscoverage['collections/AnderssonTree.js'][70]++;
      var dir = cmp == -1? "left": "right";
      _$jscoverage['collections/AnderssonTree.js'][71]++;
      root[dir] = remove(root[dir], data, compare);
    }
  }
  _$jscoverage['collections/AnderssonTree.js'][74]++;
  if (root != nil) {
    _$jscoverage['collections/AnderssonTree.js'][75]++;
    var rLevel = root.level;
    _$jscoverage['collections/AnderssonTree.js'][76]++;
    var rLeftLevel = root.left.level, rRightLevel = root.right.level;
    _$jscoverage['collections/AnderssonTree.js'][77]++;
    if (rLeftLevel < rLevel - 1 || rRightLevel < rLevel - 1) {
      _$jscoverage['collections/AnderssonTree.js'][78]++;
      if (rRightLevel > --root.level) {
        _$jscoverage['collections/AnderssonTree.js'][79]++;
        root.right.level = root.level;
      }
      _$jscoverage['collections/AnderssonTree.js'][81]++;
      root = skew(root);
      _$jscoverage['collections/AnderssonTree.js'][82]++;
      root = split(root);
    }
  }
  _$jscoverage['collections/AnderssonTree.js'][85]++;
  return root;
});
_$jscoverage['collections/AnderssonTree.js'][104]++;
module.exports = exports = define(Tree, {instance: {isEmpty: (function () {
  _$jscoverage['collections/AnderssonTree.js'][110]++;
  return this.__root == nil || this["super"](arguments);
}), insert: (function (data) {
  _$jscoverage['collections/AnderssonTree.js'][114]++;
  if (this.__root == null) {
    _$jscoverage['collections/AnderssonTree.js'][114]++;
    this.__root = nil;
  }
  _$jscoverage['collections/AnderssonTree.js'][115]++;
  this.__root = insert(this.__root, data, this.compare);
}), remove: (function (data) {
  _$jscoverage['collections/AnderssonTree.js'][119]++;
  this.__root = remove(this.__root, data, this.compare);
}), traverseWithCondition: (function (node, order, callback) {
  _$jscoverage['collections/AnderssonTree.js'][124]++;
  var cont = true;
  _$jscoverage['collections/AnderssonTree.js'][125]++;
  if (node != nil) {
    _$jscoverage['collections/AnderssonTree.js'][126]++;
    return this["super"](arguments);
  }
  _$jscoverage['collections/AnderssonTree.js'][128]++;
  return cont;
}), traverse: (function (node, order, callback) {
  _$jscoverage['collections/AnderssonTree.js'][133]++;
  if (node != nil) {
    _$jscoverage['collections/AnderssonTree.js'][134]++;
    this["super"](arguments);
  }
}), contains: (function (value) {
  _$jscoverage['collections/AnderssonTree.js'][139]++;
  if (this.__root != nil) {
    _$jscoverage['collections/AnderssonTree.js'][140]++;
    return this["super"](arguments);
  }
  _$jscoverage['collections/AnderssonTree.js'][142]++;
  return false;
}), __printNode: (function (node, level) {
  _$jscoverage['collections/AnderssonTree.js'][146]++;
  var str = [];
  _$jscoverage['collections/AnderssonTree.js'][147]++;
  if (node.data == null || node == null) {
    _$jscoverage['collections/AnderssonTree.js'][148]++;
    str.push(multiply("\t", level));
    _$jscoverage['collections/AnderssonTree.js'][149]++;
    str.push("~");
    _$jscoverage['collections/AnderssonTree.js'][150]++;
    console.log(str.join(""));
  }
  else {
    _$jscoverage['collections/AnderssonTree.js'][152]++;
    this.__printNode(node.right, level + 1);
    _$jscoverage['collections/AnderssonTree.js'][153]++;
    str.push(multiply("\t", level));
    _$jscoverage['collections/AnderssonTree.js'][154]++;
    str.push(node.data + ":" + node.level + "\n");
    _$jscoverage['collections/AnderssonTree.js'][155]++;
    console.log(str.join(""));
    _$jscoverage['collections/AnderssonTree.js'][156]++;
    this.__printNode(node.left, level + 1);
  }
})}});
_$jscoverage['collections/AnderssonTree.js'].source = ["var define = require(\"../define\").define,","        Tree = require(\"./Tree\"),","        base = require(\"../base\"),","        multiply = base.string.multiply;","","var RED = \"red\", BLACK = \"black\";","","","var nil = {level : 0, data : null};","","var makeNode = function(data, level) {","    return {","        data : data,","        level : level,","        left : nil,","        right : nil","    }","};","","var skew = function(root) {","    if (root.level != 0 &amp;&amp; root.left.level == root.level) {","        var save = root.left;","        root.left = save.right;","        save.right = root;","        root = save;","    }","    return root;","};","","var split = function(root) {","    if (root.level != 0 &amp;&amp; root.right.right.level == root.level) {","        var save = root.right;","        root.right = save.left;","        save.left = root;","        root = save;","        ++root.level;","    }","    return root;","};","","var insert = function(root, data, compare) {","    if (root == nil) {","        root = makeNode(data, 1);","    }","    else {","        var dir = compare(data, root.data) == -1 ? \"left\" : \"right\";","        root[dir] = insert(root[dir], data, compare);","        root = skew(root);","        root = split(root);","    }","    return root;","};","","var remove = function(root, data, compare) {","    var rLeft, rRight;","    if (root != nil) {","        var cmp = compare(data, root.data);","        if (cmp == 0) {","            rLeft = root.left,rRight = root.right;","            if (rLeft != nil &amp;&amp; rRight != nil) {","                var heir = rLeft;","                while (heir.right != nil)","                    heir = heir.right;","                root.data = heir.data;","                root.left = remove(rLeft, heir.data, compare);","            } else {","                root = root[rLeft == nil ? \"right\" : \"left\"];","            }","        } else {","            var dir = cmp == -1 ? \"left\" : \"right\";","            root[dir] = remove(root[dir], data, compare);","        }","    }","    if (root != nil) {","        var rLevel = root.level;","        var rLeftLevel = root.left.level, rRightLevel = root.right.level;","        if (rLeftLevel &lt; rLevel - 1 || rRightLevel &lt; rLevel - 1) {","            if (rRightLevel &gt; --root.level)","                root.right.level = root.level;","","            root = skew(root);","            root = split(root);","        }","    }","    return root;","};","/**"," * @class &lt;p&gt;Andersson Trees are a version of a balanced Binary tree, while similar to RedBlack Trees the balancing is not as strict.&lt;/p&gt;"," *"," * &lt;b&gt;Performance&lt;/b&gt;"," * &lt;table&gt;"," *     &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Best&lt;/td&gt;&lt;td&gt;Worst&lt;/td&gt;&lt;/tr&gt;"," *     &lt;tr&gt;&lt;td&gt;space&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;"," *     &lt;tr&gt;&lt;td&gt;Search&lt;/td&gt;&lt;td&gt;O(log n)&lt;/td&gt;&lt;td&gt;O(log n)&lt;/td&gt;&lt;/tr&gt;"," *     &lt;tr&gt;&lt;td&gt;Insert&lt;/td&gt;&lt;td&gt;O(log n)&lt;/td&gt;&lt;td&gt;O(log n)&lt;/td&gt;&lt;/tr&gt;"," *     &lt;tr&gt;&lt;td&gt;Delete&lt;/td&gt;&lt;td&gt;O(log n)&lt;/td&gt;&lt;td&gt;O(log n)&lt;/td&gt;&lt;/tr&gt;"," * &lt;table&gt;"," * @name AnderssonTree"," * @augments comb.collections.Tree"," * @memberOf comb.collections"," */","","","module.exports = exports = define(Tree, {","","            instance : {","                /**@lends comb.collections.AnderssonTree.prototype*/","","                isEmpty : function() {","                    return this.__root == nil || this.super(arguments);","                },","","                insert : function(data) {","                    if (this.__root == null) this.__root = nil;","                    this.__root = insert(this.__root, data, this.compare);","                },","","                remove : function(data) {","                    this.__root = remove(this.__root, data, this.compare);","                },","","","                traverseWithCondition : function(node, order, callback) {","                    var cont = true;","                    if (node != nil) {","                        return this.super(arguments);","                    }","                    return cont;","                },","","","                traverse : function(node, order, callback) {","                    if (node != nil) {","                        this.super(arguments);","                    }","                },","","                contains : function(value) {","                    if (this.__root != nil) {","                        return this.super(arguments);","                    }","                    return false;","                },","","                __printNode : function(node, level) {","                    var str = [];","                    if (node.data == null || node == null) {","                        str.push(multiply('\\t', level));","                        str.push(\"~\");","                        console.log(str.join(\"\"));","                    } else {","                        this.__printNode(node.right, level + 1);","                        str.push(multiply('\\t', level));","                        str.push(node.data + \":\" + node.level + \"\\n\");","                        console.log(str.join(\"\"));","                        this.__printNode(node.left, level + 1);","                    }","                }","","            }","","        });",""];
