|
74 | 74 | exports.Nil = Nil; |
75 | 75 |
|
76 | 76 | function updateChild(node, newChild) { |
77 | | - let parent = node.parent; |
| 77 | + var parent = node.parent; |
78 | 78 | if (parent !== Nil) { |
79 | 79 | if (parent.right === node) { |
80 | 80 | parent.right = newChild; |
|
172 | 172 |
|
173 | 173 | function maintainSizeBalancedTree(node) { |
174 | 174 | while (node.parent !== Nil) { |
175 | | - let childNode = node; |
| 175 | + var childNode = node; |
176 | 176 | node = node.parent; |
177 | 177 | if (node.left == childNode) { |
178 | 178 | node = maintain(node, true); |
|
236 | 236 | * @param {Object} value Value. |
237 | 237 | */ |
238 | 238 | exports.SBTree.prototype.push = function (value) { |
239 | | - let node = findRightMost(this._root); |
240 | | - let newNode = new Node(value, node, Nil, Nil, 1); |
| 239 | + var node = findRightMost(this._root); |
| 240 | + var newNode = new Node(value, node, Nil, Nil, 1); |
241 | 241 | if (node !== Nil) node.right = newNode; |
242 | 242 | this._root = maintainSizeBalancedTree(newNode); |
243 | 243 | return newNode; |
|
251 | 251 | }; |
252 | 252 |
|
253 | 253 | exports.SBTree.prototype.getIndex = function(node) { |
254 | | - let index = node.left.size; |
| 254 | + var index = node.left.size; |
255 | 255 | while (node != this._root) { |
256 | | - let parent = node.parent; |
| 256 | + var parent = node.parent; |
257 | 257 | if (parent.right === node) { |
258 | 258 | index += parent.left.size + 1; |
259 | 259 | } |
|
266 | 266 | if (pos >= this._root.size) { |
267 | 267 | return this.push(value) |
268 | 268 | } |
269 | | - let node = findNodeAtPos(this._root, pos); |
270 | | - let newNode |
| 269 | + var node = findNodeAtPos(this._root, pos); |
| 270 | + var newNode |
271 | 271 | if (node.left === Nil) { |
272 | 272 | newNode = new Node(value, node, Nil, Nil, 1); |
273 | 273 | node.left = newNode; |
|
284 | 284 | if (pos >= this._root.size) { |
285 | 285 | return Nil; // There is no element to remove |
286 | 286 | } |
287 | | - let node = findNodeAtPos(this._root, pos); |
288 | | - let maintainNode; |
| 287 | + var node = findNodeAtPos(this._root, pos); |
| 288 | + var maintainNode; |
289 | 289 |
|
290 | 290 | /* |
291 | 291 | Before remove: |
|
313 | 313 | |
314 | 314 | */ |
315 | 315 | if (node.left !== Nil){ |
316 | | - let LRM = findRightMost(node.left); |
| 316 | + var LRM = findRightMost(node.left); |
317 | 317 | updateChild(node, node.left) |
318 | 318 | LRM.right = node.right |
319 | 319 | if (LRM.right === Nil) { |
|
323 | 323 | maintainNode = LRM.right; |
324 | 324 | } |
325 | 325 | } else if (node.right !== Nil) { |
326 | | - let RLM = findLeftMost(node.right); |
| 326 | + var RLM = findLeftMost(node.right); |
327 | 327 | updateChild(node, node.right) |
328 | 328 | RLM.left = node.left |
329 | 329 | if (RLM.left === Nil) { |
|
0 commit comments