data-structure-typed 2.5.0 → 2.5.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.
- 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 +5 -1
- package/README.md +124 -29
- package/dist/cjs/binary-tree.cjs +26282 -0
- package/dist/cjs/graph.cjs +5422 -0
- package/dist/cjs/hash.cjs +1310 -0
- package/dist/cjs/heap.cjs +1602 -0
- package/dist/cjs/index.cjs +31257 -14673
- package/dist/cjs/linked-list.cjs +4576 -0
- package/dist/cjs/matrix.cjs +1080 -0
- package/dist/cjs/priority-queue.cjs +1376 -0
- package/dist/cjs/queue.cjs +4264 -0
- package/dist/cjs/stack.cjs +907 -0
- package/dist/cjs/trie.cjs +1223 -0
- package/dist/cjs-legacy/binary-tree.cjs +26319 -0
- package/dist/cjs-legacy/graph.cjs +5420 -0
- package/dist/cjs-legacy/hash.cjs +1310 -0
- package/dist/cjs-legacy/heap.cjs +1599 -0
- package/dist/cjs-legacy/index.cjs +31268 -14679
- package/dist/cjs-legacy/linked-list.cjs +4582 -0
- package/dist/cjs-legacy/matrix.cjs +1083 -0
- package/dist/cjs-legacy/priority-queue.cjs +1374 -0
- package/dist/cjs-legacy/queue.cjs +4262 -0
- package/dist/cjs-legacy/stack.cjs +907 -0
- package/dist/cjs-legacy/trie.cjs +1222 -0
- package/dist/esm/binary-tree.mjs +26267 -0
- package/dist/esm/graph.mjs +5409 -0
- package/dist/esm/hash.mjs +1307 -0
- package/dist/esm/heap.mjs +1596 -0
- package/dist/esm/index.mjs +31254 -14674
- package/dist/esm/linked-list.mjs +4569 -0
- package/dist/esm/matrix.mjs +1076 -0
- package/dist/esm/priority-queue.mjs +1372 -0
- package/dist/esm/queue.mjs +4260 -0
- package/dist/esm/stack.mjs +905 -0
- package/dist/esm/trie.mjs +1220 -0
- package/dist/esm-legacy/binary-tree.mjs +26304 -0
- package/dist/esm-legacy/graph.mjs +5407 -0
- package/dist/esm-legacy/hash.mjs +1307 -0
- package/dist/esm-legacy/heap.mjs +1593 -0
- package/dist/esm-legacy/index.mjs +31265 -14680
- package/dist/esm-legacy/linked-list.mjs +4575 -0
- package/dist/esm-legacy/matrix.mjs +1079 -0
- package/dist/esm-legacy/priority-queue.mjs +1370 -0
- package/dist/esm-legacy/queue.mjs +4258 -0
- package/dist/esm-legacy/stack.mjs +905 -0
- package/dist/esm-legacy/trie.mjs +1219 -0
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- 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 +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- 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/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- 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 +31196 -14608
- package/dist/umd/data-structure-typed.min.js +11 -5
- 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 +6644 -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 +6293 -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 +6888 -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 +1389 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -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 +615 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
- package/docs-site-docusaurus/docs/guide/faq.md +180 -0
- package/docs-site-docusaurus/docs/guide/guides.md +597 -0
- package/docs-site-docusaurus/docs/guide/installation.md +62 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
- package/docs-site-docusaurus/docs/guide/overview.md +645 -0
- package/docs-site-docusaurus/docs/guide/performance.md +835 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -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 +120 -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/llms.txt +37 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/llms.txt +37 -0
- package/package.json +159 -55
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- 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 +287 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
- package/src/data-structures/binary-tree/binary-tree.ts +581 -6
- package/src/data-structures/binary-tree/bst.ts +922 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
- package/src/data-structures/binary-tree/segment-tree.ts +139 -2
- package/src/data-structures/binary-tree/tree-map.ts +3300 -495
- package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
- package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
- package/src/data-structures/binary-tree/tree-set.ts +3122 -440
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +230 -0
- package/src/data-structures/graph/undirected-graph.ts +207 -0
- package/src/data-structures/hash/hash-map.ts +270 -19
- package/src/data-structures/heap/heap.ts +326 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
- package/src/data-structures/matrix/matrix.ts +194 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +350 -5
- package/src/data-structures/queue/queue.ts +276 -0
- package/src/data-structures/stack/stack.ts +230 -0
- package/src/data-structures/trie/trie.ts +283 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- 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
|
@@ -0,0 +1,2244 @@
|
|
|
1
|
+
[**data-structure-typed**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[data-structure-typed](../README.md) / Queue
|
|
6
|
+
|
|
7
|
+
# Class: Queue\<E, R\>
|
|
8
|
+
|
|
9
|
+
Defined in: [data-structures/queue/queue.ts:91](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L91)
|
|
10
|
+
|
|
11
|
+
Array-backed queue with amortized O(1) enqueue/dequeue via an offset pointer and optional auto-compaction.
|
|
12
|
+
|
|
13
|
+
## Remarks
|
|
14
|
+
|
|
15
|
+
Time O(1), Space O(1)
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// Queue as message broker for event processing
|
|
21
|
+
interface Message {
|
|
22
|
+
id: string;
|
|
23
|
+
type: 'email' | 'sms' | 'push';
|
|
24
|
+
recipient: string;
|
|
25
|
+
content: string;
|
|
26
|
+
timestamp: Date;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create a message queue for real-time event processing
|
|
30
|
+
const messageQueue = new Queue<Message>([
|
|
31
|
+
{
|
|
32
|
+
id: 'msg-001',
|
|
33
|
+
type: 'email',
|
|
34
|
+
recipient: 'user@example.com',
|
|
35
|
+
content: 'Welcome!',
|
|
36
|
+
timestamp: new Date()
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'msg-002',
|
|
40
|
+
type: 'sms',
|
|
41
|
+
recipient: '+1234567890',
|
|
42
|
+
content: 'OTP: 123456',
|
|
43
|
+
timestamp: new Date()
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'msg-003',
|
|
47
|
+
type: 'push',
|
|
48
|
+
recipient: 'device-token-xyz',
|
|
49
|
+
content: 'New notification',
|
|
50
|
+
timestamp: new Date()
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'msg-004',
|
|
54
|
+
type: 'email',
|
|
55
|
+
recipient: 'admin@example.com',
|
|
56
|
+
content: 'Daily report',
|
|
57
|
+
timestamp: new Date()
|
|
58
|
+
}
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
// Process messages in FIFO order (first message first)
|
|
62
|
+
const processedMessages: string[] = [];
|
|
63
|
+
while (messageQueue.length > 0) {
|
|
64
|
+
const message = messageQueue.shift();
|
|
65
|
+
if (message) {
|
|
66
|
+
processedMessages.push(`${message.type}:${message.recipient}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Verify messages were processed in order
|
|
71
|
+
console.log(processedMessages); // [
|
|
72
|
+
// 'email:user@example.com',
|
|
73
|
+
// 'sms:+1234567890',
|
|
74
|
+
// 'push:device-token-xyz',
|
|
75
|
+
// 'email:admin@example.com'
|
|
76
|
+
// ];
|
|
77
|
+
|
|
78
|
+
// Queue should be empty after processing all messages
|
|
79
|
+
console.log(messageQueue.length); // 0;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// Convert queue to array
|
|
84
|
+
const q = new Queue<number>([10, 20, 30]);
|
|
85
|
+
console.log(q.toArray()); // [10, 20, 30];
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Extends
|
|
89
|
+
|
|
90
|
+
- [`LinearBase`](LinearBase.md)\<`E`, `R`\>
|
|
91
|
+
|
|
92
|
+
## Type Parameters
|
|
93
|
+
|
|
94
|
+
### E
|
|
95
|
+
|
|
96
|
+
`E` = `any`
|
|
97
|
+
|
|
98
|
+
### R
|
|
99
|
+
|
|
100
|
+
`R` = `any`
|
|
101
|
+
|
|
102
|
+
1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
|
|
103
|
+
2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
|
|
104
|
+
3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
|
|
105
|
+
4. Task Scheduling: Managing the order of task execution in operating systems or applications.
|
|
106
|
+
5. Data Buffering: Acting as a buffer for data packets in network communication.
|
|
107
|
+
6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
|
|
108
|
+
7. Real-time Queuing: Like queuing systems in banks or supermarkets.
|
|
109
|
+
|
|
110
|
+
## Constructors
|
|
111
|
+
|
|
112
|
+
### Constructor
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
new Queue<E, R>(elements?, options?): Queue<E, R>;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Defined in: [data-structures/queue/queue.ts:100](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L100)
|
|
119
|
+
|
|
120
|
+
Create a Queue and optionally bulk-insert elements.
|
|
121
|
+
|
|
122
|
+
#### Parameters
|
|
123
|
+
|
|
124
|
+
##### elements?
|
|
125
|
+
|
|
126
|
+
`Iterable`\<`E`, `any`, `any`\> \| `Iterable`\<`R`, `any`, `any`\>
|
|
127
|
+
|
|
128
|
+
Iterable of elements (or raw records if toElementFn is set).
|
|
129
|
+
|
|
130
|
+
##### options?
|
|
131
|
+
|
|
132
|
+
`QueueOptions`\<`E`, `R`\>
|
|
133
|
+
|
|
134
|
+
Options such as toElementFn, maxLen, and autoCompactRatio.
|
|
135
|
+
|
|
136
|
+
#### Returns
|
|
137
|
+
|
|
138
|
+
`Queue`\<`E`, `R`\>
|
|
139
|
+
|
|
140
|
+
New Queue instance.
|
|
141
|
+
|
|
142
|
+
#### Remarks
|
|
143
|
+
|
|
144
|
+
Time O(N), Space O(N)
|
|
145
|
+
|
|
146
|
+
#### Overrides
|
|
147
|
+
|
|
148
|
+
[`LinearBase`](LinearBase.md).[`constructor`](LinearBase.md#constructor)
|
|
149
|
+
|
|
150
|
+
## Properties
|
|
151
|
+
|
|
152
|
+
### autoCompactRatio
|
|
153
|
+
|
|
154
|
+
#### Get Signature
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
get autoCompactRatio(): number;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Defined in: [data-structures/queue/queue.ts:141](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L141)
|
|
161
|
+
|
|
162
|
+
Get the compaction threshold (offset/size).
|
|
163
|
+
|
|
164
|
+
##### Remarks
|
|
165
|
+
|
|
166
|
+
Time O(1), Space O(1)
|
|
167
|
+
|
|
168
|
+
##### Returns
|
|
169
|
+
|
|
170
|
+
`number`
|
|
171
|
+
|
|
172
|
+
Auto-compaction ratio in (0,1].
|
|
173
|
+
|
|
174
|
+
#### Set Signature
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
set autoCompactRatio(value): void;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Defined in: [data-structures/queue/queue.ts:152](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L152)
|
|
181
|
+
|
|
182
|
+
Set the compaction threshold.
|
|
183
|
+
|
|
184
|
+
##### Remarks
|
|
185
|
+
|
|
186
|
+
Time O(1), Space O(1)
|
|
187
|
+
|
|
188
|
+
##### Parameters
|
|
189
|
+
|
|
190
|
+
###### value
|
|
191
|
+
|
|
192
|
+
`number`
|
|
193
|
+
|
|
194
|
+
New ratio; compacts when offset/size exceeds this value.
|
|
195
|
+
|
|
196
|
+
##### Returns
|
|
197
|
+
|
|
198
|
+
`void`
|
|
199
|
+
|
|
200
|
+
void
|
|
201
|
+
|
|
202
|
+
***
|
|
203
|
+
|
|
204
|
+
### elements
|
|
205
|
+
|
|
206
|
+
#### Get Signature
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
get elements(): E[];
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Defined in: [data-structures/queue/queue.ts:117](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L117)
|
|
213
|
+
|
|
214
|
+
Get the underlying array buffer.
|
|
215
|
+
|
|
216
|
+
##### Remarks
|
|
217
|
+
|
|
218
|
+
Time O(1), Space O(1)
|
|
219
|
+
|
|
220
|
+
##### Returns
|
|
221
|
+
|
|
222
|
+
`E`[]
|
|
223
|
+
|
|
224
|
+
Backing array of elements.
|
|
225
|
+
|
|
226
|
+
***
|
|
227
|
+
|
|
228
|
+
### first
|
|
229
|
+
|
|
230
|
+
#### Get Signature
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
get first(): E | undefined;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Defined in: [data-structures/queue/queue.ts:254](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L254)
|
|
237
|
+
|
|
238
|
+
Get the first element (front) without removing it.
|
|
239
|
+
|
|
240
|
+
##### Remarks
|
|
241
|
+
|
|
242
|
+
Time O(1), Space O(1)
|
|
243
|
+
|
|
244
|
+
##### Example
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
// View the front element
|
|
248
|
+
const q = new Queue<string>(['first', 'second', 'third']);
|
|
249
|
+
console.log(q.first); // 'first';
|
|
250
|
+
console.log(q.length); // 3;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
##### Returns
|
|
254
|
+
|
|
255
|
+
`E` \| `undefined`
|
|
256
|
+
|
|
257
|
+
Front element or undefined.
|
|
258
|
+
|
|
259
|
+
*
|
|
260
|
+
|
|
261
|
+
***
|
|
262
|
+
|
|
263
|
+
### last
|
|
264
|
+
|
|
265
|
+
#### Get Signature
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
get last(): E | undefined;
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Defined in: [data-structures/queue/queue.ts:264](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L264)
|
|
272
|
+
|
|
273
|
+
Get the last element (back) without removing it.
|
|
274
|
+
|
|
275
|
+
##### Remarks
|
|
276
|
+
|
|
277
|
+
Time O(1), Space O(1)
|
|
278
|
+
|
|
279
|
+
##### Returns
|
|
280
|
+
|
|
281
|
+
`E` \| `undefined`
|
|
282
|
+
|
|
283
|
+
Back element or undefined.
|
|
284
|
+
|
|
285
|
+
***
|
|
286
|
+
|
|
287
|
+
### length
|
|
288
|
+
|
|
289
|
+
#### Get Signature
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
get length(): number;
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Defined in: [data-structures/queue/queue.ts:204](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L204)
|
|
296
|
+
|
|
297
|
+
Get the number of elements currently in the queue.
|
|
298
|
+
|
|
299
|
+
##### Remarks
|
|
300
|
+
|
|
301
|
+
Time O(1), Space O(1)
|
|
302
|
+
|
|
303
|
+
##### Example
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
// Track queue length
|
|
307
|
+
const q = new Queue<number>();
|
|
308
|
+
console.log(q.length); // 0;
|
|
309
|
+
q.push(1);
|
|
310
|
+
q.push(2);
|
|
311
|
+
console.log(q.length); // 2;
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
##### Returns
|
|
315
|
+
|
|
316
|
+
`number`
|
|
317
|
+
|
|
318
|
+
Current length.
|
|
319
|
+
|
|
320
|
+
*
|
|
321
|
+
|
|
322
|
+
#### Overrides
|
|
323
|
+
|
|
324
|
+
[`LinearBase`](LinearBase.md).[`length`](LinearBase.md#length)
|
|
325
|
+
|
|
326
|
+
***
|
|
327
|
+
|
|
328
|
+
### maxLen
|
|
329
|
+
|
|
330
|
+
#### Get Signature
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
get maxLen(): number;
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Defined in: [data-structures/base/linear-base.ts:100](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L100)
|
|
337
|
+
|
|
338
|
+
Upper bound for length (if positive), or `-1` when unbounded.
|
|
339
|
+
|
|
340
|
+
##### Remarks
|
|
341
|
+
|
|
342
|
+
Time O(1), Space O(1)
|
|
343
|
+
|
|
344
|
+
##### Returns
|
|
345
|
+
|
|
346
|
+
`number`
|
|
347
|
+
|
|
348
|
+
Maximum allowed length.
|
|
349
|
+
|
|
350
|
+
#### Inherited from
|
|
351
|
+
|
|
352
|
+
[`LinearBase`](LinearBase.md).[`maxLen`](LinearBase.md#maxlen)
|
|
353
|
+
|
|
354
|
+
***
|
|
355
|
+
|
|
356
|
+
### offset
|
|
357
|
+
|
|
358
|
+
#### Get Signature
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
get offset(): number;
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Defined in: [data-structures/queue/queue.ts:129](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L129)
|
|
365
|
+
|
|
366
|
+
Get the current start offset into the array.
|
|
367
|
+
|
|
368
|
+
##### Remarks
|
|
369
|
+
|
|
370
|
+
Time O(1), Space O(1)
|
|
371
|
+
|
|
372
|
+
##### Returns
|
|
373
|
+
|
|
374
|
+
`number`
|
|
375
|
+
|
|
376
|
+
Zero-based offset.
|
|
377
|
+
|
|
378
|
+
***
|
|
379
|
+
|
|
380
|
+
### toElementFn
|
|
381
|
+
|
|
382
|
+
#### Get Signature
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
get toElementFn(): ((rawElement) => E) | undefined;
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L48)
|
|
389
|
+
|
|
390
|
+
Exposes the current `toElementFn`, if configured.
|
|
391
|
+
|
|
392
|
+
##### Remarks
|
|
393
|
+
|
|
394
|
+
Time O(1), Space O(1).
|
|
395
|
+
|
|
396
|
+
##### Returns
|
|
397
|
+
|
|
398
|
+
((`rawElement`) => `E`) \| `undefined`
|
|
399
|
+
|
|
400
|
+
The converter function or `undefined` when not set.
|
|
401
|
+
|
|
402
|
+
#### Inherited from
|
|
403
|
+
|
|
404
|
+
[`LinearBase`](LinearBase.md).[`toElementFn`](LinearBase.md#toelementfn)
|
|
405
|
+
|
|
406
|
+
## Methods
|
|
407
|
+
|
|
408
|
+
### \[iterator\]()
|
|
409
|
+
|
|
410
|
+
```ts
|
|
411
|
+
iterator: IterableIterator<E>;
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L61)
|
|
415
|
+
|
|
416
|
+
Returns an iterator over the structure's elements.
|
|
417
|
+
|
|
418
|
+
#### Parameters
|
|
419
|
+
|
|
420
|
+
##### args
|
|
421
|
+
|
|
422
|
+
...`unknown`[]
|
|
423
|
+
|
|
424
|
+
Optional iterator arguments forwarded to the internal iterator.
|
|
425
|
+
|
|
426
|
+
#### Returns
|
|
427
|
+
|
|
428
|
+
`IterableIterator`\<`E`\>
|
|
429
|
+
|
|
430
|
+
An `IterableIterator<E>` that yields the elements in traversal order.
|
|
431
|
+
|
|
432
|
+
#### Remarks
|
|
433
|
+
|
|
434
|
+
Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
|
|
435
|
+
|
|
436
|
+
#### Inherited from
|
|
437
|
+
|
|
438
|
+
[`LinearBase`](LinearBase.md).[`[iterator]`](LinearBase.md#iterator)
|
|
439
|
+
|
|
440
|
+
***
|
|
441
|
+
|
|
442
|
+
### addAt()
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
addAt(index, newElement): boolean;
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Defined in: [data-structures/queue/queue.ts:605](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L605)
|
|
449
|
+
|
|
450
|
+
Insert a new element at a given index.
|
|
451
|
+
|
|
452
|
+
#### Parameters
|
|
453
|
+
|
|
454
|
+
##### index
|
|
455
|
+
|
|
456
|
+
`number`
|
|
457
|
+
|
|
458
|
+
Zero-based index from the front.
|
|
459
|
+
|
|
460
|
+
##### newElement
|
|
461
|
+
|
|
462
|
+
`E`
|
|
463
|
+
|
|
464
|
+
Element to insert.
|
|
465
|
+
|
|
466
|
+
#### Returns
|
|
467
|
+
|
|
468
|
+
`boolean`
|
|
469
|
+
|
|
470
|
+
True if inserted.
|
|
471
|
+
|
|
472
|
+
#### Remarks
|
|
473
|
+
|
|
474
|
+
Time O(N), Space O(1)
|
|
475
|
+
|
|
476
|
+
#### Overrides
|
|
477
|
+
|
|
478
|
+
[`LinearBase`](LinearBase.md).[`addAt`](LinearBase.md#addat)
|
|
479
|
+
|
|
480
|
+
***
|
|
481
|
+
|
|
482
|
+
### at()
|
|
483
|
+
|
|
484
|
+
```ts
|
|
485
|
+
at(index): E | undefined;
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
Defined in: [data-structures/queue/queue.ts:578](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L578)
|
|
489
|
+
|
|
490
|
+
Get the element at a given logical index.
|
|
491
|
+
|
|
492
|
+
#### Parameters
|
|
493
|
+
|
|
494
|
+
##### index
|
|
495
|
+
|
|
496
|
+
`number`
|
|
497
|
+
|
|
498
|
+
Zero-based index from the front.
|
|
499
|
+
|
|
500
|
+
#### Returns
|
|
501
|
+
|
|
502
|
+
`E` \| `undefined`
|
|
503
|
+
|
|
504
|
+
Element or undefined.
|
|
505
|
+
|
|
506
|
+
*
|
|
507
|
+
|
|
508
|
+
#### Remarks
|
|
509
|
+
|
|
510
|
+
Time O(1), Space O(1)
|
|
511
|
+
|
|
512
|
+
#### Example
|
|
513
|
+
|
|
514
|
+
```ts
|
|
515
|
+
// Access element by index
|
|
516
|
+
const q = new Queue<string>(['a', 'b', 'c']);
|
|
517
|
+
console.log(q.at(0)); // 'a';
|
|
518
|
+
console.log(q.at(2)); // 'c';
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
#### Overrides
|
|
522
|
+
|
|
523
|
+
[`LinearBase`](LinearBase.md).[`at`](LinearBase.md#at)
|
|
524
|
+
|
|
525
|
+
***
|
|
526
|
+
|
|
527
|
+
### clear()
|
|
528
|
+
|
|
529
|
+
```ts
|
|
530
|
+
clear(): void;
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Defined in: [data-structures/queue/queue.ts:681](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L681)
|
|
534
|
+
|
|
535
|
+
Remove all elements and reset offset.
|
|
536
|
+
|
|
537
|
+
#### Returns
|
|
538
|
+
|
|
539
|
+
`void`
|
|
540
|
+
|
|
541
|
+
void
|
|
542
|
+
|
|
543
|
+
*
|
|
544
|
+
|
|
545
|
+
#### Remarks
|
|
546
|
+
|
|
547
|
+
Time O(1), Space O(1)
|
|
548
|
+
|
|
549
|
+
#### Example
|
|
550
|
+
|
|
551
|
+
```ts
|
|
552
|
+
// Remove all elements
|
|
553
|
+
const q = new Queue<number>([1, 2, 3]);
|
|
554
|
+
q.clear();
|
|
555
|
+
console.log(q.length); // 0;
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
#### Overrides
|
|
559
|
+
|
|
560
|
+
[`LinearBase`](LinearBase.md).[`clear`](LinearBase.md#clear)
|
|
561
|
+
|
|
562
|
+
***
|
|
563
|
+
|
|
564
|
+
### clone()
|
|
565
|
+
|
|
566
|
+
```ts
|
|
567
|
+
clone(): this;
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
Defined in: [data-structures/queue/queue.ts:808](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L808)
|
|
571
|
+
|
|
572
|
+
Deep clone this queue and its parameters.
|
|
573
|
+
|
|
574
|
+
#### Returns
|
|
575
|
+
|
|
576
|
+
`this`
|
|
577
|
+
|
|
578
|
+
A new queue with the same content and options.
|
|
579
|
+
|
|
580
|
+
*
|
|
581
|
+
|
|
582
|
+
#### Remarks
|
|
583
|
+
|
|
584
|
+
Time O(N), Space O(N)
|
|
585
|
+
|
|
586
|
+
#### Example
|
|
587
|
+
|
|
588
|
+
```ts
|
|
589
|
+
// Create independent copy
|
|
590
|
+
const q = new Queue<number>([1, 2, 3]);
|
|
591
|
+
const copy = q.clone();
|
|
592
|
+
copy.shift();
|
|
593
|
+
console.log(q.length); // 3;
|
|
594
|
+
console.log(copy.length); // 2;
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
#### Overrides
|
|
598
|
+
|
|
599
|
+
[`LinearBase`](LinearBase.md).[`clone`](LinearBase.md#clone)
|
|
600
|
+
|
|
601
|
+
***
|
|
602
|
+
|
|
603
|
+
### compact()
|
|
604
|
+
|
|
605
|
+
```ts
|
|
606
|
+
compact(): boolean;
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
Defined in: [data-structures/queue/queue.ts:731](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L731)
|
|
610
|
+
|
|
611
|
+
Compact storage by discarding consumed head elements.
|
|
612
|
+
|
|
613
|
+
#### Returns
|
|
614
|
+
|
|
615
|
+
`boolean`
|
|
616
|
+
|
|
617
|
+
True when compaction performed.
|
|
618
|
+
|
|
619
|
+
*
|
|
620
|
+
|
|
621
|
+
#### Remarks
|
|
622
|
+
|
|
623
|
+
Time O(N), Space O(N)
|
|
624
|
+
|
|
625
|
+
#### Example
|
|
626
|
+
|
|
627
|
+
```ts
|
|
628
|
+
// Reclaim unused memory
|
|
629
|
+
const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
630
|
+
q.shift();
|
|
631
|
+
q.shift();
|
|
632
|
+
q.compact();
|
|
633
|
+
console.log(q.length); // 3;
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
***
|
|
637
|
+
|
|
638
|
+
### concat()
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
concat(...items): this;
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
Defined in: [data-structures/base/linear-base.ts:165](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L165)
|
|
645
|
+
|
|
646
|
+
Concatenate elements and/or containers.
|
|
647
|
+
|
|
648
|
+
#### Parameters
|
|
649
|
+
|
|
650
|
+
##### items
|
|
651
|
+
|
|
652
|
+
...(`E` \| `Queue`\<`E`, `R`\>)[]
|
|
653
|
+
|
|
654
|
+
Elements or other containers.
|
|
655
|
+
|
|
656
|
+
#### Returns
|
|
657
|
+
|
|
658
|
+
`this`
|
|
659
|
+
|
|
660
|
+
New container with combined elements (`this` type).
|
|
661
|
+
|
|
662
|
+
#### Remarks
|
|
663
|
+
|
|
664
|
+
Time O(sum(length)), Space O(sum(length))
|
|
665
|
+
|
|
666
|
+
#### Inherited from
|
|
667
|
+
|
|
668
|
+
[`LinearBase`](LinearBase.md).[`concat`](LinearBase.md#concat)
|
|
669
|
+
|
|
670
|
+
***
|
|
671
|
+
|
|
672
|
+
### delete()
|
|
673
|
+
|
|
674
|
+
```ts
|
|
675
|
+
delete(element): boolean;
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
Defined in: [data-structures/queue/queue.ts:524](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L524)
|
|
679
|
+
|
|
680
|
+
Delete the first occurrence of a specific element.
|
|
681
|
+
|
|
682
|
+
#### Parameters
|
|
683
|
+
|
|
684
|
+
##### element
|
|
685
|
+
|
|
686
|
+
`E`
|
|
687
|
+
|
|
688
|
+
Element to remove (strict equality via Object.is).
|
|
689
|
+
|
|
690
|
+
#### Returns
|
|
691
|
+
|
|
692
|
+
`boolean`
|
|
693
|
+
|
|
694
|
+
True if an element was removed.
|
|
695
|
+
|
|
696
|
+
*
|
|
697
|
+
|
|
698
|
+
#### Remarks
|
|
699
|
+
|
|
700
|
+
Time O(N), Space O(1)
|
|
701
|
+
|
|
702
|
+
#### Example
|
|
703
|
+
|
|
704
|
+
```ts
|
|
705
|
+
// Remove specific element
|
|
706
|
+
const q = new Queue<number>([1, 2, 3, 2]);
|
|
707
|
+
q.delete(2);
|
|
708
|
+
console.log(q.length); // 3;
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
#### Overrides
|
|
712
|
+
|
|
713
|
+
[`LinearBase`](LinearBase.md).[`delete`](LinearBase.md#delete)
|
|
714
|
+
|
|
715
|
+
***
|
|
716
|
+
|
|
717
|
+
### deleteAt()
|
|
718
|
+
|
|
719
|
+
```ts
|
|
720
|
+
deleteAt(index): E | undefined;
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
Defined in: [data-structures/queue/queue.ts:590](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L590)
|
|
724
|
+
|
|
725
|
+
Delete the element at a given index.
|
|
726
|
+
|
|
727
|
+
#### Parameters
|
|
728
|
+
|
|
729
|
+
##### index
|
|
730
|
+
|
|
731
|
+
`number`
|
|
732
|
+
|
|
733
|
+
Zero-based index from the front.
|
|
734
|
+
|
|
735
|
+
#### Returns
|
|
736
|
+
|
|
737
|
+
`E` \| `undefined`
|
|
738
|
+
|
|
739
|
+
Removed element or undefined.
|
|
740
|
+
|
|
741
|
+
#### Remarks
|
|
742
|
+
|
|
743
|
+
Time O(N), Space O(1)
|
|
744
|
+
|
|
745
|
+
#### Overrides
|
|
746
|
+
|
|
747
|
+
[`LinearBase`](LinearBase.md).[`deleteAt`](LinearBase.md#deleteat)
|
|
748
|
+
|
|
749
|
+
***
|
|
750
|
+
|
|
751
|
+
### every()
|
|
752
|
+
|
|
753
|
+
```ts
|
|
754
|
+
every(predicate, thisArg?): boolean;
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L87)
|
|
758
|
+
|
|
759
|
+
Tests whether all elements satisfy the predicate.
|
|
760
|
+
|
|
761
|
+
#### Parameters
|
|
762
|
+
|
|
763
|
+
##### predicate
|
|
764
|
+
|
|
765
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
766
|
+
|
|
767
|
+
Function invoked for each element with signature `(value, index, self)`.
|
|
768
|
+
|
|
769
|
+
##### thisArg?
|
|
770
|
+
|
|
771
|
+
`unknown`
|
|
772
|
+
|
|
773
|
+
Optional `this` binding for the predicate.
|
|
774
|
+
|
|
775
|
+
#### Returns
|
|
776
|
+
|
|
777
|
+
`boolean`
|
|
778
|
+
|
|
779
|
+
`true` if every element passes; otherwise `false`.
|
|
780
|
+
|
|
781
|
+
#### Remarks
|
|
782
|
+
|
|
783
|
+
Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
|
|
784
|
+
|
|
785
|
+
#### Inherited from
|
|
786
|
+
|
|
787
|
+
[`LinearBase`](LinearBase.md).[`every`](LinearBase.md#every)
|
|
788
|
+
|
|
789
|
+
***
|
|
790
|
+
|
|
791
|
+
### fill()
|
|
792
|
+
|
|
793
|
+
```ts
|
|
794
|
+
fill(
|
|
795
|
+
value,
|
|
796
|
+
start?,
|
|
797
|
+
end?): this;
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
Defined in: [data-structures/base/linear-base.ts:292](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L292)
|
|
801
|
+
|
|
802
|
+
Fill a range with a value.
|
|
803
|
+
|
|
804
|
+
#### Parameters
|
|
805
|
+
|
|
806
|
+
##### value
|
|
807
|
+
|
|
808
|
+
`E`
|
|
809
|
+
|
|
810
|
+
Value to set.
|
|
811
|
+
|
|
812
|
+
##### start?
|
|
813
|
+
|
|
814
|
+
`number` = `0`
|
|
815
|
+
|
|
816
|
+
Inclusive start.
|
|
817
|
+
|
|
818
|
+
##### end?
|
|
819
|
+
|
|
820
|
+
`number` = `...`
|
|
821
|
+
|
|
822
|
+
Exclusive end.
|
|
823
|
+
|
|
824
|
+
#### Returns
|
|
825
|
+
|
|
826
|
+
`this`
|
|
827
|
+
|
|
828
|
+
This list.
|
|
829
|
+
|
|
830
|
+
#### Remarks
|
|
831
|
+
|
|
832
|
+
Time O(n), Space O(1)
|
|
833
|
+
|
|
834
|
+
#### Inherited from
|
|
835
|
+
|
|
836
|
+
[`LinearBase`](LinearBase.md).[`fill`](LinearBase.md#fill)
|
|
837
|
+
|
|
838
|
+
***
|
|
839
|
+
|
|
840
|
+
### filter()
|
|
841
|
+
|
|
842
|
+
```ts
|
|
843
|
+
filter(predicate, thisArg?): this;
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
Defined in: [data-structures/queue/queue.ts:861](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L861)
|
|
847
|
+
|
|
848
|
+
Filter elements into a new queue of the same class.
|
|
849
|
+
|
|
850
|
+
#### Parameters
|
|
851
|
+
|
|
852
|
+
##### predicate
|
|
853
|
+
|
|
854
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
855
|
+
|
|
856
|
+
Predicate (element, index, queue) → boolean to keep element.
|
|
857
|
+
|
|
858
|
+
##### thisArg?
|
|
859
|
+
|
|
860
|
+
`unknown`
|
|
861
|
+
|
|
862
|
+
Value for `this` inside the predicate.
|
|
863
|
+
|
|
864
|
+
#### Returns
|
|
865
|
+
|
|
866
|
+
`this`
|
|
867
|
+
|
|
868
|
+
A new queue with kept elements.
|
|
869
|
+
|
|
870
|
+
*
|
|
871
|
+
|
|
872
|
+
#### Remarks
|
|
873
|
+
|
|
874
|
+
Time O(N), Space O(N)
|
|
875
|
+
|
|
876
|
+
#### Example
|
|
877
|
+
|
|
878
|
+
```ts
|
|
879
|
+
// Filter elements
|
|
880
|
+
const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
881
|
+
const evens = q.filter(x => x % 2 === 0);
|
|
882
|
+
console.log(evens.length); // 2;
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
#### Overrides
|
|
886
|
+
|
|
887
|
+
[`LinearBase`](LinearBase.md).[`filter`](LinearBase.md#filter)
|
|
888
|
+
|
|
889
|
+
***
|
|
890
|
+
|
|
891
|
+
### find()
|
|
892
|
+
|
|
893
|
+
#### Call Signature
|
|
894
|
+
|
|
895
|
+
```ts
|
|
896
|
+
find<S>(predicate, thisArg?): S | undefined;
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L163)
|
|
900
|
+
|
|
901
|
+
Finds the first element that satisfies the predicate and returns it.
|
|
902
|
+
|
|
903
|
+
Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
|
|
904
|
+
|
|
905
|
+
##### Type Parameters
|
|
906
|
+
|
|
907
|
+
###### S
|
|
908
|
+
|
|
909
|
+
`S`
|
|
910
|
+
|
|
911
|
+
##### Parameters
|
|
912
|
+
|
|
913
|
+
###### predicate
|
|
914
|
+
|
|
915
|
+
`ElementCallback`\<`E`, `R`, `S`\>
|
|
916
|
+
|
|
917
|
+
Type-guard predicate: `(value, index, self) => value is S`.
|
|
918
|
+
|
|
919
|
+
###### thisArg?
|
|
920
|
+
|
|
921
|
+
`unknown`
|
|
922
|
+
|
|
923
|
+
Optional `this` binding for the predicate.
|
|
924
|
+
|
|
925
|
+
##### Returns
|
|
926
|
+
|
|
927
|
+
`S` \| `undefined`
|
|
928
|
+
|
|
929
|
+
The matched element typed as `S`, or `undefined` if not found.
|
|
930
|
+
|
|
931
|
+
##### Remarks
|
|
932
|
+
|
|
933
|
+
Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
934
|
+
|
|
935
|
+
##### Inherited from
|
|
936
|
+
|
|
937
|
+
[`LinearBase`](LinearBase.md).[`find`](LinearBase.md#find)
|
|
938
|
+
|
|
939
|
+
#### Call Signature
|
|
940
|
+
|
|
941
|
+
```ts
|
|
942
|
+
find(predicate, thisArg?): E | undefined;
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L164)
|
|
946
|
+
|
|
947
|
+
Finds the first element that satisfies the predicate and returns it.
|
|
948
|
+
|
|
949
|
+
Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
|
|
950
|
+
|
|
951
|
+
##### Parameters
|
|
952
|
+
|
|
953
|
+
###### predicate
|
|
954
|
+
|
|
955
|
+
`ElementCallback`\<`E`, `R`, `unknown`\>
|
|
956
|
+
|
|
957
|
+
Type-guard predicate: `(value, index, self) => value is S`.
|
|
958
|
+
|
|
959
|
+
###### thisArg?
|
|
960
|
+
|
|
961
|
+
`unknown`
|
|
962
|
+
|
|
963
|
+
Optional `this` binding for the predicate.
|
|
964
|
+
|
|
965
|
+
##### Returns
|
|
966
|
+
|
|
967
|
+
`E` \| `undefined`
|
|
968
|
+
|
|
969
|
+
The matched element typed as `S`, or `undefined` if not found.
|
|
970
|
+
|
|
971
|
+
##### Remarks
|
|
972
|
+
|
|
973
|
+
Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
974
|
+
|
|
975
|
+
##### Inherited from
|
|
976
|
+
|
|
977
|
+
[`LinearBase`](LinearBase.md).[`find`](LinearBase.md#find)
|
|
978
|
+
|
|
979
|
+
***
|
|
980
|
+
|
|
981
|
+
### findIndex()
|
|
982
|
+
|
|
983
|
+
```ts
|
|
984
|
+
findIndex(predicate, thisArg?): number;
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
Defined in: [data-structures/base/linear-base.ts:151](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L151)
|
|
988
|
+
|
|
989
|
+
Find the first index matching a predicate.
|
|
990
|
+
|
|
991
|
+
#### Parameters
|
|
992
|
+
|
|
993
|
+
##### predicate
|
|
994
|
+
|
|
995
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
996
|
+
|
|
997
|
+
`(element, index, self) => boolean`.
|
|
998
|
+
|
|
999
|
+
##### thisArg?
|
|
1000
|
+
|
|
1001
|
+
`unknown`
|
|
1002
|
+
|
|
1003
|
+
Optional `this` for callback.
|
|
1004
|
+
|
|
1005
|
+
#### Returns
|
|
1006
|
+
|
|
1007
|
+
`number`
|
|
1008
|
+
|
|
1009
|
+
Index or `-1`.
|
|
1010
|
+
|
|
1011
|
+
#### Remarks
|
|
1012
|
+
|
|
1013
|
+
Time O(n), Space O(1)
|
|
1014
|
+
|
|
1015
|
+
#### Inherited from
|
|
1016
|
+
|
|
1017
|
+
[`LinearBase`](LinearBase.md).[`findIndex`](LinearBase.md#findindex)
|
|
1018
|
+
|
|
1019
|
+
***
|
|
1020
|
+
|
|
1021
|
+
### forEach()
|
|
1022
|
+
|
|
1023
|
+
```ts
|
|
1024
|
+
forEach(callbackfn, thisArg?): void;
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L133)
|
|
1028
|
+
|
|
1029
|
+
Invokes a callback for each element in iteration order.
|
|
1030
|
+
|
|
1031
|
+
#### Parameters
|
|
1032
|
+
|
|
1033
|
+
##### callbackfn
|
|
1034
|
+
|
|
1035
|
+
`ElementCallback`\<`E`, `R`, `void`\>
|
|
1036
|
+
|
|
1037
|
+
Function invoked per element with signature `(value, index, self)`.
|
|
1038
|
+
|
|
1039
|
+
##### thisArg?
|
|
1040
|
+
|
|
1041
|
+
`unknown`
|
|
1042
|
+
|
|
1043
|
+
Optional `this` binding for the callback.
|
|
1044
|
+
|
|
1045
|
+
#### Returns
|
|
1046
|
+
|
|
1047
|
+
`void`
|
|
1048
|
+
|
|
1049
|
+
`void`.
|
|
1050
|
+
|
|
1051
|
+
#### Remarks
|
|
1052
|
+
|
|
1053
|
+
Time O(n), Space O(1).
|
|
1054
|
+
|
|
1055
|
+
#### Inherited from
|
|
1056
|
+
|
|
1057
|
+
[`LinearBase`](LinearBase.md).[`forEach`](LinearBase.md#foreach)
|
|
1058
|
+
|
|
1059
|
+
***
|
|
1060
|
+
|
|
1061
|
+
### has()
|
|
1062
|
+
|
|
1063
|
+
```ts
|
|
1064
|
+
has(element): boolean;
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
Defined in: [data-structures/base/iterable-element-base.ts:189](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L189)
|
|
1068
|
+
|
|
1069
|
+
Checks whether a strictly-equal element exists in the structure.
|
|
1070
|
+
|
|
1071
|
+
#### Parameters
|
|
1072
|
+
|
|
1073
|
+
##### element
|
|
1074
|
+
|
|
1075
|
+
`E`
|
|
1076
|
+
|
|
1077
|
+
The element to test with `===` equality.
|
|
1078
|
+
|
|
1079
|
+
#### Returns
|
|
1080
|
+
|
|
1081
|
+
`boolean`
|
|
1082
|
+
|
|
1083
|
+
`true` if an equal element is found; otherwise `false`.
|
|
1084
|
+
|
|
1085
|
+
#### Remarks
|
|
1086
|
+
|
|
1087
|
+
Time O(n) in the worst case. Space O(1).
|
|
1088
|
+
|
|
1089
|
+
#### Inherited from
|
|
1090
|
+
|
|
1091
|
+
[`LinearBase`](LinearBase.md).[`has`](LinearBase.md#has)
|
|
1092
|
+
|
|
1093
|
+
***
|
|
1094
|
+
|
|
1095
|
+
### indexOf()
|
|
1096
|
+
|
|
1097
|
+
```ts
|
|
1098
|
+
indexOf(searchElement, fromIndex?): number;
|
|
1099
|
+
```
|
|
1100
|
+
|
|
1101
|
+
Defined in: [data-structures/base/linear-base.ts:111](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L111)
|
|
1102
|
+
|
|
1103
|
+
First index of a value from the left.
|
|
1104
|
+
|
|
1105
|
+
#### Parameters
|
|
1106
|
+
|
|
1107
|
+
##### searchElement
|
|
1108
|
+
|
|
1109
|
+
`E`
|
|
1110
|
+
|
|
1111
|
+
Value to match.
|
|
1112
|
+
|
|
1113
|
+
##### fromIndex?
|
|
1114
|
+
|
|
1115
|
+
`number` = `0`
|
|
1116
|
+
|
|
1117
|
+
Start position (supports negative index).
|
|
1118
|
+
|
|
1119
|
+
#### Returns
|
|
1120
|
+
|
|
1121
|
+
`number`
|
|
1122
|
+
|
|
1123
|
+
Index or `-1` if not found.
|
|
1124
|
+
|
|
1125
|
+
#### Remarks
|
|
1126
|
+
|
|
1127
|
+
Time O(n), Space O(1)
|
|
1128
|
+
|
|
1129
|
+
#### Inherited from
|
|
1130
|
+
|
|
1131
|
+
[`LinearBase`](LinearBase.md).[`indexOf`](LinearBase.md#indexof)
|
|
1132
|
+
|
|
1133
|
+
***
|
|
1134
|
+
|
|
1135
|
+
### isEmpty()
|
|
1136
|
+
|
|
1137
|
+
```ts
|
|
1138
|
+
isEmpty(): boolean;
|
|
1139
|
+
```
|
|
1140
|
+
|
|
1141
|
+
Defined in: [data-structures/queue/queue.ts:339](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L339)
|
|
1142
|
+
|
|
1143
|
+
Check whether the queue is empty.
|
|
1144
|
+
|
|
1145
|
+
#### Returns
|
|
1146
|
+
|
|
1147
|
+
`boolean`
|
|
1148
|
+
|
|
1149
|
+
True if length is 0.
|
|
1150
|
+
|
|
1151
|
+
*
|
|
1152
|
+
|
|
1153
|
+
#### Remarks
|
|
1154
|
+
|
|
1155
|
+
Time O(1), Space O(1)
|
|
1156
|
+
|
|
1157
|
+
#### Example
|
|
1158
|
+
|
|
1159
|
+
```ts
|
|
1160
|
+
// Queue for...of iteration and isEmpty check
|
|
1161
|
+
const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
1162
|
+
|
|
1163
|
+
const elements: string[] = [];
|
|
1164
|
+
for (const item of queue) {
|
|
1165
|
+
elements.push(item);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// Verify all elements are iterated in order
|
|
1169
|
+
console.log(elements); // ['A', 'B', 'C', 'D'];
|
|
1170
|
+
|
|
1171
|
+
// Process all elements
|
|
1172
|
+
while (queue.length > 0) {
|
|
1173
|
+
queue.shift();
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
console.log(queue.length); // 0;
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
#### Overrides
|
|
1180
|
+
|
|
1181
|
+
[`LinearBase`](LinearBase.md).[`isEmpty`](LinearBase.md#isempty)
|
|
1182
|
+
|
|
1183
|
+
***
|
|
1184
|
+
|
|
1185
|
+
### join()
|
|
1186
|
+
|
|
1187
|
+
```ts
|
|
1188
|
+
join(separator?): string;
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1191
|
+
Defined in: [data-structures/base/linear-base.ts:228](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L228)
|
|
1192
|
+
|
|
1193
|
+
Join all elements into a string.
|
|
1194
|
+
|
|
1195
|
+
#### Parameters
|
|
1196
|
+
|
|
1197
|
+
##### separator?
|
|
1198
|
+
|
|
1199
|
+
`string` = `','`
|
|
1200
|
+
|
|
1201
|
+
Separator string.
|
|
1202
|
+
|
|
1203
|
+
#### Returns
|
|
1204
|
+
|
|
1205
|
+
`string`
|
|
1206
|
+
|
|
1207
|
+
Concatenated string.
|
|
1208
|
+
|
|
1209
|
+
#### Remarks
|
|
1210
|
+
|
|
1211
|
+
Time O(n), Space O(n)
|
|
1212
|
+
|
|
1213
|
+
#### Inherited from
|
|
1214
|
+
|
|
1215
|
+
[`LinearBase`](LinearBase.md).[`join`](LinearBase.md#join)
|
|
1216
|
+
|
|
1217
|
+
***
|
|
1218
|
+
|
|
1219
|
+
### lastIndexOf()
|
|
1220
|
+
|
|
1221
|
+
```ts
|
|
1222
|
+
lastIndexOf(searchElement, fromIndex?): number;
|
|
1223
|
+
```
|
|
1224
|
+
|
|
1225
|
+
Defined in: [data-structures/base/linear-base.ts:131](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L131)
|
|
1226
|
+
|
|
1227
|
+
Last index of a value from the right.
|
|
1228
|
+
|
|
1229
|
+
#### Parameters
|
|
1230
|
+
|
|
1231
|
+
##### searchElement
|
|
1232
|
+
|
|
1233
|
+
`E`
|
|
1234
|
+
|
|
1235
|
+
Value to match.
|
|
1236
|
+
|
|
1237
|
+
##### fromIndex?
|
|
1238
|
+
|
|
1239
|
+
`number` = `...`
|
|
1240
|
+
|
|
1241
|
+
Start position (supports negative index).
|
|
1242
|
+
|
|
1243
|
+
#### Returns
|
|
1244
|
+
|
|
1245
|
+
`number`
|
|
1246
|
+
|
|
1247
|
+
Index or `-1` if not found.
|
|
1248
|
+
|
|
1249
|
+
#### Remarks
|
|
1250
|
+
|
|
1251
|
+
Time O(n), Space O(1)
|
|
1252
|
+
|
|
1253
|
+
#### Inherited from
|
|
1254
|
+
|
|
1255
|
+
[`LinearBase`](LinearBase.md).[`lastIndexOf`](LinearBase.md#lastindexof)
|
|
1256
|
+
|
|
1257
|
+
***
|
|
1258
|
+
|
|
1259
|
+
### map()
|
|
1260
|
+
|
|
1261
|
+
```ts
|
|
1262
|
+
map<EM, RM>(
|
|
1263
|
+
callback,
|
|
1264
|
+
options?,
|
|
1265
|
+
thisArg?): Queue<EM, RM>;
|
|
1266
|
+
```
|
|
1267
|
+
|
|
1268
|
+
Defined in: [data-structures/queue/queue.ts:920](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L920)
|
|
1269
|
+
|
|
1270
|
+
Map each element to a new element in a possibly different-typed queue.
|
|
1271
|
+
|
|
1272
|
+
#### Type Parameters
|
|
1273
|
+
|
|
1274
|
+
##### EM
|
|
1275
|
+
|
|
1276
|
+
`EM`
|
|
1277
|
+
|
|
1278
|
+
##### RM
|
|
1279
|
+
|
|
1280
|
+
`RM`
|
|
1281
|
+
|
|
1282
|
+
#### Parameters
|
|
1283
|
+
|
|
1284
|
+
##### callback
|
|
1285
|
+
|
|
1286
|
+
`ElementCallback`\<`E`, `R`, `EM`\>
|
|
1287
|
+
|
|
1288
|
+
Mapping function (element, index, queue) → newElement.
|
|
1289
|
+
|
|
1290
|
+
##### options?
|
|
1291
|
+
|
|
1292
|
+
`QueueOptions`\<`EM`, `RM`\>
|
|
1293
|
+
|
|
1294
|
+
Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
|
|
1295
|
+
|
|
1296
|
+
##### thisArg?
|
|
1297
|
+
|
|
1298
|
+
`unknown`
|
|
1299
|
+
|
|
1300
|
+
Value for `this` inside the callback.
|
|
1301
|
+
|
|
1302
|
+
#### Returns
|
|
1303
|
+
|
|
1304
|
+
`Queue`\<`EM`, `RM`\>
|
|
1305
|
+
|
|
1306
|
+
A new Queue with mapped elements.
|
|
1307
|
+
|
|
1308
|
+
*
|
|
1309
|
+
|
|
1310
|
+
#### Remarks
|
|
1311
|
+
|
|
1312
|
+
Time O(N), Space O(N)
|
|
1313
|
+
|
|
1314
|
+
#### Example
|
|
1315
|
+
|
|
1316
|
+
```ts
|
|
1317
|
+
// Transform elements
|
|
1318
|
+
const q = new Queue<number>([1, 2, 3]);
|
|
1319
|
+
const doubled = q.map(x => x * 2);
|
|
1320
|
+
console.log(doubled.toArray()); // [2, 4, 6];
|
|
1321
|
+
```
|
|
1322
|
+
|
|
1323
|
+
#### Overrides
|
|
1324
|
+
|
|
1325
|
+
[`LinearBase`](LinearBase.md).[`map`](LinearBase.md#map)
|
|
1326
|
+
|
|
1327
|
+
***
|
|
1328
|
+
|
|
1329
|
+
### mapSame()
|
|
1330
|
+
|
|
1331
|
+
```ts
|
|
1332
|
+
mapSame(callback, thisArg?): this;
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
Defined in: [data-structures/queue/queue.ts:943](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L943)
|
|
1336
|
+
|
|
1337
|
+
Map each element to a new value of the same type.
|
|
1338
|
+
|
|
1339
|
+
#### Parameters
|
|
1340
|
+
|
|
1341
|
+
##### callback
|
|
1342
|
+
|
|
1343
|
+
`ElementCallback`\<`E`, `R`, `E`\>
|
|
1344
|
+
|
|
1345
|
+
Mapping function (element, index, queue) → element.
|
|
1346
|
+
|
|
1347
|
+
##### thisArg?
|
|
1348
|
+
|
|
1349
|
+
`unknown`
|
|
1350
|
+
|
|
1351
|
+
Value for `this` inside the callback.
|
|
1352
|
+
|
|
1353
|
+
#### Returns
|
|
1354
|
+
|
|
1355
|
+
`this`
|
|
1356
|
+
|
|
1357
|
+
A new queue with mapped elements (same element type).
|
|
1358
|
+
|
|
1359
|
+
#### Remarks
|
|
1360
|
+
|
|
1361
|
+
Time O(N), Space O(N)
|
|
1362
|
+
|
|
1363
|
+
#### Overrides
|
|
1364
|
+
|
|
1365
|
+
[`LinearBase`](LinearBase.md).[`mapSame`](LinearBase.md#mapsame)
|
|
1366
|
+
|
|
1367
|
+
***
|
|
1368
|
+
|
|
1369
|
+
### print()
|
|
1370
|
+
|
|
1371
|
+
```ts
|
|
1372
|
+
print(): void;
|
|
1373
|
+
```
|
|
1374
|
+
|
|
1375
|
+
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L269)
|
|
1376
|
+
|
|
1377
|
+
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1378
|
+
|
|
1379
|
+
#### Returns
|
|
1380
|
+
|
|
1381
|
+
`void`
|
|
1382
|
+
|
|
1383
|
+
`void`.
|
|
1384
|
+
|
|
1385
|
+
#### Remarks
|
|
1386
|
+
|
|
1387
|
+
Time O(n) due to materialization, Space O(n) for the intermediate representation.
|
|
1388
|
+
|
|
1389
|
+
#### Inherited from
|
|
1390
|
+
|
|
1391
|
+
[`LinearBase`](LinearBase.md).[`print`](LinearBase.md#print)
|
|
1392
|
+
|
|
1393
|
+
***
|
|
1394
|
+
|
|
1395
|
+
### push()
|
|
1396
|
+
|
|
1397
|
+
```ts
|
|
1398
|
+
push(element): boolean;
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
Defined in: [data-structures/queue/queue.ts:395](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L395)
|
|
1402
|
+
|
|
1403
|
+
Enqueue one element at the back.
|
|
1404
|
+
|
|
1405
|
+
#### Parameters
|
|
1406
|
+
|
|
1407
|
+
##### element
|
|
1408
|
+
|
|
1409
|
+
`E`
|
|
1410
|
+
|
|
1411
|
+
Element to enqueue.
|
|
1412
|
+
|
|
1413
|
+
#### Returns
|
|
1414
|
+
|
|
1415
|
+
`boolean`
|
|
1416
|
+
|
|
1417
|
+
True on success.
|
|
1418
|
+
|
|
1419
|
+
*
|
|
1420
|
+
|
|
1421
|
+
#### Remarks
|
|
1422
|
+
|
|
1423
|
+
Time O(1), Space O(1)
|
|
1424
|
+
|
|
1425
|
+
#### Example
|
|
1426
|
+
|
|
1427
|
+
```ts
|
|
1428
|
+
// basic Queue creation and push operation
|
|
1429
|
+
// Create a simple Queue with initial values
|
|
1430
|
+
const queue = new Queue([1, 2, 3, 4, 5]);
|
|
1431
|
+
|
|
1432
|
+
// Verify the queue maintains insertion order
|
|
1433
|
+
console.log([...queue]); // [1, 2, 3, 4, 5];
|
|
1434
|
+
|
|
1435
|
+
// Check length
|
|
1436
|
+
console.log(queue.length); // 5;
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
#### Overrides
|
|
1440
|
+
|
|
1441
|
+
[`LinearBase`](LinearBase.md).[`push`](LinearBase.md#push)
|
|
1442
|
+
|
|
1443
|
+
***
|
|
1444
|
+
|
|
1445
|
+
### pushMany()
|
|
1446
|
+
|
|
1447
|
+
```ts
|
|
1448
|
+
pushMany(elements): boolean[];
|
|
1449
|
+
```
|
|
1450
|
+
|
|
1451
|
+
Defined in: [data-structures/queue/queue.ts:408](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L408)
|
|
1452
|
+
|
|
1453
|
+
Enqueue many elements from an iterable.
|
|
1454
|
+
|
|
1455
|
+
#### Parameters
|
|
1456
|
+
|
|
1457
|
+
##### elements
|
|
1458
|
+
|
|
1459
|
+
`Iterable`\<`E`, `any`, `any`\> \| `Iterable`\<`R`, `any`, `any`\>
|
|
1460
|
+
|
|
1461
|
+
Iterable of elements (or raw records if toElementFn is set).
|
|
1462
|
+
|
|
1463
|
+
#### Returns
|
|
1464
|
+
|
|
1465
|
+
`boolean`[]
|
|
1466
|
+
|
|
1467
|
+
Array of per-element success flags.
|
|
1468
|
+
|
|
1469
|
+
#### Remarks
|
|
1470
|
+
|
|
1471
|
+
Time O(N), Space O(1)
|
|
1472
|
+
|
|
1473
|
+
#### Overrides
|
|
1474
|
+
|
|
1475
|
+
[`LinearBase`](LinearBase.md).[`pushMany`](LinearBase.md#pushmany)
|
|
1476
|
+
|
|
1477
|
+
***
|
|
1478
|
+
|
|
1479
|
+
### reduce()
|
|
1480
|
+
|
|
1481
|
+
Reduces all elements to a single accumulated value.
|
|
1482
|
+
|
|
1483
|
+
#### Param
|
|
1484
|
+
|
|
1485
|
+
Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
|
|
1486
|
+
|
|
1487
|
+
#### Param
|
|
1488
|
+
|
|
1489
|
+
Reducer of signature `(acc, value, index, self) => nextAcc`.
|
|
1490
|
+
|
|
1491
|
+
#### Param
|
|
1492
|
+
|
|
1493
|
+
The initial accumulator value of type `E`.
|
|
1494
|
+
|
|
1495
|
+
#### Template
|
|
1496
|
+
|
|
1497
|
+
The accumulator type when it differs from `E`.
|
|
1498
|
+
|
|
1499
|
+
#### Param
|
|
1500
|
+
|
|
1501
|
+
Reducer of signature `(acc: U, value, index, self) => U`.
|
|
1502
|
+
|
|
1503
|
+
#### Param
|
|
1504
|
+
|
|
1505
|
+
The initial accumulator value of type `U`.
|
|
1506
|
+
|
|
1507
|
+
#### Remarks
|
|
1508
|
+
|
|
1509
|
+
Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
|
|
1510
|
+
|
|
1511
|
+
#### Call Signature
|
|
1512
|
+
|
|
1513
|
+
```ts
|
|
1514
|
+
reduce(callbackfn): E;
|
|
1515
|
+
```
|
|
1516
|
+
|
|
1517
|
+
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L194)
|
|
1518
|
+
|
|
1519
|
+
##### Parameters
|
|
1520
|
+
|
|
1521
|
+
###### callbackfn
|
|
1522
|
+
|
|
1523
|
+
`ReduceElementCallback`\<`E`, `R`\>
|
|
1524
|
+
|
|
1525
|
+
##### Returns
|
|
1526
|
+
|
|
1527
|
+
`E`
|
|
1528
|
+
|
|
1529
|
+
##### Inherited from
|
|
1530
|
+
|
|
1531
|
+
[`LinearBase`](LinearBase.md).[`reduce`](LinearBase.md#reduce)
|
|
1532
|
+
|
|
1533
|
+
#### Call Signature
|
|
1534
|
+
|
|
1535
|
+
```ts
|
|
1536
|
+
reduce(callbackfn, initialValue): E;
|
|
1537
|
+
```
|
|
1538
|
+
|
|
1539
|
+
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L195)
|
|
1540
|
+
|
|
1541
|
+
##### Parameters
|
|
1542
|
+
|
|
1543
|
+
###### callbackfn
|
|
1544
|
+
|
|
1545
|
+
`ReduceElementCallback`\<`E`, `R`\>
|
|
1546
|
+
|
|
1547
|
+
###### initialValue
|
|
1548
|
+
|
|
1549
|
+
`E`
|
|
1550
|
+
|
|
1551
|
+
##### Returns
|
|
1552
|
+
|
|
1553
|
+
`E`
|
|
1554
|
+
|
|
1555
|
+
##### Inherited from
|
|
1556
|
+
|
|
1557
|
+
[`LinearBase`](LinearBase.md).[`reduce`](LinearBase.md#reduce)
|
|
1558
|
+
|
|
1559
|
+
#### Call Signature
|
|
1560
|
+
|
|
1561
|
+
```ts
|
|
1562
|
+
reduce<U>(callbackfn, initialValue): U;
|
|
1563
|
+
```
|
|
1564
|
+
|
|
1565
|
+
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L196)
|
|
1566
|
+
|
|
1567
|
+
##### Type Parameters
|
|
1568
|
+
|
|
1569
|
+
###### U
|
|
1570
|
+
|
|
1571
|
+
`U`
|
|
1572
|
+
|
|
1573
|
+
##### Parameters
|
|
1574
|
+
|
|
1575
|
+
###### callbackfn
|
|
1576
|
+
|
|
1577
|
+
`ReduceElementCallback`\<`E`, `R`, `U`\>
|
|
1578
|
+
|
|
1579
|
+
###### initialValue
|
|
1580
|
+
|
|
1581
|
+
`U`
|
|
1582
|
+
|
|
1583
|
+
##### Returns
|
|
1584
|
+
|
|
1585
|
+
`U`
|
|
1586
|
+
|
|
1587
|
+
##### Inherited from
|
|
1588
|
+
|
|
1589
|
+
[`LinearBase`](LinearBase.md).[`reduce`](LinearBase.md#reduce)
|
|
1590
|
+
|
|
1591
|
+
***
|
|
1592
|
+
|
|
1593
|
+
### reduceRight()
|
|
1594
|
+
|
|
1595
|
+
```ts
|
|
1596
|
+
reduceRight<U>(callbackfn, initialValue): U;
|
|
1597
|
+
```
|
|
1598
|
+
|
|
1599
|
+
Defined in: [data-structures/base/linear-base.ts:256](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L256)
|
|
1600
|
+
|
|
1601
|
+
Right-to-left reduction over elements.
|
|
1602
|
+
|
|
1603
|
+
#### Type Parameters
|
|
1604
|
+
|
|
1605
|
+
##### U
|
|
1606
|
+
|
|
1607
|
+
`U`
|
|
1608
|
+
|
|
1609
|
+
#### Parameters
|
|
1610
|
+
|
|
1611
|
+
##### callbackfn
|
|
1612
|
+
|
|
1613
|
+
`ReduceLinearCallback`\<`E`, `U`\>
|
|
1614
|
+
|
|
1615
|
+
`(acc, element, index, self) => acc`.
|
|
1616
|
+
|
|
1617
|
+
##### initialValue
|
|
1618
|
+
|
|
1619
|
+
`U`
|
|
1620
|
+
|
|
1621
|
+
Initial accumulator (optional generic overloads supported).
|
|
1622
|
+
|
|
1623
|
+
#### Returns
|
|
1624
|
+
|
|
1625
|
+
`U`
|
|
1626
|
+
|
|
1627
|
+
Final accumulator.
|
|
1628
|
+
|
|
1629
|
+
#### Remarks
|
|
1630
|
+
|
|
1631
|
+
Time O(n), Space O(1)
|
|
1632
|
+
|
|
1633
|
+
#### Inherited from
|
|
1634
|
+
|
|
1635
|
+
[`LinearBase`](LinearBase.md).[`reduceRight`](LinearBase.md#reduceright)
|
|
1636
|
+
|
|
1637
|
+
***
|
|
1638
|
+
|
|
1639
|
+
### reverse()
|
|
1640
|
+
|
|
1641
|
+
```ts
|
|
1642
|
+
reverse(): this;
|
|
1643
|
+
```
|
|
1644
|
+
|
|
1645
|
+
Defined in: [data-structures/queue/queue.ts:631](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L631)
|
|
1646
|
+
|
|
1647
|
+
Reverse the queue in-place by compacting then reversing.
|
|
1648
|
+
|
|
1649
|
+
#### Returns
|
|
1650
|
+
|
|
1651
|
+
`this`
|
|
1652
|
+
|
|
1653
|
+
This queue.
|
|
1654
|
+
|
|
1655
|
+
#### Remarks
|
|
1656
|
+
|
|
1657
|
+
Time O(N), Space O(N)
|
|
1658
|
+
|
|
1659
|
+
#### Overrides
|
|
1660
|
+
|
|
1661
|
+
[`LinearBase`](LinearBase.md).[`reverse`](LinearBase.md#reverse)
|
|
1662
|
+
|
|
1663
|
+
***
|
|
1664
|
+
|
|
1665
|
+
### setAt()
|
|
1666
|
+
|
|
1667
|
+
```ts
|
|
1668
|
+
setAt(index, newElement): boolean;
|
|
1669
|
+
```
|
|
1670
|
+
|
|
1671
|
+
Defined in: [data-structures/queue/queue.ts:619](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L619)
|
|
1672
|
+
|
|
1673
|
+
Replace the element at a given index.
|
|
1674
|
+
|
|
1675
|
+
#### Parameters
|
|
1676
|
+
|
|
1677
|
+
##### index
|
|
1678
|
+
|
|
1679
|
+
`number`
|
|
1680
|
+
|
|
1681
|
+
Zero-based index from the front.
|
|
1682
|
+
|
|
1683
|
+
##### newElement
|
|
1684
|
+
|
|
1685
|
+
`E`
|
|
1686
|
+
|
|
1687
|
+
New element to set.
|
|
1688
|
+
|
|
1689
|
+
#### Returns
|
|
1690
|
+
|
|
1691
|
+
`boolean`
|
|
1692
|
+
|
|
1693
|
+
True if updated.
|
|
1694
|
+
|
|
1695
|
+
#### Remarks
|
|
1696
|
+
|
|
1697
|
+
Time O(1), Space O(1)
|
|
1698
|
+
|
|
1699
|
+
#### Overrides
|
|
1700
|
+
|
|
1701
|
+
[`LinearBase`](LinearBase.md).[`setAt`](LinearBase.md#setat)
|
|
1702
|
+
|
|
1703
|
+
***
|
|
1704
|
+
|
|
1705
|
+
### shift()
|
|
1706
|
+
|
|
1707
|
+
```ts
|
|
1708
|
+
shift(): E | undefined;
|
|
1709
|
+
```
|
|
1710
|
+
|
|
1711
|
+
Defined in: [data-structures/queue/queue.ts:472](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L472)
|
|
1712
|
+
|
|
1713
|
+
Dequeue one element from the front (amortized via offset).
|
|
1714
|
+
|
|
1715
|
+
#### Returns
|
|
1716
|
+
|
|
1717
|
+
`E` \| `undefined`
|
|
1718
|
+
|
|
1719
|
+
Removed element or undefined.
|
|
1720
|
+
|
|
1721
|
+
*
|
|
1722
|
+
|
|
1723
|
+
#### Remarks
|
|
1724
|
+
|
|
1725
|
+
Time O(1) amortized, Space O(1)
|
|
1726
|
+
|
|
1727
|
+
#### Example
|
|
1728
|
+
|
|
1729
|
+
```ts
|
|
1730
|
+
// Queue shift and peek operations
|
|
1731
|
+
const queue = new Queue<number>([10, 20, 30, 40]);
|
|
1732
|
+
|
|
1733
|
+
// Peek at the front element without removing it
|
|
1734
|
+
console.log(queue.first); // 10;
|
|
1735
|
+
|
|
1736
|
+
// Remove and get the first element (FIFO)
|
|
1737
|
+
const first = queue.shift();
|
|
1738
|
+
console.log(first); // 10;
|
|
1739
|
+
|
|
1740
|
+
// Verify remaining elements and length decreased
|
|
1741
|
+
console.log([...queue]); // [20, 30, 40];
|
|
1742
|
+
console.log(queue.length); // 3;
|
|
1743
|
+
```
|
|
1744
|
+
|
|
1745
|
+
***
|
|
1746
|
+
|
|
1747
|
+
### slice()
|
|
1748
|
+
|
|
1749
|
+
```ts
|
|
1750
|
+
slice(start?, end?): this;
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
Defined in: [data-structures/base/linear-base.ts:273](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L273)
|
|
1754
|
+
|
|
1755
|
+
Create a shallow copy of a subrange.
|
|
1756
|
+
|
|
1757
|
+
#### Parameters
|
|
1758
|
+
|
|
1759
|
+
##### start?
|
|
1760
|
+
|
|
1761
|
+
`number` = `0`
|
|
1762
|
+
|
|
1763
|
+
Inclusive start (supports negative index).
|
|
1764
|
+
|
|
1765
|
+
##### end?
|
|
1766
|
+
|
|
1767
|
+
`number` = `...`
|
|
1768
|
+
|
|
1769
|
+
Exclusive end (supports negative index).
|
|
1770
|
+
|
|
1771
|
+
#### Returns
|
|
1772
|
+
|
|
1773
|
+
`this`
|
|
1774
|
+
|
|
1775
|
+
New list with the range (`this` type).
|
|
1776
|
+
|
|
1777
|
+
#### Remarks
|
|
1778
|
+
|
|
1779
|
+
Time O(n), Space O(n)
|
|
1780
|
+
|
|
1781
|
+
#### Inherited from
|
|
1782
|
+
|
|
1783
|
+
[`LinearBase`](LinearBase.md).[`slice`](LinearBase.md#slice)
|
|
1784
|
+
|
|
1785
|
+
***
|
|
1786
|
+
|
|
1787
|
+
### some()
|
|
1788
|
+
|
|
1789
|
+
```ts
|
|
1790
|
+
some(predicate, thisArg?): boolean;
|
|
1791
|
+
```
|
|
1792
|
+
|
|
1793
|
+
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L110)
|
|
1794
|
+
|
|
1795
|
+
Tests whether at least one element satisfies the predicate.
|
|
1796
|
+
|
|
1797
|
+
#### Parameters
|
|
1798
|
+
|
|
1799
|
+
##### predicate
|
|
1800
|
+
|
|
1801
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
1802
|
+
|
|
1803
|
+
Function invoked for each element with signature `(value, index, self)`.
|
|
1804
|
+
|
|
1805
|
+
##### thisArg?
|
|
1806
|
+
|
|
1807
|
+
`unknown`
|
|
1808
|
+
|
|
1809
|
+
Optional `this` binding for the predicate.
|
|
1810
|
+
|
|
1811
|
+
#### Returns
|
|
1812
|
+
|
|
1813
|
+
`boolean`
|
|
1814
|
+
|
|
1815
|
+
`true` if any element passes; otherwise `false`.
|
|
1816
|
+
|
|
1817
|
+
#### Remarks
|
|
1818
|
+
|
|
1819
|
+
Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
1820
|
+
|
|
1821
|
+
#### Inherited from
|
|
1822
|
+
|
|
1823
|
+
[`LinearBase`](LinearBase.md).[`some`](LinearBase.md#some)
|
|
1824
|
+
|
|
1825
|
+
***
|
|
1826
|
+
|
|
1827
|
+
### sort()
|
|
1828
|
+
|
|
1829
|
+
```ts
|
|
1830
|
+
sort(compareFn?): this;
|
|
1831
|
+
```
|
|
1832
|
+
|
|
1833
|
+
Defined in: [data-structures/base/linear-base.ts:185](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L185)
|
|
1834
|
+
|
|
1835
|
+
In-place stable order via array sort semantics.
|
|
1836
|
+
|
|
1837
|
+
#### Parameters
|
|
1838
|
+
|
|
1839
|
+
##### compareFn?
|
|
1840
|
+
|
|
1841
|
+
(`a`, `b`) => `number`
|
|
1842
|
+
|
|
1843
|
+
Comparator `(a, b) => number`.
|
|
1844
|
+
|
|
1845
|
+
#### Returns
|
|
1846
|
+
|
|
1847
|
+
`this`
|
|
1848
|
+
|
|
1849
|
+
This container.
|
|
1850
|
+
|
|
1851
|
+
#### Remarks
|
|
1852
|
+
|
|
1853
|
+
Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1854
|
+
|
|
1855
|
+
#### Inherited from
|
|
1856
|
+
|
|
1857
|
+
[`LinearBase`](LinearBase.md).[`sort`](LinearBase.md#sort)
|
|
1858
|
+
|
|
1859
|
+
***
|
|
1860
|
+
|
|
1861
|
+
### splice()
|
|
1862
|
+
|
|
1863
|
+
```ts
|
|
1864
|
+
splice(
|
|
1865
|
+
start,
|
|
1866
|
+
deleteCount?, ...
|
|
1867
|
+
items?): this;
|
|
1868
|
+
```
|
|
1869
|
+
|
|
1870
|
+
Defined in: [data-structures/queue/queue.ts:746](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L746)
|
|
1871
|
+
|
|
1872
|
+
Remove and/or insert elements at a position (array-like).
|
|
1873
|
+
|
|
1874
|
+
#### Parameters
|
|
1875
|
+
|
|
1876
|
+
##### start
|
|
1877
|
+
|
|
1878
|
+
`number`
|
|
1879
|
+
|
|
1880
|
+
Start index (clamped to [0, length]).
|
|
1881
|
+
|
|
1882
|
+
##### deleteCount?
|
|
1883
|
+
|
|
1884
|
+
`number` = `0`
|
|
1885
|
+
|
|
1886
|
+
Number of elements to remove (default 0).
|
|
1887
|
+
|
|
1888
|
+
##### items?
|
|
1889
|
+
|
|
1890
|
+
...`E`[]
|
|
1891
|
+
|
|
1892
|
+
Elements to insert after `start`.
|
|
1893
|
+
|
|
1894
|
+
#### Returns
|
|
1895
|
+
|
|
1896
|
+
`this`
|
|
1897
|
+
|
|
1898
|
+
A new queue containing the removed elements (typed as `this`).
|
|
1899
|
+
|
|
1900
|
+
#### Remarks
|
|
1901
|
+
|
|
1902
|
+
Time O(N + M), Space O(M)
|
|
1903
|
+
|
|
1904
|
+
#### Overrides
|
|
1905
|
+
|
|
1906
|
+
[`LinearBase`](LinearBase.md).[`splice`](LinearBase.md#splice)
|
|
1907
|
+
|
|
1908
|
+
***
|
|
1909
|
+
|
|
1910
|
+
### toArray()
|
|
1911
|
+
|
|
1912
|
+
```ts
|
|
1913
|
+
toArray(): E[];
|
|
1914
|
+
```
|
|
1915
|
+
|
|
1916
|
+
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L246)
|
|
1917
|
+
|
|
1918
|
+
Materializes the elements into a new array.
|
|
1919
|
+
|
|
1920
|
+
#### Returns
|
|
1921
|
+
|
|
1922
|
+
`E`[]
|
|
1923
|
+
|
|
1924
|
+
A shallow array copy of the iteration order.
|
|
1925
|
+
|
|
1926
|
+
#### Remarks
|
|
1927
|
+
|
|
1928
|
+
Time O(n), Space O(n).
|
|
1929
|
+
|
|
1930
|
+
#### Inherited from
|
|
1931
|
+
|
|
1932
|
+
[`LinearBase`](LinearBase.md).[`toArray`](LinearBase.md#toarray)
|
|
1933
|
+
|
|
1934
|
+
***
|
|
1935
|
+
|
|
1936
|
+
### toReversedArray()
|
|
1937
|
+
|
|
1938
|
+
```ts
|
|
1939
|
+
toReversedArray(): E[];
|
|
1940
|
+
```
|
|
1941
|
+
|
|
1942
|
+
Defined in: [data-structures/base/linear-base.ts:237](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L237)
|
|
1943
|
+
|
|
1944
|
+
Snapshot elements into a reversed array.
|
|
1945
|
+
|
|
1946
|
+
#### Returns
|
|
1947
|
+
|
|
1948
|
+
`E`[]
|
|
1949
|
+
|
|
1950
|
+
New reversed array.
|
|
1951
|
+
|
|
1952
|
+
#### Remarks
|
|
1953
|
+
|
|
1954
|
+
Time O(n), Space O(n)
|
|
1955
|
+
|
|
1956
|
+
#### Inherited from
|
|
1957
|
+
|
|
1958
|
+
[`LinearBase`](LinearBase.md).[`toReversedArray`](LinearBase.md#toreversedarray)
|
|
1959
|
+
|
|
1960
|
+
***
|
|
1961
|
+
|
|
1962
|
+
### toVisual()
|
|
1963
|
+
|
|
1964
|
+
```ts
|
|
1965
|
+
toVisual(): E[];
|
|
1966
|
+
```
|
|
1967
|
+
|
|
1968
|
+
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L258)
|
|
1969
|
+
|
|
1970
|
+
Returns a representation of the structure suitable for quick visualization.
|
|
1971
|
+
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
1972
|
+
|
|
1973
|
+
#### Returns
|
|
1974
|
+
|
|
1975
|
+
`E`[]
|
|
1976
|
+
|
|
1977
|
+
A visual representation (array by default).
|
|
1978
|
+
|
|
1979
|
+
#### Remarks
|
|
1980
|
+
|
|
1981
|
+
Time O(n), Space O(n).
|
|
1982
|
+
|
|
1983
|
+
#### Inherited from
|
|
1984
|
+
|
|
1985
|
+
[`LinearBase`](LinearBase.md).[`toVisual`](LinearBase.md#tovisual)
|
|
1986
|
+
|
|
1987
|
+
***
|
|
1988
|
+
|
|
1989
|
+
### values()
|
|
1990
|
+
|
|
1991
|
+
```ts
|
|
1992
|
+
values(): IterableIterator<E>;
|
|
1993
|
+
```
|
|
1994
|
+
|
|
1995
|
+
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L72)
|
|
1996
|
+
|
|
1997
|
+
Returns an iterator over the values (alias of the default iterator).
|
|
1998
|
+
|
|
1999
|
+
#### Returns
|
|
2000
|
+
|
|
2001
|
+
`IterableIterator`\<`E`\>
|
|
2002
|
+
|
|
2003
|
+
An `IterableIterator<E>` over all elements.
|
|
2004
|
+
|
|
2005
|
+
#### Remarks
|
|
2006
|
+
|
|
2007
|
+
Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
|
|
2008
|
+
|
|
2009
|
+
#### Inherited from
|
|
2010
|
+
|
|
2011
|
+
[`LinearBase`](LinearBase.md).[`values`](LinearBase.md#values)
|
|
2012
|
+
|
|
2013
|
+
***
|
|
2014
|
+
|
|
2015
|
+
### fromArray()
|
|
2016
|
+
|
|
2017
|
+
```ts
|
|
2018
|
+
static fromArray<E>(elements): Queue<E>;
|
|
2019
|
+
```
|
|
2020
|
+
|
|
2021
|
+
Defined in: [data-structures/queue/queue.ts:276](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L276)
|
|
2022
|
+
|
|
2023
|
+
Create a queue from an array of elements.
|
|
2024
|
+
|
|
2025
|
+
#### Type Parameters
|
|
2026
|
+
|
|
2027
|
+
##### E
|
|
2028
|
+
|
|
2029
|
+
`E`
|
|
2030
|
+
|
|
2031
|
+
#### Parameters
|
|
2032
|
+
|
|
2033
|
+
##### elements
|
|
2034
|
+
|
|
2035
|
+
`E`[]
|
|
2036
|
+
|
|
2037
|
+
Array of elements to enqueue in order.
|
|
2038
|
+
|
|
2039
|
+
#### Returns
|
|
2040
|
+
|
|
2041
|
+
`Queue`\<`E`\>
|
|
2042
|
+
|
|
2043
|
+
A new queue populated from the array.
|
|
2044
|
+
|
|
2045
|
+
#### Remarks
|
|
2046
|
+
|
|
2047
|
+
Time O(N), Space O(N)
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
---
|
|
2051
|
+
|
|
2052
|
+
## Protected Members
|
|
2053
|
+
|
|
2054
|
+
### \_toElementFn?
|
|
2055
|
+
|
|
2056
|
+
```ts
|
|
2057
|
+
protected optional _toElementFn?: (rawElement) => E;
|
|
2058
|
+
```
|
|
2059
|
+
|
|
2060
|
+
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L39)
|
|
2061
|
+
|
|
2062
|
+
The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
2063
|
+
|
|
2064
|
+
#### Parameters
|
|
2065
|
+
|
|
2066
|
+
##### rawElement
|
|
2067
|
+
|
|
2068
|
+
`R`
|
|
2069
|
+
|
|
2070
|
+
#### Returns
|
|
2071
|
+
|
|
2072
|
+
`E`
|
|
2073
|
+
|
|
2074
|
+
#### Remarks
|
|
2075
|
+
|
|
2076
|
+
Time O(1), Space O(1).
|
|
2077
|
+
|
|
2078
|
+
#### Inherited from
|
|
2079
|
+
|
|
2080
|
+
[`LinearBase`](LinearBase.md).[`_toElementFn`](LinearBase.md#_toelementfn)
|
|
2081
|
+
|
|
2082
|
+
## Accessors
|
|
2083
|
+
|
|
2084
|
+
### \_createInstance()
|
|
2085
|
+
|
|
2086
|
+
```ts
|
|
2087
|
+
protected _createInstance(options?): this;
|
|
2088
|
+
```
|
|
2089
|
+
|
|
2090
|
+
Defined in: [data-structures/queue/queue.ts:1003](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L1003)
|
|
2091
|
+
|
|
2092
|
+
(Protected) Create an empty instance of the same concrete class.
|
|
2093
|
+
|
|
2094
|
+
#### Parameters
|
|
2095
|
+
|
|
2096
|
+
##### options?
|
|
2097
|
+
|
|
2098
|
+
`LinearBaseOptions`\<`E`, `R`\>
|
|
2099
|
+
|
|
2100
|
+
Options forwarded to the constructor.
|
|
2101
|
+
|
|
2102
|
+
#### Returns
|
|
2103
|
+
|
|
2104
|
+
`this`
|
|
2105
|
+
|
|
2106
|
+
An empty like-kind queue instance.
|
|
2107
|
+
|
|
2108
|
+
#### Remarks
|
|
2109
|
+
|
|
2110
|
+
Time O(1), Space O(1)
|
|
2111
|
+
|
|
2112
|
+
#### Overrides
|
|
2113
|
+
|
|
2114
|
+
[`LinearBase`](LinearBase.md).[`_createInstance`](LinearBase.md#_createinstance)
|
|
2115
|
+
|
|
2116
|
+
***
|
|
2117
|
+
|
|
2118
|
+
### \_createLike()
|
|
2119
|
+
|
|
2120
|
+
```ts
|
|
2121
|
+
protected _createLike<EM, RM>(elements?, options?): Queue<EM, RM>;
|
|
2122
|
+
```
|
|
2123
|
+
|
|
2124
|
+
Defined in: [data-structures/queue/queue.ts:1018](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L1018)
|
|
2125
|
+
|
|
2126
|
+
(Protected) Create a like-kind queue and seed it from an iterable.
|
|
2127
|
+
|
|
2128
|
+
#### Type Parameters
|
|
2129
|
+
|
|
2130
|
+
##### EM
|
|
2131
|
+
|
|
2132
|
+
`EM` = `E`
|
|
2133
|
+
|
|
2134
|
+
##### RM
|
|
2135
|
+
|
|
2136
|
+
`RM` = `R`
|
|
2137
|
+
|
|
2138
|
+
#### Parameters
|
|
2139
|
+
|
|
2140
|
+
##### elements?
|
|
2141
|
+
|
|
2142
|
+
`Iterable`\<`EM`, `any`, `any`\> \| `Iterable`\<`RM`, `any`, `any`\>
|
|
2143
|
+
|
|
2144
|
+
Iterable used to seed the new queue.
|
|
2145
|
+
|
|
2146
|
+
##### options?
|
|
2147
|
+
|
|
2148
|
+
`QueueOptions`\<`EM`, `RM`\>
|
|
2149
|
+
|
|
2150
|
+
Options forwarded to the constructor.
|
|
2151
|
+
|
|
2152
|
+
#### Returns
|
|
2153
|
+
|
|
2154
|
+
`Queue`\<`EM`, `RM`\>
|
|
2155
|
+
|
|
2156
|
+
A like-kind Queue instance.
|
|
2157
|
+
|
|
2158
|
+
#### Remarks
|
|
2159
|
+
|
|
2160
|
+
Time O(N), Space O(N)
|
|
2161
|
+
|
|
2162
|
+
***
|
|
2163
|
+
|
|
2164
|
+
### \_getIterator()
|
|
2165
|
+
|
|
2166
|
+
```ts
|
|
2167
|
+
protected _getIterator(): IterableIterator<E>;
|
|
2168
|
+
```
|
|
2169
|
+
|
|
2170
|
+
Defined in: [data-structures/queue/queue.ts:979](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L979)
|
|
2171
|
+
|
|
2172
|
+
(Protected) Iterate elements from front to back.
|
|
2173
|
+
|
|
2174
|
+
#### Returns
|
|
2175
|
+
|
|
2176
|
+
`IterableIterator`\<`E`\>
|
|
2177
|
+
|
|
2178
|
+
Iterator of E.
|
|
2179
|
+
|
|
2180
|
+
#### Remarks
|
|
2181
|
+
|
|
2182
|
+
Time O(N), Space O(1)
|
|
2183
|
+
|
|
2184
|
+
#### Overrides
|
|
2185
|
+
|
|
2186
|
+
[`LinearBase`](LinearBase.md).[`_getIterator`](LinearBase.md#_getiterator)
|
|
2187
|
+
|
|
2188
|
+
***
|
|
2189
|
+
|
|
2190
|
+
### \_getReverseIterator()
|
|
2191
|
+
|
|
2192
|
+
```ts
|
|
2193
|
+
protected _getReverseIterator(): IterableIterator<E>;
|
|
2194
|
+
```
|
|
2195
|
+
|
|
2196
|
+
Defined in: [data-structures/queue/queue.ts:989](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L989)
|
|
2197
|
+
|
|
2198
|
+
(Protected) Iterate elements from back to front.
|
|
2199
|
+
|
|
2200
|
+
#### Returns
|
|
2201
|
+
|
|
2202
|
+
`IterableIterator`\<`E`\>
|
|
2203
|
+
|
|
2204
|
+
Iterator of E.
|
|
2205
|
+
|
|
2206
|
+
#### Remarks
|
|
2207
|
+
|
|
2208
|
+
Time O(N), Space O(1)
|
|
2209
|
+
|
|
2210
|
+
#### Overrides
|
|
2211
|
+
|
|
2212
|
+
[`LinearBase`](LinearBase.md).[`_getReverseIterator`](LinearBase.md#_getreverseiterator)
|
|
2213
|
+
|
|
2214
|
+
***
|
|
2215
|
+
|
|
2216
|
+
### \_setAutoCompactRatio()
|
|
2217
|
+
|
|
2218
|
+
```ts
|
|
2219
|
+
protected _setAutoCompactRatio(value): void;
|
|
2220
|
+
```
|
|
2221
|
+
|
|
2222
|
+
Defined in: [data-structures/queue/queue.ts:969](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/queue/queue.ts#L969)
|
|
2223
|
+
|
|
2224
|
+
(Protected) Set the internal auto-compaction ratio.
|
|
2225
|
+
|
|
2226
|
+
#### Parameters
|
|
2227
|
+
|
|
2228
|
+
##### value
|
|
2229
|
+
|
|
2230
|
+
`number`
|
|
2231
|
+
|
|
2232
|
+
New ratio to assign.
|
|
2233
|
+
|
|
2234
|
+
#### Returns
|
|
2235
|
+
|
|
2236
|
+
`void`
|
|
2237
|
+
|
|
2238
|
+
void
|
|
2239
|
+
|
|
2240
|
+
#### Remarks
|
|
2241
|
+
|
|
2242
|
+
Time O(1), Space O(1)
|
|
2243
|
+
|
|
2244
|
+
***
|