data-structure-typed 2.6.1 → 2.6.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/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +72 -104
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +67 -101
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +17 -17
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +68 -96
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +41 -74
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +46 -79
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/Queue.md +54 -78
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +68 -98
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +33 -53
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +57 -124
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +45 -116
- package/docs-site-docusaurus/docs/api/classes/Trie.md +37 -61
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +1 -1
- package/src/data-structures/binary-tree/tree-multi-set.ts +15 -11
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: DoublyLinkedListNode\<E\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/linked-list/doubly-linked-list.ts:
|
|
9
|
+
Defined in: [data-structures/linked-list/doubly-linked-list.ts:16](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/linked-list/doubly-linked-list.ts#L16)
|
|
10
10
|
|
|
11
11
|
Node of a doubly linked list; stores value and prev/next links.
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ Time O(1), Space O(1)
|
|
|
32
32
|
new DoublyLinkedListNode<E>(value): DoublyLinkedListNode<E>;
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Defined in: [data-structures/linked-list/doubly-linked-list.ts:
|
|
35
|
+
Defined in: [data-structures/linked-list/doubly-linked-list.ts:23](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/linked-list/doubly-linked-list.ts#L23)
|
|
36
36
|
|
|
37
37
|
Create a node.
|
|
38
38
|
|
|
@@ -68,7 +68,7 @@ Time O(1), Space O(1)
|
|
|
68
68
|
get next(): DoublyLinkedListNode<E> | undefined;
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
Defined in: [data-structures/linked-list/doubly-linked-list.ts:
|
|
71
|
+
Defined in: [data-structures/linked-list/doubly-linked-list.ts:37](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/linked-list/doubly-linked-list.ts#L37)
|
|
72
72
|
|
|
73
73
|
Get the next node link.
|
|
74
74
|
|
|
@@ -88,7 +88,7 @@ Next node or undefined.
|
|
|
88
88
|
set next(value): void;
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
Defined in: [data-structures/linked-list/doubly-linked-list.ts:
|
|
91
|
+
Defined in: [data-structures/linked-list/doubly-linked-list.ts:47](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/linked-list/doubly-linked-list.ts#L47)
|
|
92
92
|
|
|
93
93
|
Set the next node link.
|
|
94
94
|
|
|
@@ -124,7 +124,7 @@ void
|
|
|
124
124
|
get prev(): DoublyLinkedListNode<E> | undefined;
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
Defined in: [data-structures/linked-list/doubly-linked-list.ts:
|
|
127
|
+
Defined in: [data-structures/linked-list/doubly-linked-list.ts:58](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/linked-list/doubly-linked-list.ts#L58)
|
|
128
128
|
|
|
129
129
|
Get the previous node link.
|
|
130
130
|
|
|
@@ -144,7 +144,7 @@ Previous node or undefined.
|
|
|
144
144
|
set prev(value): void;
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
Defined in: [data-structures/linked-list/doubly-linked-list.ts:
|
|
147
|
+
Defined in: [data-structures/linked-list/doubly-linked-list.ts:68](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/linked-list/doubly-linked-list.ts#L68)
|
|
148
148
|
|
|
149
149
|
Set the previous node link.
|
|
150
150
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: FibonacciHeap\<E\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
9
|
+
Defined in: [data-structures/heap/heap.ts:844](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L844)
|
|
10
10
|
|
|
11
11
|
Fibonacci heap (min-heap) optimized for fast merges and amortized operations.
|
|
12
12
|
|
|
@@ -34,7 +34,7 @@ examples will be generated by unit test
|
|
|
34
34
|
new FibonacciHeap<E>(comparator?): FibonacciHeap<E>;
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
37
|
+
Defined in: [data-structures/heap/heap.ts:853](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L853)
|
|
38
38
|
|
|
39
39
|
Create a FibonacciHeap.
|
|
40
40
|
|
|
@@ -66,7 +66,7 @@ Time O(1), Space O(1)
|
|
|
66
66
|
get min(): FibonacciHeapNode<E> | undefined;
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
69
|
+
Defined in: [data-structures/heap/heap.ts:883](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L883)
|
|
70
70
|
|
|
71
71
|
Get the current minimum node.
|
|
72
72
|
|
|
@@ -90,7 +90,7 @@ Min node or undefined.
|
|
|
90
90
|
get root(): FibonacciHeapNode<E> | undefined;
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
93
|
+
Defined in: [data-structures/heap/heap.ts:866](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L866)
|
|
94
94
|
|
|
95
95
|
Get the circular root list head.
|
|
96
96
|
|
|
@@ -112,7 +112,7 @@ Root node or undefined.
|
|
|
112
112
|
consumeLinkedList(head?): FibonacciHeapNode<E>[];
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
115
|
+
Defined in: [data-structures/heap/heap.ts:928](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L928)
|
|
116
116
|
|
|
117
117
|
Collect nodes from a circular doubly linked list starting at head.
|
|
118
118
|
|
|
@@ -142,7 +142,7 @@ Time O(K), Space O(K)
|
|
|
142
142
|
merge(heapToMerge): void;
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
145
|
+
Defined in: [data-structures/heap/heap.ts:996](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L996)
|
|
146
146
|
|
|
147
147
|
Meld another heap into this heap.
|
|
148
148
|
|
|
@@ -172,7 +172,7 @@ Time O(1), Space O(1)
|
|
|
172
172
|
mergeWithChild(parent, node): void;
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
175
|
+
Defined in: [data-structures/heap/heap.ts:949](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L949)
|
|
176
176
|
|
|
177
177
|
Insert a node into a parent's child list (circular).
|
|
178
178
|
|
|
@@ -208,7 +208,7 @@ Time O(1), Space O(1)
|
|
|
208
208
|
pop(): E | undefined;
|
|
209
209
|
```
|
|
210
210
|
|
|
211
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
211
|
+
Defined in: [data-structures/heap/heap.ts:968](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L968)
|
|
212
212
|
|
|
213
213
|
Remove and return the minimum element, consolidating the root list.
|
|
214
214
|
|
|
@@ -230,7 +230,7 @@ Time O(log N) amortized, Space O(1)
|
|
|
230
230
|
push(element): boolean;
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
233
|
+
Defined in: [data-structures/heap/heap.ts:908](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L908)
|
|
234
234
|
|
|
235
235
|
Push an element into the root list.
|
|
236
236
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: FibonacciHeapNode\<E\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/heap/heap.ts:
|
|
9
|
+
Defined in: [data-structures/heap/heap.ts:822](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/heap/heap.ts#L822)
|
|
10
10
|
|
|
11
11
|
Node container used by FibonacciHeap.
|
|
12
12
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: HashMap\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
9
|
+
Defined in: [data-structures/hash/hash-map.ts:103](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L103)
|
|
10
10
|
|
|
11
11
|
Hash-based map. Supports object keys and custom hashing; offers O(1) average set/get/has.
|
|
12
12
|
|
|
@@ -72,7 +72,11 @@ Time O(1), Space O(1)
|
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
// Aggregate values
|
|
75
|
-
const counts = new HashMap<string, number>([
|
|
75
|
+
const counts = new HashMap<string, number>([
|
|
76
|
+
['a', 5],
|
|
77
|
+
['b', 3],
|
|
78
|
+
['c', 8]
|
|
79
|
+
]);
|
|
76
80
|
|
|
77
81
|
const total = counts.reduce((sum, v) => sum + (v ?? 0), 0);
|
|
78
82
|
console.log(total); // 16;
|
|
@@ -80,7 +84,10 @@ Time O(1), Space O(1)
|
|
|
80
84
|
|
|
81
85
|
```ts
|
|
82
86
|
// Iterate over entries
|
|
83
|
-
const map = new HashMap<string, number>([
|
|
87
|
+
const map = new HashMap<string, number>([
|
|
88
|
+
['x', 1],
|
|
89
|
+
['y', 2]
|
|
90
|
+
]);
|
|
84
91
|
const keys: string[] = [];
|
|
85
92
|
|
|
86
93
|
map.forEach((v, k) => keys.push(k));
|
|
@@ -119,7 +126,7 @@ If you try to insert another entry with the same key, the new one will replace t
|
|
|
119
126
|
new HashMap<K, V, R>(entryOrRawElements?, options?): HashMap<K, V, R>;
|
|
120
127
|
```
|
|
121
128
|
|
|
122
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
129
|
+
Defined in: [data-structures/hash/hash-map.ts:113](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L113)
|
|
123
130
|
|
|
124
131
|
Create a HashMap and optionally bulk-insert entries.
|
|
125
132
|
|
|
@@ -163,7 +170,7 @@ IterableEntryBase<K, V>.constructor
|
|
|
163
170
|
get hashFn(): (key) => string;
|
|
164
171
|
```
|
|
165
172
|
|
|
166
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
173
|
+
Defined in: [data-structures/hash/hash-map.ts:172](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L172)
|
|
167
174
|
|
|
168
175
|
Get the current hash function for non-object keys.
|
|
169
176
|
|
|
@@ -187,7 +194,7 @@ Hash function.
|
|
|
187
194
|
get objMap(): Map<object, V>;
|
|
188
195
|
```
|
|
189
196
|
|
|
190
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
197
|
+
Defined in: [data-structures/hash/hash-map.ts:141](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L141)
|
|
191
198
|
|
|
192
199
|
Get the internal Map used for object/function keys.
|
|
193
200
|
|
|
@@ -211,7 +218,7 @@ Map of object→value.
|
|
|
211
218
|
get size(): number;
|
|
212
219
|
```
|
|
213
220
|
|
|
214
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
221
|
+
Defined in: [data-structures/hash/hash-map.ts:161](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L161)
|
|
215
222
|
|
|
216
223
|
Get the number of distinct keys stored.
|
|
217
224
|
|
|
@@ -239,7 +246,7 @@ Current size.
|
|
|
239
246
|
get store(): object;
|
|
240
247
|
```
|
|
241
248
|
|
|
242
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
249
|
+
Defined in: [data-structures/hash/hash-map.ts:130](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L130)
|
|
243
250
|
|
|
244
251
|
Get the internal store for non-object keys.
|
|
245
252
|
|
|
@@ -263,7 +270,7 @@ Internal record of string→{key,value}.
|
|
|
263
270
|
get toEntryFn(): ((rawElement) => [K, V]) | undefined;
|
|
264
271
|
```
|
|
265
272
|
|
|
266
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
273
|
+
Defined in: [data-structures/hash/hash-map.ts:150](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L150)
|
|
267
274
|
|
|
268
275
|
Get the raw→entry converter function if present.
|
|
269
276
|
|
|
@@ -317,7 +324,7 @@ Time O(n) to iterate, Space O(1)
|
|
|
317
324
|
clear(): void;
|
|
318
325
|
```
|
|
319
326
|
|
|
320
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
327
|
+
Defined in: [data-structures/hash/hash-map.ts:202](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L202)
|
|
321
328
|
|
|
322
329
|
Remove all entries and reset counters.
|
|
323
330
|
|
|
@@ -327,8 +334,6 @@ Remove all entries and reset counters.
|
|
|
327
334
|
|
|
328
335
|
void
|
|
329
336
|
|
|
330
|
-
*
|
|
331
|
-
|
|
332
337
|
#### Remarks
|
|
333
338
|
|
|
334
339
|
Time O(N), Space O(1)
|
|
@@ -337,7 +342,10 @@ Time O(N), Space O(1)
|
|
|
337
342
|
|
|
338
343
|
```ts
|
|
339
344
|
// Remove all entries
|
|
340
|
-
const map = new HashMap<string, number>([
|
|
345
|
+
const map = new HashMap<string, number>([
|
|
346
|
+
['a', 1],
|
|
347
|
+
['b', 2]
|
|
348
|
+
]);
|
|
341
349
|
map.clear();
|
|
342
350
|
console.log(map.isEmpty()); // true;
|
|
343
351
|
```
|
|
@@ -354,7 +362,7 @@ Time O(N), Space O(1)
|
|
|
354
362
|
clone(): this;
|
|
355
363
|
```
|
|
356
364
|
|
|
357
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
365
|
+
Defined in: [data-structures/hash/hash-map.ts:393](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L393)
|
|
358
366
|
|
|
359
367
|
Deep clone this map, preserving hashing behavior.
|
|
360
368
|
|
|
@@ -364,8 +372,6 @@ Deep clone this map, preserving hashing behavior.
|
|
|
364
372
|
|
|
365
373
|
A new map with the same content.
|
|
366
374
|
|
|
367
|
-
*
|
|
368
|
-
|
|
369
375
|
#### Remarks
|
|
370
376
|
|
|
371
377
|
Time O(N), Space O(N)
|
|
@@ -392,7 +398,7 @@ Time O(N), Space O(N)
|
|
|
392
398
|
delete(key): boolean;
|
|
393
399
|
```
|
|
394
400
|
|
|
395
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
401
|
+
Defined in: [data-structures/hash/hash-map.ts:355](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L355)
|
|
396
402
|
|
|
397
403
|
Delete an entry by key.
|
|
398
404
|
|
|
@@ -410,8 +416,6 @@ Key to delete.
|
|
|
410
416
|
|
|
411
417
|
True if the key was found and removed.
|
|
412
418
|
|
|
413
|
-
*
|
|
414
|
-
|
|
415
419
|
#### Remarks
|
|
416
420
|
|
|
417
421
|
Time O(1), Space O(1)
|
|
@@ -420,7 +424,11 @@ Time O(1), Space O(1)
|
|
|
420
424
|
|
|
421
425
|
```ts
|
|
422
426
|
// Remove entries by key
|
|
423
|
-
const map = new HashMap<string, number>([
|
|
427
|
+
const map = new HashMap<string, number>([
|
|
428
|
+
['x', 10],
|
|
429
|
+
['y', 20],
|
|
430
|
+
['z', 30]
|
|
431
|
+
]);
|
|
424
432
|
|
|
425
433
|
console.log(map.delete('y')); // true;
|
|
426
434
|
console.log(map.has('y')); // false;
|
|
@@ -501,7 +509,7 @@ Time O(n), Space O(1)
|
|
|
501
509
|
filter(predicate, thisArg?): this;
|
|
502
510
|
```
|
|
503
511
|
|
|
504
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
512
|
+
Defined in: [data-structures/hash/hash-map.ts:455](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L455)
|
|
505
513
|
|
|
506
514
|
Filter entries into a new map.
|
|
507
515
|
|
|
@@ -525,8 +533,6 @@ Value for `this` inside the predicate.
|
|
|
525
533
|
|
|
526
534
|
A new map containing entries that satisfied the predicate.
|
|
527
535
|
|
|
528
|
-
*
|
|
529
|
-
|
|
530
536
|
#### Remarks
|
|
531
537
|
|
|
532
538
|
Time O(N), Space O(N)
|
|
@@ -650,7 +656,7 @@ Time O(n), Space O(1)
|
|
|
650
656
|
get(key): V | undefined;
|
|
651
657
|
```
|
|
652
658
|
|
|
653
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
659
|
+
Defined in: [data-structures/hash/hash-map.ts:311](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L311)
|
|
654
660
|
|
|
655
661
|
Get the value for a key.
|
|
656
662
|
|
|
@@ -668,8 +674,6 @@ Key to look up.
|
|
|
668
674
|
|
|
669
675
|
Value or undefined.
|
|
670
676
|
|
|
671
|
-
*
|
|
672
|
-
|
|
673
677
|
#### Remarks
|
|
674
678
|
|
|
675
679
|
Time O(1), Space O(1)
|
|
@@ -711,7 +715,7 @@ Time O(1), Space O(1)
|
|
|
711
715
|
has(key): boolean;
|
|
712
716
|
```
|
|
713
717
|
|
|
714
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
718
|
+
Defined in: [data-structures/hash/hash-map.ts:332](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L332)
|
|
715
719
|
|
|
716
720
|
Check if a key exists.
|
|
717
721
|
|
|
@@ -729,8 +733,6 @@ Key to test.
|
|
|
729
733
|
|
|
730
734
|
True if present.
|
|
731
735
|
|
|
732
|
-
*
|
|
733
|
-
|
|
734
736
|
#### Remarks
|
|
735
737
|
|
|
736
738
|
Time O(1), Space O(1)
|
|
@@ -739,7 +741,10 @@ Time O(1), Space O(1)
|
|
|
739
741
|
|
|
740
742
|
```ts
|
|
741
743
|
// Check key existence
|
|
742
|
-
const map = new HashMap<string, number>([
|
|
744
|
+
const map = new HashMap<string, number>([
|
|
745
|
+
['a', 1],
|
|
746
|
+
['b', 2]
|
|
747
|
+
]);
|
|
743
748
|
|
|
744
749
|
console.log(map.has('a')); // true;
|
|
745
750
|
console.log(map.has('z')); // false;
|
|
@@ -791,7 +796,7 @@ Time O(n), Space O(1)
|
|
|
791
796
|
isEmpty(): boolean;
|
|
792
797
|
```
|
|
793
798
|
|
|
794
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
799
|
+
Defined in: [data-structures/hash/hash-map.ts:185](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L185)
|
|
795
800
|
|
|
796
801
|
Check whether the map is empty.
|
|
797
802
|
|
|
@@ -801,8 +806,6 @@ Check whether the map is empty.
|
|
|
801
806
|
|
|
802
807
|
True if size is 0.
|
|
803
808
|
|
|
804
|
-
*
|
|
805
|
-
|
|
806
809
|
#### Remarks
|
|
807
810
|
|
|
808
811
|
Time O(1), Space O(1)
|
|
@@ -827,7 +830,7 @@ Time O(1), Space O(1)
|
|
|
827
830
|
isEntry(rawElement): rawElement is [K, V];
|
|
828
831
|
```
|
|
829
832
|
|
|
830
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
833
|
+
Defined in: [data-structures/hash/hash-map.ts:213](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L213)
|
|
831
834
|
|
|
832
835
|
Type guard: check if a raw value is a [key, value] entry.
|
|
833
836
|
|
|
@@ -881,7 +884,7 @@ Time O(n), Space O(1)
|
|
|
881
884
|
map<VM>(callbackfn, thisArg?): HashMap<K, VM>;
|
|
882
885
|
```
|
|
883
886
|
|
|
884
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
887
|
+
Defined in: [data-structures/hash/hash-map.ts:416](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L416)
|
|
885
888
|
|
|
886
889
|
Map values to a new map with the same keys.
|
|
887
890
|
|
|
@@ -911,8 +914,6 @@ Value for `this` inside the callback.
|
|
|
911
914
|
|
|
912
915
|
A new map with transformed values.
|
|
913
916
|
|
|
914
|
-
*
|
|
915
|
-
|
|
916
917
|
#### Remarks
|
|
917
918
|
|
|
918
919
|
Time O(N), Space O(N)
|
|
@@ -921,7 +922,10 @@ Time O(N), Space O(N)
|
|
|
921
922
|
|
|
922
923
|
```ts
|
|
923
924
|
// Transform all values
|
|
924
|
-
const prices = new HashMap<string, number>([
|
|
925
|
+
const prices = new HashMap<string, number>([
|
|
926
|
+
['apple', 1],
|
|
927
|
+
['banana', 2]
|
|
928
|
+
]);
|
|
925
929
|
|
|
926
930
|
const doubled = prices.map(v => (v ?? 0) * 2);
|
|
927
931
|
console.log(doubled.get('apple')); // 2;
|
|
@@ -1010,7 +1014,7 @@ Time O(n), Space O(1)
|
|
|
1010
1014
|
set(key, value): this;
|
|
1011
1015
|
```
|
|
1012
1016
|
|
|
1013
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
1017
|
+
Defined in: [data-structures/hash/hash-map.ts:242](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L242)
|
|
1014
1018
|
|
|
1015
1019
|
Insert or replace a single entry.
|
|
1016
1020
|
|
|
@@ -1034,8 +1038,6 @@ Value.
|
|
|
1034
1038
|
|
|
1035
1039
|
True when the operation succeeds.
|
|
1036
1040
|
|
|
1037
|
-
*
|
|
1038
|
-
|
|
1039
1041
|
#### Remarks
|
|
1040
1042
|
|
|
1041
1043
|
Time O(1), Space O(1)
|
|
@@ -1070,7 +1072,7 @@ Time O(1), Space O(1)
|
|
|
1070
1072
|
setHashFn(fn): this;
|
|
1071
1073
|
```
|
|
1072
1074
|
|
|
1073
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
1075
|
+
Defined in: [data-structures/hash/hash-map.ts:375](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L375)
|
|
1074
1076
|
|
|
1075
1077
|
Replace the hash function and rehash the non-object store.
|
|
1076
1078
|
|
|
@@ -1100,7 +1102,7 @@ Time O(N), Space O(N)
|
|
|
1100
1102
|
setMany(entryOrRawElements): boolean[];
|
|
1101
1103
|
```
|
|
1102
1104
|
|
|
1103
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
1105
|
+
Defined in: [data-structures/hash/hash-map.ts:269](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L269)
|
|
1104
1106
|
|
|
1105
1107
|
Insert many entries from an iterable.
|
|
1106
1108
|
|
|
@@ -1118,8 +1120,6 @@ Iterable of entries or raw elements to insert.
|
|
|
1118
1120
|
|
|
1119
1121
|
Array of per-entry results.
|
|
1120
1122
|
|
|
1121
|
-
*
|
|
1122
|
-
|
|
1123
1123
|
#### Remarks
|
|
1124
1124
|
|
|
1125
1125
|
Time O(N), Space O(N)
|
|
@@ -1129,7 +1129,11 @@ Time O(N), Space O(N)
|
|
|
1129
1129
|
```ts
|
|
1130
1130
|
// Add multiple entries
|
|
1131
1131
|
const map = new HashMap<string, number>();
|
|
1132
|
-
map.setMany([
|
|
1132
|
+
map.setMany([
|
|
1133
|
+
['a', 1],
|
|
1134
|
+
['b', 2],
|
|
1135
|
+
['c', 3]
|
|
1136
|
+
]);
|
|
1133
1137
|
console.log(map.size); // 3;
|
|
1134
1138
|
```
|
|
1135
1139
|
|
|
@@ -1262,7 +1266,7 @@ Time O(n), Space O(1)
|
|
|
1262
1266
|
protected _createLike<TK, TV, TR>(entries?, options?): this;
|
|
1263
1267
|
```
|
|
1264
1268
|
|
|
1265
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
1269
|
+
Defined in: [data-structures/hash/hash-map.ts:472](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L472)
|
|
1266
1270
|
|
|
1267
1271
|
(Protected) Create a like-kind instance and seed it from an iterable.
|
|
1268
1272
|
|
|
@@ -1312,7 +1316,7 @@ Time O(N), Space O(N)
|
|
|
1312
1316
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
1313
1317
|
```
|
|
1314
1318
|
|
|
1315
|
-
Defined in: [data-structures/hash/hash-map.ts:
|
|
1319
|
+
Defined in: [data-structures/hash/hash-map.ts:489](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/hash/hash-map.ts#L489)
|
|
1316
1320
|
|
|
1317
1321
|
Underlying iterator for the default iteration protocol.
|
|
1318
1322
|
|