data-structure-typed 2.4.5 → 2.5.1
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/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +3 -1
- package/README.md +78 -31
- package/dist/cjs/binary-tree.cjs +23698 -0
- package/dist/cjs/graph.cjs +5236 -0
- package/dist/cjs/hash.cjs +1262 -0
- package/dist/cjs/heap.cjs +1540 -0
- package/dist/cjs/index.cjs +24509 -2899
- package/dist/cjs/linked-list.cjs +4370 -0
- package/dist/cjs/matrix.cjs +1042 -0
- package/dist/cjs/priority-queue.cjs +1314 -0
- package/dist/cjs/queue.cjs +4090 -0
- package/dist/cjs/stack.cjs +861 -0
- package/dist/cjs/trie.cjs +1173 -0
- package/dist/cjs-legacy/binary-tree.cjs +23730 -0
- package/dist/cjs-legacy/graph.cjs +5234 -0
- package/dist/cjs-legacy/hash.cjs +1262 -0
- package/dist/cjs-legacy/heap.cjs +1537 -0
- package/dist/cjs-legacy/index.cjs +32555 -10936
- package/dist/cjs-legacy/linked-list.cjs +4376 -0
- package/dist/cjs-legacy/matrix.cjs +1045 -0
- package/dist/cjs-legacy/priority-queue.cjs +1312 -0
- package/dist/cjs-legacy/queue.cjs +4088 -0
- package/dist/cjs-legacy/stack.cjs +861 -0
- package/dist/cjs-legacy/trie.cjs +1172 -0
- package/dist/esm/binary-tree.mjs +23683 -0
- package/dist/esm/graph.mjs +5223 -0
- package/dist/esm/hash.mjs +1259 -0
- package/dist/esm/heap.mjs +1534 -0
- package/dist/esm/index.mjs +24507 -2898
- package/dist/esm/linked-list.mjs +4363 -0
- package/dist/esm/matrix.mjs +1038 -0
- package/dist/esm/priority-queue.mjs +1310 -0
- package/dist/esm/queue.mjs +4086 -0
- package/dist/esm/stack.mjs +859 -0
- package/dist/esm/trie.mjs +1170 -0
- package/dist/esm-legacy/binary-tree.mjs +23715 -0
- package/dist/esm-legacy/graph.mjs +5221 -0
- package/dist/esm-legacy/hash.mjs +1259 -0
- package/dist/esm-legacy/heap.mjs +1531 -0
- package/dist/esm-legacy/index.mjs +32553 -10935
- package/dist/esm-legacy/linked-list.mjs +4369 -0
- package/dist/esm-legacy/matrix.mjs +1041 -0
- package/dist/esm-legacy/priority-queue.mjs +1308 -0
- package/dist/esm-legacy/queue.mjs +4084 -0
- package/dist/esm-legacy/stack.mjs +859 -0
- package/dist/esm-legacy/trie.mjs +1169 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +368 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +473 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +931 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +792 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +592 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +320 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3662 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3487 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2778 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3414 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +419 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +384 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +462 -89
- package/dist/types/data-structures/heap/heap.d.ts +567 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +631 -49
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +581 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +775 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +491 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +578 -71
- package/dist/types/data-structures/queue/queue.d.ts +451 -42
- package/dist/types/data-structures/stack/stack.d.ts +374 -32
- package/dist/types/data-structures/trie/trie.d.ts +458 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +32432 -10808
- package/dist/umd/data-structure-typed.min.js +10 -4
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
- package/docs-site-docusaurus/docs/guide/guides.md +611 -0
- package/docs-site-docusaurus/docs/guide/installation.md +60 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
- package/docs-site-docusaurus/docs/guide/overview.md +638 -0
- package/docs-site-docusaurus/docs/guide/performance.md +833 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +71 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/package.json +109 -12
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -18,71 +18,6 @@ import { LinearBase } from '../base/linear-base';
|
|
|
18
18
|
* 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
|
|
19
19
|
* 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
|
|
20
20
|
* @example
|
|
21
|
-
* // basic Deque creation and push/pop operations
|
|
22
|
-
* // Create a simple Deque with initial values
|
|
23
|
-
* const deque = new Deque([1, 2, 3, 4, 5]);
|
|
24
|
-
*
|
|
25
|
-
* // Verify the deque maintains insertion order
|
|
26
|
-
* console.log([...deque]); // [1, 2, 3, 4, 5];
|
|
27
|
-
*
|
|
28
|
-
* // Check length
|
|
29
|
-
* console.log(deque.length); // 5;
|
|
30
|
-
*
|
|
31
|
-
* // Push to the end
|
|
32
|
-
* deque.push(6);
|
|
33
|
-
* console.log(deque.length); // 6;
|
|
34
|
-
*
|
|
35
|
-
* // Pop from the end
|
|
36
|
-
* const last = deque.pop();
|
|
37
|
-
* console.log(last); // 6;
|
|
38
|
-
* @example
|
|
39
|
-
* // Deque shift and unshift operations
|
|
40
|
-
* const deque = new Deque<number>([20, 30, 40]);
|
|
41
|
-
*
|
|
42
|
-
* // Unshift adds to the front
|
|
43
|
-
* deque.unshift(10);
|
|
44
|
-
* console.log([...deque]); // [10, 20, 30, 40];
|
|
45
|
-
*
|
|
46
|
-
* // Shift removes from the front (O(1) complexity!)
|
|
47
|
-
* const first = deque.shift();
|
|
48
|
-
* console.log(first); // 10;
|
|
49
|
-
*
|
|
50
|
-
* // Verify remaining elements
|
|
51
|
-
* console.log([...deque]); // [20, 30, 40];
|
|
52
|
-
* console.log(deque.length); // 3;
|
|
53
|
-
* @example
|
|
54
|
-
* // Deque peek at both ends
|
|
55
|
-
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
56
|
-
*
|
|
57
|
-
* // Get first element without removing
|
|
58
|
-
* const first = deque.at(0);
|
|
59
|
-
* console.log(first); // 10;
|
|
60
|
-
*
|
|
61
|
-
* // Get last element without removing
|
|
62
|
-
* const last = deque.at(deque.length - 1);
|
|
63
|
-
* console.log(last); // 50;
|
|
64
|
-
*
|
|
65
|
-
* // Length unchanged
|
|
66
|
-
* console.log(deque.length); // 5;
|
|
67
|
-
* @example
|
|
68
|
-
* // Deque for...of iteration and reverse
|
|
69
|
-
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
70
|
-
*
|
|
71
|
-
* // Iterate forward
|
|
72
|
-
* const forward: string[] = [];
|
|
73
|
-
* for (const item of deque) {
|
|
74
|
-
* forward.push(item);
|
|
75
|
-
* }
|
|
76
|
-
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
77
|
-
*
|
|
78
|
-
* // Reverse the deque
|
|
79
|
-
* deque.reverse();
|
|
80
|
-
* const backward: string[] = [];
|
|
81
|
-
* for (const item of deque) {
|
|
82
|
-
* backward.push(item);
|
|
83
|
-
* }
|
|
84
|
-
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
85
|
-
* @example
|
|
86
21
|
* // Deque as sliding window for stream processing
|
|
87
22
|
* interface DataPoint {
|
|
88
23
|
* timestamp: number;
|
|
@@ -133,6 +68,10 @@ import { LinearBase } from '../base/linear-base';
|
|
|
133
68
|
* console.log(windowResults[2].windowSize); // 3; // Windows are at max size from 3rd onwards
|
|
134
69
|
* console.log(windowResults[4].windowSize); // 3; // Last window still has 3 elements
|
|
135
70
|
* console.log(dataWindow.length); // 3;
|
|
71
|
+
* @example
|
|
72
|
+
* // Convert deque to array
|
|
73
|
+
* const dq = new Deque<number>([10, 20, 30]);
|
|
74
|
+
* console.log(dq.toArray()); // [10, 20, 30];
|
|
136
75
|
*/
|
|
137
76
|
export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
138
77
|
protected _equals: (a: E, b: E) => boolean;
|
|
@@ -227,12 +166,93 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
227
166
|
* Get the first element without removing it.
|
|
228
167
|
* @remarks Time O(1), Space O(1)
|
|
229
168
|
* @returns First element or undefined.
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
* @example
|
|
201
|
+
* // Deque peek at both ends
|
|
202
|
+
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
203
|
+
*
|
|
204
|
+
* // Get first element without removing
|
|
205
|
+
* const first = deque.at(0);
|
|
206
|
+
* console.log(first); // 10;
|
|
207
|
+
*
|
|
208
|
+
* // Get last element without removing
|
|
209
|
+
* const last = deque.at(deque.length - 1);
|
|
210
|
+
* console.log(last); // 50;
|
|
211
|
+
*
|
|
212
|
+
* // Length unchanged
|
|
213
|
+
* console.log(deque.length); // 5;
|
|
230
214
|
*/
|
|
231
215
|
get first(): E | undefined;
|
|
232
216
|
/**
|
|
233
217
|
* Get the last element without removing it.
|
|
234
218
|
* @remarks Time O(1), Space O(1)
|
|
235
219
|
* @returns Last element or undefined.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
* @example
|
|
252
|
+
* // Peek at the back element
|
|
253
|
+
* const dq = new Deque<string>(['a', 'b', 'c']);
|
|
254
|
+
* console.log(dq.last); // 'c';
|
|
255
|
+
* console.log(dq.first); // 'a';
|
|
236
256
|
*/
|
|
237
257
|
get last(): E | undefined;
|
|
238
258
|
/**
|
|
@@ -251,18 +271,139 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
251
271
|
* @remarks Time O(1) amortized, Space O(1)
|
|
252
272
|
* @param element - Element to append.
|
|
253
273
|
* @returns True when appended.
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
* @example
|
|
306
|
+
* // basic Deque creation and push/pop operations
|
|
307
|
+
* // Create a simple Deque with initial values
|
|
308
|
+
* const deque = new Deque([1, 2, 3, 4, 5]);
|
|
309
|
+
*
|
|
310
|
+
* // Verify the deque maintains insertion order
|
|
311
|
+
* console.log([...deque]); // [1, 2, 3, 4, 5];
|
|
312
|
+
*
|
|
313
|
+
* // Check length
|
|
314
|
+
* console.log(deque.length); // 5;
|
|
315
|
+
*
|
|
316
|
+
* // Push to the end
|
|
317
|
+
* deque.push(6);
|
|
318
|
+
* console.log(deque.length); // 6;
|
|
319
|
+
*
|
|
320
|
+
* // Pop from the end
|
|
321
|
+
* const last = deque.pop();
|
|
322
|
+
* console.log(last); // 6;
|
|
254
323
|
*/
|
|
255
324
|
push(element: E): boolean;
|
|
256
325
|
/**
|
|
257
326
|
* Remove and return the last element.
|
|
258
327
|
* @remarks Time O(1), Space O(1)
|
|
259
328
|
* @returns Removed element or undefined.
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
* @example
|
|
361
|
+
* // Remove from the back
|
|
362
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
363
|
+
* console.log(dq.pop()); // 3;
|
|
364
|
+
* console.log(dq.length); // 2;
|
|
260
365
|
*/
|
|
261
366
|
pop(): E | undefined;
|
|
262
367
|
/**
|
|
263
368
|
* Remove and return the first element.
|
|
264
369
|
* @remarks Time O(1) amortized, Space O(1)
|
|
265
370
|
* @returns Removed element or undefined.
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
* @example
|
|
403
|
+
* // Remove from the front
|
|
404
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
405
|
+
* console.log(dq.shift()); // 1;
|
|
406
|
+
* console.log(dq.length); // 2;
|
|
266
407
|
*/
|
|
267
408
|
shift(): E | undefined;
|
|
268
409
|
/**
|
|
@@ -270,6 +411,52 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
270
411
|
* @remarks Time O(1) amortized, Space O(1)
|
|
271
412
|
* @param element - Element to prepend.
|
|
272
413
|
* @returns True when prepended.
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
* @example
|
|
446
|
+
* // Deque shift and unshift operations
|
|
447
|
+
* const deque = new Deque<number>([20, 30, 40]);
|
|
448
|
+
*
|
|
449
|
+
* // Unshift adds to the front
|
|
450
|
+
* deque.unshift(10);
|
|
451
|
+
* console.log([...deque]); // [10, 20, 30, 40];
|
|
452
|
+
*
|
|
453
|
+
* // Shift removes from the front (O(1) complexity!)
|
|
454
|
+
* const first = deque.shift();
|
|
455
|
+
* console.log(first); // 10;
|
|
456
|
+
*
|
|
457
|
+
* // Verify remaining elements
|
|
458
|
+
* console.log([...deque]); // [20, 30, 40];
|
|
459
|
+
* console.log(deque.length); // 3;
|
|
273
460
|
*/
|
|
274
461
|
unshift(element: E): boolean;
|
|
275
462
|
/**
|
|
@@ -290,12 +477,79 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
290
477
|
* Check whether the deque is empty.
|
|
291
478
|
* @remarks Time O(1), Space O(1)
|
|
292
479
|
* @returns True if length is 0.
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
* @example
|
|
510
|
+
* // Check if empty
|
|
511
|
+
* const dq = new Deque();
|
|
512
|
+
* console.log(dq.isEmpty()); // true;
|
|
293
513
|
*/
|
|
294
514
|
isEmpty(): boolean;
|
|
295
515
|
/**
|
|
296
516
|
* Remove all elements and reset structure.
|
|
297
517
|
* @remarks Time O(1), Space O(1)
|
|
298
518
|
* @returns void
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
* @example
|
|
549
|
+
* // Remove all elements
|
|
550
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
551
|
+
* dq.clear();
|
|
552
|
+
* console.log(dq.length); // 0;
|
|
299
553
|
*/
|
|
300
554
|
clear(): void;
|
|
301
555
|
/**
|
|
@@ -303,6 +557,39 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
303
557
|
* @remarks Time O(1), Space O(1)
|
|
304
558
|
* @param pos - Zero-based position from the front.
|
|
305
559
|
* @returns Element or undefined.
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
* @example
|
|
589
|
+
* // Access by index
|
|
590
|
+
* const dq = new Deque<string>(['a', 'b', 'c']);
|
|
591
|
+
* console.log(dq.at(0)); // 'a';
|
|
592
|
+
* console.log(dq.at(2)); // 'c';
|
|
306
593
|
*/
|
|
307
594
|
at(pos: number): E | undefined;
|
|
308
595
|
/**
|
|
@@ -359,6 +646,39 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
359
646
|
* @remarks Time O(N), Space O(1)
|
|
360
647
|
* @param element - Element to remove (using the configured equality).
|
|
361
648
|
* @returns True if an element was removed.
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
* @example
|
|
678
|
+
* // Remove element
|
|
679
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
680
|
+
* dq.delete(2);
|
|
681
|
+
* console.log(dq.length); // 2;
|
|
362
682
|
*/
|
|
363
683
|
delete(element: E): boolean;
|
|
364
684
|
/**
|
|
@@ -379,6 +699,55 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
379
699
|
* Reverse the deque by reversing buckets and pointers.
|
|
380
700
|
* @remarks Time O(N), Space O(N)
|
|
381
701
|
* @returns This deque.
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
* @example
|
|
734
|
+
* // Deque for...of iteration and reverse
|
|
735
|
+
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
736
|
+
*
|
|
737
|
+
* // Iterate forward
|
|
738
|
+
* const forward: string[] = [];
|
|
739
|
+
* for (const item of deque) {
|
|
740
|
+
* forward.push(item);
|
|
741
|
+
* }
|
|
742
|
+
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
743
|
+
*
|
|
744
|
+
* // Reverse the deque
|
|
745
|
+
* deque.reverse();
|
|
746
|
+
* const backward: string[] = [];
|
|
747
|
+
* for (const item of deque) {
|
|
748
|
+
* backward.push(item);
|
|
749
|
+
* }
|
|
750
|
+
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
382
751
|
*/
|
|
383
752
|
reverse(): this;
|
|
384
753
|
/**
|
|
@@ -407,6 +776,41 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
407
776
|
* Compact the deque by removing unused buckets.
|
|
408
777
|
* @remarks Time O(N), Space O(1)
|
|
409
778
|
* @returns True if compaction was performed (bucket count reduced).
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
* @example
|
|
808
|
+
* // Reclaim memory
|
|
809
|
+
* const dq = new Deque<number>([1, 2, 3, 4, 5]);
|
|
810
|
+
* dq.shift();
|
|
811
|
+
* dq.shift();
|
|
812
|
+
* dq.compact();
|
|
813
|
+
* console.log(dq.length); // 3;
|
|
410
814
|
*/
|
|
411
815
|
compact(): boolean;
|
|
412
816
|
shrinkToFit(): void;
|
|
@@ -414,6 +818,42 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
414
818
|
* Deep clone this deque, preserving options.
|
|
415
819
|
* @remarks Time O(N), Space O(N)
|
|
416
820
|
* @returns A new deque with the same content and options.
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
* @example
|
|
851
|
+
* // Create independent copy
|
|
852
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
853
|
+
* const copy = dq.clone();
|
|
854
|
+
* copy.pop();
|
|
855
|
+
* console.log(dq.length); // 3;
|
|
856
|
+
* console.log(copy.length); // 2;
|
|
417
857
|
*/
|
|
418
858
|
clone(): this;
|
|
419
859
|
/**
|
|
@@ -422,8 +862,42 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
422
862
|
* @param predicate - Predicate (value, index, deque) → boolean to keep element.
|
|
423
863
|
* @param [thisArg] - Value for `this` inside the predicate.
|
|
424
864
|
* @returns A new deque with kept elements.
|
|
425
|
-
|
|
426
|
-
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
* @example
|
|
895
|
+
* // Filter elements
|
|
896
|
+
* const dq = new Deque<number>([1, 2, 3, 4]);
|
|
897
|
+
* const result = dq.filter(x => x > 2);
|
|
898
|
+
* console.log(result.length); // 2;
|
|
899
|
+
*/
|
|
900
|
+
filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
|
|
427
901
|
/**
|
|
428
902
|
* Map elements into a new deque of the same element type.
|
|
429
903
|
* @remarks Time O(N), Space O(N)
|
|
@@ -431,7 +905,7 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
431
905
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
432
906
|
* @returns A new deque with mapped values.
|
|
433
907
|
*/
|
|
434
|
-
mapSame(callback: ElementCallback<E, R, E>, thisArg?:
|
|
908
|
+
mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
|
|
435
909
|
/**
|
|
436
910
|
* Map elements into a new deque (possibly different element type).
|
|
437
911
|
* @remarks Time O(N), Space O(N)
|
|
@@ -441,8 +915,41 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
441
915
|
* @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
|
|
442
916
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
443
917
|
* @returns A new Deque with mapped elements.
|
|
444
|
-
|
|
445
|
-
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
* @example
|
|
947
|
+
* // Transform elements
|
|
948
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
949
|
+
* const result = dq.map(x => x * 10);
|
|
950
|
+
* console.log(result.toArray()); // [10, 20, 30];
|
|
951
|
+
*/
|
|
952
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: IterableElementBaseOptions<EM, RM>, thisArg?: unknown): Deque<EM, RM>;
|
|
446
953
|
/**
|
|
447
954
|
* (Protected) Set the internal bucket size.
|
|
448
955
|
* @remarks Time O(1), Space O(1)
|
|
@@ -489,7 +996,7 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
489
996
|
* @param [options] - Options forwarded to the constructor.
|
|
490
997
|
* @returns A like-kind Deque instance.
|
|
491
998
|
*/
|
|
492
|
-
protected _createLike<T = E, RR = R>(elements?: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR>, options?: DequeOptions<T, RR>):
|
|
999
|
+
protected _createLike<T = E, RR = R>(elements?: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR>, options?: DequeOptions<T, RR>): Deque<T, RR>;
|
|
493
1000
|
/**
|
|
494
1001
|
* (Protected) Iterate elements from back to front.
|
|
495
1002
|
* @remarks Time O(N), Space O(1)
|