Skip to content

Commit 5da0c59

Browse files
committed
do rotate next
1 parent 131ec3f commit 5da0c59

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/sorted-queue.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class SortedQueue<V, K = any> {
420420
if (v <= 0) {
421421

422422
if (!currentNode.left) {
423-
// newNode.parent = currentNode;
423+
newNode.parent = currentNode;
424424
currentNode.left = newNode;
425425
// newNode.leftOrRight = 'left';
426426
// this.doLeftRotation(currentNode);
@@ -435,7 +435,7 @@ class SortedQueue<V, K = any> {
435435

436436

437437
if (!currentNode.right) {
438-
// newNode.parent = currentNode;
438+
newNode.parent = currentNode;
439439
currentNode.right = newNode;
440440
// newNode.leftOrRight = 'right';
441441
// this.doRightRotation(currentNode);
@@ -452,7 +452,6 @@ class SortedQueue<V, K = any> {
452452

453453
}
454454

455-
456455
compareNodesByBoolean(a: SortedQueueNode<V, K>, b: SortedQueueNode<V, K>) {
457456
return this.compareByBoolean(a.getValue(), b.getValue())
458457
}
@@ -463,19 +462,19 @@ const getNode = <V, K>(v: number, diff: number, count: number): SortedQueueNode<
463462
// console.log(v, count);
464463
return new SortedQueueNode<V, K>(
465464
{val: v as any, key: v as any},
466-
count > 9 ? emptyNodeSymbol : getNode(v - diff, diff / 2, count + 1),
467-
count > 9 ? emptyNodeSymbol : getNode(v + diff, diff / 2, count + 1),
465+
count > 16 ? emptyNodeSymbol : getNode(v - diff, diff / 2, count + 1),
466+
count > 16 ? emptyNodeSymbol : getNode(v + diff, diff / 2, count + 1),
468467
);
469468
}
470469

471470
console.time('foo')
472-
const rootNode3 = getNode(0.5, 0.25, 1);
473-
(rootNode3 as any).isRoot = true;
471+
const rootNode = getNode(0.5, 0.25, 1);
472+
(rootNode as any).isRoot = true;
474473
console.timeEnd('foo');
475474
// process.exit(0);
476475

477476

478-
const rootNode = new SortedQueueNode<number, number>(
477+
const rootNode2 = new SortedQueueNode<number, number>(
479478
{val: 0.5},
480479

481480
new SortedQueueNode<number, number>(
@@ -548,7 +547,7 @@ const vals = [];
548547

549548
console.time('start');
550549

551-
for (let i = 0; i < 5; i++) {
550+
for (let i = 0; i < 1000; i++) {
552551
const r = Math.random();
553552
// console.time(String(r));
554553
sq.insert(r);

0 commit comments

Comments
 (0)