Skip to content

Commit d3673b0

Browse files
committed
Pass the whole gulp build.
1 parent 2854031 commit d3673b0

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

src/data-structures/size-balanced-tree.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
* @module data-structures/size-balanced-tree
3131
*/
3232
(function (exports) {
33-
3433
'use strict';
3534

36-
37-
3835
/**
3936
* Node of the Size-Balanced tree.
4037
*
@@ -101,14 +98,16 @@
10198
10299
childNode
103100
/ \
104-
node CR
101+
node CR
105102
/ \
106103
NL CL
107104
*/
108105
node.right = childNode.left;
109-
if (node.right !== Nil) node.right.parent = node;
106+
if (node.right !== Nil) {
107+
node.right.parent = node;
108+
}
110109
childNode.left = node;
111-
updateChild(node, childNode) //Access node.parent
110+
updateChild(node, childNode); //Access node.parent
112111
node.parent = childNode;
113112
node.updateSize();
114113
return childNode;
@@ -126,14 +125,16 @@
126125
127126
childNode
128127
/ \
129-
CL node
128+
CL node
130129
/ \
131130
CR NR
132131
*/
133132
node.left = childNode.right;
134-
if (node.left !== Nil) node.left.parent = node;
133+
if (node.left !== Nil) {
134+
node.left.parent = node;
135+
}
135136
childNode.right = node;
136-
updateChild(node, childNode) //Access node.parent
137+
updateChild(node, childNode); //Access node.parent
137138
node.parent = childNode;
138139
node.updateSize();
139140
return childNode;
@@ -174,7 +175,7 @@
174175
while (node.parent !== Nil) {
175176
var childNode = node;
176177
node = node.parent;
177-
if (node.left == childNode) {
178+
if (node.left === childNode) {
178179
node = maintain(node, true);
179180
} else {
180181
node = maintain(node, false);
@@ -198,12 +199,12 @@
198199
}
199200

200201
function findNodeAtPos(node, pos) {
201-
while (pos != node.left.size) {
202+
while (pos !== node.left.size) {
202203
if (pos < node.left.size) {
203204
node = node.left;
204205
} else {
205206
pos -= node.left.size;
206-
--pos; //The node element should be decrement by 1
207+
pos -= 1; //The node element should be decrement by 1
207208
node = node.right;
208209
}
209210
}
@@ -220,13 +221,12 @@
220221
this._root = Nil;
221222
};
222223

223-
224224
exports.SBTree.prototype = {
225225
get size() {
226226
return this._root.size;
227227
},
228-
}
229-
228+
};
229+
230230
/**
231231
* Push a value to the end of tree.<br><br>
232232
* Complexity: O(log N).
@@ -238,21 +238,23 @@
238238
exports.SBTree.prototype.push = function (value) {
239239
var node = findRightMost(this._root);
240240
var newNode = new Node(value, node, Nil, Nil, 1);
241-
if (node !== Nil) node.right = newNode;
241+
if (node !== Nil) {
242+
node.right = newNode;
243+
}
242244
this._root = maintainSizeBalancedTree(newNode);
243245
return newNode;
244246
};
245247

246-
exports.SBTree.prototype.get = function(pos) {
248+
exports.SBTree.prototype.get = function (pos) {
247249
if (pos >= this._root.size) {
248250
return Nil;
249251
}
250252
return findNodeAtPos(this._root, pos);
251253
};
252254

253-
exports.SBTree.prototype.getIndex = function(node) {
255+
exports.SBTree.prototype.getIndex = function (node) {
254256
var index = node.left.size;
255-
while (node != this._root) {
257+
while (node !== this._root) {
256258
var parent = node.parent;
257259
if (parent.right === node) {
258260
index += parent.left.size + 1;
@@ -262,12 +264,12 @@
262264
return index;
263265
};
264266

265-
exports.SBTree.prototype.insert = function(pos, value) {
267+
exports.SBTree.prototype.insert = function (pos, value) {
266268
if (pos >= this._root.size) {
267-
return this.push(value)
269+
return this.push(value);
268270
}
269271
var node = findNodeAtPos(this._root, pos);
270-
var newNode
272+
var newNode;
271273
if (node.left === Nil) {
272274
newNode = new Node(value, node, Nil, Nil, 1);
273275
node.left = newNode;
@@ -280,7 +282,7 @@
280282
return newNode;
281283
};
282284

283-
exports.SBTree.prototype.remove = function(pos) {
285+
exports.SBTree.prototype.remove = function (pos) {
284286
if (pos >= this._root.size) {
285287
return Nil; // There is no element to remove
286288
}
@@ -289,7 +291,8 @@
289291

290292
/*
291293
Before remove:
292-
P(node's parent, be notices, N either be left child or right child of P)
294+
P (node's parent, be notices,
295+
| N either be left child or right child of P)
293296
|
294297
N(node)
295298
/ \
@@ -302,20 +305,20 @@
302305
After remove node N:
303306
P(node's parent)
304307
/
305-
L
308+
L
306309
\
307310
\
308311
LRM(Left-Rightmost)
309312
\
310313
R
311314
312315
N(node) is wild node that was removed
313-
316+
314317
*/
315318
if (node.left !== Nil){
316319
var LRM = findRightMost(node.left);
317-
updateChild(node, node.left)
318-
LRM.right = node.right
320+
updateChild(node, node.left);
321+
LRM.right = node.right;
319322
if (LRM.right === Nil) {
320323
maintainNode = LRM;
321324
} else {
@@ -324,21 +327,20 @@
324327
}
325328
} else if (node.right !== Nil) {
326329
var RLM = findLeftMost(node.right);
327-
updateChild(node, node.right)
328-
RLM.left = node.left
330+
updateChild(node, node.right);
331+
RLM.left = node.left;
329332
if (RLM.left === Nil) {
330333
maintainNode = RLM;
331334
} else {
332335
RLM.left.parent = RLM;
333336
maintainNode = RLM.left;
334337
}
335338
} else {
336-
updateChild(node, Nil)
339+
updateChild(node, Nil);
337340
maintainNode = node.parent;
338341
}
339342
this._root = maintainSizeBalancedTree(maintainNode);
340343
return node;
341344
};
342345

343-
344346
})(typeof module === 'undefined' ? window : module.exports);

test/data-structures/size-balanced-tree.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ describe('SBTree', function () {
6262
expect(Nil.parent).toBe(Nil);
6363
expect(Nil.value).toBe(null);
6464
}
65-
it('test updateChild', function() {
65+
66+
it('test updateChild', function () {
6667
updateChild(Nil, Nil);
6768
checkNil();
6869
var root = new Node(10, Nil, Nil, Nil, 1);
@@ -149,15 +150,15 @@ describe('SBTree', function () {
149150
checkNil();
150151
});
151152

152-
it('test getIndex', function(){
153+
it('test getIndex', function () {
153154
var sTree = new SBTree();
154-
for (let i = 0; i < 10000; ++i) {
155-
let key = i.toString();
155+
for (var i = 0; i < 10000; ++i) {
156+
var key = i.toString();
156157
sTree.push(key);
157158
}
158159

159-
for (let i=0; i<100; ++i) {
160-
let item = sTree.get(i);
160+
for (var i = 0; i < 100; ++i) {
161+
var item = sTree.get(i);
161162
expect(item.value).toBe(i.toString());
162163
expect(sTree.getIndex(item)).toBe(i);
163164
}

0 commit comments

Comments
 (0)