max-priority-queue-typed 2.4.5 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/dist/cjs/index.cjs +694 -119
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +693 -118
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +694 -119
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +693 -118
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
- package/dist/types/data-structures/heap/heap.d.ts +581 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +593 -71
- package/dist/types/data-structures/queue/queue.d.ts +463 -42
- package/dist/types/data-structures/stack/stack.d.ts +384 -32
- package/dist/types/data-structures/trie/trie.d.ts +470 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/max-priority-queue-typed.js +691 -116
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -19,83 +19,6 @@ import { IterableEntryBase } from '../base';
|
|
|
19
19
|
* If you try to insert another entry with the same key, the new one will replace the old entry.
|
|
20
20
|
* 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
|
|
21
21
|
* @example
|
|
22
|
-
* // should maintain insertion order
|
|
23
|
-
* const linkedHashMap = new LinkedHashMap<number, string>();
|
|
24
|
-
* linkedHashMap.set(1, 'A');
|
|
25
|
-
* linkedHashMap.set(2, 'B');
|
|
26
|
-
* linkedHashMap.set(3, 'C');
|
|
27
|
-
*
|
|
28
|
-
* const result = Array.from(linkedHashMap);
|
|
29
|
-
* console.log(result); // [
|
|
30
|
-
* // [1, 'A'],
|
|
31
|
-
* // [2, 'B'],
|
|
32
|
-
* // [3, 'C']
|
|
33
|
-
* // ];
|
|
34
|
-
* @example
|
|
35
|
-
* // basic HashMap creation and set operation
|
|
36
|
-
* // Create a simple HashMap with key-value pairs
|
|
37
|
-
* const map = new HashMap<number, string>([
|
|
38
|
-
* [1, 'one'],
|
|
39
|
-
* [2, 'two'],
|
|
40
|
-
* [3, 'three']
|
|
41
|
-
* ]);
|
|
42
|
-
*
|
|
43
|
-
* // Verify size
|
|
44
|
-
* console.log(map.size); // 3;
|
|
45
|
-
*
|
|
46
|
-
* // Set a new key-value pair
|
|
47
|
-
* map.set(4, 'four');
|
|
48
|
-
* console.log(map.size); // 4;
|
|
49
|
-
*
|
|
50
|
-
* // Verify entries
|
|
51
|
-
* console.log([...map.entries()]); // length: 4;
|
|
52
|
-
* @example
|
|
53
|
-
* // HashMap get and has operations
|
|
54
|
-
* const map = new HashMap<string, number>([
|
|
55
|
-
* ['apple', 1],
|
|
56
|
-
* ['banana', 2],
|
|
57
|
-
* ['cherry', 3]
|
|
58
|
-
* ]);
|
|
59
|
-
*
|
|
60
|
-
* // Check if key exists
|
|
61
|
-
* console.log(map.has('apple')); // true;
|
|
62
|
-
* console.log(map.has('date')); // false;
|
|
63
|
-
*
|
|
64
|
-
* // Get value by key
|
|
65
|
-
* console.log(map.get('banana')); // 2;
|
|
66
|
-
* console.log(map.get('grape')); // undefined;
|
|
67
|
-
*
|
|
68
|
-
* // Get all keys and values
|
|
69
|
-
* const keys = [...map.keys()];
|
|
70
|
-
* const values = [...map.values()];
|
|
71
|
-
* console.log(keys); // contains 'apple';
|
|
72
|
-
* console.log(values); // contains 3;
|
|
73
|
-
* @example
|
|
74
|
-
* // HashMap iteration and filter operations
|
|
75
|
-
* const map = new HashMap<number, string>([
|
|
76
|
-
* [1, 'Alice'],
|
|
77
|
-
* [2, 'Bob'],
|
|
78
|
-
* [3, 'Charlie'],
|
|
79
|
-
* [4, 'Diana'],
|
|
80
|
-
* [5, 'Eve']
|
|
81
|
-
* ]);
|
|
82
|
-
*
|
|
83
|
-
* // Iterate through entries
|
|
84
|
-
* const entries: [number, string][] = [];
|
|
85
|
-
* for (const [key, value] of map) {
|
|
86
|
-
* entries.push([key, value]);
|
|
87
|
-
* }
|
|
88
|
-
* console.log(entries); // length: 5;
|
|
89
|
-
*
|
|
90
|
-
* // Filter operation (for iteration with collection methods)
|
|
91
|
-
* const filtered = [...map].filter(([key]) => key > 2);
|
|
92
|
-
* console.log(filtered.length); // 3;
|
|
93
|
-
*
|
|
94
|
-
* // Map operation
|
|
95
|
-
* const values = [...map.values()].map(v => v.length);
|
|
96
|
-
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
97
|
-
* console.log(values); // contains 7;
|
|
98
|
-
* @example
|
|
99
22
|
* // HashMap for user session caching O(1) performance
|
|
100
23
|
* interface UserSession {
|
|
101
24
|
* userId: number;
|
|
@@ -147,6 +70,19 @@ import { IterableEntryBase } from '../base';
|
|
|
147
70
|
* // Get all active sessions
|
|
148
71
|
* const activeCount = [...sessionCache.values()].length;
|
|
149
72
|
* console.log(activeCount); // 2;
|
|
73
|
+
* @example
|
|
74
|
+
* // Aggregate values
|
|
75
|
+
* const counts = new HashMap<string, number>([['a', 5], ['b', 3], ['c', 8]]);
|
|
76
|
+
*
|
|
77
|
+
* const total = counts.reduce((sum, v) => sum + (v ?? 0), 0);
|
|
78
|
+
* console.log(total); // 16;
|
|
79
|
+
* @example
|
|
80
|
+
* // Iterate over entries
|
|
81
|
+
* const map = new HashMap<string, number>([['x', 1], ['y', 2]]);
|
|
82
|
+
* const keys: string[] = [];
|
|
83
|
+
*
|
|
84
|
+
* map.forEach((v, k) => keys.push(k));
|
|
85
|
+
* console.log(keys.sort()); // ['x', 'y'];
|
|
150
86
|
*/
|
|
151
87
|
export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
|
|
152
88
|
/**
|
|
@@ -200,12 +136,81 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
200
136
|
* Check whether the map is empty.
|
|
201
137
|
* @remarks Time O(1), Space O(1)
|
|
202
138
|
* @returns True if size is 0.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
* @example
|
|
170
|
+
* // Check if empty
|
|
171
|
+
* const map = new HashMap();
|
|
172
|
+
* console.log(map.isEmpty()); // true;
|
|
203
173
|
*/
|
|
204
174
|
isEmpty(): boolean;
|
|
205
175
|
/**
|
|
206
176
|
* Remove all entries and reset counters.
|
|
207
177
|
* @remarks Time O(N), Space O(1)
|
|
208
178
|
* @returns void
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
* @example
|
|
210
|
+
* // Remove all entries
|
|
211
|
+
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
212
|
+
* map.clear();
|
|
213
|
+
* console.log(map.isEmpty()); // true;
|
|
209
214
|
*/
|
|
210
215
|
clear(): void;
|
|
211
216
|
/**
|
|
@@ -213,13 +218,95 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
213
218
|
* @remarks Time O(1), Space O(1)
|
|
214
219
|
* @returns True if the value is a 2-tuple.
|
|
215
220
|
*/
|
|
216
|
-
isEntry(rawElement:
|
|
221
|
+
isEntry(rawElement: unknown): rawElement is [K, V];
|
|
217
222
|
/**
|
|
218
223
|
* Insert or replace a single entry.
|
|
219
224
|
* @remarks Time O(1), Space O(1)
|
|
220
225
|
* @param key - Key.
|
|
221
226
|
* @param value - Value.
|
|
222
227
|
* @returns True when the operation succeeds.
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
* @example
|
|
293
|
+
* // basic HashMap creation and set operation
|
|
294
|
+
* // Create a simple HashMap with key-value pairs
|
|
295
|
+
* const map = new HashMap<number, string>([
|
|
296
|
+
* [1, 'one'],
|
|
297
|
+
* [2, 'two'],
|
|
298
|
+
* [3, 'three']
|
|
299
|
+
* ]);
|
|
300
|
+
*
|
|
301
|
+
* // Verify size
|
|
302
|
+
* console.log(map.size); // 3;
|
|
303
|
+
*
|
|
304
|
+
* // Set a new key-value pair
|
|
305
|
+
* map.set(4, 'four');
|
|
306
|
+
* console.log(map.size); // 4;
|
|
307
|
+
*
|
|
308
|
+
* // Verify entries
|
|
309
|
+
* console.log([...map.entries()]); // length: 4;
|
|
223
310
|
*/
|
|
224
311
|
set(key: K, value: V): boolean;
|
|
225
312
|
/**
|
|
@@ -227,6 +314,41 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
227
314
|
* @remarks Time O(N), Space O(N)
|
|
228
315
|
* @param entryOrRawElements - Iterable of entries or raw elements to insert.
|
|
229
316
|
* @returns Array of per-entry results.
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
* @example
|
|
348
|
+
* // Add multiple entries
|
|
349
|
+
* const map = new HashMap<string, number>();
|
|
350
|
+
* map.setMany([['a', 1], ['b', 2], ['c', 3]]);
|
|
351
|
+
* console.log(map.size); // 3;
|
|
230
352
|
*/
|
|
231
353
|
setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
|
|
232
354
|
/**
|
|
@@ -234,6 +356,59 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
234
356
|
* @remarks Time O(1), Space O(1)
|
|
235
357
|
* @param key - Key to look up.
|
|
236
358
|
* @returns Value or undefined.
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
* @example
|
|
392
|
+
* // HashMap get and has operations
|
|
393
|
+
* const map = new HashMap<string, number>([
|
|
394
|
+
* ['apple', 1],
|
|
395
|
+
* ['banana', 2],
|
|
396
|
+
* ['cherry', 3]
|
|
397
|
+
* ]);
|
|
398
|
+
*
|
|
399
|
+
* // Check if key exists
|
|
400
|
+
* console.log(map.has('apple')); // true;
|
|
401
|
+
* console.log(map.has('date')); // false;
|
|
402
|
+
*
|
|
403
|
+
* // Get value by key
|
|
404
|
+
* console.log(map.get('banana')); // 2;
|
|
405
|
+
* console.log(map.get('grape')); // undefined;
|
|
406
|
+
*
|
|
407
|
+
* // Get all keys and values
|
|
408
|
+
* const keys = [...map.keys()];
|
|
409
|
+
* const values = [...map.values()];
|
|
410
|
+
* console.log(keys); // contains 'apple';
|
|
411
|
+
* console.log(values); // contains 3;
|
|
237
412
|
*/
|
|
238
413
|
get(key: K): V | undefined;
|
|
239
414
|
/**
|
|
@@ -241,6 +416,44 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
241
416
|
* @remarks Time O(1), Space O(1)
|
|
242
417
|
* @param key - Key to test.
|
|
243
418
|
* @returns True if present.
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
* @example
|
|
452
|
+
* // Check key existence
|
|
453
|
+
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
454
|
+
*
|
|
455
|
+
* console.log(map.has('a')); // true;
|
|
456
|
+
* console.log(map.has('z')); // false;
|
|
244
457
|
*/
|
|
245
458
|
has(key: K): boolean;
|
|
246
459
|
/**
|
|
@@ -248,6 +461,45 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
248
461
|
* @remarks Time O(1), Space O(1)
|
|
249
462
|
* @param key - Key to delete.
|
|
250
463
|
* @returns True if the key was found and removed.
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
* @example
|
|
497
|
+
* // Remove entries by key
|
|
498
|
+
* const map = new HashMap<string, number>([['x', 10], ['y', 20], ['z', 30]]);
|
|
499
|
+
*
|
|
500
|
+
* console.log(map.delete('y')); // true;
|
|
501
|
+
* console.log(map.has('y')); // false;
|
|
502
|
+
* console.log(map.size); // 2;
|
|
251
503
|
*/
|
|
252
504
|
delete(key: K): boolean;
|
|
253
505
|
/**
|
|
@@ -261,6 +513,42 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
261
513
|
* Deep clone this map, preserving hashing behavior.
|
|
262
514
|
* @remarks Time O(N), Space O(N)
|
|
263
515
|
* @returns A new map with the same content.
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
* @example
|
|
547
|
+
* // Create independent copy
|
|
548
|
+
* const map = new HashMap<string, number>([['a', 1]]);
|
|
549
|
+
* const copy = map.clone();
|
|
550
|
+
* copy.set('a', 99);
|
|
551
|
+
* console.log(map.get('a')); // 1;
|
|
264
552
|
*/
|
|
265
553
|
clone(): this;
|
|
266
554
|
/**
|
|
@@ -270,16 +558,112 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
270
558
|
* @param callbackfn - Mapping function (key, value, index, map) → newValue.
|
|
271
559
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
272
560
|
* @returns A new map with transformed values.
|
|
273
|
-
|
|
274
|
-
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
* @example
|
|
594
|
+
* // Transform all values
|
|
595
|
+
* const prices = new HashMap<string, number>([['apple', 1], ['banana', 2]]);
|
|
596
|
+
*
|
|
597
|
+
* const doubled = prices.map(v => (v ?? 0) * 2);
|
|
598
|
+
* console.log(doubled.get('apple')); // 2;
|
|
599
|
+
* console.log(doubled.get('banana')); // 4;
|
|
600
|
+
*/
|
|
601
|
+
map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: unknown): HashMap<K, VM>;
|
|
275
602
|
/**
|
|
276
603
|
* Filter entries into a new map.
|
|
277
604
|
* @remarks Time O(N), Space O(N)
|
|
278
605
|
* @param predicate - Predicate (key, value, index, map) → boolean.
|
|
279
606
|
* @param [thisArg] - Value for `this` inside the predicate.
|
|
280
607
|
* @returns A new map containing entries that satisfied the predicate.
|
|
281
|
-
|
|
282
|
-
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
* @example
|
|
641
|
+
* // HashMap iteration and filter operations
|
|
642
|
+
* const map = new HashMap<number, string>([
|
|
643
|
+
* [1, 'Alice'],
|
|
644
|
+
* [2, 'Bob'],
|
|
645
|
+
* [3, 'Charlie'],
|
|
646
|
+
* [4, 'Diana'],
|
|
647
|
+
* [5, 'Eve']
|
|
648
|
+
* ]);
|
|
649
|
+
*
|
|
650
|
+
* // Iterate through entries
|
|
651
|
+
* const entries: [number, string][] = [];
|
|
652
|
+
* for (const [key, value] of map) {
|
|
653
|
+
* entries.push([key, value]);
|
|
654
|
+
* }
|
|
655
|
+
* console.log(entries); // length: 5;
|
|
656
|
+
*
|
|
657
|
+
* // Filter operation (for iteration with collection methods)
|
|
658
|
+
* const filtered = [...map].filter(([key]) => key > 2);
|
|
659
|
+
* console.log(filtered.length); // 3;
|
|
660
|
+
*
|
|
661
|
+
* // Map operation
|
|
662
|
+
* const values = [...map.values()].map(v => v.length);
|
|
663
|
+
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
664
|
+
* console.log(values); // contains 7;
|
|
665
|
+
*/
|
|
666
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): any;
|
|
283
667
|
/**
|
|
284
668
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
285
669
|
* @remarks Time O(N), Space O(N)
|
|
@@ -290,10 +674,10 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
290
674
|
* @param [options] - Options forwarded to the constructor.
|
|
291
675
|
* @returns A like-kind map instance.
|
|
292
676
|
*/
|
|
293
|
-
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?:
|
|
677
|
+
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?: Record<string, unknown>): this;
|
|
294
678
|
protected _rehashNoObj(): void;
|
|
295
679
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
296
|
-
protected _isObjKey(key:
|
|
680
|
+
protected _isObjKey(key: unknown): key is object | ((...args: unknown[]) => unknown);
|
|
297
681
|
protected _getNoObjKey(key: K): string;
|
|
298
682
|
}
|
|
299
683
|
/**
|
|
@@ -408,10 +792,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
408
792
|
*/
|
|
409
793
|
deleteAt(index: number): boolean;
|
|
410
794
|
isEmpty(): boolean;
|
|
411
|
-
isEntry(rawElement:
|
|
795
|
+
isEntry(rawElement: unknown): rawElement is [K, V];
|
|
412
796
|
clear(): void;
|
|
413
|
-
clone():
|
|
414
|
-
filter(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
797
|
+
clone(): this;
|
|
798
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): this;
|
|
415
799
|
/**
|
|
416
800
|
* Map each entry to a new [key, value] pair and preserve order.
|
|
417
801
|
* @remarks Time O(N), Space O(N)
|
|
@@ -421,8 +805,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
421
805
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
422
806
|
* @returns A new map of the same class with transformed entries.
|
|
423
807
|
*/
|
|
424
|
-
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?:
|
|
808
|
+
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: unknown): LinkedHashMap<MK, MV>;
|
|
425
809
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
426
810
|
protected _deleteNode(node: HashMapLinkedNode<K, V | undefined>): boolean;
|
|
427
|
-
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?:
|
|
811
|
+
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?: Record<string, unknown>): this;
|
|
428
812
|
}
|