graph-typed 1.45.1 → 1.45.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -271,19 +271,28 @@ class Heap {
|
|
|
271
271
|
* @param index - The index of the newly added element.
|
|
272
272
|
*/
|
|
273
273
|
bubbleUp(index) {
|
|
274
|
-
const element = this.nodes[index];
|
|
274
|
+
// const element = this.nodes[index];
|
|
275
|
+
// while (index > 0) {
|
|
276
|
+
// const parentIndex = (index - 1) >> 1;
|
|
277
|
+
// const parent = this.nodes[parentIndex];
|
|
278
|
+
// if (this.comparator(element, parent) < 0) {
|
|
279
|
+
// this.nodes[index] = parent;
|
|
280
|
+
// this.nodes[parentIndex] = element;
|
|
281
|
+
// index = parentIndex;
|
|
282
|
+
// } else {
|
|
283
|
+
// break;
|
|
284
|
+
// }
|
|
285
|
+
// }
|
|
286
|
+
const item = this.nodes[index];
|
|
275
287
|
while (index > 0) {
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
if (this.comparator(
|
|
279
|
-
this.nodes[index] = parent;
|
|
280
|
-
this.nodes[parentIndex] = element;
|
|
281
|
-
index = parentIndex;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
288
|
+
const parent = (index - 1) >> 1;
|
|
289
|
+
const parentItem = this.nodes[parent];
|
|
290
|
+
if (this.comparator(parentItem, item) <= 0)
|
|
284
291
|
break;
|
|
285
|
-
|
|
292
|
+
this.nodes[index] = parentItem;
|
|
293
|
+
index = parent;
|
|
286
294
|
}
|
|
295
|
+
this.nodes[index] = item;
|
|
287
296
|
}
|
|
288
297
|
/**
|
|
289
298
|
* Time Complexity: O(log n)
|
|
@@ -297,8 +306,8 @@ class Heap {
|
|
|
297
306
|
* @param index - The index from which to start sinking.
|
|
298
307
|
*/
|
|
299
308
|
sinkDown(index) {
|
|
300
|
-
const leftChildIndex =
|
|
301
|
-
const rightChildIndex =
|
|
309
|
+
const leftChildIndex = index << 1 | 1;
|
|
310
|
+
const rightChildIndex = leftChildIndex + 1;
|
|
302
311
|
const length = this.nodes.length;
|
|
303
312
|
let targetIndex = index;
|
|
304
313
|
if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graph-typed",
|
|
3
|
-
"version": "1.45.
|
|
3
|
+
"version": "1.45.2",
|
|
4
4
|
"description": "Graph. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -136,6 +136,6 @@
|
|
|
136
136
|
"typescript": "^4.9.5"
|
|
137
137
|
},
|
|
138
138
|
"dependencies": {
|
|
139
|
-
"data-structure-typed": "^1.45.
|
|
139
|
+
"data-structure-typed": "^1.45.2"
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -305,18 +305,28 @@ export class Heap<E = any> {
|
|
|
305
305
|
* @param index - The index of the newly added element.
|
|
306
306
|
*/
|
|
307
307
|
protected bubbleUp(index: number): void {
|
|
308
|
-
const element = this.nodes[index];
|
|
308
|
+
// const element = this.nodes[index];
|
|
309
|
+
// while (index > 0) {
|
|
310
|
+
// const parentIndex = (index - 1) >> 1;
|
|
311
|
+
// const parent = this.nodes[parentIndex];
|
|
312
|
+
// if (this.comparator(element, parent) < 0) {
|
|
313
|
+
// this.nodes[index] = parent;
|
|
314
|
+
// this.nodes[parentIndex] = element;
|
|
315
|
+
// index = parentIndex;
|
|
316
|
+
// } else {
|
|
317
|
+
// break;
|
|
318
|
+
// }
|
|
319
|
+
// }
|
|
320
|
+
|
|
321
|
+
const item = this.nodes[index];
|
|
309
322
|
while (index > 0) {
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
if (this.comparator(
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
index = parentIndex;
|
|
316
|
-
} else {
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
323
|
+
const parent = (index - 1) >> 1;
|
|
324
|
+
const parentItem = this.nodes[parent];
|
|
325
|
+
if (this.comparator(parentItem, item) <= 0) break;
|
|
326
|
+
this.nodes[index] = parentItem;
|
|
327
|
+
index = parent;
|
|
319
328
|
}
|
|
329
|
+
this.nodes[index] = item;
|
|
320
330
|
}
|
|
321
331
|
|
|
322
332
|
/**
|
|
@@ -332,8 +342,8 @@ export class Heap<E = any> {
|
|
|
332
342
|
* @param index - The index from which to start sinking.
|
|
333
343
|
*/
|
|
334
344
|
protected sinkDown(index: number): void {
|
|
335
|
-
const leftChildIndex =
|
|
336
|
-
const rightChildIndex =
|
|
345
|
+
const leftChildIndex = index << 1 | 1;
|
|
346
|
+
const rightChildIndex = leftChildIndex + 1;
|
|
337
347
|
const length = this.nodes.length;
|
|
338
348
|
let targetIndex = index;
|
|
339
349
|
|