Comparing version 0.2.0 to 0.3.0
@@ -161,2 +161,42 @@ /** | ||
/** | ||
* Find the least/first node. | ||
* | ||
* @method _findLeast | ||
* @private | ||
* @return {Node} Retuns the first node. | ||
*/ | ||
RBTree.prototype._findLeast = function(){ | ||
var cur = this.root | ||
if (cur) { | ||
while (cur.ln) { | ||
cur = cur.ln | ||
} | ||
} | ||
return cur | ||
} | ||
/** | ||
* Find the greatest/last node. | ||
* | ||
* @method _findGreatest | ||
* @private | ||
* @return {Node} Returns the last node. | ||
*/ | ||
RBTree.prototype._findGreatest = function(){ | ||
var cur = this.root | ||
if (cur) { | ||
while (cur.rn) { | ||
cur = cur.rn | ||
} | ||
} | ||
return cur | ||
} | ||
/** | ||
* Find the first RBTree Node coming from the low side that is greater-than | ||
@@ -176,8 +216,8 @@ * `key`. | ||
while (cur) { | ||
cmp = this.cmp(key, cur.key) | ||
if ( cmp < 0 /* key < cur.key */) { | ||
cmp = this.cmp(cur.key, key) | ||
if ( cmp > 0 /* cur.key > key */) { | ||
last = cur | ||
cur = cur.ln | ||
} | ||
else /* key >= cur.key */ { | ||
else if ( cmp <= 0 /* cur.key <= key */) { | ||
cur = cur.rn | ||
@@ -187,3 +227,3 @@ } | ||
return cur ? cur : last | ||
return last | ||
} | ||
@@ -207,8 +247,8 @@ | ||
while (cur) { | ||
cmp = this.cmp(key, cur.key) | ||
if ( cmp < 0 /* key < cur.key */) { | ||
cmp = this.cmp(cur.key, key) | ||
if ( cmp > 0 /* cur.key > key */) { | ||
last = cur | ||
cur = cur.ln | ||
} | ||
else if ( cmp > 0 /* key > cur.key */) { | ||
else if ( cmp < 0 /* cur.key < key */) { | ||
cur = cur.rn | ||
@@ -239,13 +279,10 @@ } | ||
while (cur) { | ||
cmp = this.cmp(key, cur.key) | ||
if ( cmp > 0 /* key > cur.key */) { | ||
cmp = this.cmp(cur.key, key) | ||
if ( cmp < 0 /* cur.key < key */) { | ||
last = cur | ||
cur = cur.rn | ||
} | ||
else if ( cmp < 0 /* key < cur.key */) { | ||
else if ( cmp >= 0 /* cur.key > key */) { | ||
cur = cur.ln | ||
} | ||
else /* cmp == 0; key === cur.key */ { | ||
break | ||
} | ||
} | ||
@@ -272,8 +309,8 @@ | ||
while (cur) { | ||
cmp = this.cmp(key, cur.key) | ||
if ( cmp > 0 /* key > cur.key */) { | ||
cmp = this.cmp(cur.key, key) | ||
if ( cmp < 0 /* cur.key < key */) { | ||
last = cur | ||
cur = cur.rn | ||
} | ||
else if ( cmp < 0 /*key < cur.key */) { | ||
else if ( cmp > 0 /* cur.key > key */) { | ||
cur = cur.ln | ||
@@ -321,3 +358,3 @@ } | ||
/** | ||
* Find the next Node after the given Node. | ||
* Find the previous Node before the given Node. | ||
* | ||
@@ -376,3 +413,3 @@ * @method _findPrev | ||
fn(cur.key, cur.value) | ||
fn(cur.key, cur.val) | ||
@@ -396,3 +433,3 @@ if (reverse) cur = cur.ln | ||
var cur = this._find(key) | ||
return cur !== null | ||
return !!cur | ||
} | ||
@@ -411,3 +448,3 @@ | ||
var cur = this._find(key) | ||
if (cur) return cur.value | ||
if (cur) return cur.val | ||
return undefined | ||
@@ -438,3 +475,3 @@ } | ||
if (cmp === 0) { | ||
cur.value = val | ||
cur.val = val | ||
return //no new Node -> so no balancing -> so return from put() | ||
@@ -617,3 +654,3 @@ } | ||
cur.key = victim.key | ||
cur.value = victim.value | ||
cur.val = victim.val | ||
@@ -788,3 +825,3 @@ cur = victim | ||
this.key = key | ||
this.value = val | ||
this.val = val | ||
this.parent = (parent === undefined) ? null : parent | ||
@@ -837,4 +874,3 @@ this.ln = null | ||
Object.defineProperty(this, 'key' , const_null_prop) | ||
Object.defineProperty(this, 'value', const_null_prop) | ||
Object.defineProperty(this, 'key' , const_null_prop) | ||
Object.defineProperty(this, 'val' , const_null_prop) | ||
Object.defineProperty(this, 'ln' , const_null_prop) | ||
@@ -841,0 +877,0 @@ Object.defineProperty(this, 'rn' , const_null_prop) |
{ | ||
"name" : "rbtree" | ||
, "version" : "0.2.0" | ||
, "version" : "0.3.0" | ||
, "description" : "An implementation of a Red-Black Tree for node.js" | ||
@@ -5,0 +5,0 @@ , "keywords" : ["datastructure", "tree", "red-black", "red-black tree"] |
30828
958