Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5427c7

Browse files
committed
Add comments
1 parent 9a8c73a commit f5427c7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/data-structures/red-black-tree.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,30 @@
6666
this._root = null;
6767
}
6868

69+
/**
70+
* Adds value associated with given key.
71+
* Complexity O(log n)
72+
*/
6973
RBTree.prototype.put = function (key, value) {
7074
this._root = this._put(key, value, this._root);
7175
this._root.setColor(Colors.BLACK);
7276
};
7377

78+
/**
79+
* Returns true or false depending on whether
80+
* given node is red.
81+
*/
7482
RBTree.prototype.isRed = function (node) {
7583
if (!node) {
7684
return false;
7785
}
7886
return node.isRed();
7987
};
8088

89+
/**
90+
* Helper function for insertion of given key, value pair
91+
* into the red-black tree.
92+
*/
8193
RBTree.prototype._put = function (key, value, node) {
8294
var newRoot = node;
8395
if (node === null) {

0 commit comments

Comments
 (0)