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-legacy/hash.cjs
CHANGED
|
@@ -239,9 +239,9 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
239
239
|
*/
|
|
240
240
|
constructor(entryOrRawElements = [], options) {
|
|
241
241
|
super();
|
|
242
|
+
__publicField(this, "_toEntryFn");
|
|
242
243
|
__publicField(this, "_store", {});
|
|
243
244
|
__publicField(this, "_objMap", /* @__PURE__ */ new Map());
|
|
244
|
-
__publicField(this, "_toEntryFn");
|
|
245
245
|
__publicField(this, "_size", 0);
|
|
246
246
|
__publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
|
|
247
247
|
if (options) {
|
|
@@ -292,107 +292,30 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
292
292
|
return this._hashFn;
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
|
-
|
|
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
|
-
* @example
|
|
339
|
-
* // Check if empty
|
|
340
|
-
* const map = new HashMap();
|
|
341
|
-
* console.log(map.isEmpty()); // true;
|
|
342
|
-
*/
|
|
295
|
+
* Check whether the map is empty.
|
|
296
|
+
* @remarks Time O(1), Space O(1)
|
|
297
|
+
* @returns True if size is 0.
|
|
298
|
+
* @example
|
|
299
|
+
* // Check if empty
|
|
300
|
+
* const map = new HashMap();
|
|
301
|
+
* console.log(map.isEmpty()); // true;
|
|
302
|
+
*/
|
|
343
303
|
isEmpty() {
|
|
344
304
|
return this._size === 0;
|
|
345
305
|
}
|
|
346
306
|
/**
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
* @example
|
|
391
|
-
* // Remove all entries
|
|
392
|
-
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
393
|
-
* map.clear();
|
|
394
|
-
* console.log(map.isEmpty()); // true;
|
|
395
|
-
*/
|
|
307
|
+
* Remove all entries and reset counters.
|
|
308
|
+
* @remarks Time O(N), Space O(1)
|
|
309
|
+
* @returns void
|
|
310
|
+
* @example
|
|
311
|
+
* // Remove all entries
|
|
312
|
+
* const map = new HashMap<string, number>([
|
|
313
|
+
* ['a', 1],
|
|
314
|
+
* ['b', 2]
|
|
315
|
+
* ]);
|
|
316
|
+
* map.clear();
|
|
317
|
+
* console.log(map.isEmpty()); // true;
|
|
318
|
+
*/
|
|
396
319
|
clear() {
|
|
397
320
|
this._store = {};
|
|
398
321
|
this._objMap.clear();
|
|
@@ -407,114 +330,30 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
407
330
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
408
331
|
}
|
|
409
332
|
/**
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
* @example
|
|
500
|
-
* // basic HashMap creation and set operation
|
|
501
|
-
* // Create a simple HashMap with key-value pairs
|
|
502
|
-
* const map = new HashMap<number, string>([
|
|
503
|
-
* [1, 'one'],
|
|
504
|
-
* [2, 'two'],
|
|
505
|
-
* [3, 'three']
|
|
506
|
-
* ]);
|
|
507
|
-
*
|
|
508
|
-
* // Verify size
|
|
509
|
-
* console.log(map.size); // 3;
|
|
510
|
-
*
|
|
511
|
-
* // Set a new key-value pair
|
|
512
|
-
* map.set(4, 'four');
|
|
513
|
-
* console.log(map.size); // 4;
|
|
514
|
-
*
|
|
515
|
-
* // Verify entries
|
|
516
|
-
* console.log([...map.entries()]); // length: 4;
|
|
517
|
-
*/
|
|
333
|
+
* Insert or replace a single entry.
|
|
334
|
+
* @remarks Time O(1), Space O(1)
|
|
335
|
+
* @param key - Key.
|
|
336
|
+
* @param value - Value.
|
|
337
|
+
* @returns True when the operation succeeds.
|
|
338
|
+
* @example
|
|
339
|
+
* // basic HashMap creation and set operation
|
|
340
|
+
* // Create a simple HashMap with key-value pairs
|
|
341
|
+
* const map = new HashMap<number, string>([
|
|
342
|
+
* [1, 'one'],
|
|
343
|
+
* [2, 'two'],
|
|
344
|
+
* [3, 'three']
|
|
345
|
+
* ]);
|
|
346
|
+
*
|
|
347
|
+
* // Verify size
|
|
348
|
+
* console.log(map.size); // 3;
|
|
349
|
+
*
|
|
350
|
+
* // Set a new key-value pair
|
|
351
|
+
* map.set(4, 'four');
|
|
352
|
+
* console.log(map.size); // 4;
|
|
353
|
+
*
|
|
354
|
+
* // Verify entries
|
|
355
|
+
* console.log([...map.entries()]); // length: 4;
|
|
356
|
+
*/
|
|
518
357
|
set(key, value) {
|
|
519
358
|
if (this._isObjKey(key)) {
|
|
520
359
|
if (!this.objMap.has(key)) this._size++;
|
|
@@ -527,56 +366,20 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
527
366
|
return this;
|
|
528
367
|
}
|
|
529
368
|
/**
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
* @example
|
|
575
|
-
* // Add multiple entries
|
|
576
|
-
* const map = new HashMap<string, number>();
|
|
577
|
-
* map.setMany([['a', 1], ['b', 2], ['c', 3]]);
|
|
578
|
-
* console.log(map.size); // 3;
|
|
579
|
-
*/
|
|
369
|
+
* Insert many entries from an iterable.
|
|
370
|
+
* @remarks Time O(N), Space O(N)
|
|
371
|
+
* @param entryOrRawElements - Iterable of entries or raw elements to insert.
|
|
372
|
+
* @returns Array of per-entry results.
|
|
373
|
+
* @example
|
|
374
|
+
* // Add multiple entries
|
|
375
|
+
* const map = new HashMap<string, number>();
|
|
376
|
+
* map.setMany([
|
|
377
|
+
* ['a', 1],
|
|
378
|
+
* ['b', 2],
|
|
379
|
+
* ['c', 3]
|
|
380
|
+
* ]);
|
|
381
|
+
* console.log(map.size); // 3;
|
|
382
|
+
*/
|
|
580
383
|
setMany(entryOrRawElements) {
|
|
581
384
|
const results = [];
|
|
582
385
|
for (const rawEle of entryOrRawElements) {
|
|
@@ -592,74 +395,32 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
592
395
|
return results;
|
|
593
396
|
}
|
|
594
397
|
/**
|
|
595
|
-
|
|
596
|
-
|
|
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
|
-
* @example
|
|
642
|
-
* // HashMap get and has operations
|
|
643
|
-
* const map = new HashMap<string, number>([
|
|
644
|
-
* ['apple', 1],
|
|
645
|
-
* ['banana', 2],
|
|
646
|
-
* ['cherry', 3]
|
|
647
|
-
* ]);
|
|
648
|
-
*
|
|
649
|
-
* // Check if key exists
|
|
650
|
-
* console.log(map.has('apple')); // true;
|
|
651
|
-
* console.log(map.has('date')); // false;
|
|
652
|
-
*
|
|
653
|
-
* // Get value by key
|
|
654
|
-
* console.log(map.get('banana')); // 2;
|
|
655
|
-
* console.log(map.get('grape')); // undefined;
|
|
656
|
-
*
|
|
657
|
-
* // Get all keys and values
|
|
658
|
-
* const keys = [...map.keys()];
|
|
659
|
-
* const values = [...map.values()];
|
|
660
|
-
* console.log(keys); // contains 'apple';
|
|
661
|
-
* console.log(values); // contains 3;
|
|
662
|
-
*/
|
|
398
|
+
* Get the value for a key.
|
|
399
|
+
* @remarks Time O(1), Space O(1)
|
|
400
|
+
* @param key - Key to look up.
|
|
401
|
+
* @returns Value or undefined.
|
|
402
|
+
* @example
|
|
403
|
+
* // HashMap get and has operations
|
|
404
|
+
* const map = new HashMap<string, number>([
|
|
405
|
+
* ['apple', 1],
|
|
406
|
+
* ['banana', 2],
|
|
407
|
+
* ['cherry', 3]
|
|
408
|
+
* ]);
|
|
409
|
+
*
|
|
410
|
+
* // Check if key exists
|
|
411
|
+
* console.log(map.has('apple')); // true;
|
|
412
|
+
* console.log(map.has('date')); // false;
|
|
413
|
+
*
|
|
414
|
+
* // Get value by key
|
|
415
|
+
* console.log(map.get('banana')); // 2;
|
|
416
|
+
* console.log(map.get('grape')); // undefined;
|
|
417
|
+
*
|
|
418
|
+
* // Get all keys and values
|
|
419
|
+
* const keys = [...map.keys()];
|
|
420
|
+
* const values = [...map.values()];
|
|
421
|
+
* console.log(keys); // contains 'apple';
|
|
422
|
+
* console.log(values); // contains 3;
|
|
423
|
+
*/
|
|
663
424
|
get(key) {
|
|
664
425
|
var _a;
|
|
665
426
|
if (this._isObjKey(key)) return this.objMap.get(key);
|
|
@@ -667,119 +428,42 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
667
428
|
return (_a = this._store[strKey]) == null ? void 0 : _a.value;
|
|
668
429
|
}
|
|
669
430
|
/**
|
|
670
|
-
|
|
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
|
-
* @example
|
|
717
|
-
* // Check key existence
|
|
718
|
-
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
719
|
-
*
|
|
720
|
-
* console.log(map.has('a')); // true;
|
|
721
|
-
* console.log(map.has('z')); // false;
|
|
722
|
-
*/
|
|
431
|
+
* Check if a key exists.
|
|
432
|
+
* @remarks Time O(1), Space O(1)
|
|
433
|
+
* @param key - Key to test.
|
|
434
|
+
* @returns True if present.
|
|
435
|
+
* @example
|
|
436
|
+
* // Check key existence
|
|
437
|
+
* const map = new HashMap<string, number>([
|
|
438
|
+
* ['a', 1],
|
|
439
|
+
* ['b', 2]
|
|
440
|
+
* ]);
|
|
441
|
+
*
|
|
442
|
+
* console.log(map.has('a')); // true;
|
|
443
|
+
* console.log(map.has('z')); // false;
|
|
444
|
+
*/
|
|
723
445
|
has(key) {
|
|
724
446
|
if (this._isObjKey(key)) return this.objMap.has(key);
|
|
725
447
|
const strKey = this._getNoObjKey(key);
|
|
726
448
|
return strKey in this.store;
|
|
727
449
|
}
|
|
728
450
|
/**
|
|
729
|
-
|
|
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
|
-
* @example
|
|
776
|
-
* // Remove entries by key
|
|
777
|
-
* const map = new HashMap<string, number>([['x', 10], ['y', 20], ['z', 30]]);
|
|
778
|
-
*
|
|
779
|
-
* console.log(map.delete('y')); // true;
|
|
780
|
-
* console.log(map.has('y')); // false;
|
|
781
|
-
* console.log(map.size); // 2;
|
|
782
|
-
*/
|
|
451
|
+
* Delete an entry by key.
|
|
452
|
+
* @remarks Time O(1), Space O(1)
|
|
453
|
+
* @param key - Key to delete.
|
|
454
|
+
* @returns True if the key was found and removed.
|
|
455
|
+
* @example
|
|
456
|
+
* // Remove entries by key
|
|
457
|
+
* const map = new HashMap<string, number>([
|
|
458
|
+
* ['x', 10],
|
|
459
|
+
* ['y', 20],
|
|
460
|
+
* ['z', 30]
|
|
461
|
+
* ]);
|
|
462
|
+
*
|
|
463
|
+
* console.log(map.delete('y')); // true;
|
|
464
|
+
* console.log(map.has('y')); // false;
|
|
465
|
+
* console.log(map.size); // 2;
|
|
466
|
+
*/
|
|
783
467
|
delete(key) {
|
|
784
468
|
if (this._isObjKey(key)) {
|
|
785
469
|
if (this.objMap.has(key)) this._size--;
|
|
@@ -806,117 +490,38 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
806
490
|
return this;
|
|
807
491
|
}
|
|
808
492
|
/**
|
|
809
|
-
|
|
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
|
-
* @example
|
|
853
|
-
* // Create independent copy
|
|
854
|
-
* const map = new HashMap<string, number>([['a', 1]]);
|
|
855
|
-
* const copy = map.clone();
|
|
856
|
-
* copy.set('a', 99);
|
|
857
|
-
* console.log(map.get('a')); // 1;
|
|
858
|
-
*/
|
|
493
|
+
* Deep clone this map, preserving hashing behavior.
|
|
494
|
+
* @remarks Time O(N), Space O(N)
|
|
495
|
+
* @returns A new map with the same content.
|
|
496
|
+
* @example
|
|
497
|
+
* // Create independent copy
|
|
498
|
+
* const map = new HashMap<string, number>([['a', 1]]);
|
|
499
|
+
* const copy = map.clone();
|
|
500
|
+
* copy.set('a', 99);
|
|
501
|
+
* console.log(map.get('a')); // 1;
|
|
502
|
+
*/
|
|
859
503
|
clone() {
|
|
860
504
|
const opts = { hashFn: this._hashFn, toEntryFn: this._toEntryFn };
|
|
861
505
|
return this._createLike(this, opts);
|
|
862
506
|
}
|
|
863
507
|
/**
|
|
864
|
-
|
|
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
|
-
* @example
|
|
913
|
-
* // Transform all values
|
|
914
|
-
* const prices = new HashMap<string, number>([['apple', 1], ['banana', 2]]);
|
|
915
|
-
*
|
|
916
|
-
* const doubled = prices.map(v => (v ?? 0) * 2);
|
|
917
|
-
* console.log(doubled.get('apple')); // 2;
|
|
918
|
-
* console.log(doubled.get('banana')); // 4;
|
|
919
|
-
*/
|
|
508
|
+
* Map values to a new map with the same keys.
|
|
509
|
+
* @remarks Time O(N), Space O(N)
|
|
510
|
+
* @template VM
|
|
511
|
+
* @param callbackfn - Mapping function (key, value, index, map) → newValue.
|
|
512
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
513
|
+
* @returns A new map with transformed values.
|
|
514
|
+
* @example
|
|
515
|
+
* // Transform all values
|
|
516
|
+
* const prices = new HashMap<string, number>([
|
|
517
|
+
* ['apple', 1],
|
|
518
|
+
* ['banana', 2]
|
|
519
|
+
* ]);
|
|
520
|
+
*
|
|
521
|
+
* const doubled = prices.map(v => (v ?? 0) * 2);
|
|
522
|
+
* console.log(doubled.get('apple')); // 2;
|
|
523
|
+
* console.log(doubled.get('banana')); // 4;
|
|
524
|
+
*/
|
|
920
525
|
map(callbackfn, thisArg) {
|
|
921
526
|
const out = this._createLike();
|
|
922
527
|
let index = 0;
|
|
@@ -924,79 +529,37 @@ var _HashMap = class _HashMap extends IterableEntryBase {
|
|
|
924
529
|
return out;
|
|
925
530
|
}
|
|
926
531
|
/**
|
|
927
|
-
|
|
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
|
-
* @example
|
|
975
|
-
* // HashMap iteration and filter operations
|
|
976
|
-
* const map = new HashMap<number, string>([
|
|
977
|
-
* [1, 'Alice'],
|
|
978
|
-
* [2, 'Bob'],
|
|
979
|
-
* [3, 'Charlie'],
|
|
980
|
-
* [4, 'Diana'],
|
|
981
|
-
* [5, 'Eve']
|
|
982
|
-
* ]);
|
|
983
|
-
*
|
|
984
|
-
* // Iterate through entries
|
|
985
|
-
* const entries: [number, string][] = [];
|
|
986
|
-
* for (const [key, value] of map) {
|
|
987
|
-
* entries.push([key, value]);
|
|
988
|
-
* }
|
|
989
|
-
* console.log(entries); // length: 5;
|
|
990
|
-
*
|
|
991
|
-
* // Filter operation (for iteration with collection methods)
|
|
992
|
-
* const filtered = [...map].filter(([key]) => key > 2);
|
|
993
|
-
* console.log(filtered.length); // 3;
|
|
994
|
-
*
|
|
995
|
-
* // Map operation
|
|
996
|
-
* const values = [...map.values()].map(v => v.length);
|
|
997
|
-
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
998
|
-
* console.log(values); // contains 7;
|
|
999
|
-
*/
|
|
532
|
+
* Filter entries into a new map.
|
|
533
|
+
* @remarks Time O(N), Space O(N)
|
|
534
|
+
* @param predicate - Predicate (key, value, index, map) → boolean.
|
|
535
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
536
|
+
* @returns A new map containing entries that satisfied the predicate.
|
|
537
|
+
* @example
|
|
538
|
+
* // HashMap iteration and filter operations
|
|
539
|
+
* const map = new HashMap<number, string>([
|
|
540
|
+
* [1, 'Alice'],
|
|
541
|
+
* [2, 'Bob'],
|
|
542
|
+
* [3, 'Charlie'],
|
|
543
|
+
* [4, 'Diana'],
|
|
544
|
+
* [5, 'Eve']
|
|
545
|
+
* ]);
|
|
546
|
+
*
|
|
547
|
+
* // Iterate through entries
|
|
548
|
+
* const entries: [number, string][] = [];
|
|
549
|
+
* for (const [key, value] of map) {
|
|
550
|
+
* entries.push([key, value]);
|
|
551
|
+
* }
|
|
552
|
+
* console.log(entries); // length: 5;
|
|
553
|
+
*
|
|
554
|
+
* // Filter operation (for iteration with collection methods)
|
|
555
|
+
* const filtered = [...map].filter(([key]) => key > 2);
|
|
556
|
+
* console.log(filtered.length); // 3;
|
|
557
|
+
*
|
|
558
|
+
* // Map operation
|
|
559
|
+
* const values = [...map.values()].map(v => v.length);
|
|
560
|
+
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
561
|
+
* console.log(values); // contains 7;
|
|
562
|
+
*/
|
|
1000
563
|
filter(predicate, thisArg) {
|
|
1001
564
|
const out = this._createLike();
|
|
1002
565
|
let index = 0;
|
|
@@ -1067,13 +630,19 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
|
1067
630
|
__publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
|
|
1068
631
|
__publicField(this, "_head");
|
|
1069
632
|
__publicField(this, "_tail");
|
|
633
|
+
__publicField(this, "_size", 0);
|
|
1070
634
|
__publicField(this, "_toEntryFn", /* @__PURE__ */ __name((rawElement) => {
|
|
1071
635
|
if (this.isEntry(rawElement)) {
|
|
1072
636
|
return rawElement;
|
|
1073
637
|
}
|
|
1074
|
-
raise(
|
|
638
|
+
raise(
|
|
639
|
+
TypeError,
|
|
640
|
+
ERR.invalidArgument(
|
|
641
|
+
"If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.",
|
|
642
|
+
"HashMap"
|
|
643
|
+
)
|
|
644
|
+
);
|
|
1075
645
|
}, "_toEntryFn"));
|
|
1076
|
-
__publicField(this, "_size", 0);
|
|
1077
646
|
this._sentinel = {};
|
|
1078
647
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
1079
648
|
if (options) {
|