File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 114
114
return newRoot ;
115
115
} ;
116
116
117
+ /**
118
+ * Flip the colors of the both neighbours of given node.
119
+ * Complexity O(1).
120
+ */
117
121
RBTree . prototype . _flipColors = function ( node ) {
118
122
node . getLeft ( ) . flipColor ( ) ;
119
123
node . getRight ( ) . flipColor ( ) ;
120
124
} ;
121
125
126
+ /*
127
+ * Rotates given node to left.
128
+ * Complexity O(1).
129
+ */
122
130
RBTree . prototype . _rotateLeft = function ( node ) {
123
131
var x = node . getRight ( ) ;
124
132
if ( x !== null ) {
131
139
return x ;
132
140
} ;
133
141
142
+ /*
143
+ * Rotates given node to right.
144
+ * Complexity O(1).
145
+ */
134
146
RBTree . prototype . _rotateRight = function ( node ) {
135
147
var x = node . getLeft ( ) ;
136
148
if ( x !== null ) {
143
155
return x ;
144
156
} ;
145
157
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
+ */
146
165
RBTree . prototype . get = function ( key ) {
147
166
return this . _get ( this . _root , key ) ;
148
167
} ;
You can’t perform that action at this time.
0 commit comments