Skip to content

Commit c4c96bc

Browse files
committed
add some fixes
1 parent ac44b2c commit c4c96bc

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/sorted-queue.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ class SortedQueue<V, K = any> {
194194
}
195195

196196
if(!node.left.right){
197+
throw 'foo111'
197198
node.left.right = node.right;
198199
return parent;
199200
}
200201

201202
if(!node.right.left){
203+
throw 'bar222'
202204
node.right.left = node.left;
203205
return parent;
204206
}
@@ -211,16 +213,12 @@ class SortedQueue<V, K = any> {
211213
}
212214

213215

214-
if(!node.parent){
215-
throw new Error('tbd');
216-
}
217-
218216
if(true){
219217

220218
rightMost.parent.right = rightMost.left;
221219
rightMost.left = node.left;
222220
rightMost.right = node.right;
223-
rightMost.parent = node.parent;
221+
rightMost.parent = parent;
224222

225223
if(!parent){
226224
this.rootNode = rightMost;
@@ -242,8 +240,6 @@ class SortedQueue<V, K = any> {
242240
}
243241

244242

245-
246-
247243
return parent;
248244

249245

@@ -642,8 +638,8 @@ const getNode = <V, K>(v: number, diff: number, count: number): SortedQueueNode<
642638
// console.log(v, count);
643639
return new SortedQueueNode<V, K>(
644640
{val: v as any, key: v as any},
645-
count > 16 ? emptyNodeSymbol : getNode(v - diff, diff / 2, count + 1),
646-
count > 16 ? emptyNodeSymbol : getNode(v + diff, diff / 2, count + 1),
641+
count > 4 ? emptyNodeSymbol : getNode(v - diff, diff / 2, count + 1),
642+
count > 4 ? emptyNodeSymbol : getNode(v + diff, diff / 2, count + 1),
647643
);
648644
}
649645

@@ -727,7 +723,7 @@ const vals = [];
727723

728724
console.time('start');
729725

730-
for (let i = 0; i < 1000; i++) {
726+
for (let i = 0; i < 0; i++) {
731727
const r = Math.random();
732728
// console.time(String(r));
733729
sq.insert(r);
@@ -876,6 +872,15 @@ for (const v of vals) {
876872
// sq.findNextLargest(sq.findNextLargest(sq.findNextLargest(sq.findNextLargest()))).val
877873
// );
878874

875+
const x = sq.remove(sq.rootNode);
876+
console.log({x});
877+
console.log('new root-node val:', sq.rootNode.val);
878+
console.log('new root-node left val:', sq.rootNode.left.val);
879+
console.log('new root-node right val:', sq.rootNode.right.val);
880+
sq.logInOrder(sq.rootNode);
881+
882+
throw 'bar'
883+
879884
let count = 0;
880885
let smallest = sq.findSmallestValFromRoot();
881886
console.log(smallest.val);

0 commit comments

Comments
 (0)