data-structure-typed 2.5.2 → 2.5.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 +3 -1
- package/MIGRATION.md +169 -0
- package/README.md +60 -6
- package/README_CN.md +551 -143
- package/SPECIFICATION.md +20 -14
- package/SPECIFICATION.zh-CN.md +20 -14
- package/dist/cjs/binary-tree.cjs +2417 -132
- package/dist/cjs/graph.cjs +248 -14
- package/dist/cjs/hash.cjs +62 -7
- package/dist/cjs/heap.cjs +103 -16
- package/dist/cjs/index.cjs +3046 -124
- package/dist/cjs/linked-list.cjs +219 -0
- package/dist/cjs/matrix.cjs +32 -0
- package/dist/cjs/priority-queue.cjs +101 -14
- package/dist/cjs/queue.cjs +215 -0
- package/dist/cjs/stack.cjs +44 -4
- package/dist/cjs/trie.cjs +44 -0
- package/dist/cjs-legacy/binary-tree.cjs +2406 -123
- package/dist/cjs-legacy/graph.cjs +248 -14
- package/dist/cjs-legacy/hash.cjs +62 -7
- package/dist/cjs-legacy/heap.cjs +103 -16
- package/dist/cjs-legacy/index.cjs +3105 -185
- package/dist/cjs-legacy/linked-list.cjs +219 -0
- package/dist/cjs-legacy/matrix.cjs +32 -0
- package/dist/cjs-legacy/priority-queue.cjs +101 -14
- package/dist/cjs-legacy/queue.cjs +215 -0
- package/dist/cjs-legacy/stack.cjs +44 -4
- package/dist/cjs-legacy/trie.cjs +44 -0
- package/dist/esm/binary-tree.mjs +2417 -132
- package/dist/esm/graph.mjs +248 -14
- package/dist/esm/hash.mjs +62 -7
- package/dist/esm/heap.mjs +103 -16
- package/dist/esm/index.mjs +3046 -124
- package/dist/esm/linked-list.mjs +219 -0
- package/dist/esm/matrix.mjs +32 -0
- package/dist/esm/priority-queue.mjs +101 -14
- package/dist/esm/queue.mjs +215 -0
- package/dist/esm/stack.mjs +44 -4
- package/dist/esm/trie.mjs +44 -0
- package/dist/esm-legacy/binary-tree.mjs +2406 -123
- package/dist/esm-legacy/graph.mjs +248 -14
- package/dist/esm-legacy/hash.mjs +62 -7
- package/dist/esm-legacy/heap.mjs +103 -16
- package/dist/esm-legacy/index.mjs +3105 -185
- package/dist/esm-legacy/linked-list.mjs +219 -0
- package/dist/esm-legacy/matrix.mjs +32 -0
- package/dist/esm-legacy/priority-queue.mjs +101 -14
- package/dist/esm-legacy/queue.mjs +215 -0
- package/dist/esm-legacy/stack.mjs +44 -4
- package/dist/esm-legacy/trie.mjs +44 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
- package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
- package/dist/types/data-structures/heap/heap.d.ts +98 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
- package/dist/types/data-structures/queue/deque.d.ts +82 -0
- package/dist/types/data-structures/queue/queue.d.ts +61 -0
- package/dist/types/data-structures/stack/stack.d.ts +42 -2
- package/dist/types/data-structures/trie/trie.d.ts +48 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/data-structure-typed.js +3105 -185
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
- package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +143 -155
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
- package/docs-site-docusaurus/docs/api/classes/Queue.md +111 -59
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
- package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
- package/docs-site-docusaurus/docs/guide/faq.md +53 -0
- package/docs-site-docusaurus/docs/guide/guides.md +8 -9
- package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
- package/docs-site-docusaurus/docs/guide/overview.md +131 -17
- package/docs-site-docusaurus/src/pages/index.tsx +4 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/package.json +7 -6
- package/src/data-structures/binary-tree/avl-tree.ts +52 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
- package/src/data-structures/binary-tree/binary-tree.ts +167 -81
- package/src/data-structures/binary-tree/bst.ts +101 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
- package/src/data-structures/binary-tree/segment-tree.ts +24 -0
- package/src/data-structures/binary-tree/tree-map.ts +540 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
- package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
- package/src/data-structures/binary-tree/tree-set.ts +520 -3
- package/src/data-structures/graph/directed-graph.ts +41 -1
- package/src/data-structures/graph/undirected-graph.ts +37 -1
- package/src/data-structures/hash/hash-map.ts +67 -12
- package/src/data-structures/heap/heap.ts +107 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
- package/src/data-structures/matrix/matrix.ts +32 -0
- package/src/data-structures/queue/deque.ts +85 -0
- package/src/data-structures/queue/queue.ts +73 -0
- package/src/data-structures/stack/stack.ts +45 -5
- package/src/data-structures/trie/trie.ts +48 -0
- package/src/interfaces/binary-tree.ts +1 -9
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
package/dist/esm-legacy/hash.mjs
CHANGED
|
@@ -321,6 +321,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
321
321
|
|
|
322
322
|
|
|
323
323
|
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
324
328
|
|
|
325
329
|
|
|
326
330
|
|
|
@@ -366,6 +370,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
366
370
|
|
|
367
371
|
|
|
368
372
|
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
369
377
|
|
|
370
378
|
|
|
371
379
|
|
|
@@ -457,6 +465,14 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
457
465
|
|
|
458
466
|
|
|
459
467
|
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
460
476
|
|
|
461
477
|
|
|
462
478
|
|
|
@@ -494,7 +510,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
494
510
|
if (this.store[strKey] === void 0) this._size++;
|
|
495
511
|
this._store[strKey] = { key, value };
|
|
496
512
|
}
|
|
497
|
-
return
|
|
513
|
+
return this;
|
|
498
514
|
}
|
|
499
515
|
/**
|
|
500
516
|
* Insert many entries from an iterable.
|
|
@@ -529,6 +545,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
529
545
|
|
|
530
546
|
|
|
531
547
|
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
532
552
|
|
|
533
553
|
|
|
534
554
|
|
|
@@ -546,7 +566,11 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
546
566
|
let key, value;
|
|
547
567
|
if (this.isEntry(rawEle)) [key, value] = rawEle;
|
|
548
568
|
else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
|
|
549
|
-
if (key !== void 0 && value !== void 0)
|
|
569
|
+
if (key !== void 0 && value !== void 0) {
|
|
570
|
+
const sizeBefore = this._size;
|
|
571
|
+
this.set(key, value);
|
|
572
|
+
results.push(sizeBefore < this._size);
|
|
573
|
+
}
|
|
550
574
|
}
|
|
551
575
|
return results;
|
|
552
576
|
}
|
|
@@ -585,6 +609,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
585
609
|
|
|
586
610
|
|
|
587
611
|
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
588
616
|
|
|
589
617
|
|
|
590
618
|
|
|
@@ -653,6 +681,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
653
681
|
|
|
654
682
|
|
|
655
683
|
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
656
688
|
|
|
657
689
|
|
|
658
690
|
|
|
@@ -705,6 +737,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
705
737
|
|
|
706
738
|
|
|
707
739
|
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
708
744
|
|
|
709
745
|
|
|
710
746
|
|
|
@@ -775,6 +811,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
775
811
|
|
|
776
812
|
|
|
777
813
|
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
778
818
|
|
|
779
819
|
|
|
780
820
|
|
|
@@ -828,6 +868,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
828
868
|
|
|
829
869
|
|
|
830
870
|
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
831
875
|
|
|
832
876
|
|
|
833
877
|
|
|
@@ -883,6 +927,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
883
927
|
|
|
884
928
|
|
|
885
929
|
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
886
934
|
|
|
887
935
|
|
|
888
936
|
|
|
@@ -1092,7 +1140,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1092
1140
|
* @remarks Time O(1), Space O(1)
|
|
1093
1141
|
* @param key - Key.
|
|
1094
1142
|
* @param [value] - Value.
|
|
1095
|
-
* @returns
|
|
1143
|
+
* @returns This map (for chaining).
|
|
1096
1144
|
*/
|
|
1097
1145
|
set(key, value) {
|
|
1098
1146
|
let node;
|
|
@@ -1127,7 +1175,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1127
1175
|
this._sentinel.prev = node;
|
|
1128
1176
|
this._size++;
|
|
1129
1177
|
}
|
|
1130
|
-
return
|
|
1178
|
+
return this;
|
|
1131
1179
|
}
|
|
1132
1180
|
setMany(entryOrRawElements) {
|
|
1133
1181
|
const results = [];
|
|
@@ -1135,7 +1183,11 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1135
1183
|
let key, value;
|
|
1136
1184
|
if (this.isEntry(rawEle)) [key, value] = rawEle;
|
|
1137
1185
|
else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
|
|
1138
|
-
if (key !== void 0 && value !== void 0)
|
|
1186
|
+
if (key !== void 0 && value !== void 0) {
|
|
1187
|
+
const sizeBefore = this._size;
|
|
1188
|
+
this.set(key, value);
|
|
1189
|
+
results.push(sizeBefore < this._size);
|
|
1190
|
+
}
|
|
1139
1191
|
}
|
|
1140
1192
|
return results;
|
|
1141
1193
|
}
|
|
@@ -1213,13 +1265,16 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1213
1265
|
* Delete the entry at a given index.
|
|
1214
1266
|
* @remarks Time O(N), Space O(1)
|
|
1215
1267
|
* @param index - Zero-based index.
|
|
1216
|
-
* @returns
|
|
1268
|
+
* @returns The removed entry [key, value].
|
|
1269
|
+
* @throws {RangeError} If index is out of bounds.
|
|
1217
1270
|
*/
|
|
1218
1271
|
deleteAt(index) {
|
|
1219
1272
|
rangeCheck(index, 0, this._size - 1);
|
|
1220
1273
|
let node = this.head;
|
|
1221
1274
|
while (index--) node = node.next;
|
|
1222
|
-
|
|
1275
|
+
const entry = [node.key, node.value];
|
|
1276
|
+
this._deleteNode(node);
|
|
1277
|
+
return entry;
|
|
1223
1278
|
}
|
|
1224
1279
|
isEmpty() {
|
|
1225
1280
|
return this._size === 0;
|
package/dist/esm-legacy/heap.mjs
CHANGED
|
@@ -326,6 +326,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
326
326
|
|
|
327
327
|
|
|
328
328
|
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
329
333
|
|
|
330
334
|
|
|
331
335
|
|
|
@@ -380,7 +384,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
380
384
|
}
|
|
381
385
|
/**
|
|
382
386
|
* Insert an element.
|
|
383
|
-
* @remarks Time O(
|
|
387
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
384
388
|
* @param element - Element to insert.
|
|
385
389
|
* @returns True.
|
|
386
390
|
|
|
@@ -413,6 +417,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
413
417
|
|
|
414
418
|
|
|
415
419
|
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
416
424
|
|
|
417
425
|
|
|
418
426
|
|
|
@@ -470,6 +478,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
470
478
|
|
|
471
479
|
|
|
472
480
|
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
473
485
|
|
|
474
486
|
|
|
475
487
|
|
|
@@ -530,10 +542,41 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
530
542
|
|
|
531
543
|
|
|
532
544
|
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
533
548
|
|
|
534
549
|
|
|
535
550
|
|
|
536
551
|
|
|
552
|
+
* @example
|
|
553
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
554
|
+
* interface Task {
|
|
555
|
+
* id: number;
|
|
556
|
+
* priority: number;
|
|
557
|
+
* name: string;
|
|
558
|
+
* }
|
|
559
|
+
*
|
|
560
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
561
|
+
* const tasks: Task[] = [
|
|
562
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
563
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
564
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
565
|
+
* ];
|
|
566
|
+
*
|
|
567
|
+
* const maxHeap = new Heap(tasks, {
|
|
568
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
569
|
+
* });
|
|
570
|
+
*
|
|
571
|
+
* console.log(maxHeap.size); // 3;
|
|
572
|
+
*
|
|
573
|
+
* // Peek returns highest priority task
|
|
574
|
+
* const topTask = maxHeap.peek();
|
|
575
|
+
* console.log(topTask?.priority); // 8;
|
|
576
|
+
* console.log(topTask?.name); // 'Alert';
|
|
577
|
+
*/
|
|
578
|
+
/**
|
|
579
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
537
580
|
* @example
|
|
538
581
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
539
582
|
* interface Task {
|
|
@@ -561,6 +604,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
561
604
|
* console.log(topTask?.name); // 'Alert';
|
|
562
605
|
*/
|
|
563
606
|
poll() {
|
|
607
|
+
return this.pop();
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
611
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
612
|
+
* @returns The removed top element, or undefined if empty.
|
|
613
|
+
*/
|
|
614
|
+
pop() {
|
|
564
615
|
if (this.elements.length === 0) return;
|
|
565
616
|
const value = this.elements[0];
|
|
566
617
|
const last = this.elements.pop();
|
|
@@ -604,6 +655,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
604
655
|
|
|
605
656
|
|
|
606
657
|
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
607
662
|
|
|
608
663
|
|
|
609
664
|
|
|
@@ -704,6 +759,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
704
759
|
|
|
705
760
|
|
|
706
761
|
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
707
766
|
|
|
708
767
|
|
|
709
768
|
|
|
@@ -751,6 +810,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
751
810
|
|
|
752
811
|
|
|
753
812
|
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
754
817
|
|
|
755
818
|
|
|
756
819
|
|
|
@@ -765,16 +828,6 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
765
828
|
clear() {
|
|
766
829
|
this._elements = [];
|
|
767
830
|
}
|
|
768
|
-
/**
|
|
769
|
-
* Replace the backing array and rebuild the heap.
|
|
770
|
-
* @remarks Time O(N), Space O(N)
|
|
771
|
-
* @param elements - Iterable used to refill the heap.
|
|
772
|
-
* @returns Array of per-node results from fixing steps.
|
|
773
|
-
*/
|
|
774
|
-
refill(elements) {
|
|
775
|
-
this._elements = Array.from(elements);
|
|
776
|
-
return this.fix();
|
|
777
|
-
}
|
|
778
831
|
/**
|
|
779
832
|
* Check if an equal element exists in the heap.
|
|
780
833
|
* @remarks Time O(N), Space O(1)
|
|
@@ -801,6 +854,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
801
854
|
|
|
802
855
|
|
|
803
856
|
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
804
861
|
|
|
805
862
|
|
|
806
863
|
|
|
@@ -848,6 +905,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
848
905
|
|
|
849
906
|
|
|
850
907
|
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
851
912
|
|
|
852
913
|
|
|
853
914
|
|
|
@@ -869,7 +930,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
869
930
|
}
|
|
870
931
|
if (index < 0) return false;
|
|
871
932
|
if (index === 0) {
|
|
872
|
-
this.
|
|
933
|
+
this.pop();
|
|
873
934
|
} else if (index === this.elements.length - 1) {
|
|
874
935
|
this.elements.pop();
|
|
875
936
|
} else {
|
|
@@ -879,13 +940,19 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
879
940
|
}
|
|
880
941
|
return true;
|
|
881
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
945
|
+
*/
|
|
946
|
+
deleteBy(predicate) {
|
|
947
|
+
return this.deleteWhere(predicate);
|
|
948
|
+
}
|
|
882
949
|
/**
|
|
883
950
|
* Delete the first element that matches a predicate.
|
|
884
951
|
* @remarks Time O(N), Space O(1)
|
|
885
952
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
886
953
|
* @returns True if an element was removed.
|
|
887
954
|
*/
|
|
888
|
-
|
|
955
|
+
deleteWhere(predicate) {
|
|
889
956
|
let idx = -1;
|
|
890
957
|
for (let i = 0; i < this.elements.length; i++) {
|
|
891
958
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -895,7 +962,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
895
962
|
}
|
|
896
963
|
if (idx < 0) return false;
|
|
897
964
|
if (idx === 0) {
|
|
898
|
-
this.
|
|
965
|
+
this.pop();
|
|
899
966
|
} else if (idx === this.elements.length - 1) {
|
|
900
967
|
this.elements.pop();
|
|
901
968
|
} else {
|
|
@@ -941,6 +1008,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
941
1008
|
|
|
942
1009
|
|
|
943
1010
|
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
944
1015
|
|
|
945
1016
|
|
|
946
1017
|
|
|
@@ -1021,6 +1092,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1021
1092
|
|
|
1022
1093
|
|
|
1023
1094
|
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1024
1099
|
|
|
1025
1100
|
|
|
1026
1101
|
|
|
@@ -1074,6 +1149,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1074
1149
|
|
|
1075
1150
|
|
|
1076
1151
|
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1077
1156
|
|
|
1078
1157
|
|
|
1079
1158
|
|
|
@@ -1126,6 +1205,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1126
1205
|
|
|
1127
1206
|
|
|
1128
1207
|
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1129
1212
|
|
|
1130
1213
|
|
|
1131
1214
|
|
|
@@ -1185,6 +1268,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1185
1268
|
|
|
1186
1269
|
|
|
1187
1270
|
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1188
1275
|
|
|
1189
1276
|
|
|
1190
1277
|
|
|
@@ -1367,7 +1454,7 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
1367
1454
|
* Push an element into the root list.
|
|
1368
1455
|
* @remarks Time O(1) amortized, Space O(1)
|
|
1369
1456
|
* @param element - Element to insert.
|
|
1370
|
-
* @returns
|
|
1457
|
+
* @returns True when the element is added.
|
|
1371
1458
|
*/
|
|
1372
1459
|
push(element) {
|
|
1373
1460
|
const node = this.createNode(element);
|
|
@@ -1376,7 +1463,7 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
1376
1463
|
this.mergeWithRoot(node);
|
|
1377
1464
|
if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
|
|
1378
1465
|
this._size++;
|
|
1379
|
-
return
|
|
1466
|
+
return true;
|
|
1380
1467
|
}
|
|
1381
1468
|
peek() {
|
|
1382
1469
|
return this.min ? this.min.element : void 0;
|