/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['collections/AVLTree.js']) {
  _$jscoverage['collections/AVLTree.js'] = [];
  _$jscoverage['collections/AVLTree.js'][1] = 0;
  _$jscoverage['collections/AVLTree.js'][6] = 0;
  _$jscoverage['collections/AVLTree.js'][10] = 0;
  _$jscoverage['collections/AVLTree.js'][11] = 0;
  _$jscoverage['collections/AVLTree.js'][19] = 0;
  _$jscoverage['collections/AVLTree.js'][20] = 0;
  _$jscoverage['collections/AVLTree.js'][21] = 0;
  _$jscoverage['collections/AVLTree.js'][22] = 0;
  _$jscoverage['collections/AVLTree.js'][23] = 0;
  _$jscoverage['collections/AVLTree.js'][27] = 0;
  _$jscoverage['collections/AVLTree.js'][28] = 0;
  _$jscoverage['collections/AVLTree.js'][29] = 0;
  _$jscoverage['collections/AVLTree.js'][32] = 0;
  _$jscoverage['collections/AVLTree.js'][33] = 0;
  _$jscoverage['collections/AVLTree.js'][34] = 0;
  _$jscoverage['collections/AVLTree.js'][35] = 0;
  _$jscoverage['collections/AVLTree.js'][36] = 0;
  _$jscoverage['collections/AVLTree.js'][37] = 0;
  _$jscoverage['collections/AVLTree.js'][38] = 0;
  _$jscoverage['collections/AVLTree.js'][39] = 0;
  _$jscoverage['collections/AVLTree.js'][42] = 0;
  _$jscoverage['collections/AVLTree.js'][43] = 0;
  _$jscoverage['collections/AVLTree.js'][45] = 0;
  _$jscoverage['collections/AVLTree.js'][48] = 0;
  _$jscoverage['collections/AVLTree.js'][49] = 0;
  _$jscoverage['collections/AVLTree.js'][51] = 0;
  _$jscoverage['collections/AVLTree.js'][52] = 0;
  _$jscoverage['collections/AVLTree.js'][54] = 0;
  _$jscoverage['collections/AVLTree.js'][55] = 0;
  _$jscoverage['collections/AVLTree.js'][56] = 0;
  _$jscoverage['collections/AVLTree.js'][59] = 0;
  _$jscoverage['collections/AVLTree.js'][60] = 0;
  _$jscoverage['collections/AVLTree.js'][63] = 0;
  _$jscoverage['collections/AVLTree.js'][67] = 0;
  _$jscoverage['collections/AVLTree.js'][68] = 0;
  _$jscoverage['collections/AVLTree.js'][69] = 0;
  _$jscoverage['collections/AVLTree.js'][70] = 0;
  _$jscoverage['collections/AVLTree.js'][71] = 0;
  _$jscoverage['collections/AVLTree.js'][72] = 0;
  _$jscoverage['collections/AVLTree.js'][73] = 0;
  _$jscoverage['collections/AVLTree.js'][75] = 0;
  _$jscoverage['collections/AVLTree.js'][76] = 0;
  _$jscoverage['collections/AVLTree.js'][77] = 0;
  _$jscoverage['collections/AVLTree.js'][80] = 0;
  _$jscoverage['collections/AVLTree.js'][81] = 0;
  _$jscoverage['collections/AVLTree.js'][82] = 0;
  _$jscoverage['collections/AVLTree.js'][83] = 0;
  _$jscoverage['collections/AVLTree.js'][85] = 0;
  _$jscoverage['collections/AVLTree.js'][88] = 0;
  _$jscoverage['collections/AVLTree.js'][89] = 0;
  _$jscoverage['collections/AVLTree.js'][90] = 0;
  _$jscoverage['collections/AVLTree.js'][92] = 0;
  _$jscoverage['collections/AVLTree.js'][93] = 0;
  _$jscoverage['collections/AVLTree.js'][95] = 0;
  _$jscoverage['collections/AVLTree.js'][97] = 0;
  _$jscoverage['collections/AVLTree.js'][99] = 0;
  _$jscoverage['collections/AVLTree.js'][100] = 0;
  _$jscoverage['collections/AVLTree.js'][101] = 0;
  _$jscoverage['collections/AVLTree.js'][102] = 0;
  _$jscoverage['collections/AVLTree.js'][103] = 0;
  _$jscoverage['collections/AVLTree.js'][108] = 0;
  _$jscoverage['collections/AVLTree.js'][111] = 0;
  _$jscoverage['collections/AVLTree.js'][112] = 0;
  _$jscoverage['collections/AVLTree.js'][113] = 0;
  _$jscoverage['collections/AVLTree.js'][115] = 0;
  _$jscoverage['collections/AVLTree.js'][116] = 0;
  _$jscoverage['collections/AVLTree.js'][118] = 0;
  _$jscoverage['collections/AVLTree.js'][119] = 0;
  _$jscoverage['collections/AVLTree.js'][120] = 0;
  _$jscoverage['collections/AVLTree.js'][121] = 0;
  _$jscoverage['collections/AVLTree.js'][122] = 0;
  _$jscoverage['collections/AVLTree.js'][125] = 0;
  _$jscoverage['collections/AVLTree.js'][126] = 0;
  _$jscoverage['collections/AVLTree.js'][127] = 0;
  _$jscoverage['collections/AVLTree.js'][129] = 0;
  _$jscoverage['collections/AVLTree.js'][131] = 0;
  _$jscoverage['collections/AVLTree.js'][134] = 0;
  _$jscoverage['collections/AVLTree.js'][135] = 0;
  _$jscoverage['collections/AVLTree.js'][136] = 0;
  _$jscoverage['collections/AVLTree.js'][138] = 0;
  _$jscoverage['collections/AVLTree.js'][140] = 0;
  _$jscoverage['collections/AVLTree.js'][141] = 0;
  _$jscoverage['collections/AVLTree.js'][142] = 0;
  _$jscoverage['collections/AVLTree.js'][143] = 0;
  _$jscoverage['collections/AVLTree.js'][144] = 0;
  _$jscoverage['collections/AVLTree.js'][147] = 0;
  _$jscoverage['collections/AVLTree.js'][171] = 0;
  _$jscoverage['collections/AVLTree.js'][176] = 0;
  _$jscoverage['collections/AVLTree.js'][177] = 0;
  _$jscoverage['collections/AVLTree.js'][182] = 0;
  _$jscoverage['collections/AVLTree.js'][186] = 0;
  _$jscoverage['collections/AVLTree.js'][187] = 0;
  _$jscoverage['collections/AVLTree.js'][188] = 0;
  _$jscoverage['collections/AVLTree.js'][189] = 0;
  _$jscoverage['collections/AVLTree.js'][190] = 0;
  _$jscoverage['collections/AVLTree.js'][192] = 0;
  _$jscoverage['collections/AVLTree.js'][193] = 0;
  _$jscoverage['collections/AVLTree.js'][194] = 0;
  _$jscoverage['collections/AVLTree.js'][195] = 0;
  _$jscoverage['collections/AVLTree.js'][196] = 0;
}
_$jscoverage['collections/AVLTree.js'][1]++;
var define = require("../define").define, Tree = require("./Tree"), base = require("../base"), multiply = base.string.multiply;
_$jscoverage['collections/AVLTree.js'][6]++;
var abs = Math.abs;
_$jscoverage['collections/AVLTree.js'][10]++;
var makeNode = (function (data) {
  _$jscoverage['collections/AVLTree.js'][11]++;
  return ({data: data, balance: 0, left: null, right: null});
});
_$jscoverage['collections/AVLTree.js'][19]++;
var rotateSingle = (function (root, dir, otherDir) {
  _$jscoverage['collections/AVLTree.js'][20]++;
  var save = root[otherDir];
  _$jscoverage['collections/AVLTree.js'][21]++;
  root[otherDir] = save[dir];
  _$jscoverage['collections/AVLTree.js'][22]++;
  save[dir] = root;
  _$jscoverage['collections/AVLTree.js'][23]++;
  return save;
});
_$jscoverage['collections/AVLTree.js'][27]++;
var rotateDouble = (function (root, dir, otherDir) {
  _$jscoverage['collections/AVLTree.js'][28]++;
  root[otherDir] = rotateSingle(root[otherDir], otherDir, dir);
  _$jscoverage['collections/AVLTree.js'][29]++;
  return rotateSingle(root, dir, otherDir);
});
_$jscoverage['collections/AVLTree.js'][32]++;
var adjustBalance = (function (root, dir, bal) {
  _$jscoverage['collections/AVLTree.js'][33]++;
  var otherDir = dir == "left"? "right": "left";
  _$jscoverage['collections/AVLTree.js'][34]++;
  var n = root[dir], nn = n[otherDir];
  _$jscoverage['collections/AVLTree.js'][35]++;
  if (nn.balance == 0) {
    _$jscoverage['collections/AVLTree.js'][36]++;
    root.balance = n.balance = 0;
  }
  else {
    _$jscoverage['collections/AVLTree.js'][37]++;
    if (nn.balance == bal) {
      _$jscoverage['collections/AVLTree.js'][38]++;
      root.balance = - bal;
      _$jscoverage['collections/AVLTree.js'][39]++;
      n.balance = 0;
    }
    else {
      _$jscoverage['collections/AVLTree.js'][42]++;
      root.balance = 0;
      _$jscoverage['collections/AVLTree.js'][43]++;
      n.balance = bal;
    }
  }
  _$jscoverage['collections/AVLTree.js'][45]++;
  nn.balance = 0;
});
_$jscoverage['collections/AVLTree.js'][48]++;
var insertAdjustBalance = (function (root, dir) {
  _$jscoverage['collections/AVLTree.js'][49]++;
  var otherDir = dir == "left"? "right": "left";
  _$jscoverage['collections/AVLTree.js'][51]++;
  var n = root[dir];
  _$jscoverage['collections/AVLTree.js'][52]++;
  var bal = dir == "left"? -1: 1;
  _$jscoverage['collections/AVLTree.js'][54]++;
  if (n.balance == bal) {
    _$jscoverage['collections/AVLTree.js'][55]++;
    root.balance = n.balance = 0;
    _$jscoverage['collections/AVLTree.js'][56]++;
    root = rotateSingle(root, otherDir, dir);
  }
  else {
    _$jscoverage['collections/AVLTree.js'][59]++;
    adjustBalance(root, dir, bal);
    _$jscoverage['collections/AVLTree.js'][60]++;
    root = rotateDouble(root, otherDir, dir);
  }
  _$jscoverage['collections/AVLTree.js'][63]++;
  return root;
});
_$jscoverage['collections/AVLTree.js'][67]++;
var removeAdjustBalance = (function (root, dir, done) {
  _$jscoverage['collections/AVLTree.js'][68]++;
  var otherDir = dir == "left"? "right": "left";
  _$jscoverage['collections/AVLTree.js'][69]++;
  var n = root[otherDir];
  _$jscoverage['collections/AVLTree.js'][70]++;
  var bal = dir == "left"? -1: 1;
  _$jscoverage['collections/AVLTree.js'][71]++;
  if (n.balance == - bal) {
    _$jscoverage['collections/AVLTree.js'][72]++;
    root.balance = n.balance = 0;
    _$jscoverage['collections/AVLTree.js'][73]++;
    root = rotateSingle(root, dir, otherDir);
  }
  else {
    _$jscoverage['collections/AVLTree.js'][75]++;
    if (n.balance == bal) {
      _$jscoverage['collections/AVLTree.js'][76]++;
      adjustBalance(root, otherDir, - bal);
      _$jscoverage['collections/AVLTree.js'][77]++;
      root = rotateDouble(root, dir, otherDir);
    }
    else {
      _$jscoverage['collections/AVLTree.js'][80]++;
      root.balance = - bal;
      _$jscoverage['collections/AVLTree.js'][81]++;
      n.balance = bal;
      _$jscoverage['collections/AVLTree.js'][82]++;
      root = rotateSingle(root, dir, otherDir);
      _$jscoverage['collections/AVLTree.js'][83]++;
      done.done = true;
    }
  }
  _$jscoverage['collections/AVLTree.js'][85]++;
  return root;
});
_$jscoverage['collections/AVLTree.js'][88]++;
var insert = (function (root, data, done, compare) {
  _$jscoverage['collections/AVLTree.js'][89]++;
  if (root == null || root == undefined) {
    _$jscoverage['collections/AVLTree.js'][90]++;
    root = makeNode(data);
  }
  else {
    _$jscoverage['collections/AVLTree.js'][92]++;
    var dir = compare(data, root.data) == -1? "left": "right";
    _$jscoverage['collections/AVLTree.js'][93]++;
    root[dir] = insert(root[dir], data, done, compare);
    _$jscoverage['collections/AVLTree.js'][95]++;
    if (! done.done) {
      _$jscoverage['collections/AVLTree.js'][97]++;
      root.balance += dir == "left"? -1: 1;
      _$jscoverage['collections/AVLTree.js'][99]++;
      if (root.balance == 0) {
        _$jscoverage['collections/AVLTree.js'][100]++;
        done.done = true;
      }
      else {
        _$jscoverage['collections/AVLTree.js'][101]++;
        if (abs(root.balance) > 1) {
          _$jscoverage['collections/AVLTree.js'][102]++;
          root = insertAdjustBalance(root, dir);
          _$jscoverage['collections/AVLTree.js'][103]++;
          done.done = true;
        }
      }
    }
  }
  _$jscoverage['collections/AVLTree.js'][108]++;
  return root;
});
_$jscoverage['collections/AVLTree.js'][111]++;
var remove = (function (root, data, done, compare) {
  _$jscoverage['collections/AVLTree.js'][112]++;
  var dir, cmp, save, b;
  _$jscoverage['collections/AVLTree.js'][113]++;
  if (root) {
    _$jscoverage['collections/AVLTree.js'][115]++;
    cmp = compare(data, root.data);
    _$jscoverage['collections/AVLTree.js'][116]++;
    if (cmp === 0) {
      _$jscoverage['collections/AVLTree.js'][118]++;
      var l = root.left, r = root.right;
      _$jscoverage['collections/AVLTree.js'][119]++;
      if (! l || ! r) {
        _$jscoverage['collections/AVLTree.js'][120]++;
        dir = ! l? "right": "left";
        _$jscoverage['collections/AVLTree.js'][121]++;
        save = root[dir];
        _$jscoverage['collections/AVLTree.js'][122]++;
        return save;
      }
      else {
        _$jscoverage['collections/AVLTree.js'][125]++;
        var heir = l, r;
        _$jscoverage['collections/AVLTree.js'][126]++;
        while ((r = heir.right) != null) {
          _$jscoverage['collections/AVLTree.js'][127]++;
          heir = r;
}
        _$jscoverage['collections/AVLTree.js'][129]++;
        root.data = heir.data;
        _$jscoverage['collections/AVLTree.js'][131]++;
        data = heir.data;
      }
    }
    _$jscoverage['collections/AVLTree.js'][134]++;
    dir = compare(root.data, data) == -1? "right": "left";
    _$jscoverage['collections/AVLTree.js'][135]++;
    root[dir] = remove(root[dir], data, done, compare);
    _$jscoverage['collections/AVLTree.js'][136]++;
    if (! done.done) {
      _$jscoverage['collections/AVLTree.js'][138]++;
      b = (root.balance += (dir == "left"? 1: -1));
      _$jscoverage['collections/AVLTree.js'][140]++;
      var a = abs(b);
      _$jscoverage['collections/AVLTree.js'][141]++;
      if (a === 1) {
        _$jscoverage['collections/AVLTree.js'][142]++;
        done.done = true;
      }
      else {
        _$jscoverage['collections/AVLTree.js'][143]++;
        if (a > 1) {
          _$jscoverage['collections/AVLTree.js'][144]++;
          root = removeAdjustBalance(root, dir, done);
        }
      }
    }
  }
  _$jscoverage['collections/AVLTree.js'][147]++;
  return root;
});
_$jscoverage['collections/AVLTree.js'][171]++;
module.exports = exports = define(Tree, {instance: {insert: (function (data) {
  _$jscoverage['collections/AVLTree.js'][176]++;
  var done = {done: false};
  _$jscoverage['collections/AVLTree.js'][177]++;
  this.__root = insert(this.__root, data, done, this.compare);
}), remove: (function (data) {
  _$jscoverage['collections/AVLTree.js'][182]++;
  this.__root = remove(this.__root, data, {done: false}, this.compare);
}), __printNode: (function (node, level) {
  _$jscoverage['collections/AVLTree.js'][186]++;
  var str = [];
  _$jscoverage['collections/AVLTree.js'][187]++;
  if (node == null) {
    _$jscoverage['collections/AVLTree.js'][188]++;
    str.push(multiply("\t", level));
    _$jscoverage['collections/AVLTree.js'][189]++;
    str.push("~");
    _$jscoverage['collections/AVLTree.js'][190]++;
    console.log(str.join(""));
  }
  else {
    _$jscoverage['collections/AVLTree.js'][192]++;
    this.__printNode(node.right, level + 1);
    _$jscoverage['collections/AVLTree.js'][193]++;
    str.push(multiply("\t", level));
    _$jscoverage['collections/AVLTree.js'][194]++;
    str.push(node.data + ":" + node.balance + "\n");
    _$jscoverage['collections/AVLTree.js'][195]++;
    console.log(str.join(""));
    _$jscoverage['collections/AVLTree.js'][196]++;
    this.__printNode(node.left, level + 1);
  }
})}});
_$jscoverage['collections/AVLTree.js'].source = ["var define = require(\"../define\").define,","        Tree = require(\"./Tree\"),","        base = require(\"../base\"),","        multiply = base.string.multiply;","","var abs = Math.abs;","","","","var makeNode = function(data) {","    return {","        data : data,","        balance : 0,","        left : null,","        right : null","    }","};","","var rotateSingle = function(root, dir, otherDir) {","    var save = root[otherDir];","    root[otherDir] = save[dir];","    save[dir] = root;","    return save;","};","","","var rotateDouble = function(root, dir, otherDir) {","    root[otherDir] = rotateSingle(root[otherDir], otherDir, dir);","    return rotateSingle(root, dir, otherDir);","};","","var adjustBalance = function(root, dir, bal) {","    var otherDir = dir == \"left\" ? \"right\" : \"left\";","    var n = root[dir], nn = n[otherDir];","    if (nn.balance == 0)","        root.balance = n.balance = 0;","    else if (nn.balance == bal) {","        root.balance = -bal;","        n.balance = 0;","    }","    else { /* nn.balance == -bal */","        root.balance = 0;","        n.balance = bal;","    }","    nn.balance = 0;","};","","var insertAdjustBalance = function(root, dir) {","    var otherDir = dir == \"left\" ? \"right\" : \"left\";","","    var n = root[dir];","    var bal = dir == \"left\" ? -1 : +1;","","    if (n.balance == bal) {","        root.balance = n.balance = 0;","        root = rotateSingle(root, otherDir, dir);","    }","    else {","        adjustBalance(root, dir, bal);","        root = rotateDouble(root, otherDir, dir);","    }","","    return root;","","};","","var removeAdjustBalance = function(root, dir, done) {","    var otherDir = dir == \"left\" ? \"right\" : \"left\";","    var n = root[otherDir];","    var bal = dir == \"left\" ? -1 : 1;","    if (n.balance == -bal) {","        root.balance = n.balance = 0;","        root = rotateSingle(root, dir, otherDir);","    }","    else if (n.balance == bal) {","        adjustBalance(root, otherDir, -bal);","        root = rotateDouble(root, dir, otherDir);","    }","    else { /* n.balance == 0 */","        root.balance = -bal;","        n.balance = bal;","        root = rotateSingle(root, dir, otherDir);","        done.done = true;","    }","    return root;","};","","var insert = function(root, data, done, compare) {","    if (root == null || root == undefined)","        root = makeNode(data);","    else {","        var dir = compare(data, root.data) == -1 ? \"left\" : \"right\";","        root[dir] = insert(root[dir], data, done, compare);","","        if (!done.done) {","            /* Update balance factors */","            root.balance += dir == \"left\" ? -1 : 1;","            /* Rebalance as necessary and terminate */","            if (root.balance == 0)","                done.done = true;","            else if (abs(root.balance) &gt; 1) {","                root = insertAdjustBalance(root, dir);","                done.done = true;","            }","        }","    }","","    return root;","};","","var remove = function(root, data, done, compare) {","    var dir, cmp, save, b;","    if (root) {","        //Remove node","        cmp = compare(data, root.data);","        if (cmp === 0) {","            // Unlink and fix parent","            var l = root.left, r = root.right;","            if (!l || !r) {","                dir = !l ? \"right\" : \"left\";","                save = root[dir];","                return save;","            }","            else {","                var heir = l, r;","                while ((r = heir.right) != null) {","                    heir = r;","                }","                root.data = heir.data;","                //reset and start searching","                data = heir.data;","            }","        }","        dir = compare(root.data, data) == -1 ? \"right\" : \"left\";","        root[dir] = remove(root[dir], data, done, compare);","        if (!done.done) {","            /* Update balance factors */","            b = (root.balance += (dir == \"left\" ? 1 : -1));","            /* Terminate or rebalance as necessary */","            var a = abs(b);","            if (a === 1)","                done.done = true;","            else if (a &gt; 1)","                root = removeAdjustBalance(root, dir, done);","        }","    }","    return root;","};","","","/**"," * @class &lt;p&gt;An AVL tree is a self-balancing binary search tree."," *    In an AVL tree, the heights of the two child subtrees of any node differ by at most one."," *    Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases,"," *    where n is the number of nodes in the tree prior to the operation."," *    Insertions and deletions may require the tree to be rebalanced by one or more tree rotations.&lt;/p&gt;"," * &lt;p&gt;AVL trees are more rigidly balanced than red-black trees, leading to slower insertion and removal but faster retrieval&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 AVLTree"," * @augments comb.collections.Tree"," * @memberOf comb.collections"," */","module.exports = exports  = define(Tree, {","    instance : {","        /**@lends comb.collections.AVLTree.prototype*/","","        insert : function(data) {","            var done = {done : false};","            this.__root = insert(this.__root, data, done, this.compare);","        },","","","        remove : function(data) {","            this.__root = remove(this.__root, data, {done : false}, this.compare);","        },","","        __printNode : function(node, level) {","            var str = [];","            if (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.balance + \"\\n\");","                console.log(str.join(\"\"));","                this.__printNode(node.left, level + 1);","            }","        }","","    }","});",""];
