data-structure-typed 1.45.1 → 1.45.3
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.
- package/CHANGELOG.md +1 -1
- package/COMMANDS.md +6 -1
- package/README.md +56 -16
- package/benchmark/report.html +18 -15
- package/benchmark/report.json +157 -116
- package/dist/cjs/data-structures/heap/heap.js +21 -12
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/mjs/data-structures/heap/heap.js +21 -12
- package/dist/umd/data-structure-typed.js +9 -11
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/heap/heap.ts +22 -12
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/performance/data-structures/comparation.test.ts +142 -0
- package/test/performance/data-structures/hash/hash-map.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +1 -1
- package/test/performance/data-structures/queue/deque.test.ts +1 -1
- package/test/performance/data-structures/queue/queue.test.ts +1 -1
- package/test/performance/data-structures/stack/stack.test.ts +2 -2
- package/test/performance/reportor.ts +34 -8
- package/test/unit/data-structures/heap/heap.test.ts +38 -0
- package/test/utils/index.ts +1 -0
- package/test/utils/performanc.ts +7 -0
|
@@ -3773,18 +3773,16 @@ var dataStructureTyped = (() => {
|
|
|
3773
3773
|
* @param index - The index of the newly added element.
|
|
3774
3774
|
*/
|
|
3775
3775
|
bubbleUp(index) {
|
|
3776
|
-
const
|
|
3776
|
+
const item = this.nodes[index];
|
|
3777
3777
|
while (index > 0) {
|
|
3778
|
-
const
|
|
3779
|
-
const
|
|
3780
|
-
if (this.comparator(
|
|
3781
|
-
this.nodes[index] = parent;
|
|
3782
|
-
this.nodes[parentIndex] = element;
|
|
3783
|
-
index = parentIndex;
|
|
3784
|
-
} else {
|
|
3778
|
+
const parent = index - 1 >> 1;
|
|
3779
|
+
const parentItem = this.nodes[parent];
|
|
3780
|
+
if (this.comparator(parentItem, item) <= 0)
|
|
3785
3781
|
break;
|
|
3786
|
-
|
|
3782
|
+
this.nodes[index] = parentItem;
|
|
3783
|
+
index = parent;
|
|
3787
3784
|
}
|
|
3785
|
+
this.nodes[index] = item;
|
|
3788
3786
|
}
|
|
3789
3787
|
/**
|
|
3790
3788
|
* Time Complexity: O(log n)
|
|
@@ -3798,8 +3796,8 @@ var dataStructureTyped = (() => {
|
|
|
3798
3796
|
* @param index - The index from which to start sinking.
|
|
3799
3797
|
*/
|
|
3800
3798
|
sinkDown(index) {
|
|
3801
|
-
const leftChildIndex =
|
|
3802
|
-
const rightChildIndex =
|
|
3799
|
+
const leftChildIndex = index << 1 | 1;
|
|
3800
|
+
const rightChildIndex = leftChildIndex + 1;
|
|
3803
3801
|
const length = this.nodes.length;
|
|
3804
3802
|
let targetIndex = index;
|
|
3805
3803
|
if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
|