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/cjs-legacy/hash.cjs
CHANGED
|
@@ -323,6 +323,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
323
323
|
|
|
324
324
|
|
|
325
325
|
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
326
330
|
|
|
327
331
|
|
|
328
332
|
|
|
@@ -368,6 +372,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
368
372
|
|
|
369
373
|
|
|
370
374
|
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
371
379
|
|
|
372
380
|
|
|
373
381
|
|
|
@@ -459,6 +467,14 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
459
467
|
|
|
460
468
|
|
|
461
469
|
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
462
478
|
|
|
463
479
|
|
|
464
480
|
|
|
@@ -496,7 +512,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
496
512
|
if (this.store[strKey] === void 0) this._size++;
|
|
497
513
|
this._store[strKey] = { key, value };
|
|
498
514
|
}
|
|
499
|
-
return
|
|
515
|
+
return this;
|
|
500
516
|
}
|
|
501
517
|
/**
|
|
502
518
|
* Insert many entries from an iterable.
|
|
@@ -531,6 +547,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
531
547
|
|
|
532
548
|
|
|
533
549
|
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
534
554
|
|
|
535
555
|
|
|
536
556
|
|
|
@@ -548,7 +568,11 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
548
568
|
let key, value;
|
|
549
569
|
if (this.isEntry(rawEle)) [key, value] = rawEle;
|
|
550
570
|
else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
|
|
551
|
-
if (key !== void 0 && value !== void 0)
|
|
571
|
+
if (key !== void 0 && value !== void 0) {
|
|
572
|
+
const sizeBefore = this._size;
|
|
573
|
+
this.set(key, value);
|
|
574
|
+
results.push(sizeBefore < this._size);
|
|
575
|
+
}
|
|
552
576
|
}
|
|
553
577
|
return results;
|
|
554
578
|
}
|
|
@@ -587,6 +611,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
587
611
|
|
|
588
612
|
|
|
589
613
|
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
590
618
|
|
|
591
619
|
|
|
592
620
|
|
|
@@ -655,6 +683,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
655
683
|
|
|
656
684
|
|
|
657
685
|
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
658
690
|
|
|
659
691
|
|
|
660
692
|
|
|
@@ -707,6 +739,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
707
739
|
|
|
708
740
|
|
|
709
741
|
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
710
746
|
|
|
711
747
|
|
|
712
748
|
|
|
@@ -777,6 +813,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
777
813
|
|
|
778
814
|
|
|
779
815
|
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
780
820
|
|
|
781
821
|
|
|
782
822
|
|
|
@@ -830,6 +870,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
830
870
|
|
|
831
871
|
|
|
832
872
|
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
833
877
|
|
|
834
878
|
|
|
835
879
|
|
|
@@ -885,6 +929,10 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
885
929
|
|
|
886
930
|
|
|
887
931
|
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
888
936
|
|
|
889
937
|
|
|
890
938
|
|
|
@@ -1094,7 +1142,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1094
1142
|
* @remarks Time O(1), Space O(1)
|
|
1095
1143
|
* @param key - Key.
|
|
1096
1144
|
* @param [value] - Value.
|
|
1097
|
-
* @returns
|
|
1145
|
+
* @returns This map (for chaining).
|
|
1098
1146
|
*/
|
|
1099
1147
|
set(key, value) {
|
|
1100
1148
|
let node;
|
|
@@ -1129,7 +1177,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1129
1177
|
this._sentinel.prev = node;
|
|
1130
1178
|
this._size++;
|
|
1131
1179
|
}
|
|
1132
|
-
return
|
|
1180
|
+
return this;
|
|
1133
1181
|
}
|
|
1134
1182
|
setMany(entryOrRawElements) {
|
|
1135
1183
|
const results = [];
|
|
@@ -1137,7 +1185,11 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1137
1185
|
let key, value;
|
|
1138
1186
|
if (this.isEntry(rawEle)) [key, value] = rawEle;
|
|
1139
1187
|
else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
|
|
1140
|
-
if (key !== void 0 && value !== void 0)
|
|
1188
|
+
if (key !== void 0 && value !== void 0) {
|
|
1189
|
+
const sizeBefore = this._size;
|
|
1190
|
+
this.set(key, value);
|
|
1191
|
+
results.push(sizeBefore < this._size);
|
|
1192
|
+
}
|
|
1141
1193
|
}
|
|
1142
1194
|
return results;
|
|
1143
1195
|
}
|
|
@@ -1215,13 +1267,16 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1215
1267
|
* Delete the entry at a given index.
|
|
1216
1268
|
* @remarks Time O(N), Space O(1)
|
|
1217
1269
|
* @param index - Zero-based index.
|
|
1218
|
-
* @returns
|
|
1270
|
+
* @returns The removed entry [key, value].
|
|
1271
|
+
* @throws {RangeError} If index is out of bounds.
|
|
1219
1272
|
*/
|
|
1220
1273
|
deleteAt(index) {
|
|
1221
1274
|
rangeCheck(index, 0, this._size - 1);
|
|
1222
1275
|
let node = this.head;
|
|
1223
1276
|
while (index--) node = node.next;
|
|
1224
|
-
|
|
1277
|
+
const entry = [node.key, node.value];
|
|
1278
|
+
this._deleteNode(node);
|
|
1279
|
+
return entry;
|
|
1225
1280
|
}
|
|
1226
1281
|
isEmpty() {
|
|
1227
1282
|
return this._size === 0;
|
package/dist/cjs-legacy/heap.cjs
CHANGED
|
@@ -328,6 +328,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
328
328
|
|
|
329
329
|
|
|
330
330
|
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
331
335
|
|
|
332
336
|
|
|
333
337
|
|
|
@@ -382,7 +386,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
382
386
|
}
|
|
383
387
|
/**
|
|
384
388
|
* Insert an element.
|
|
385
|
-
* @remarks Time O(
|
|
389
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
386
390
|
* @param element - Element to insert.
|
|
387
391
|
* @returns True.
|
|
388
392
|
|
|
@@ -415,6 +419,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
415
419
|
|
|
416
420
|
|
|
417
421
|
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
418
426
|
|
|
419
427
|
|
|
420
428
|
|
|
@@ -472,6 +480,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
472
480
|
|
|
473
481
|
|
|
474
482
|
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
475
487
|
|
|
476
488
|
|
|
477
489
|
|
|
@@ -532,10 +544,41 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
532
544
|
|
|
533
545
|
|
|
534
546
|
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
535
550
|
|
|
536
551
|
|
|
537
552
|
|
|
538
553
|
|
|
554
|
+
* @example
|
|
555
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
556
|
+
* interface Task {
|
|
557
|
+
* id: number;
|
|
558
|
+
* priority: number;
|
|
559
|
+
* name: string;
|
|
560
|
+
* }
|
|
561
|
+
*
|
|
562
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
563
|
+
* const tasks: Task[] = [
|
|
564
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
565
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
566
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
567
|
+
* ];
|
|
568
|
+
*
|
|
569
|
+
* const maxHeap = new Heap(tasks, {
|
|
570
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
571
|
+
* });
|
|
572
|
+
*
|
|
573
|
+
* console.log(maxHeap.size); // 3;
|
|
574
|
+
*
|
|
575
|
+
* // Peek returns highest priority task
|
|
576
|
+
* const topTask = maxHeap.peek();
|
|
577
|
+
* console.log(topTask?.priority); // 8;
|
|
578
|
+
* console.log(topTask?.name); // 'Alert';
|
|
579
|
+
*/
|
|
580
|
+
/**
|
|
581
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
539
582
|
* @example
|
|
540
583
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
541
584
|
* interface Task {
|
|
@@ -563,6 +606,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
563
606
|
* console.log(topTask?.name); // 'Alert';
|
|
564
607
|
*/
|
|
565
608
|
poll() {
|
|
609
|
+
return this.pop();
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
613
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
614
|
+
* @returns The removed top element, or undefined if empty.
|
|
615
|
+
*/
|
|
616
|
+
pop() {
|
|
566
617
|
if (this.elements.length === 0) return;
|
|
567
618
|
const value = this.elements[0];
|
|
568
619
|
const last = this.elements.pop();
|
|
@@ -606,6 +657,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
606
657
|
|
|
607
658
|
|
|
608
659
|
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
609
664
|
|
|
610
665
|
|
|
611
666
|
|
|
@@ -706,6 +761,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
706
761
|
|
|
707
762
|
|
|
708
763
|
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
709
768
|
|
|
710
769
|
|
|
711
770
|
|
|
@@ -753,6 +812,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
753
812
|
|
|
754
813
|
|
|
755
814
|
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
756
819
|
|
|
757
820
|
|
|
758
821
|
|
|
@@ -767,16 +830,6 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
767
830
|
clear() {
|
|
768
831
|
this._elements = [];
|
|
769
832
|
}
|
|
770
|
-
/**
|
|
771
|
-
* Replace the backing array and rebuild the heap.
|
|
772
|
-
* @remarks Time O(N), Space O(N)
|
|
773
|
-
* @param elements - Iterable used to refill the heap.
|
|
774
|
-
* @returns Array of per-node results from fixing steps.
|
|
775
|
-
*/
|
|
776
|
-
refill(elements) {
|
|
777
|
-
this._elements = Array.from(elements);
|
|
778
|
-
return this.fix();
|
|
779
|
-
}
|
|
780
833
|
/**
|
|
781
834
|
* Check if an equal element exists in the heap.
|
|
782
835
|
* @remarks Time O(N), Space O(1)
|
|
@@ -803,6 +856,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
803
856
|
|
|
804
857
|
|
|
805
858
|
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
806
863
|
|
|
807
864
|
|
|
808
865
|
|
|
@@ -850,6 +907,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
850
907
|
|
|
851
908
|
|
|
852
909
|
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
853
914
|
|
|
854
915
|
|
|
855
916
|
|
|
@@ -871,7 +932,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
871
932
|
}
|
|
872
933
|
if (index < 0) return false;
|
|
873
934
|
if (index === 0) {
|
|
874
|
-
this.
|
|
935
|
+
this.pop();
|
|
875
936
|
} else if (index === this.elements.length - 1) {
|
|
876
937
|
this.elements.pop();
|
|
877
938
|
} else {
|
|
@@ -881,13 +942,19 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
881
942
|
}
|
|
882
943
|
return true;
|
|
883
944
|
}
|
|
945
|
+
/**
|
|
946
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
947
|
+
*/
|
|
948
|
+
deleteBy(predicate) {
|
|
949
|
+
return this.deleteWhere(predicate);
|
|
950
|
+
}
|
|
884
951
|
/**
|
|
885
952
|
* Delete the first element that matches a predicate.
|
|
886
953
|
* @remarks Time O(N), Space O(1)
|
|
887
954
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
888
955
|
* @returns True if an element was removed.
|
|
889
956
|
*/
|
|
890
|
-
|
|
957
|
+
deleteWhere(predicate) {
|
|
891
958
|
let idx = -1;
|
|
892
959
|
for (let i = 0; i < this.elements.length; i++) {
|
|
893
960
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -897,7 +964,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
897
964
|
}
|
|
898
965
|
if (idx < 0) return false;
|
|
899
966
|
if (idx === 0) {
|
|
900
|
-
this.
|
|
967
|
+
this.pop();
|
|
901
968
|
} else if (idx === this.elements.length - 1) {
|
|
902
969
|
this.elements.pop();
|
|
903
970
|
} else {
|
|
@@ -943,6 +1010,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
943
1010
|
|
|
944
1011
|
|
|
945
1012
|
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
946
1017
|
|
|
947
1018
|
|
|
948
1019
|
|
|
@@ -1023,6 +1094,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1023
1094
|
|
|
1024
1095
|
|
|
1025
1096
|
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1026
1101
|
|
|
1027
1102
|
|
|
1028
1103
|
|
|
@@ -1076,6 +1151,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1076
1151
|
|
|
1077
1152
|
|
|
1078
1153
|
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1079
1158
|
|
|
1080
1159
|
|
|
1081
1160
|
|
|
@@ -1128,6 +1207,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1128
1207
|
|
|
1129
1208
|
|
|
1130
1209
|
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1131
1214
|
|
|
1132
1215
|
|
|
1133
1216
|
|
|
@@ -1187,6 +1270,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1187
1270
|
|
|
1188
1271
|
|
|
1189
1272
|
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
|
|
1190
1277
|
|
|
1191
1278
|
|
|
1192
1279
|
|
|
@@ -1369,7 +1456,7 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
1369
1456
|
* Push an element into the root list.
|
|
1370
1457
|
* @remarks Time O(1) amortized, Space O(1)
|
|
1371
1458
|
* @param element - Element to insert.
|
|
1372
|
-
* @returns
|
|
1459
|
+
* @returns True when the element is added.
|
|
1373
1460
|
*/
|
|
1374
1461
|
push(element) {
|
|
1375
1462
|
const node = this.createNode(element);
|
|
@@ -1378,7 +1465,7 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
1378
1465
|
this.mergeWithRoot(node);
|
|
1379
1466
|
if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
|
|
1380
1467
|
this._size++;
|
|
1381
|
-
return
|
|
1468
|
+
return true;
|
|
1382
1469
|
}
|
|
1383
1470
|
peek() {
|
|
1384
1471
|
return this.min ? this.min.element : void 0;
|