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
package/dist/cjs/hash.cjs
CHANGED
|
@@ -232,6 +232,7 @@ var HashMap = class extends IterableEntryBase {
|
|
|
232
232
|
static {
|
|
233
233
|
__name(this, "HashMap");
|
|
234
234
|
}
|
|
235
|
+
_toEntryFn;
|
|
235
236
|
/**
|
|
236
237
|
* Create a HashMap and optionally bulk-insert entries.
|
|
237
238
|
* @remarks Time O(N), Space O(N)
|
|
@@ -266,7 +267,6 @@ var HashMap = class extends IterableEntryBase {
|
|
|
266
267
|
get objMap() {
|
|
267
268
|
return this._objMap;
|
|
268
269
|
}
|
|
269
|
-
_toEntryFn;
|
|
270
270
|
/**
|
|
271
271
|
* Get the raw→entry converter function if present.
|
|
272
272
|
* @remarks Time O(1), Space O(1)
|
|
@@ -294,107 +294,30 @@ var HashMap = class extends IterableEntryBase {
|
|
|
294
294
|
return this._hashFn;
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
* @example
|
|
341
|
-
* // Check if empty
|
|
342
|
-
* const map = new HashMap();
|
|
343
|
-
* console.log(map.isEmpty()); // true;
|
|
344
|
-
*/
|
|
297
|
+
* Check whether the map is empty.
|
|
298
|
+
* @remarks Time O(1), Space O(1)
|
|
299
|
+
* @returns True if size is 0.
|
|
300
|
+
* @example
|
|
301
|
+
* // Check if empty
|
|
302
|
+
* const map = new HashMap();
|
|
303
|
+
* console.log(map.isEmpty()); // true;
|
|
304
|
+
*/
|
|
345
305
|
isEmpty() {
|
|
346
306
|
return this._size === 0;
|
|
347
307
|
}
|
|
348
308
|
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
392
|
-
* @example
|
|
393
|
-
* // Remove all entries
|
|
394
|
-
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
395
|
-
* map.clear();
|
|
396
|
-
* console.log(map.isEmpty()); // true;
|
|
397
|
-
*/
|
|
309
|
+
* Remove all entries and reset counters.
|
|
310
|
+
* @remarks Time O(N), Space O(1)
|
|
311
|
+
* @returns void
|
|
312
|
+
* @example
|
|
313
|
+
* // Remove all entries
|
|
314
|
+
* const map = new HashMap<string, number>([
|
|
315
|
+
* ['a', 1],
|
|
316
|
+
* ['b', 2]
|
|
317
|
+
* ]);
|
|
318
|
+
* map.clear();
|
|
319
|
+
* console.log(map.isEmpty()); // true;
|
|
320
|
+
*/
|
|
398
321
|
clear() {
|
|
399
322
|
this._store = {};
|
|
400
323
|
this._objMap.clear();
|
|
@@ -409,114 +332,30 @@ var HashMap = class extends IterableEntryBase {
|
|
|
409
332
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
410
333
|
}
|
|
411
334
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
* @example
|
|
502
|
-
* // basic HashMap creation and set operation
|
|
503
|
-
* // Create a simple HashMap with key-value pairs
|
|
504
|
-
* const map = new HashMap<number, string>([
|
|
505
|
-
* [1, 'one'],
|
|
506
|
-
* [2, 'two'],
|
|
507
|
-
* [3, 'three']
|
|
508
|
-
* ]);
|
|
509
|
-
*
|
|
510
|
-
* // Verify size
|
|
511
|
-
* console.log(map.size); // 3;
|
|
512
|
-
*
|
|
513
|
-
* // Set a new key-value pair
|
|
514
|
-
* map.set(4, 'four');
|
|
515
|
-
* console.log(map.size); // 4;
|
|
516
|
-
*
|
|
517
|
-
* // Verify entries
|
|
518
|
-
* console.log([...map.entries()]); // length: 4;
|
|
519
|
-
*/
|
|
335
|
+
* Insert or replace a single entry.
|
|
336
|
+
* @remarks Time O(1), Space O(1)
|
|
337
|
+
* @param key - Key.
|
|
338
|
+
* @param value - Value.
|
|
339
|
+
* @returns True when the operation succeeds.
|
|
340
|
+
* @example
|
|
341
|
+
* // basic HashMap creation and set operation
|
|
342
|
+
* // Create a simple HashMap with key-value pairs
|
|
343
|
+
* const map = new HashMap<number, string>([
|
|
344
|
+
* [1, 'one'],
|
|
345
|
+
* [2, 'two'],
|
|
346
|
+
* [3, 'three']
|
|
347
|
+
* ]);
|
|
348
|
+
*
|
|
349
|
+
* // Verify size
|
|
350
|
+
* console.log(map.size); // 3;
|
|
351
|
+
*
|
|
352
|
+
* // Set a new key-value pair
|
|
353
|
+
* map.set(4, 'four');
|
|
354
|
+
* console.log(map.size); // 4;
|
|
355
|
+
*
|
|
356
|
+
* // Verify entries
|
|
357
|
+
* console.log([...map.entries()]); // length: 4;
|
|
358
|
+
*/
|
|
520
359
|
set(key, value) {
|
|
521
360
|
if (this._isObjKey(key)) {
|
|
522
361
|
if (!this.objMap.has(key)) this._size++;
|
|
@@ -529,56 +368,20 @@ var HashMap = class extends IterableEntryBase {
|
|
|
529
368
|
return this;
|
|
530
369
|
}
|
|
531
370
|
/**
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
* @example
|
|
577
|
-
* // Add multiple entries
|
|
578
|
-
* const map = new HashMap<string, number>();
|
|
579
|
-
* map.setMany([['a', 1], ['b', 2], ['c', 3]]);
|
|
580
|
-
* console.log(map.size); // 3;
|
|
581
|
-
*/
|
|
371
|
+
* Insert many entries from an iterable.
|
|
372
|
+
* @remarks Time O(N), Space O(N)
|
|
373
|
+
* @param entryOrRawElements - Iterable of entries or raw elements to insert.
|
|
374
|
+
* @returns Array of per-entry results.
|
|
375
|
+
* @example
|
|
376
|
+
* // Add multiple entries
|
|
377
|
+
* const map = new HashMap<string, number>();
|
|
378
|
+
* map.setMany([
|
|
379
|
+
* ['a', 1],
|
|
380
|
+
* ['b', 2],
|
|
381
|
+
* ['c', 3]
|
|
382
|
+
* ]);
|
|
383
|
+
* console.log(map.size); // 3;
|
|
384
|
+
*/
|
|
582
385
|
setMany(entryOrRawElements) {
|
|
583
386
|
const results = [];
|
|
584
387
|
for (const rawEle of entryOrRawElements) {
|
|
@@ -594,193 +397,74 @@ var HashMap = class extends IterableEntryBase {
|
|
|
594
397
|
return results;
|
|
595
398
|
}
|
|
596
399
|
/**
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
* @example
|
|
644
|
-
* // HashMap get and has operations
|
|
645
|
-
* const map = new HashMap<string, number>([
|
|
646
|
-
* ['apple', 1],
|
|
647
|
-
* ['banana', 2],
|
|
648
|
-
* ['cherry', 3]
|
|
649
|
-
* ]);
|
|
650
|
-
*
|
|
651
|
-
* // Check if key exists
|
|
652
|
-
* console.log(map.has('apple')); // true;
|
|
653
|
-
* console.log(map.has('date')); // false;
|
|
654
|
-
*
|
|
655
|
-
* // Get value by key
|
|
656
|
-
* console.log(map.get('banana')); // 2;
|
|
657
|
-
* console.log(map.get('grape')); // undefined;
|
|
658
|
-
*
|
|
659
|
-
* // Get all keys and values
|
|
660
|
-
* const keys = [...map.keys()];
|
|
661
|
-
* const values = [...map.values()];
|
|
662
|
-
* console.log(keys); // contains 'apple';
|
|
663
|
-
* console.log(values); // contains 3;
|
|
664
|
-
*/
|
|
400
|
+
* Get the value for a key.
|
|
401
|
+
* @remarks Time O(1), Space O(1)
|
|
402
|
+
* @param key - Key to look up.
|
|
403
|
+
* @returns Value or undefined.
|
|
404
|
+
* @example
|
|
405
|
+
* // HashMap get and has operations
|
|
406
|
+
* const map = new HashMap<string, number>([
|
|
407
|
+
* ['apple', 1],
|
|
408
|
+
* ['banana', 2],
|
|
409
|
+
* ['cherry', 3]
|
|
410
|
+
* ]);
|
|
411
|
+
*
|
|
412
|
+
* // Check if key exists
|
|
413
|
+
* console.log(map.has('apple')); // true;
|
|
414
|
+
* console.log(map.has('date')); // false;
|
|
415
|
+
*
|
|
416
|
+
* // Get value by key
|
|
417
|
+
* console.log(map.get('banana')); // 2;
|
|
418
|
+
* console.log(map.get('grape')); // undefined;
|
|
419
|
+
*
|
|
420
|
+
* // Get all keys and values
|
|
421
|
+
* const keys = [...map.keys()];
|
|
422
|
+
* const values = [...map.values()];
|
|
423
|
+
* console.log(keys); // contains 'apple';
|
|
424
|
+
* console.log(values); // contains 3;
|
|
425
|
+
*/
|
|
665
426
|
get(key) {
|
|
666
427
|
if (this._isObjKey(key)) return this.objMap.get(key);
|
|
667
428
|
const strKey = this._getNoObjKey(key);
|
|
668
429
|
return this._store[strKey]?.value;
|
|
669
430
|
}
|
|
670
431
|
/**
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
* @example
|
|
718
|
-
* // Check key existence
|
|
719
|
-
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
720
|
-
*
|
|
721
|
-
* console.log(map.has('a')); // true;
|
|
722
|
-
* console.log(map.has('z')); // false;
|
|
723
|
-
*/
|
|
432
|
+
* Check if a key exists.
|
|
433
|
+
* @remarks Time O(1), Space O(1)
|
|
434
|
+
* @param key - Key to test.
|
|
435
|
+
* @returns True if present.
|
|
436
|
+
* @example
|
|
437
|
+
* // Check key existence
|
|
438
|
+
* const map = new HashMap<string, number>([
|
|
439
|
+
* ['a', 1],
|
|
440
|
+
* ['b', 2]
|
|
441
|
+
* ]);
|
|
442
|
+
*
|
|
443
|
+
* console.log(map.has('a')); // true;
|
|
444
|
+
* console.log(map.has('z')); // false;
|
|
445
|
+
*/
|
|
724
446
|
has(key) {
|
|
725
447
|
if (this._isObjKey(key)) return this.objMap.has(key);
|
|
726
448
|
const strKey = this._getNoObjKey(key);
|
|
727
449
|
return strKey in this.store;
|
|
728
450
|
}
|
|
729
451
|
/**
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
* @example
|
|
777
|
-
* // Remove entries by key
|
|
778
|
-
* const map = new HashMap<string, number>([['x', 10], ['y', 20], ['z', 30]]);
|
|
779
|
-
*
|
|
780
|
-
* console.log(map.delete('y')); // true;
|
|
781
|
-
* console.log(map.has('y')); // false;
|
|
782
|
-
* console.log(map.size); // 2;
|
|
783
|
-
*/
|
|
452
|
+
* Delete an entry by key.
|
|
453
|
+
* @remarks Time O(1), Space O(1)
|
|
454
|
+
* @param key - Key to delete.
|
|
455
|
+
* @returns True if the key was found and removed.
|
|
456
|
+
* @example
|
|
457
|
+
* // Remove entries by key
|
|
458
|
+
* const map = new HashMap<string, number>([
|
|
459
|
+
* ['x', 10],
|
|
460
|
+
* ['y', 20],
|
|
461
|
+
* ['z', 30]
|
|
462
|
+
* ]);
|
|
463
|
+
*
|
|
464
|
+
* console.log(map.delete('y')); // true;
|
|
465
|
+
* console.log(map.has('y')); // false;
|
|
466
|
+
* console.log(map.size); // 2;
|
|
467
|
+
*/
|
|
784
468
|
delete(key) {
|
|
785
469
|
if (this._isObjKey(key)) {
|
|
786
470
|
if (this.objMap.has(key)) this._size--;
|
|
@@ -807,117 +491,38 @@ var HashMap = class extends IterableEntryBase {
|
|
|
807
491
|
return this;
|
|
808
492
|
}
|
|
809
493
|
/**
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
* @example
|
|
854
|
-
* // Create independent copy
|
|
855
|
-
* const map = new HashMap<string, number>([['a', 1]]);
|
|
856
|
-
* const copy = map.clone();
|
|
857
|
-
* copy.set('a', 99);
|
|
858
|
-
* console.log(map.get('a')); // 1;
|
|
859
|
-
*/
|
|
494
|
+
* Deep clone this map, preserving hashing behavior.
|
|
495
|
+
* @remarks Time O(N), Space O(N)
|
|
496
|
+
* @returns A new map with the same content.
|
|
497
|
+
* @example
|
|
498
|
+
* // Create independent copy
|
|
499
|
+
* const map = new HashMap<string, number>([['a', 1]]);
|
|
500
|
+
* const copy = map.clone();
|
|
501
|
+
* copy.set('a', 99);
|
|
502
|
+
* console.log(map.get('a')); // 1;
|
|
503
|
+
*/
|
|
860
504
|
clone() {
|
|
861
505
|
const opts = { hashFn: this._hashFn, toEntryFn: this._toEntryFn };
|
|
862
506
|
return this._createLike(this, opts);
|
|
863
507
|
}
|
|
864
508
|
/**
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
* @example
|
|
914
|
-
* // Transform all values
|
|
915
|
-
* const prices = new HashMap<string, number>([['apple', 1], ['banana', 2]]);
|
|
916
|
-
*
|
|
917
|
-
* const doubled = prices.map(v => (v ?? 0) * 2);
|
|
918
|
-
* console.log(doubled.get('apple')); // 2;
|
|
919
|
-
* console.log(doubled.get('banana')); // 4;
|
|
920
|
-
*/
|
|
509
|
+
* Map values to a new map with the same keys.
|
|
510
|
+
* @remarks Time O(N), Space O(N)
|
|
511
|
+
* @template VM
|
|
512
|
+
* @param callbackfn - Mapping function (key, value, index, map) → newValue.
|
|
513
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
514
|
+
* @returns A new map with transformed values.
|
|
515
|
+
* @example
|
|
516
|
+
* // Transform all values
|
|
517
|
+
* const prices = new HashMap<string, number>([
|
|
518
|
+
* ['apple', 1],
|
|
519
|
+
* ['banana', 2]
|
|
520
|
+
* ]);
|
|
521
|
+
*
|
|
522
|
+
* const doubled = prices.map(v => (v ?? 0) * 2);
|
|
523
|
+
* console.log(doubled.get('apple')); // 2;
|
|
524
|
+
* console.log(doubled.get('banana')); // 4;
|
|
525
|
+
*/
|
|
921
526
|
map(callbackfn, thisArg) {
|
|
922
527
|
const out = this._createLike();
|
|
923
528
|
let index = 0;
|
|
@@ -925,79 +530,37 @@ var HashMap = class extends IterableEntryBase {
|
|
|
925
530
|
return out;
|
|
926
531
|
}
|
|
927
532
|
/**
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
* @example
|
|
976
|
-
* // HashMap iteration and filter operations
|
|
977
|
-
* const map = new HashMap<number, string>([
|
|
978
|
-
* [1, 'Alice'],
|
|
979
|
-
* [2, 'Bob'],
|
|
980
|
-
* [3, 'Charlie'],
|
|
981
|
-
* [4, 'Diana'],
|
|
982
|
-
* [5, 'Eve']
|
|
983
|
-
* ]);
|
|
984
|
-
*
|
|
985
|
-
* // Iterate through entries
|
|
986
|
-
* const entries: [number, string][] = [];
|
|
987
|
-
* for (const [key, value] of map) {
|
|
988
|
-
* entries.push([key, value]);
|
|
989
|
-
* }
|
|
990
|
-
* console.log(entries); // length: 5;
|
|
991
|
-
*
|
|
992
|
-
* // Filter operation (for iteration with collection methods)
|
|
993
|
-
* const filtered = [...map].filter(([key]) => key > 2);
|
|
994
|
-
* console.log(filtered.length); // 3;
|
|
995
|
-
*
|
|
996
|
-
* // Map operation
|
|
997
|
-
* const values = [...map.values()].map(v => v.length);
|
|
998
|
-
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
999
|
-
* console.log(values); // contains 7;
|
|
1000
|
-
*/
|
|
533
|
+
* Filter entries into a new map.
|
|
534
|
+
* @remarks Time O(N), Space O(N)
|
|
535
|
+
* @param predicate - Predicate (key, value, index, map) → boolean.
|
|
536
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
537
|
+
* @returns A new map containing entries that satisfied the predicate.
|
|
538
|
+
* @example
|
|
539
|
+
* // HashMap iteration and filter operations
|
|
540
|
+
* const map = new HashMap<number, string>([
|
|
541
|
+
* [1, 'Alice'],
|
|
542
|
+
* [2, 'Bob'],
|
|
543
|
+
* [3, 'Charlie'],
|
|
544
|
+
* [4, 'Diana'],
|
|
545
|
+
* [5, 'Eve']
|
|
546
|
+
* ]);
|
|
547
|
+
*
|
|
548
|
+
* // Iterate through entries
|
|
549
|
+
* const entries: [number, string][] = [];
|
|
550
|
+
* for (const [key, value] of map) {
|
|
551
|
+
* entries.push([key, value]);
|
|
552
|
+
* }
|
|
553
|
+
* console.log(entries); // length: 5;
|
|
554
|
+
*
|
|
555
|
+
* // Filter operation (for iteration with collection methods)
|
|
556
|
+
* const filtered = [...map].filter(([key]) => key > 2);
|
|
557
|
+
* console.log(filtered.length); // 3;
|
|
558
|
+
*
|
|
559
|
+
* // Map operation
|
|
560
|
+
* const values = [...map.values()].map(v => v.length);
|
|
561
|
+
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
562
|
+
* console.log(values); // contains 7;
|
|
563
|
+
*/
|
|
1001
564
|
filter(predicate, thisArg) {
|
|
1002
565
|
const out = this._createLike();
|
|
1003
566
|
let index = 0;
|
|
@@ -1117,12 +680,6 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
1117
680
|
get tail() {
|
|
1118
681
|
return this._tail;
|
|
1119
682
|
}
|
|
1120
|
-
_toEntryFn = /* @__PURE__ */ __name((rawElement) => {
|
|
1121
|
-
if (this.isEntry(rawElement)) {
|
|
1122
|
-
return rawElement;
|
|
1123
|
-
}
|
|
1124
|
-
raise(TypeError, ERR.invalidArgument("If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.", "HashMap"));
|
|
1125
|
-
}, "_toEntryFn");
|
|
1126
683
|
get toEntryFn() {
|
|
1127
684
|
return this._toEntryFn;
|
|
1128
685
|
}
|
|
@@ -1356,6 +913,18 @@ var LinkedHashMap = class extends IterableEntryBase {
|
|
|
1356
913
|
}
|
|
1357
914
|
return out;
|
|
1358
915
|
}
|
|
916
|
+
_toEntryFn = /* @__PURE__ */ __name((rawElement) => {
|
|
917
|
+
if (this.isEntry(rawElement)) {
|
|
918
|
+
return rawElement;
|
|
919
|
+
}
|
|
920
|
+
raise(
|
|
921
|
+
TypeError,
|
|
922
|
+
ERR.invalidArgument(
|
|
923
|
+
"If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.",
|
|
924
|
+
"HashMap"
|
|
925
|
+
)
|
|
926
|
+
);
|
|
927
|
+
}, "_toEntryFn");
|
|
1359
928
|
*_getIterator() {
|
|
1360
929
|
let node = this.head;
|
|
1361
930
|
while (node !== this._sentinel) {
|