data-structure-typed 1.50.2 → 1.50.4
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/.github/ISSUE_TEMPLATE/bug_report.md +0 -13
- package/CHANGELOG.md +1 -1
- package/README.md +23 -21
- package/README_zh-CN.md +7 -7
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -155
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +50 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +400 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/cjs/data-structures/hash/hash-map.js +196 -62
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/cjs/data-structures/heap/heap.js +29 -20
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/cjs/data-structures/queue/deque.js +100 -16
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/cjs/data-structures/queue/queue.js +65 -45
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/cjs/data-structures/stack/stack.js +36 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/cjs/data-structures/trie/trie.js +115 -36
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/{tree-multimap.js → tree-multi-map.js} +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +46 -9
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/mjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +91 -25
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +397 -0
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/mjs/data-structures/hash/hash-map.js +204 -70
- package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/mjs/data-structures/heap/heap.js +29 -20
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/mjs/data-structures/matrix/matrix.js +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/mjs/data-structures/queue/deque.js +105 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/mjs/data-structures/queue/queue.js +65 -45
- package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/mjs/data-structures/stack/stack.js +36 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/mjs/data-structures/trie/trie.js +118 -39
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.js +1 -0
- package/dist/umd/data-structure-typed.js +1876 -656
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +59 -58
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/test/integration/index.html +2 -2
- package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/{tree-multimap.test.ts → avl-tree-multi-map.test.ts} +55 -55
- package/test/unit/data-structures/binary-tree/overall.test.ts +24 -25
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +706 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/queue/queue.test.ts +2 -0
- package/test/unit/unrestricted-interconversion.test.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/mjs/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -86,6 +86,10 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
86
86
|
* @returns The top element or undefined if the heap is empty.
|
|
87
87
|
*/
|
|
88
88
|
poll(): E | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*/
|
|
89
93
|
/**
|
|
90
94
|
* Time Complexity: O(1)
|
|
91
95
|
* Space Complexity: O(1)
|
|
@@ -104,11 +108,11 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
104
108
|
*/
|
|
105
109
|
clear(): void;
|
|
106
110
|
/**
|
|
107
|
-
* Time Complexity: O(n)
|
|
111
|
+
* Time Complexity: O(n)
|
|
108
112
|
* Space Complexity: O(n)
|
|
109
113
|
*/
|
|
110
114
|
/**
|
|
111
|
-
* Time Complexity: O(n)
|
|
115
|
+
* Time Complexity: O(n)
|
|
112
116
|
* Space Complexity: O(n)
|
|
113
117
|
*
|
|
114
118
|
* Clear and add elements of the heap
|
|
@@ -116,11 +120,11 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
116
120
|
*/
|
|
117
121
|
refill(elements: E[]): boolean[];
|
|
118
122
|
/**
|
|
119
|
-
* Time Complexity: O(n)
|
|
123
|
+
* Time Complexity: O(n)
|
|
120
124
|
* Space Complexity: O(1)
|
|
121
125
|
*/
|
|
122
126
|
/**
|
|
123
|
-
* Time Complexity: O(n)
|
|
127
|
+
* Time Complexity: O(n)
|
|
124
128
|
* Space Complexity: O(1)
|
|
125
129
|
*
|
|
126
130
|
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
@@ -129,11 +133,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
129
133
|
*/
|
|
130
134
|
has(element: E): boolean;
|
|
131
135
|
/**
|
|
132
|
-
* Time Complexity: O(n)
|
|
136
|
+
* Time Complexity: O(n)
|
|
133
137
|
* Space Complexity: O(1)
|
|
138
|
+
* The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
|
|
134
139
|
*/
|
|
135
140
|
/**
|
|
136
|
-
* Time Complexity: O(n)
|
|
141
|
+
* Time Complexity: O(n)
|
|
137
142
|
* Space Complexity: O(1)
|
|
138
143
|
*
|
|
139
144
|
* The `delete` function removes an element from an array-like data structure, maintaining the order
|
|
@@ -145,12 +150,13 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
145
150
|
*/
|
|
146
151
|
delete(element: E): boolean;
|
|
147
152
|
/**
|
|
148
|
-
* Time Complexity: O(n)
|
|
149
|
-
* Space Complexity: O(
|
|
153
|
+
* Time Complexity: O(n)
|
|
154
|
+
* Space Complexity: O(log n)
|
|
155
|
+
* where log n is the height of the heap.
|
|
150
156
|
*/
|
|
151
157
|
/**
|
|
152
|
-
* Time Complexity: O(n)
|
|
153
|
-
* Space Complexity: O(
|
|
158
|
+
* Time Complexity: O(n)
|
|
159
|
+
* Space Complexity: O(log n)
|
|
154
160
|
*
|
|
155
161
|
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
156
162
|
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
@@ -194,12 +200,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
194
200
|
*/
|
|
195
201
|
sort(): E[];
|
|
196
202
|
/**
|
|
197
|
-
* Time Complexity: O(log n)
|
|
198
|
-
* Space Complexity: O(
|
|
203
|
+
* Time Complexity: O(n log n)
|
|
204
|
+
* Space Complexity: O(n)
|
|
199
205
|
*/
|
|
200
206
|
/**
|
|
201
|
-
* Time Complexity: O(n)
|
|
202
|
-
* Space Complexity: O(
|
|
207
|
+
* Time Complexity: O(n log n)
|
|
208
|
+
* Space Complexity: O(n)
|
|
203
209
|
*
|
|
204
210
|
* Fix the entire heap to maintain heap properties.
|
|
205
211
|
*/
|
|
@@ -255,7 +261,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
255
261
|
*/
|
|
256
262
|
protected _getIterator(): IterableIterator<E>;
|
|
257
263
|
/**
|
|
258
|
-
* Time Complexity: O(n)
|
|
264
|
+
* Time Complexity: O(log n)
|
|
259
265
|
* Space Complexity: O(1)
|
|
260
266
|
*/
|
|
261
267
|
/**
|
|
@@ -266,6 +272,10 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
266
272
|
* @param index - The index of the newly added element.
|
|
267
273
|
*/
|
|
268
274
|
protected _bubbleUp(index: number): boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Time Complexity: O(log n)
|
|
277
|
+
* Space Complexity: O(1)
|
|
278
|
+
*/
|
|
269
279
|
/**
|
|
270
280
|
* Time Complexity: O(log n)
|
|
271
281
|
* Space Complexity: O(1)
|
|
@@ -397,11 +407,11 @@ export declare class FibonacciHeap<E> {
|
|
|
397
407
|
*/
|
|
398
408
|
mergeWithChild(parent: FibonacciHeapNode<E>, node: FibonacciHeapNode<E>): void;
|
|
399
409
|
/**
|
|
400
|
-
* Time Complexity: O(log n)
|
|
410
|
+
* Time Complexity: O(log n)
|
|
401
411
|
* Space Complexity: O(1)
|
|
402
412
|
*/
|
|
403
413
|
/**
|
|
404
|
-
* Time Complexity: O(log n)
|
|
414
|
+
* Time Complexity: O(log n)
|
|
405
415
|
* Space Complexity: O(1)
|
|
406
416
|
*
|
|
407
417
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -409,11 +419,11 @@ export declare class FibonacciHeap<E> {
|
|
|
409
419
|
*/
|
|
410
420
|
poll(): E | undefined;
|
|
411
421
|
/**
|
|
412
|
-
* Time Complexity: O(log n)
|
|
422
|
+
* Time Complexity: O(log n)
|
|
413
423
|
* Space Complexity: O(1)
|
|
414
424
|
*/
|
|
415
425
|
/**
|
|
416
|
-
* Time Complexity: O(log n)
|
|
426
|
+
* Time Complexity: O(log n)
|
|
417
427
|
* Space Complexity: O(1)
|
|
418
428
|
*
|
|
419
429
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -39,7 +39,6 @@ export class Heap extends IterableElementBase {
|
|
|
39
39
|
for (const el of elements) {
|
|
40
40
|
this.add(el);
|
|
41
41
|
}
|
|
42
|
-
// this.fix();
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
_comparator = (a, b) => {
|
|
@@ -126,6 +125,10 @@ export class Heap extends IterableElementBase {
|
|
|
126
125
|
}
|
|
127
126
|
return value;
|
|
128
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Time Complexity: O(1)
|
|
130
|
+
* Space Complexity: O(1)
|
|
131
|
+
*/
|
|
129
132
|
/**
|
|
130
133
|
* Time Complexity: O(1)
|
|
131
134
|
* Space Complexity: O(1)
|
|
@@ -150,11 +153,11 @@ export class Heap extends IterableElementBase {
|
|
|
150
153
|
this._elements = [];
|
|
151
154
|
}
|
|
152
155
|
/**
|
|
153
|
-
* Time Complexity: O(n)
|
|
156
|
+
* Time Complexity: O(n)
|
|
154
157
|
* Space Complexity: O(n)
|
|
155
158
|
*/
|
|
156
159
|
/**
|
|
157
|
-
* Time Complexity: O(n)
|
|
160
|
+
* Time Complexity: O(n)
|
|
158
161
|
* Space Complexity: O(n)
|
|
159
162
|
*
|
|
160
163
|
* Clear and add elements of the heap
|
|
@@ -165,11 +168,11 @@ export class Heap extends IterableElementBase {
|
|
|
165
168
|
return this.fix();
|
|
166
169
|
}
|
|
167
170
|
/**
|
|
168
|
-
* Time Complexity: O(n)
|
|
171
|
+
* Time Complexity: O(n)
|
|
169
172
|
* Space Complexity: O(1)
|
|
170
173
|
*/
|
|
171
174
|
/**
|
|
172
|
-
* Time Complexity: O(n)
|
|
175
|
+
* Time Complexity: O(n)
|
|
173
176
|
* Space Complexity: O(1)
|
|
174
177
|
*
|
|
175
178
|
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
@@ -180,11 +183,12 @@ export class Heap extends IterableElementBase {
|
|
|
180
183
|
return this.elements.includes(element);
|
|
181
184
|
}
|
|
182
185
|
/**
|
|
183
|
-
* Time Complexity: O(n)
|
|
186
|
+
* Time Complexity: O(n)
|
|
184
187
|
* Space Complexity: O(1)
|
|
188
|
+
* The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
|
|
185
189
|
*/
|
|
186
190
|
/**
|
|
187
|
-
* Time Complexity: O(n)
|
|
191
|
+
* Time Complexity: O(n)
|
|
188
192
|
* Space Complexity: O(1)
|
|
189
193
|
*
|
|
190
194
|
* The `delete` function removes an element from an array-like data structure, maintaining the order
|
|
@@ -212,12 +216,13 @@ export class Heap extends IterableElementBase {
|
|
|
212
216
|
return true;
|
|
213
217
|
}
|
|
214
218
|
/**
|
|
215
|
-
* Time Complexity: O(n)
|
|
216
|
-
* Space Complexity: O(
|
|
219
|
+
* Time Complexity: O(n)
|
|
220
|
+
* Space Complexity: O(log n)
|
|
221
|
+
* where log n is the height of the heap.
|
|
217
222
|
*/
|
|
218
223
|
/**
|
|
219
|
-
* Time Complexity: O(n)
|
|
220
|
-
* Space Complexity: O(
|
|
224
|
+
* Time Complexity: O(n)
|
|
225
|
+
* Space Complexity: O(log n)
|
|
221
226
|
*
|
|
222
227
|
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
223
228
|
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
@@ -301,12 +306,12 @@ export class Heap extends IterableElementBase {
|
|
|
301
306
|
return visitedNode;
|
|
302
307
|
}
|
|
303
308
|
/**
|
|
304
|
-
* Time Complexity: O(log n)
|
|
305
|
-
* Space Complexity: O(
|
|
309
|
+
* Time Complexity: O(n log n)
|
|
310
|
+
* Space Complexity: O(n)
|
|
306
311
|
*/
|
|
307
312
|
/**
|
|
308
|
-
* Time Complexity: O(n)
|
|
309
|
-
* Space Complexity: O(
|
|
313
|
+
* Time Complexity: O(n log n)
|
|
314
|
+
* Space Complexity: O(n)
|
|
310
315
|
*
|
|
311
316
|
* Fix the entire heap to maintain heap properties.
|
|
312
317
|
*/
|
|
@@ -389,7 +394,7 @@ export class Heap extends IterableElementBase {
|
|
|
389
394
|
}
|
|
390
395
|
}
|
|
391
396
|
/**
|
|
392
|
-
* Time Complexity: O(n)
|
|
397
|
+
* Time Complexity: O(log n)
|
|
393
398
|
* Space Complexity: O(1)
|
|
394
399
|
*/
|
|
395
400
|
/**
|
|
@@ -412,6 +417,10 @@ export class Heap extends IterableElementBase {
|
|
|
412
417
|
this.elements[index] = element;
|
|
413
418
|
return true;
|
|
414
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Time Complexity: O(log n)
|
|
422
|
+
* Space Complexity: O(1)
|
|
423
|
+
*/
|
|
415
424
|
/**
|
|
416
425
|
* Time Complexity: O(log n)
|
|
417
426
|
* Space Complexity: O(1)
|
|
@@ -623,11 +632,11 @@ export class FibonacciHeap {
|
|
|
623
632
|
}
|
|
624
633
|
}
|
|
625
634
|
/**
|
|
626
|
-
* Time Complexity: O(log n)
|
|
635
|
+
* Time Complexity: O(log n)
|
|
627
636
|
* Space Complexity: O(1)
|
|
628
637
|
*/
|
|
629
638
|
/**
|
|
630
|
-
* Time Complexity: O(log n)
|
|
639
|
+
* Time Complexity: O(log n)
|
|
631
640
|
* Space Complexity: O(1)
|
|
632
641
|
*
|
|
633
642
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -637,11 +646,11 @@ export class FibonacciHeap {
|
|
|
637
646
|
return this.pop();
|
|
638
647
|
}
|
|
639
648
|
/**
|
|
640
|
-
* Time Complexity: O(log n)
|
|
649
|
+
* Time Complexity: O(log n)
|
|
641
650
|
* Space Complexity: O(1)
|
|
642
651
|
*/
|
|
643
652
|
/**
|
|
644
|
-
* Time Complexity: O(log n)
|
|
653
|
+
* Time Complexity: O(log n)
|
|
645
654
|
* Space Complexity: O(1)
|
|
646
655
|
*
|
|
647
656
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -8,15 +8,51 @@
|
|
|
8
8
|
import type { ElementCallback } from '../../types';
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
export declare class DoublyLinkedListNode<E = any> {
|
|
11
|
-
value: E;
|
|
12
|
-
next: DoublyLinkedListNode<E> | undefined;
|
|
13
|
-
prev: DoublyLinkedListNode<E> | undefined;
|
|
14
11
|
/**
|
|
15
12
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
16
13
|
* @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
17
14
|
* is defined as a generic type "E".
|
|
18
15
|
*/
|
|
19
16
|
constructor(value: E);
|
|
17
|
+
protected _value: E;
|
|
18
|
+
/**
|
|
19
|
+
* The function returns the value of a protected variable.
|
|
20
|
+
* @returns The value of the variable `_value` is being returned.
|
|
21
|
+
*/
|
|
22
|
+
get value(): E;
|
|
23
|
+
/**
|
|
24
|
+
* The above function sets the value of a variable.
|
|
25
|
+
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
26
|
+
*/
|
|
27
|
+
set value(value: E);
|
|
28
|
+
protected _next: DoublyLinkedListNode<E> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The "next" function returns the next node in a doubly linked list.
|
|
31
|
+
* @returns The `next` property is being returned. It can be either a `DoublyLinkedListNode<E>`
|
|
32
|
+
* object or `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
get next(): DoublyLinkedListNode<E> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The "next" property of a DoublyLinkedListNode is set to the provided value.
|
|
37
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
38
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
39
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
40
|
+
*/
|
|
41
|
+
set next(value: DoublyLinkedListNode<E> | undefined);
|
|
42
|
+
protected _prev: DoublyLinkedListNode<E> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The `prev` function returns the previous node in a doubly linked list.
|
|
45
|
+
* @returns The `prev` property of the `DoublyLinkedListNode` class is being returned. It can either
|
|
46
|
+
* be a `DoublyLinkedListNode` object or `undefined`.
|
|
47
|
+
*/
|
|
48
|
+
get prev(): DoublyLinkedListNode<E> | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The function sets the previous node of a doubly linked list node.
|
|
51
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
52
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
53
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
54
|
+
*/
|
|
55
|
+
set prev(value: DoublyLinkedListNode<E> | undefined);
|
|
20
56
|
}
|
|
21
57
|
/**
|
|
22
58
|
* 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
|
|
@@ -52,12 +88,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
52
88
|
*/
|
|
53
89
|
get size(): number;
|
|
54
90
|
/**
|
|
55
|
-
* Time Complexity: O(
|
|
56
|
-
* Space Complexity: O(
|
|
91
|
+
* Time Complexity: O(1)
|
|
92
|
+
* Space Complexity: O(1)
|
|
57
93
|
* where n is the number of elements in the linked list.
|
|
58
94
|
*/
|
|
59
95
|
/**
|
|
60
|
-
* Time Complexity: O(
|
|
96
|
+
* Time Complexity: O(1)
|
|
61
97
|
* Space Complexity: O(1)
|
|
62
98
|
*
|
|
63
99
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -69,7 +105,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
69
105
|
* Space Complexity: O(1)
|
|
70
106
|
*/
|
|
71
107
|
/**
|
|
72
|
-
* Time Complexity: O(
|
|
108
|
+
* Time Complexity: O(1)
|
|
73
109
|
* Space Complexity: O(1)
|
|
74
110
|
*
|
|
75
111
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -77,11 +113,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
77
113
|
*/
|
|
78
114
|
get last(): E | undefined;
|
|
79
115
|
/**
|
|
80
|
-
* Time Complexity: O(
|
|
81
|
-
* Space Complexity: O(
|
|
116
|
+
* Time Complexity: O(n)
|
|
117
|
+
* Space Complexity: O(n)
|
|
82
118
|
*/
|
|
83
119
|
/**
|
|
84
|
-
* Time Complexity: O(n)
|
|
120
|
+
* Time Complexity: O(n)
|
|
85
121
|
* Space Complexity: O(n)
|
|
86
122
|
*
|
|
87
123
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
@@ -116,7 +152,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
116
152
|
*/
|
|
117
153
|
pop(): E | undefined;
|
|
118
154
|
/**
|
|
119
|
-
* Time Complexity: O(
|
|
155
|
+
* Time Complexity: O(1)
|
|
120
156
|
* Space Complexity: O(1)
|
|
121
157
|
*/
|
|
122
158
|
/**
|
|
@@ -129,7 +165,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
129
165
|
*/
|
|
130
166
|
shift(): E | undefined;
|
|
131
167
|
/**
|
|
132
|
-
* Time Complexity: O(
|
|
168
|
+
* Time Complexity: O(1)
|
|
133
169
|
* Space Complexity: O(1)
|
|
134
170
|
*/
|
|
135
171
|
/**
|
|
@@ -205,12 +241,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
205
241
|
*/
|
|
206
242
|
addAt(index: number, value: E): boolean;
|
|
207
243
|
/**
|
|
208
|
-
* Time Complexity: O(n)
|
|
244
|
+
* Time Complexity: O(1) or O(n)
|
|
209
245
|
* Space Complexity: O(1)
|
|
210
246
|
* where n is the number of elements in the linked list.
|
|
211
247
|
*/
|
|
212
248
|
/**
|
|
213
|
-
* Time Complexity: O(n)
|
|
249
|
+
* Time Complexity: O(1) or O(n)
|
|
214
250
|
* Space Complexity: O(1)
|
|
215
251
|
*
|
|
216
252
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -224,11 +260,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
224
260
|
*/
|
|
225
261
|
addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
226
262
|
/**
|
|
227
|
-
* Time Complexity: O(n)
|
|
263
|
+
* Time Complexity: O(1) or O(n)
|
|
228
264
|
* Space Complexity: O(1)
|
|
229
265
|
*/
|
|
230
266
|
/**
|
|
231
|
-
* Time Complexity: O(n)
|
|
267
|
+
* Time Complexity: O(1) or O(n)
|
|
232
268
|
* Space Complexity: O(1)
|
|
233
269
|
*
|
|
234
270
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -252,7 +288,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
252
288
|
*/
|
|
253
289
|
deleteAt(index: number): boolean;
|
|
254
290
|
/**
|
|
255
|
-
* Time Complexity: O(n)
|
|
291
|
+
* Time Complexity: O(1) or O(n)
|
|
292
|
+
* Space Complexity: O(1)
|
|
293
|
+
*/
|
|
294
|
+
/**
|
|
295
|
+
* Time Complexity: O(1) or O(n)
|
|
256
296
|
* Space Complexity: O(1)
|
|
257
297
|
*
|
|
258
298
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -267,6 +307,9 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
267
307
|
* Space Complexity: O(1)
|
|
268
308
|
*/
|
|
269
309
|
/**
|
|
310
|
+
* Time Complexity: O(1)
|
|
311
|
+
* Space Complexity: O(1)
|
|
312
|
+
*
|
|
270
313
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
271
314
|
* @returns A boolean value is being returned.
|
|
272
315
|
*/
|
|
@@ -276,6 +319,9 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
276
319
|
* Space Complexity: O(1)
|
|
277
320
|
*/
|
|
278
321
|
/**
|
|
322
|
+
* Time Complexity: O(1)
|
|
323
|
+
* Space Complexity: O(1)
|
|
324
|
+
*
|
|
279
325
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
280
326
|
*/
|
|
281
327
|
clear(): void;
|
|
@@ -296,7 +342,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
296
342
|
indexOf(value: E): number;
|
|
297
343
|
/**
|
|
298
344
|
* Time Complexity: O(n)
|
|
299
|
-
* Space Complexity: O(
|
|
345
|
+
* Space Complexity: O(1)
|
|
300
346
|
*/
|
|
301
347
|
/**
|
|
302
348
|
* Time Complexity: O(n)
|
|
@@ -312,7 +358,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
312
358
|
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
313
359
|
/**
|
|
314
360
|
* Time Complexity: O(n)
|
|
315
|
-
* Space Complexity: O(
|
|
361
|
+
* Space Complexity: O(1)
|
|
316
362
|
*/
|
|
317
363
|
/**
|
|
318
364
|
* Time Complexity: O(n)
|
|
@@ -360,8 +406,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
360
406
|
*/
|
|
361
407
|
clone(): DoublyLinkedList<E>;
|
|
362
408
|
/**
|
|
363
|
-
* Time Complexity: O(
|
|
364
|
-
* Space Complexity: O(
|
|
409
|
+
* Time Complexity: O(n)
|
|
410
|
+
* Space Complexity: O(n)
|
|
365
411
|
*/
|
|
366
412
|
/**
|
|
367
413
|
* Time Complexity: O(n)
|
|
@@ -382,8 +428,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
382
428
|
*/
|
|
383
429
|
filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
|
|
384
430
|
/**
|
|
385
|
-
* Time Complexity: O(
|
|
386
|
-
* Space Complexity: O(
|
|
431
|
+
* Time Complexity: O(n)
|
|
432
|
+
* Space Complexity: O(n)
|
|
387
433
|
*/
|
|
388
434
|
/**
|
|
389
435
|
* Time Complexity: O(n)
|
|
@@ -429,7 +475,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
429
475
|
*/
|
|
430
476
|
pollLast(): E | undefined;
|
|
431
477
|
/**
|
|
432
|
-
* Time Complexity: O(
|
|
478
|
+
* Time Complexity: O(1)
|
|
433
479
|
* Space Complexity: O(1)
|
|
434
480
|
*/
|
|
435
481
|
/**
|
|
@@ -442,7 +488,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
442
488
|
*/
|
|
443
489
|
pollFirst(): E | undefined;
|
|
444
490
|
/**
|
|
445
|
-
* Time Complexity: O(
|
|
491
|
+
* Time Complexity: O(1)
|
|
446
492
|
* Space Complexity: O(1)
|
|
447
493
|
*/
|
|
448
494
|
/**
|