Skip to content

Commit 687492f

Browse files
committed
Fix the remove operation
1 parent 8530563 commit 687492f

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

src/data-structures/interval-tree.js

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// The implementation doesn't work properly!
2-
// Most of the operations are still buggy, not properly implemented.
31
(function (exports) {
42
'use strict';
53

@@ -176,16 +174,14 @@
176174
// Adjust the max value
177175
var p = node.parentNode;
178176
if (p) {
179-
var maxNode = this.findMax(p);
180-
if (maxNode.interval[1] > p.max) {
181-
var max = maxNode.interval[1];
182-
while (maxNode) {
183-
if (max > maxNode.max && maxNode.max === node.interval[1]) {
184-
maxNode.max = max;
185-
maxNode = maxNode.parentNode;
186-
} else {
187-
maxNode = false;
188-
}
177+
var maxNode = this.findMax(p),
178+
max = maxNode.interval[1];
179+
while (maxNode) {
180+
if (maxNode.max === node.interval[1]) {
181+
maxNode.max = max;
182+
maxNode = maxNode.parentNode;
183+
} else {
184+
maxNode = false;
189185
}
190186
}
191187
}
@@ -204,35 +200,3 @@
204200
exports.IntervalTree = IntervalTree;
205201

206202
}(typeof exports === 'undefined' ? window : exports));
207-
208-
var IntervalTree = exports.IntervalTree;
209-
210-
var t = new IntervalTree();
211-
212-
t.add([1, 2]);
213-
t.add([-1, 8]);
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());
233-
console.log(t.root);
234-
235-
//console.log(t.intersects([19, 29]));
236-
//console.log(t.contains(16));
237-
238-
console.log('Height:', t.height());

0 commit comments

Comments
 (0)