data-structure-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/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +3 -1
- package/README.md +78 -31
- package/dist/cjs/binary-tree.cjs +23698 -0
- package/dist/cjs/graph.cjs +5236 -0
- package/dist/cjs/hash.cjs +1262 -0
- package/dist/cjs/heap.cjs +1540 -0
- package/dist/cjs/index.cjs +24509 -2899
- package/dist/cjs/linked-list.cjs +4370 -0
- package/dist/cjs/matrix.cjs +1042 -0
- package/dist/cjs/priority-queue.cjs +1314 -0
- package/dist/cjs/queue.cjs +4090 -0
- package/dist/cjs/stack.cjs +861 -0
- package/dist/cjs/trie.cjs +1173 -0
- package/dist/cjs-legacy/binary-tree.cjs +23730 -0
- package/dist/cjs-legacy/graph.cjs +5234 -0
- package/dist/cjs-legacy/hash.cjs +1262 -0
- package/dist/cjs-legacy/heap.cjs +1537 -0
- package/dist/cjs-legacy/index.cjs +32555 -10936
- package/dist/cjs-legacy/linked-list.cjs +4376 -0
- package/dist/cjs-legacy/matrix.cjs +1045 -0
- package/dist/cjs-legacy/priority-queue.cjs +1312 -0
- package/dist/cjs-legacy/queue.cjs +4088 -0
- package/dist/cjs-legacy/stack.cjs +861 -0
- package/dist/cjs-legacy/trie.cjs +1172 -0
- package/dist/esm/binary-tree.mjs +23683 -0
- package/dist/esm/graph.mjs +5223 -0
- package/dist/esm/hash.mjs +1259 -0
- package/dist/esm/heap.mjs +1534 -0
- package/dist/esm/index.mjs +24507 -2898
- package/dist/esm/linked-list.mjs +4363 -0
- package/dist/esm/matrix.mjs +1038 -0
- package/dist/esm/priority-queue.mjs +1310 -0
- package/dist/esm/queue.mjs +4086 -0
- package/dist/esm/stack.mjs +859 -0
- package/dist/esm/trie.mjs +1170 -0
- package/dist/esm-legacy/binary-tree.mjs +23715 -0
- package/dist/esm-legacy/graph.mjs +5221 -0
- package/dist/esm-legacy/hash.mjs +1259 -0
- package/dist/esm-legacy/heap.mjs +1531 -0
- package/dist/esm-legacy/index.mjs +32553 -10935
- package/dist/esm-legacy/linked-list.mjs +4369 -0
- package/dist/esm-legacy/matrix.mjs +1041 -0
- package/dist/esm-legacy/priority-queue.mjs +1308 -0
- package/dist/esm-legacy/queue.mjs +4084 -0
- package/dist/esm-legacy/stack.mjs +859 -0
- package/dist/esm-legacy/trie.mjs +1169 -0
- 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 +368 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +473 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +931 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +792 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +592 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +320 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3662 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3487 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2778 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3414 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +419 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +384 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +462 -89
- package/dist/types/data-structures/heap/heap.d.ts +567 -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 +631 -49
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +581 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +775 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +491 -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 +578 -71
- package/dist/types/data-structures/queue/queue.d.ts +451 -42
- package/dist/types/data-structures/stack/stack.d.ts +374 -32
- package/dist/types/data-structures/trie/trie.d.ts +458 -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/data-structure-typed.js +32432 -10808
- package/dist/umd/data-structure-typed.min.js +10 -4
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
- package/docs-site-docusaurus/docs/guide/guides.md +611 -0
- package/docs-site-docusaurus/docs/guide/installation.md +60 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
- package/docs-site-docusaurus/docs/guide/overview.md +638 -0
- package/docs-site-docusaurus/docs/guide/performance.md +833 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +71 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/package.json +109 -12
- 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
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -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,79 @@ 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
|
+
* @example
|
|
169
|
+
* // Check if empty
|
|
170
|
+
* const map = new HashMap();
|
|
171
|
+
* console.log(map.isEmpty()); // true;
|
|
203
172
|
*/
|
|
204
173
|
isEmpty(): boolean;
|
|
205
174
|
/**
|
|
206
175
|
* Remove all entries and reset counters.
|
|
207
176
|
* @remarks Time O(N), Space O(1)
|
|
208
177
|
* @returns void
|
|
178
|
+
|
|
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
|
+
* @example
|
|
208
|
+
* // Remove all entries
|
|
209
|
+
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
210
|
+
* map.clear();
|
|
211
|
+
* console.log(map.isEmpty()); // true;
|
|
209
212
|
*/
|
|
210
213
|
clear(): void;
|
|
211
214
|
/**
|
|
@@ -213,13 +216,93 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
213
216
|
* @remarks Time O(1), Space O(1)
|
|
214
217
|
* @returns True if the value is a 2-tuple.
|
|
215
218
|
*/
|
|
216
|
-
isEntry(rawElement:
|
|
219
|
+
isEntry(rawElement: unknown): rawElement is [K, V];
|
|
217
220
|
/**
|
|
218
221
|
* Insert or replace a single entry.
|
|
219
222
|
* @remarks Time O(1), Space O(1)
|
|
220
223
|
* @param key - Key.
|
|
221
224
|
* @param value - Value.
|
|
222
225
|
* @returns True when the operation succeeds.
|
|
226
|
+
|
|
227
|
+
|
|
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
|
+
* @example
|
|
289
|
+
* // basic HashMap creation and set operation
|
|
290
|
+
* // Create a simple HashMap with key-value pairs
|
|
291
|
+
* const map = new HashMap<number, string>([
|
|
292
|
+
* [1, 'one'],
|
|
293
|
+
* [2, 'two'],
|
|
294
|
+
* [3, 'three']
|
|
295
|
+
* ]);
|
|
296
|
+
*
|
|
297
|
+
* // Verify size
|
|
298
|
+
* console.log(map.size); // 3;
|
|
299
|
+
*
|
|
300
|
+
* // Set a new key-value pair
|
|
301
|
+
* map.set(4, 'four');
|
|
302
|
+
* console.log(map.size); // 4;
|
|
303
|
+
*
|
|
304
|
+
* // Verify entries
|
|
305
|
+
* console.log([...map.entries()]); // length: 4;
|
|
223
306
|
*/
|
|
224
307
|
set(key: K, value: V): boolean;
|
|
225
308
|
/**
|
|
@@ -227,6 +310,40 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
227
310
|
* @remarks Time O(N), Space O(N)
|
|
228
311
|
* @param entryOrRawElements - Iterable of entries or raw elements to insert.
|
|
229
312
|
* @returns Array of per-entry results.
|
|
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
|
+
|
|
341
|
+
|
|
342
|
+
* @example
|
|
343
|
+
* // Add multiple entries
|
|
344
|
+
* const map = new HashMap<string, number>();
|
|
345
|
+
* map.setMany([['a', 1], ['b', 2], ['c', 3]]);
|
|
346
|
+
* console.log(map.size); // 3;
|
|
230
347
|
*/
|
|
231
348
|
setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
|
|
232
349
|
/**
|
|
@@ -234,6 +351,58 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
234
351
|
* @remarks Time O(1), Space O(1)
|
|
235
352
|
* @param key - Key to look up.
|
|
236
353
|
* @returns Value or undefined.
|
|
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
|
+
* @example
|
|
386
|
+
* // HashMap get and has operations
|
|
387
|
+
* const map = new HashMap<string, number>([
|
|
388
|
+
* ['apple', 1],
|
|
389
|
+
* ['banana', 2],
|
|
390
|
+
* ['cherry', 3]
|
|
391
|
+
* ]);
|
|
392
|
+
*
|
|
393
|
+
* // Check if key exists
|
|
394
|
+
* console.log(map.has('apple')); // true;
|
|
395
|
+
* console.log(map.has('date')); // false;
|
|
396
|
+
*
|
|
397
|
+
* // Get value by key
|
|
398
|
+
* console.log(map.get('banana')); // 2;
|
|
399
|
+
* console.log(map.get('grape')); // undefined;
|
|
400
|
+
*
|
|
401
|
+
* // Get all keys and values
|
|
402
|
+
* const keys = [...map.keys()];
|
|
403
|
+
* const values = [...map.values()];
|
|
404
|
+
* console.log(keys); // contains 'apple';
|
|
405
|
+
* console.log(values); // contains 3;
|
|
237
406
|
*/
|
|
238
407
|
get(key: K): V | undefined;
|
|
239
408
|
/**
|
|
@@ -241,6 +410,43 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
241
410
|
* @remarks Time O(1), Space O(1)
|
|
242
411
|
* @param key - Key to test.
|
|
243
412
|
* @returns True if present.
|
|
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
|
+
* @example
|
|
445
|
+
* // Check key existence
|
|
446
|
+
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
447
|
+
*
|
|
448
|
+
* console.log(map.has('a')); // true;
|
|
449
|
+
* console.log(map.has('z')); // false;
|
|
244
450
|
*/
|
|
245
451
|
has(key: K): boolean;
|
|
246
452
|
/**
|
|
@@ -248,6 +454,44 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
248
454
|
* @remarks Time O(1), Space O(1)
|
|
249
455
|
* @param key - Key to delete.
|
|
250
456
|
* @returns True if the key was found and removed.
|
|
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
|
+
* @example
|
|
489
|
+
* // Remove entries by key
|
|
490
|
+
* const map = new HashMap<string, number>([['x', 10], ['y', 20], ['z', 30]]);
|
|
491
|
+
*
|
|
492
|
+
* console.log(map.delete('y')); // true;
|
|
493
|
+
* console.log(map.has('y')); // false;
|
|
494
|
+
* console.log(map.size); // 2;
|
|
251
495
|
*/
|
|
252
496
|
delete(key: K): boolean;
|
|
253
497
|
/**
|
|
@@ -261,6 +505,41 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
261
505
|
* Deep clone this map, preserving hashing behavior.
|
|
262
506
|
* @remarks Time O(N), Space O(N)
|
|
263
507
|
* @returns A new map with the same content.
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
* @example
|
|
538
|
+
* // Create independent copy
|
|
539
|
+
* const map = new HashMap<string, number>([['a', 1]]);
|
|
540
|
+
* const copy = map.clone();
|
|
541
|
+
* copy.set('a', 99);
|
|
542
|
+
* console.log(map.get('a')); // 1;
|
|
264
543
|
*/
|
|
265
544
|
clone(): this;
|
|
266
545
|
/**
|
|
@@ -270,16 +549,110 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
270
549
|
* @param callbackfn - Mapping function (key, value, index, map) → newValue.
|
|
271
550
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
272
551
|
* @returns A new map with transformed values.
|
|
273
|
-
|
|
274
|
-
|
|
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
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
* @example
|
|
584
|
+
* // Transform all values
|
|
585
|
+
* const prices = new HashMap<string, number>([['apple', 1], ['banana', 2]]);
|
|
586
|
+
*
|
|
587
|
+
* const doubled = prices.map(v => (v ?? 0) * 2);
|
|
588
|
+
* console.log(doubled.get('apple')); // 2;
|
|
589
|
+
* console.log(doubled.get('banana')); // 4;
|
|
590
|
+
*/
|
|
591
|
+
map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: unknown): HashMap<K, VM>;
|
|
275
592
|
/**
|
|
276
593
|
* Filter entries into a new map.
|
|
277
594
|
* @remarks Time O(N), Space O(N)
|
|
278
595
|
* @param predicate - Predicate (key, value, index, map) → boolean.
|
|
279
596
|
* @param [thisArg] - Value for `this` inside the predicate.
|
|
280
597
|
* @returns A new map containing entries that satisfied the predicate.
|
|
281
|
-
|
|
282
|
-
|
|
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
|
+
* @example
|
|
630
|
+
* // HashMap iteration and filter operations
|
|
631
|
+
* const map = new HashMap<number, string>([
|
|
632
|
+
* [1, 'Alice'],
|
|
633
|
+
* [2, 'Bob'],
|
|
634
|
+
* [3, 'Charlie'],
|
|
635
|
+
* [4, 'Diana'],
|
|
636
|
+
* [5, 'Eve']
|
|
637
|
+
* ]);
|
|
638
|
+
*
|
|
639
|
+
* // Iterate through entries
|
|
640
|
+
* const entries: [number, string][] = [];
|
|
641
|
+
* for (const [key, value] of map) {
|
|
642
|
+
* entries.push([key, value]);
|
|
643
|
+
* }
|
|
644
|
+
* console.log(entries); // length: 5;
|
|
645
|
+
*
|
|
646
|
+
* // Filter operation (for iteration with collection methods)
|
|
647
|
+
* const filtered = [...map].filter(([key]) => key > 2);
|
|
648
|
+
* console.log(filtered.length); // 3;
|
|
649
|
+
*
|
|
650
|
+
* // Map operation
|
|
651
|
+
* const values = [...map.values()].map(v => v.length);
|
|
652
|
+
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
653
|
+
* console.log(values); // contains 7;
|
|
654
|
+
*/
|
|
655
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): any;
|
|
283
656
|
/**
|
|
284
657
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
285
658
|
* @remarks Time O(N), Space O(N)
|
|
@@ -290,10 +663,10 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
290
663
|
* @param [options] - Options forwarded to the constructor.
|
|
291
664
|
* @returns A like-kind map instance.
|
|
292
665
|
*/
|
|
293
|
-
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?:
|
|
666
|
+
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?: Record<string, unknown>): this;
|
|
294
667
|
protected _rehashNoObj(): void;
|
|
295
668
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
296
|
-
protected _isObjKey(key:
|
|
669
|
+
protected _isObjKey(key: unknown): key is object | ((...args: unknown[]) => unknown);
|
|
297
670
|
protected _getNoObjKey(key: K): string;
|
|
298
671
|
}
|
|
299
672
|
/**
|
|
@@ -408,10 +781,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
408
781
|
*/
|
|
409
782
|
deleteAt(index: number): boolean;
|
|
410
783
|
isEmpty(): boolean;
|
|
411
|
-
isEntry(rawElement:
|
|
784
|
+
isEntry(rawElement: unknown): rawElement is [K, V];
|
|
412
785
|
clear(): void;
|
|
413
|
-
clone():
|
|
414
|
-
filter(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
786
|
+
clone(): this;
|
|
787
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): this;
|
|
415
788
|
/**
|
|
416
789
|
* Map each entry to a new [key, value] pair and preserve order.
|
|
417
790
|
* @remarks Time O(N), Space O(N)
|
|
@@ -421,8 +794,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
421
794
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
422
795
|
* @returns A new map of the same class with transformed entries.
|
|
423
796
|
*/
|
|
424
|
-
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?:
|
|
797
|
+
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: unknown): LinkedHashMap<MK, MV>;
|
|
425
798
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
426
799
|
protected _deleteNode(node: HashMapLinkedNode<K, V | undefined>): boolean;
|
|
427
|
-
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?:
|
|
800
|
+
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?: Record<string, unknown>): this;
|
|
428
801
|
}
|