File tree Expand file tree Collapse file tree 1 file changed +24
-20
lines changed Expand file tree Collapse file tree 1 file changed +24
-20
lines changed Original file line number Diff line number Diff line change 19
19
var child = new Node ( interval [ 0 ] , interval [ 1 ] ) ;
20
20
child . parentNode = node ;
21
21
node [ side ] = child ;
22
- if ( side === 'right' && node . max < interval [ 1 ] ) {
22
+ if ( node . max < interval [ 1 ] ) {
23
23
while ( child ) {
24
24
if ( child . max < interval [ 1 ] ) {
25
25
child . max = interval [ 1 ] ;
167
167
}
168
168
} else {
169
169
this . root = node [ side ] ;
170
- this . root . parentNode = null ;
170
+ // last node removed
171
+ if ( this . root ) {
172
+ this . root . parentNode = null ;
173
+ }
171
174
}
172
175
}
173
176
// Adjust the max value
@@ -208,25 +211,26 @@ var t = new IntervalTree();
208
211
209
212
t . add ( [ 1 , 2 ] ) ;
210
213
t . add ( [ - 1 , 8 ] ) ;
211
- t . add ( [ - 1 , 18 ] ) ;
212
- t . add ( [ 2 , 4 ] ) ;
213
- t . add ( [ 8 , 13 ] ) ;
214
- t . add ( [ 2 , 10 ] ) ;
215
- t . add ( [ - 2 , 10 ] ) ;
216
- t . add ( [ - 4 , 15 ] ) ;
217
- t . add ( [ - 6 , 15 ] ) ;
218
-
219
- t . remove ( [ 1 , 2 ] ) ;
220
- t . remove ( [ - 1 , 8 ] ) ;
221
- t . remove ( [ - 1 , 18 ] ) ;
222
- t . remove ( [ 2 , 4 ] ) ;
223
- t . remove ( [ 8 , 13 ] ) ;
224
- t . remove ( [ 2 , 10 ] ) ;
225
- t . remove ( [ - 2 , 10 ] ) ;
226
- t . remove ( [ - 4 , 15 ] ) ;
227
-
214
+ // t.add([-1, 18]);
215
+ // t.add([2, 4]);
216
+ // t.add([8, 13]);
217
+ // t.add([2, 10]);
218
+ // t.add([-2, 10]);
219
+ // t.add([-4, 15]);
220
+ // t.add([-6, 15]);
221
+
222
+ // t.remove([1, 2]);
223
+ // t.remove([-1, 8]);
224
+ // t.remove([-1, 18]);
225
+ // t.remove([2, 4]);
226
+ // t.remove([8, 13]);
227
+ // t.remove([2, 10]);
228
+ // t.remove([-2, 10]);
229
+ // t.remove([-4, 15]);
230
+ // t.remove([-6, 15]);
231
+
232
+ console . log ( t . height ( ) ) ;
228
233
console . log ( t . root ) ;
229
- console . log ( t . intersects ( [ 17 , 29 ] ) ) ;
230
234
231
235
//console.log(t.intersects([19, 29]));
232
236
//console.log(t.contains(16));
You can’t perform that action at this time.
0 commit comments