min-priority-queue-typed 2.2.2 → 2.2.4

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.
Files changed (47) hide show
  1. package/dist/cjs/index.cjs.map +1 -1
  2. package/dist/cjs-legacy/index.cjs.map +1 -1
  3. package/dist/esm/index.mjs.map +1 -1
  4. package/dist/esm-legacy/index.mjs.map +1 -1
  5. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -2
  6. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -5
  7. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +98 -5
  8. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +103 -7
  9. package/dist/types/data-structures/binary-tree/bst.d.ts +202 -39
  10. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +86 -37
  11. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +4 -5
  12. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +7 -7
  13. package/dist/types/data-structures/graph/directed-graph.d.ts +126 -1
  14. package/dist/types/data-structures/graph/undirected-graph.d.ts +160 -1
  15. package/dist/types/data-structures/hash/hash-map.d.ts +110 -27
  16. package/dist/types/data-structures/heap/heap.d.ts +107 -58
  17. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +72 -404
  18. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -5
  19. package/dist/types/data-structures/queue/deque.d.ts +95 -67
  20. package/dist/types/data-structures/queue/queue.d.ts +90 -34
  21. package/dist/types/data-structures/stack/stack.d.ts +58 -40
  22. package/dist/types/data-structures/trie/trie.d.ts +109 -47
  23. package/dist/types/interfaces/binary-tree.d.ts +1 -0
  24. package/dist/types/types/data-structures/binary-tree/bst.d.ts +5 -5
  25. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  26. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/data-structures/binary-tree/avl-tree-counter.ts +1 -2
  29. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +7 -8
  30. package/src/data-structures/binary-tree/avl-tree.ts +100 -7
  31. package/src/data-structures/binary-tree/binary-tree.ts +117 -7
  32. package/src/data-structures/binary-tree/bst.ts +431 -93
  33. package/src/data-structures/binary-tree/red-black-tree.ts +85 -37
  34. package/src/data-structures/binary-tree/tree-counter.ts +5 -7
  35. package/src/data-structures/binary-tree/tree-multi-map.ts +9 -10
  36. package/src/data-structures/graph/directed-graph.ts +126 -1
  37. package/src/data-structures/graph/undirected-graph.ts +160 -1
  38. package/src/data-structures/hash/hash-map.ts +110 -27
  39. package/src/data-structures/heap/heap.ts +107 -58
  40. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -404
  41. package/src/data-structures/linked-list/singly-linked-list.ts +121 -5
  42. package/src/data-structures/queue/deque.ts +95 -67
  43. package/src/data-structures/queue/queue.ts +90 -34
  44. package/src/data-structures/stack/stack.ts +58 -40
  45. package/src/data-structures/trie/trie.ts +109 -47
  46. package/src/interfaces/binary-tree.ts +2 -0
  47. package/src/types/data-structures/binary-tree/bst.ts +5 -5
@@ -5,8 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
9
- import { BSTOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
10
9
  import { BSTNode } from './bst';
11
10
  import { IBinaryTree } from '../../interfaces';
12
11
  import { RedBlackTree } from './red-black-tree';
@@ -188,7 +187,7 @@ export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree
188
187
  * @param [thisArg] - Value for `this` inside the callback.
189
188
  * @returns A new TreeCounter with mapped entries.
190
189
  */
191
- map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): TreeCounter<MK, MV, MR>;
190
+ map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<TreeCounterOptions<MK, MV, MR>>, thisArg?: unknown): TreeCounter<MK, MV, MR>;
192
191
  /**
193
192
  * Deep copy this tree, preserving map mode and aggregate counts.
194
193
  * @remarks Time O(N), Space O(N)
@@ -204,7 +203,7 @@ export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree
204
203
  * @param [options] - Optional constructor options for the like-kind instance.
205
204
  * @returns An empty like-kind instance.
206
205
  */
207
- protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
206
+ protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<TreeCounterOptions<TK, TV, TR>>): this;
208
207
  /**
209
208
  * (Protected) Create a like-kind instance and seed it from an iterable.
210
209
  * @remarks Time O(N log N), Space O(N)
@@ -215,7 +214,7 @@ export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree
215
214
  * @param [options] - Options merged with the current snapshot.
216
215
  * @returns A like-kind TreeCounter built from the iterable.
217
216
  */
218
- protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): TreeCounter<TK, TV, TR>;
217
+ protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<TreeCounterOptions<TK, TV, TR>>): TreeCounter<TK, TV, TR>;
219
218
  /**
220
219
  * (Protected) Normalize input into a node plus its effective value and count.
221
220
  * @remarks Time O(1), Space O(1)
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { ElemOf, EntryCallback, FamilyPosition, RBTNColor, RedBlackTreeOptions, TreeMultiMapOptions } from '../../types';
8
+ import type { ElemOf, EntryCallback, FamilyPosition, RBTNColor, TreeMultiMapOptions } from '../../types';
9
9
  import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
@@ -116,7 +116,7 @@ export declare class TreeMultiMapNode<K = any, V = any> {
116
116
  *
117
117
  * @example
118
118
  * // players ranked by score with their equipment
119
- * type Equipment = {
119
+ * type Equipment = {
120
120
  * name: string; // Equipment name
121
121
  * quality: 'legendary' | 'epic' | 'rare' | 'common';
122
122
  * level: number;
@@ -277,7 +277,7 @@ export declare class TreeMultiMapNode<K = any, V = any> {
277
277
  * // },
278
278
  * // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
279
279
  * // ]
280
- * // ]
280
+ * // ];
281
281
  */
282
282
  export declare class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[], R> implements IBinaryTree<K, V[], R> {
283
283
  /**
@@ -307,8 +307,8 @@ export declare class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTre
307
307
  * @returns True if the value was removed; false if not found.
308
308
  */
309
309
  deleteValue(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined, value: V): boolean;
310
- map<MK = K, MVArr extends unknown[] = V[], MR = any>(callback: EntryCallback<K, V[] | undefined, [MK, MVArr]>, options?: Partial<RedBlackTreeOptions<MK, MVArr, MR>>, thisArg?: unknown): TreeMultiMap<MK, ElemOf<MVArr>, MR>;
311
- map<MK = K, MV = V[], MR = any>(callback: EntryCallback<K, V[] | undefined, [MK, MV]>, options?: Partial<RedBlackTreeOptions<MK, MV, MR>>, thisArg?: unknown): RedBlackTree<MK, MV, MR>;
310
+ map<MK = K, MVArr extends unknown[] = V[], MR = any>(callback: EntryCallback<K, V[] | undefined, [MK, MVArr]>, options?: Partial<TreeMultiMapOptions<MK, MVArr, MR>>, thisArg?: unknown): TreeMultiMap<MK, ElemOf<MVArr>, MR>;
311
+ map<MK = K, MV = V[], MR = any>(callback: EntryCallback<K, V[] | undefined, [MK, MV]>, options?: Partial<TreeMultiMapOptions<MK, MV, MR>>, thisArg?: unknown): RedBlackTree<MK, MV, MR>;
312
312
  /**
313
313
  * (Protected) Create an empty instance of the same concrete class.
314
314
  * @remarks Time O(1), Space O(1)
@@ -318,7 +318,7 @@ export declare class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTre
318
318
  * @param [options] - Optional constructor options for the like-kind instance.
319
319
  * @returns An empty like-kind instance.
320
320
  */
321
- protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): this;
321
+ protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<TreeMultiMapOptions<TK, TV, TR>>): this;
322
322
  /**
323
323
  * (Protected) Create a like-kind instance and seed it from an iterable.
324
324
  * @remarks Time O(N log N), Space O(N)
@@ -329,5 +329,5 @@ export declare class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTre
329
329
  * @param [options] - Options merged with the current snapshot.
330
330
  * @returns A like-kind RedBlackTree built from the iterable.
331
331
  */
332
- protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | RedBlackTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): RedBlackTree<TK, TV, TR>;
332
+ protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | RedBlackTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<TreeMultiMapOptions<TK, TV, TR>>): RedBlackTree<TK, TV, TR>;
333
333
  }
@@ -23,7 +23,132 @@ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
23
23
  * @template VO - Concrete vertex class (extends AbstractVertex<V>).
24
24
  * @template EO - Concrete edge class (extends AbstractEdge<E>).
25
25
  * @remarks Time O(1), Space O(1)
26
- * @example examples will be generated by unit test
26
+ * @example
27
+ * // basic DirectedGraph vertex and edge creation
28
+ * // Create a simple directed graph
29
+ * const graph = new DirectedGraph<string>();
30
+ *
31
+ * // Add vertices
32
+ * graph.addVertex('A');
33
+ * graph.addVertex('B');
34
+ * graph.addVertex('C');
35
+ *
36
+ * // Verify vertices exist
37
+ * console.log(graph.hasVertex('A')); // true;
38
+ * console.log(graph.hasVertex('B')); // true;
39
+ * console.log(graph.hasVertex('C')); // true;
40
+ * console.log(graph.hasVertex('D')); // false;
41
+ *
42
+ * // Check vertex count
43
+ * console.log(graph.size); // 3;
44
+ * @example
45
+ * // DirectedGraph edge operations
46
+ * const graph = new DirectedGraph<string>();
47
+ *
48
+ * // Add vertices
49
+ * graph.addVertex('A');
50
+ * graph.addVertex('B');
51
+ * graph.addVertex('C');
52
+ *
53
+ * // Add directed edges
54
+ * graph.addEdge('A', 'B', 1);
55
+ * graph.addEdge('B', 'C', 2);
56
+ * graph.addEdge('A', 'C', 3);
57
+ *
58
+ * // Verify edges exist
59
+ * console.log(graph.hasEdge('A', 'B')); // true;
60
+ * console.log(graph.hasEdge('B', 'C')); // true;
61
+ * console.log(graph.hasEdge('C', 'B')); // false; // Graph is directed
62
+ *
63
+ * // Get neighbors of A
64
+ * const neighborsA = graph.getNeighbors('A');
65
+ * console.log(neighborsA[0].key); // 'B';
66
+ * console.log(neighborsA[1].key); // 'C';
67
+ * @example
68
+ * // DirectedGraph deleteEdge and vertex operations
69
+ * const graph = new DirectedGraph<string>();
70
+ *
71
+ * // Build a small graph
72
+ * graph.addVertex('X');
73
+ * graph.addVertex('Y');
74
+ * graph.addVertex('Z');
75
+ * graph.addEdge('X', 'Y', 1);
76
+ * graph.addEdge('Y', 'Z', 2);
77
+ *
78
+ * // Delete an edge
79
+ * graph.deleteEdgeSrcToDest('X', 'Y');
80
+ * console.log(graph.hasEdge('X', 'Y')); // false;
81
+ *
82
+ * // Edge in other direction should not exist
83
+ * console.log(graph.hasEdge('Y', 'X')); // false;
84
+ *
85
+ * // Other edges should remain
86
+ * console.log(graph.hasEdge('Y', 'Z')); // true;
87
+ *
88
+ * // Delete a vertex
89
+ * graph.deleteVertex('Y');
90
+ * console.log(graph.hasVertex('Y')); // false;
91
+ * console.log(graph.size); // 2;
92
+ * @example
93
+ * // DirectedGraph topologicalSort for task scheduling
94
+ * const graph = new DirectedGraph<string>();
95
+ *
96
+ * // Build a DAG (Directed Acyclic Graph) for task dependencies
97
+ * graph.addVertex('Design');
98
+ * graph.addVertex('Implement');
99
+ * graph.addVertex('Test');
100
+ * graph.addVertex('Deploy');
101
+ *
102
+ * // Add dependency edges
103
+ * graph.addEdge('Design', 'Implement', 1); // Design must come before Implement
104
+ * graph.addEdge('Implement', 'Test', 1); // Implement must come before Test
105
+ * graph.addEdge('Test', 'Deploy', 1); // Test must come before Deploy
106
+ *
107
+ * // Topological sort gives valid execution order
108
+ * const executionOrder = graph.topologicalSort();
109
+ * console.log(executionOrder); // defined;
110
+ * console.log(executionOrder); // ['Design', 'Implement', 'Test', 'Deploy'];
111
+ *
112
+ * // All vertices should be included
113
+ * console.log(executionOrder?.length); // 4;
114
+ * @example
115
+ * // DirectedGraph dijkstra shortest path for network routing
116
+ * // Build a weighted directed graph representing network nodes and costs
117
+ * const network = new DirectedGraph<string>();
118
+ *
119
+ * // Add network nodes
120
+ * network.addVertex('Router-A');
121
+ * network.addVertex('Router-B');
122
+ * network.addVertex('Router-C');
123
+ * network.addVertex('Router-D');
124
+ * network.addVertex('Router-E');
125
+ *
126
+ * // Add weighted edges (network latency costs)
127
+ * network.addEdge('Router-A', 'Router-B', 5);
128
+ * network.addEdge('Router-A', 'Router-C', 10);
129
+ * network.addEdge('Router-B', 'Router-D', 3);
130
+ * network.addEdge('Router-C', 'Router-D', 2);
131
+ * network.addEdge('Router-D', 'Router-E', 4);
132
+ * network.addEdge('Router-B', 'Router-E', 12);
133
+ *
134
+ * // Find shortest path from Router-A to Router-E
135
+ * const { minDist, minPath } = network.dijkstra('Router-A', 'Router-E', true, true) || {
136
+ * minDist: undefined,
137
+ * minPath: undefined
138
+ * };
139
+ *
140
+ * // Verify shortest path is found
141
+ * console.log(minDist); // defined;
142
+ * console.log(minPath); // defined;
143
+ *
144
+ * // Shortest path should be A -> B -> D -> E with cost 5+3+4=12
145
+ * // Or A -> C -> D -> E with cost 10+2+4=16
146
+ * // So the minimum is 12
147
+ * console.log(minDist); // <= 16;
148
+ *
149
+ * // Verify path is valid (includes start and end)
150
+ * console.log(minPath?.[0].key); // 'Router-A';
151
+ * console.log(minPath?.[minPath.length - 1].key); // 'Router-E';
27
152
  */
28
153
  export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V> = DirectedVertex<V>, EO extends DirectedEdge<E> = DirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
29
154
  /**
@@ -22,7 +22,166 @@ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
22
22
  * @template VO - Concrete vertex class (extends AbstractVertex<V>).
23
23
  * @template EO - Concrete edge class (extends AbstractEdge<E>).
24
24
  * @remarks Time O(1), Space O(1)
25
- * @example examples will be generated by unit test
25
+ * @example
26
+ * // basic UndirectedGraph vertex and edge creation
27
+ * // Create a simple undirected graph
28
+ * const graph = new UndirectedGraph<string>();
29
+ *
30
+ * // Add vertices
31
+ * graph.addVertex('A');
32
+ * graph.addVertex('B');
33
+ * graph.addVertex('C');
34
+ * graph.addVertex('D');
35
+ *
36
+ * // Verify vertices exist
37
+ * console.log(graph.hasVertex('A')); // true;
38
+ * console.log(graph.hasVertex('B')); // true;
39
+ * console.log(graph.hasVertex('E')); // false;
40
+ *
41
+ * // Check vertex count
42
+ * console.log(graph.size); // 4;
43
+ * @example
44
+ * // UndirectedGraph edge operations (bidirectional)
45
+ * const graph = new UndirectedGraph<string>();
46
+ *
47
+ * // Add vertices
48
+ * graph.addVertex('A');
49
+ * graph.addVertex('B');
50
+ * graph.addVertex('C');
51
+ *
52
+ * // Add undirected edges (both directions automatically)
53
+ * graph.addEdge('A', 'B', 1);
54
+ * graph.addEdge('B', 'C', 2);
55
+ * graph.addEdge('A', 'C', 3);
56
+ *
57
+ * // Verify edges exist in both directions
58
+ * console.log(graph.hasEdge('A', 'B')); // true;
59
+ * console.log(graph.hasEdge('B', 'A')); // true; // Bidirectional!
60
+ *
61
+ * console.log(graph.hasEdge('C', 'B')); // true;
62
+ * console.log(graph.hasEdge('B', 'C')); // true; // Bidirectional!
63
+ *
64
+ * // Get neighbors of A
65
+ * const neighborsA = graph.getNeighbors('A');
66
+ * console.log(neighborsA[0].key); // 'B';
67
+ * console.log(neighborsA[1].key); // 'C';
68
+ * @example
69
+ * // UndirectedGraph deleteEdge and vertex operations
70
+ * const graph = new UndirectedGraph<string>();
71
+ *
72
+ * // Build a simple undirected graph
73
+ * graph.addVertex('X');
74
+ * graph.addVertex('Y');
75
+ * graph.addVertex('Z');
76
+ * graph.addEdge('X', 'Y', 1);
77
+ * graph.addEdge('Y', 'Z', 2);
78
+ * graph.addEdge('X', 'Z', 3);
79
+ *
80
+ * // Delete an edge
81
+ * graph.deleteEdge('X', 'Y');
82
+ * console.log(graph.hasEdge('X', 'Y')); // false;
83
+ *
84
+ * // Bidirectional deletion confirmed
85
+ * console.log(graph.hasEdge('Y', 'X')); // false;
86
+ *
87
+ * // Other edges should remain
88
+ * console.log(graph.hasEdge('Y', 'Z')); // true;
89
+ * console.log(graph.hasEdge('Z', 'Y')); // true;
90
+ *
91
+ * // Delete a vertex
92
+ * graph.deleteVertex('Y');
93
+ * console.log(graph.hasVertex('Y')); // false;
94
+ * console.log(graph.size); // 2;
95
+ * @example
96
+ * // UndirectedGraph connectivity and neighbors
97
+ * const graph = new UndirectedGraph<string>();
98
+ *
99
+ * // Build a friendship network
100
+ * const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
101
+ * for (const person of people) {
102
+ * graph.addVertex(person);
103
+ * }
104
+ *
105
+ * // Add friendships (undirected edges)
106
+ * graph.addEdge('Alice', 'Bob', 1);
107
+ * graph.addEdge('Alice', 'Charlie', 1);
108
+ * graph.addEdge('Bob', 'Diana', 1);
109
+ * graph.addEdge('Charlie', 'Eve', 1);
110
+ * graph.addEdge('Diana', 'Eve', 1);
111
+ *
112
+ * // Get friends of each person
113
+ * const aliceFriends = graph.getNeighbors('Alice');
114
+ * console.log(aliceFriends[0].key); // 'Bob';
115
+ * console.log(aliceFriends[1].key); // 'Charlie';
116
+ * console.log(aliceFriends.length); // 2;
117
+ *
118
+ * const dianaFriends = graph.getNeighbors('Diana');
119
+ * console.log(dianaFriends[0].key); // 'Bob';
120
+ * console.log(dianaFriends[1].key); // 'Eve';
121
+ * console.log(dianaFriends.length); // 2;
122
+ *
123
+ * // Verify bidirectional friendship
124
+ * const bobFriends = graph.getNeighbors('Bob');
125
+ * console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
126
+ * console.log(bobFriends[1].key); // 'Diana';
127
+ * @example
128
+ * // UndirectedGraph for social network connectivity analysis
129
+ * interface Person {
130
+ * id: number;
131
+ * name: string;
132
+ * location: string;
133
+ * }
134
+ *
135
+ * // UndirectedGraph is perfect for modeling symmetric relationships
136
+ * // (friendships, collaborations, partnerships)
137
+ * const socialNetwork = new UndirectedGraph<number, Person>();
138
+ *
139
+ * // Add people as vertices
140
+ * const people: [number, Person][] = [
141
+ * [1, { id: 1, name: 'Alice', location: 'New York' }],
142
+ * [2, { id: 2, name: 'Bob', location: 'San Francisco' }],
143
+ * [3, { id: 3, name: 'Charlie', location: 'Boston' }],
144
+ * [4, { id: 4, name: 'Diana', location: 'New York' }],
145
+ * [5, { id: 5, name: 'Eve', location: 'Seattle' }]
146
+ * ];
147
+ *
148
+ * for (const [id] of people) {
149
+ * socialNetwork.addVertex(id);
150
+ * }
151
+ *
152
+ * // Add friendships (automatically bidirectional)
153
+ * socialNetwork.addEdge(1, 2, 1); // Alice <-> Bob
154
+ * socialNetwork.addEdge(1, 3, 1); // Alice <-> Charlie
155
+ * socialNetwork.addEdge(2, 4, 1); // Bob <-> Diana
156
+ * socialNetwork.addEdge(3, 5, 1); // Charlie <-> Eve
157
+ * socialNetwork.addEdge(4, 5, 1); // Diana <-> Eve
158
+ *
159
+ * console.log(socialNetwork.size); // 5;
160
+ *
161
+ * // Find direct connections for Alice
162
+ * const aliceConnections = socialNetwork.getNeighbors(1);
163
+ * console.log(aliceConnections[0].key); // 2;
164
+ * console.log(aliceConnections[1].key); // 3;
165
+ * console.log(aliceConnections.length); // 2;
166
+ *
167
+ * // Verify bidirectional connections
168
+ * console.log(socialNetwork.hasEdge(1, 2)); // true;
169
+ * console.log(socialNetwork.hasEdge(2, 1)); // true; // Friendship works both ways!
170
+ *
171
+ * // Remove a person from network
172
+ * socialNetwork.deleteVertex(2); // Bob leaves
173
+ * console.log(socialNetwork.hasVertex(2)); // false;
174
+ * console.log(socialNetwork.size); // 4;
175
+ *
176
+ * // Alice loses Bob as a friend
177
+ * const updatedAliceConnections = socialNetwork.getNeighbors(1);
178
+ * console.log(updatedAliceConnections[0].key); // 3;
179
+ * console.log(updatedAliceConnections[1]); // undefined;
180
+ *
181
+ * // Diana loses Bob as a friend
182
+ * const dianaConnections = socialNetwork.getNeighbors(4);
183
+ * console.log(dianaConnections[0].key); // 5;
184
+ * console.log(dianaConnections[1]); // undefined;
26
185
  */
27
186
  export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
28
187
  /**
@@ -20,7 +20,7 @@ import { IterableEntryBase } from '../base';
20
20
  * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
21
21
  * @example
22
22
  * // should maintain insertion order
23
- * const linkedHashMap = new LinkedHashMap<number, string>();
23
+ * const linkedHashMap = new LinkedHashMap<number, string>();
24
24
  * linkedHashMap.set(1, 'A');
25
25
  * linkedHashMap.set(2, 'B');
26
26
  * linkedHashMap.set(3, 'C');
@@ -30,40 +30,123 @@ import { IterableEntryBase } from '../base';
30
30
  * // [1, 'A'],
31
31
  * // [2, 'B'],
32
32
  * // [3, 'C']
33
- * // ]
33
+ * // ];
34
34
  * @example
35
- * // fast lookup of values by key
36
- * const hashMap = new HashMap<number, string>();
37
- * hashMap.set(1, 'A');
38
- * hashMap.set(2, 'B');
39
- * hashMap.set(3, 'C');
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
+ * ]);
40
42
  *
41
- * console.log(hashMap.get(1)); // 'A'
42
- * console.log(hashMap.get(2)); // 'B'
43
- * console.log(hashMap.get(3)); // 'C'
44
- * console.log(hashMap.get(99)); // undefined
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;
45
52
  * @example
46
- * // remove duplicates when adding multiple entries
47
- * const hashMap = new HashMap<number, string>();
48
- * hashMap.set(1, 'A');
49
- * hashMap.set(2, 'B');
50
- * hashMap.set(1, 'C'); // Update value for key 1
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;
51
63
  *
52
- * console.log(hashMap.size); // 2
53
- * console.log(hashMap.get(1)); // 'C'
54
- * console.log(hashMap.get(2)); // 'B'
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;
55
73
  * @example
56
- * // count occurrences of keys
57
- * const data = [1, 2, 1, 3, 2, 1];
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;
58
93
  *
59
- * const countMap = new HashMap<number, number>();
60
- * for (const key of data) {
61
- * countMap.set(key, (countMap.get(key) || 0) + 1);
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
+ * // HashMap for user session caching O(1) performance
100
+ * interface UserSession {
101
+ * userId: number;
102
+ * username: string;
103
+ * loginTime: number;
104
+ * lastActivity: number;
62
105
  * }
63
106
  *
64
- * console.log(countMap.get(1)); // 3
65
- * console.log(countMap.get(2)); // 2
66
- * console.log(countMap.get(3)); // 1
107
+ * // HashMap provides O(1) average-case performance for set/get/delete
108
+ * // Perfect for session management with fast lookups
109
+ * const sessionCache = new HashMap<string, UserSession>();
110
+ *
111
+ * // Simulate user sessions
112
+ * const sessions: [string, UserSession][] = [
113
+ * ['session_001', { userId: 1, username: 'alice', loginTime: 1000, lastActivity: 1050 }],
114
+ * ['session_002', { userId: 2, username: 'bob', loginTime: 1100, lastActivity: 1150 }],
115
+ * ['session_003', { userId: 3, username: 'charlie', loginTime: 1200, lastActivity: 1250 }]
116
+ * ];
117
+ *
118
+ * // Store sessions with O(1) insertion
119
+ * for (const [token, session] of sessions) {
120
+ * sessionCache.set(token, session);
121
+ * }
122
+ *
123
+ * console.log(sessionCache.size); // 3;
124
+ *
125
+ * // Retrieve session with O(1) lookup
126
+ * const userSession = sessionCache.get('session_001');
127
+ * console.log(userSession?.username); // 'alice';
128
+ * console.log(userSession?.userId); // 1;
129
+ *
130
+ * // Update session with O(1) operation
131
+ * if (userSession) {
132
+ * userSession.lastActivity = 2000;
133
+ * sessionCache.set('session_001', userSession);
134
+ * }
135
+ *
136
+ * // Check updated value
137
+ * const updated = sessionCache.get('session_001');
138
+ * console.log(updated?.lastActivity); // 2000;
139
+ *
140
+ * // Cleanup: delete expired sessions
141
+ * sessionCache.delete('session_002');
142
+ * console.log(sessionCache.has('session_002')); // false;
143
+ *
144
+ * // Verify remaining sessions
145
+ * console.log(sessionCache.size); // 2;
146
+ *
147
+ * // Get all active sessions
148
+ * const activeCount = [...sessionCache.values()].length;
149
+ * console.log(activeCount); // 2;
67
150
  */
68
151
  export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
69
152
  /**