Skip to content

Commit 3a1971f

Browse files
committed
Add comments
1 parent f5427c7 commit 3a1971f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,19 @@
114114
return newRoot;
115115
};
116116

117+
/**
118+
* Flip the colors of the both neighbours of given node.
119+
* Complexity O(1).
120+
*/
117121
RBTree.prototype._flipColors = function (node) {
118122
node.getLeft().flipColor();
119123
node.getRight().flipColor();
120124
};
121125

126+
/*
127+
* Rotates given node to left.
128+
* Complexity O(1).
129+
*/
122130
RBTree.prototype._rotateLeft = function (node) {
123131
var x = node.getRight();
124132
if (x !== null) {
@@ -131,6 +139,10 @@
131139
return x;
132140
};
133141

142+
/*
143+
* Rotates given node to right.
144+
* Complexity O(1).
145+
*/
134146
RBTree.prototype._rotateRight = function (node) {
135147
var x = node.getLeft();
136148
if (x !== null) {
@@ -143,6 +155,13 @@
143155
return x;
144156
};
145157

158+
/**
159+
* Gets value by given key.
160+
* Complexity O(log n).
161+
*
162+
* @param {*} key A key to be searched for
163+
* @return {*} A value which will be returned based on the passed key
164+
*/
146165
RBTree.prototype.get = function (key) {
147166
return this._get(this._root, key);
148167
};

0 commit comments

Comments
 (0)