min-heap-typed 2.0.5 → 2.1.0

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 (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +598 -869
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +1 -0
  64. package/dist/utils/utils.d.ts +1 -1
  65. package/dist/utils/utils.js +2 -1
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  72. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +664 -893
  74. package/src/data-structures/binary-tree/bst.ts +568 -570
  75. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  76. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +2 -0
  101. package/src/utils/utils.ts +9 -14
@@ -8,6 +8,11 @@
8
8
  import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
9
9
  import { IterableEntryBase } from '../base';
10
10
  /**
11
+ * Hash-based map. Supports object keys and custom hashing; offers O(1) average set/get/has.
12
+ * @remarks Time O(1), Space O(1)
13
+ * @template K
14
+ * @template V
15
+ * @template R
11
16
  * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key map to a value.
12
17
  * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
13
18
  * 3. Unique Keys: Keys are unique.
@@ -62,458 +67,279 @@ import { IterableEntryBase } from '../base';
62
67
  */
63
68
  export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
64
69
  /**
65
- * The constructor function initializes a HashMap object with an optional initial collection and
66
- * options.
67
- * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
68
- * `T`. It is an optional parameter and its default value is an empty array `[]`.
69
- * @param [options] - The `options` parameter is an optional object that can contain two properties:
70
+ * Create a HashMap and optionally bulk-insert entries.
71
+ * @remarks Time O(N), Space O(N)
72
+ * @param [entryOrRawElements] - Iterable of entries or raw elements to insert.
73
+ * @param [options] - Options: hash function and optional record-to-entry converter.
74
+ * @returns New HashMap instance.
70
75
  */
71
76
  constructor(entryOrRawElements?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
72
77
  protected _store: {
73
78
  [key: string]: HashMapStoreItem<K, V>;
74
79
  };
75
80
  /**
76
- * The function returns the store object, which is a dictionary of HashMapStoreItem objects.
77
- * @returns The store property is being returned. It is a dictionary-like object with string keys and
78
- * values of type HashMapStoreItem<K, V>.
81
+ * Get the internal store for non-object keys.
82
+ * @remarks Time O(1), Space O(1)
83
+ * @returns Internal record of string→{key,value}.
79
84
  */
80
85
  get store(): {
81
86
  [p: string]: HashMapStoreItem<K, V>;
82
87
  };
83
88
  protected _objMap: Map<object, V>;
84
89
  /**
85
- * The function returns the object map.
86
- * @returns The `objMap` property is being returned, which is a `Map` object with keys of type
87
- * `object` and values of type `V`.
90
+ * Get the internal Map used for object/function keys.
91
+ * @remarks Time O(1), Space O(1)
92
+ * @returns Map of object→value.
88
93
  */
89
94
  get objMap(): Map<object, V>;
90
95
  protected _toEntryFn?: (rawElement: R) => [K, V];
91
96
  /**
92
- * The function returns the value of the _toEntryFn property.
93
- * @returns The function being returned is `this._toEntryFn`.
97
+ * Get the raw→entry converter function if present.
98
+ * @remarks Time O(1), Space O(1)
99
+ * @returns Converter function or undefined.
94
100
  */
95
101
  get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
96
102
  protected _size: number;
97
103
  /**
98
- * The function returns the size of an object.
99
- * @returns The size of the object, which is a number.
104
+ * Get the number of distinct keys stored.
105
+ * @remarks Time O(1), Space O(1)
106
+ * @returns Current size.
100
107
  */
101
108
  get size(): number;
102
109
  protected _hashFn: (key: K) => string;
103
110
  /**
104
- * The hasFn function is a function that takes in an item and returns a boolean
105
- * indicating whether the item is contained within the hash table.
106
- *
107
- * @return The hash function
111
+ * Get the current hash function for non-object keys.
112
+ * @remarks Time O(1), Space O(1)
113
+ * @returns Hash function.
108
114
  */
109
115
  get hashFn(): (key: K) => string;
110
116
  /**
111
- * Time Complexity: O(1)
112
- * Space Complexity: O(1)
113
- *
114
- * The function checks if a given element is an array with exactly two elements.
115
- * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
116
- * data type.
117
- * @returns a boolean value.
118
- */
119
- isEntry(rawElement: any): rawElement is [K, V];
120
- /**
121
- * Time Complexity: O(1)
122
- * Space Complexity: O(1)
123
- *
124
- * The function checks if the size of an object is equal to zero and returns a boolean value.
125
- * @returns A boolean value indicating whether the size of the object is 0 or not.
117
+ * Check whether the map is empty.
118
+ * @remarks Time O(1), Space O(1)
119
+ * @returns True if size is 0.
126
120
  */
127
121
  isEmpty(): boolean;
128
122
  /**
129
- * Time Complexity: O(1)
130
- * Space Complexity: O(1)
131
- *
132
- * The clear() function resets the state of an object by clearing its internal store, object map, and
133
- * size.
123
+ * Remove all entries and reset counters.
124
+ * @remarks Time O(N), Space O(1)
125
+ * @returns void
134
126
  */
135
127
  clear(): void;
136
128
  /**
137
- * Time Complexity: O(1)
138
- * Space Complexity: O(1)
139
- *
140
- * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
141
- * the key is not already present.
142
- * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
143
- * can be of any type, but if it is an object, it will be stored in a Map, otherwise it will be
144
- * stored in a regular JavaScript object.
145
- * @param {V} value - The value parameter represents the value that you want to associate with the
146
- * key in the data structure.
129
+ * Type guard: check if a raw value is a [key, value] entry.
130
+ * @remarks Time O(1), Space O(1)
131
+ * @returns True if the value is a 2-tuple.
132
+ */
133
+ isEntry(rawElement: any): rawElement is [K, V];
134
+ /**
135
+ * Insert or replace a single entry.
136
+ * @remarks Time O(1), Space O(1)
137
+ * @param key - Key.
138
+ * @param value - Value.
139
+ * @returns True when the operation succeeds.
147
140
  */
148
141
  set(key: K, value: V): boolean;
149
142
  /**
150
- * Time Complexity: O(k)
151
- * Space Complexity: O(k)
152
- *
153
- * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
154
- * pair using a mapping function, and sets each key-value pair in the current object.
155
- * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
156
- * `T`.
157
- * @returns The `setMany` function is returning an array of booleans.
143
+ * Insert many entries from an iterable.
144
+ * @remarks Time O(N), Space O(N)
145
+ * @param entryOrRawElements - Iterable of entries or raw elements to insert.
146
+ * @returns Array of per-entry results.
158
147
  */
159
148
  setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
160
149
  /**
161
- * Time Complexity: O(1)
162
- * Space Complexity: O(1)
163
- *
164
- * The `get` function retrieves a value from a map based on a given key, either from an object map or
165
- * a string map.
166
- * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
167
- * of any type, but it should be compatible with the key type used when the map was created.
168
- * @returns The method `get(key: K)` returns a value of type `V` if the key exists in the `_objMap`
169
- * or `_store`, otherwise it returns `undefined`.
150
+ * Get the value for a key.
151
+ * @remarks Time O(1), Space O(1)
152
+ * @param key - Key to look up.
153
+ * @returns Value or undefined.
170
154
  */
171
155
  get(key: K): V | undefined;
172
156
  /**
173
- * Time Complexity: O(1)
174
- * Space Complexity: O(1)
175
- *
176
- * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
177
- * is an object key or not.
178
- * @param {K} key - The parameter "key" is of type K, which means it can be any type.
179
- * @returns The `has` method is returning a boolean value.
157
+ * Check if a key exists.
158
+ * @remarks Time O(1), Space O(1)
159
+ * @param key - Key to test.
160
+ * @returns True if present.
180
161
  */
181
162
  has(key: K): boolean;
182
163
  /**
183
- * Time Complexity: O(1)
184
- * Space Complexity: O(1)
185
- *
186
- * The `delete` function removes an element from a map-like data structure based on the provided key.
187
- * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
188
- * data structure.
189
- * @returns The `delete` method returns a boolean value. It returns `true` if the key was
190
- * successfully deleted from the map, and `false` if the key was not found in the map.
164
+ * Delete an entry by key.
165
+ * @remarks Time O(1), Space O(1)
166
+ * @param key - Key to delete.
167
+ * @returns True if the key was found and removed.
191
168
  */
192
169
  delete(key: K): boolean;
193
170
  /**
194
- * Time Complexity: O(n)
195
- * Space Complexity: O(n)
196
- *
197
- * The clone function creates a new HashMap with the same key-value pairs as
198
- * this one. The clone function is useful for creating a copy of an existing
199
- * HashMap, and then modifying that copy without affecting the original.
200
- *
201
- * @return A new hashmap with the same values as this one
202
- */
203
- clone(): HashMap<K, V, R>;
204
- /**
205
- * Time Complexity: O(n)
206
- * Space Complexity: O(n)
207
- *
208
- * The `map` function in TypeScript creates a new HashMap by applying a callback function to each
209
- * key-value pair in the original HashMap.
210
- * @param callbackfn - The callback function that will be called for each key-value pair in the
211
- * HashMap. It takes four parameters:
212
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
213
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
214
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
215
- * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
216
- * the provided callback function.
217
- */
218
- map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): HashMap<K, VM>;
219
- /**
220
- * Time Complexity: O(n)
221
- * Space Complexity: O(n)
222
- *
223
- * The `filter` function creates a new HashMap containing key-value pairs from the original HashMap
224
- * that satisfy a given predicate function.
225
- * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
226
- * index, and map. It is used to determine whether an element should be included in the filtered map
227
- * or not. The function should return a boolean value - true if the element should be included, and
228
- * false otherwise.
229
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
230
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
231
- * passed as the `this` value to the `predicate` function. If `thisArg` is
232
- * @returns The `filter` method is returning a new `HashMap` object that contains the key-value pairs
233
- * from the original `HashMap` that pass the provided `predicate` function.
234
- */
235
- filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
236
- /**
237
- * The function returns an iterator that yields key-value pairs from both an object store and an
238
- * object map.
171
+ * Replace the hash function and rehash the non-object store.
172
+ * @remarks Time O(N), Space O(N)
173
+ * @param fn - New hash function for non-object keys.
174
+ * @returns This map instance.
239
175
  */
240
- protected _getIterator(): IterableIterator<[K, V]>;
176
+ setHashFn(fn: (key: K) => string): this;
241
177
  /**
242
- * The function checks if a given key is an object or a function.
243
- * @param {any} key - The parameter "key" can be of any type.
244
- * @returns a boolean value.
178
+ * Deep clone this map, preserving hashing behavior.
179
+ * @remarks Time O(N), Space O(N)
180
+ * @returns A new map with the same content.
245
181
  */
246
- protected _isObjKey(key: any): key is object | ((...args: any[]) => any);
182
+ clone(): this;
183
+ /**
184
+ * Map values to a new map with the same keys.
185
+ * @remarks Time O(N), Space O(N)
186
+ * @template VM
187
+ * @param callbackfn - Mapping function (key, value, index, map) → newValue.
188
+ * @param [thisArg] - Value for `this` inside the callback.
189
+ * @returns A new map with transformed values.
190
+ */
191
+ map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): any;
247
192
  /**
248
- * The function `_getNoObjKey` takes a key and returns a string representation of the key, handling
249
- * different types of keys.
250
- * @param {K} key - The `key` parameter is of type `K`, which represents the type of the key being
251
- * passed to the `_getNoObjKey` function.
252
- * @returns a string value.
193
+ * Filter entries into a new map.
194
+ * @remarks Time O(N), Space O(N)
195
+ * @param predicate - Predicate (key, value, index, map) boolean.
196
+ * @param [thisArg] - Value for `this` inside the predicate.
197
+ * @returns A new map containing entries that satisfied the predicate.
253
198
  */
199
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): any;
200
+ /**
201
+ * (Protected) Create a like-kind instance and seed it from an iterable.
202
+ * @remarks Time O(N), Space O(N)
203
+ * @template TK
204
+ * @template TV
205
+ * @template TR
206
+ * @param [entries] - Iterable used to seed the new map.
207
+ * @param [options] - Options forwarded to the constructor.
208
+ * @returns A like-kind map instance.
209
+ */
210
+ protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?: any): any;
211
+ protected _rehashNoObj(): void;
212
+ protected _getIterator(): IterableIterator<[K, V]>;
213
+ protected _isObjKey(key: any): key is object | ((...args: any[]) => any);
254
214
  protected _getNoObjKey(key: K): string;
255
215
  }
256
216
  /**
257
- * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which entries are inserted. Therefore, when you traverse it, entries will be returned in the order they were inserted into the map.
258
- * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of entries through the linked list.
259
- * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
217
+ * Hash-based map that preserves insertion order via a doubly-linked list.
218
+ * @remarks Time O(1), Space O(1)
219
+ * @template K
220
+ * @template V
221
+ * @template R
222
+ * @example examples will be generated by unit test
260
223
  */
261
224
  export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
262
225
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
263
226
  /**
264
- * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
265
- * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements. It is
266
- * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
267
- * `entryOrRawElements` is converted to a key-value pair using the `toEntryFn` function (if provided) and
268
- * then added to the HashMap
269
- * @param [options] - The `options` parameter is an optional object that can contain the following
270
- * properties:
227
+ * Create a LinkedHashMap and optionally bulk-insert entries.
228
+ * @remarks Time O(N), Space O(N)
229
+ * @param [entryOrRawElements] - Iterable of entries or raw elements to insert.
230
+ * @param [options] - Options: hash functions and optional record-to-entry converter.
231
+ * @returns New LinkedHashMap instance.
271
232
  */
272
233
  constructor(entryOrRawElements?: Iterable<R | [K, V]>, options?: LinkedHashMapOptions<K, V, R>);
273
234
  protected _hashFn: (key: K) => string;
274
- /**
275
- * The function returns the hash function used for generating a hash value for a given key.
276
- * @returns The hash function that takes a key of type K and returns a string.
277
- */
278
235
  get hashFn(): (key: K) => string;
279
236
  protected _objHashFn: (key: K) => object;
280
237
  /**
281
- * The function returns the object hash function.
282
- * @returns The function `objHashFn` is being returned.
238
+ * Get the hash function for object/weak keys.
239
+ * @remarks Time O(1), Space O(1)
240
+ * @returns Object-hash function.
283
241
  */
284
242
  get objHashFn(): (key: K) => object;
285
243
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
286
244
  /**
287
- * The function returns a record of HashMapLinkedNode objects with string keys.
288
- * @returns The method is returning a Record object, which is a TypeScript type that represents an
289
- * object with string keys and values that are HashMapLinkedNode objects with keys of type K and
290
- * values of type V or undefined.
245
+ * Get the internal record for non-object keys.
246
+ * @remarks Time O(1), Space O(1)
247
+ * @returns Record of hash→node.
291
248
  */
292
249
  get noObjMap(): Record<string, HashMapLinkedNode<K, V | undefined>>;
293
250
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
294
- /**
295
- * The function returns the WeakMap object used to map objects to HashMapLinkedNode instances.
296
- * @returns The `objMap` property is being returned.
297
- */
298
251
  get objMap(): WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
299
252
  protected _head: HashMapLinkedNode<K, V | undefined>;
300
253
  /**
301
- * The function returns the head node of a HashMapLinkedNode.
302
- * @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
303
- * a value type `V | undefined`.
254
+ * Get the head node (first entry) sentinel link.
255
+ * @remarks Time O(1), Space O(1)
256
+ * @returns Head node or sentinel.
304
257
  */
305
258
  get head(): HashMapLinkedNode<K, V | undefined>;
306
259
  protected _tail: HashMapLinkedNode<K, V | undefined>;
307
260
  /**
308
- * The function returns the tail node of a HashMapLinkedNode.
309
- * @returns The `_tail` property of type `HashMapLinkedNode<K, V | undefined>` is being returned.
261
+ * Get the tail node (last entry) sentinel link.
262
+ * @remarks Time O(1), Space O(1)
263
+ * @returns Tail node or sentinel.
310
264
  */
311
265
  get tail(): HashMapLinkedNode<K, V | undefined>;
312
266
  protected _toEntryFn?: (rawElement: R) => [K, V];
313
- /**
314
- * The function returns the value of the _toEntryFn property.
315
- * @returns The function being returned is `this._toEntryFn`.
316
- */
317
267
  get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
318
268
  protected _size: number;
319
- /**
320
- * The function returns the size of an object.
321
- * @returns The size of the object.
322
- */
323
269
  get size(): number;
324
270
  /**
325
- * Time Complexity: O(1)
326
- * Space Complexity: O(1)
327
- *
328
- * The function returns the key-value pair at the front of a data structure.
329
- * @returns The front element of the data structure, represented as a tuple with a key (K) and a
330
- * value (V).
271
+ * Get the first [key, value] pair.
272
+ * @remarks Time O(1), Space O(1)
273
+ * @returns First entry or undefined when empty.
331
274
  */
332
275
  get first(): [K, V] | undefined;
333
276
  /**
334
- * Time Complexity: O(1)
335
- * Space Complexity: O(1)
336
- *
337
- * The function returns the key-value pair at the end of a data structure.
338
- * @returns The method is returning an array containing the key-value pair of the tail element in the
339
- * data structure.
277
+ * Get the last [key, value] pair.
278
+ * @remarks Time O(1), Space O(1)
279
+ * @returns Last entry or undefined when empty.
340
280
  */
341
281
  get last(): [K, V] | undefined;
342
282
  /**
343
- * The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
283
+ * Iterate from head tail.
284
+ * @remarks Time O(N), Space O(1)
285
+ * @returns Iterator of [key, value].
344
286
  */
345
287
  begin(): Generator<(K | V | undefined)[], void, unknown>;
346
288
  /**
347
- * The function `reverseBegin()` iterates over a linked list in reverse order, yielding each node's
348
- * key and value.
289
+ * Iterate from tail head.
290
+ * @remarks Time O(N), Space O(1)
291
+ * @returns Iterator of [key, value].
349
292
  */
350
293
  reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
351
294
  /**
352
- * Time Complexity: O(1)
353
- * Space Complexity: O(1)
354
- *
355
- * The `set` function adds a new key-value pair to a data structure, either using an object key or a
356
- * string key.
357
- * @param {K} key - The `key` parameter is the key to be set in the data structure. It can be of any
358
- * type, but typically it is a string or symbol.
359
- * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
360
- * value associated with the key being set in the data structure.
361
- * @returns the size of the data structure after the key-value pair has been set.
295
+ * Insert or replace a single entry; preserves insertion order.
296
+ * @remarks Time O(1), Space O(1)
297
+ * @param key - Key.
298
+ * @param [value] - Value.
299
+ * @returns True when the operation succeeds.
362
300
  */
363
301
  set(key: K, value?: V): boolean;
364
- /**
365
- * Time Complexity: O(k)
366
- * Space Complexity: O(k)
367
- *
368
- * The function `setMany` takes an iterable collection, converts each element into a key-value pair
369
- * using a provided function, and sets each key-value pair in the current object, returning an array
370
- * of booleans indicating the success of each set operation.
371
- * @param entryOrRawElements - The entryOrRawElements parameter is an iterable collection of elements of type
372
- * R.
373
- * @returns The `setMany` function returns an array of booleans.
374
- */
375
302
  setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
376
- /**
377
- * Time Complexity: O(1)
378
- * Space Complexity: O(1)
379
- *
380
- * The function checks if a given key exists in a map, using different logic depending on whether the
381
- * key is a weak key or not.
382
- * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
383
- * @returns The method `has` is returning a boolean value.
384
- */
385
303
  has(key: K): boolean;
386
- /**
387
- * Time Complexity: O(1)
388
- * Space Complexity: O(1)
389
- *
390
- * The function `get` retrieves the value associated with a given key from a map, either by using the
391
- * key directly or by using an index stored in the key object.
392
- * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
393
- * of any type, but typically it is a string or symbol.
394
- * @returns The value associated with the given key is being returned. If the key is an object key,
395
- * the value is retrieved from the `_nodes` array using the index stored in the `OBJ_KEY_INDEX`
396
- * property of the key. If the key is a string key, the value is retrieved from the `_noObjMap` object
397
- * using the key itself. If the key is not found, `undefined` is
398
- */
399
304
  get(key: K): V | undefined;
400
305
  /**
401
- * Time Complexity: O(n)
402
- * Space Complexity: O(1)
403
- *
404
- * The function `at` retrieves the key-value pair at a specified index in a linked list.
405
- * @param {number} index - The index parameter is a number that represents the position of the
406
- * element we want to retrieve from the data structure.
407
- * @returns The method `at(index: number)` is returning an array containing the key-value pair at
408
- * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
409
- * where `K` is the key and `V` is the value.
306
+ * Get the value at a given index in insertion order.
307
+ * @remarks Time O(N), Space O(1)
308
+ * @param index - Zero-based index.
309
+ * @returns Value at the index.
410
310
  */
411
311
  at(index: number): V | undefined;
412
- /**
413
- * Time Complexity: O(1)
414
- * Space Complexity: O(1)
415
- *
416
- * The `delete` function removes a key-value pair from a map-like data structure.
417
- * @param {K} key - The `key` parameter is the key that you want to delete from the data structure.
418
- * It can be of any type, but typically it is a string or an object.
419
- * @returns a boolean value. It returns `true` if the deletion was successful, and `false` if the key
420
- * was not found.
421
- */
422
312
  delete(key: K): boolean;
423
313
  /**
424
- * Time Complexity: O(n)
425
- * Space Complexity: O(1)
426
- *
427
- * The `deleteAt` function deletes a node at a specified index in a linked list.
428
- * @param {number} index - The index parameter represents the position at which the node should be
429
- * deleted in the linked list.
430
- * @returns The size of the list after deleting the element at the specified index.
314
+ * Delete the first entry that matches a predicate.
315
+ * @remarks Time O(N), Space O(1)
316
+ * @param predicate - Function (key, value, index, map) → boolean to decide deletion.
317
+ * @returns True if an entry was removed.
431
318
  */
432
- deleteAt(index: number): boolean;
319
+ deleteWhere(predicate: (key: K, value: V | undefined, index: number, map: this) => boolean): boolean;
433
320
  /**
434
- * Time Complexity: O(1)
435
- * Space Complexity: O(1)
436
- *
437
- * The function checks if a data structure is empty by comparing its size to zero.
438
- * @returns The method is returning a boolean value indicating whether the size of the object is 0 or
439
- * not.
321
+ * Delete the entry at a given index.
322
+ * @remarks Time O(N), Space O(1)
323
+ * @param index - Zero-based index.
324
+ * @returns True if removed.
440
325
  */
326
+ deleteAt(index: number): boolean;
441
327
  isEmpty(): boolean;
442
- /**
443
- * The function checks if a given element is an array with exactly two elements.
444
- * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
445
- * data type.
446
- * @returns a boolean value.
447
- */
448
328
  isEntry(rawElement: any): rawElement is [K, V];
449
- /**
450
- * Time Complexity: O(1)
451
- * Space Complexity: O(1)
452
- *
453
- * The `clear` function clears all the entries in a data structure and resets its properties.
454
- */
455
329
  clear(): void;
456
- /**
457
- * Time Complexity: O(n)
458
- * Space Complexity: O(n)
459
- *
460
- * The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
461
- * the original.
462
- * @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
463
- * of the original `LinkedHashMap` object.
464
- */
465
- clone(): LinkedHashMap<K, V>;
466
- /**
467
- * Time Complexity: O(n)
468
- * Space Complexity: O(n)
469
- *
470
- * The `filter` function creates a new `LinkedHashMap` containing key-value pairs from the original
471
- * map that satisfy a given predicate function.
472
- * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
473
- * `value`, `key`, `index`, and `this`. It should return a boolean value indicating whether the
474
- * current element should be included in the filtered map or not.
475
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
476
- * specify the value of `this` within the `predicate` function. It is used when you want to bind a
477
- * specific object as the context for the `predicate` function. If `thisArg` is not provided, `this
478
- * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
479
- * `LinkedHashMap` object that satisfy the given predicate function.
480
- */
481
- filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
482
- /**
483
- * Time Complexity: O(n)
484
- * Space Complexity: O(n)
485
- *
486
- * The `map` function in TypeScript creates a new `LinkedHashMap` by applying a callback function to
487
- * each key-value pair in the original map.
488
- * @param callback - The callback parameter is a function that will be called for each key-value pair
489
- * in the map. It takes four arguments: the value of the current key-value pair, the key of the
490
- * current key-value pair, the index of the current key-value pair, and the map itself. The callback
491
- * function should
492
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
493
- * specify the value of `this` within the callback function. If provided, the callback function will
494
- * be called with `thisArg` as its `this` value. If not provided, `this` will refer to the current
495
- * map
496
- * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
497
- * function.
498
- */
499
- map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: any): LinkedHashMap<MK, MV>;
500
- /**
501
- * Time Complexity: O(n)
502
- * Space Complexity: O(1)
503
- * where n is the number of entries in the LinkedHashMap.
504
- *
505
- * The above function is an iterator that yields key-value pairs from a linked list.
506
- */
507
- protected _getIterator(): Generator<[K, V], void, unknown>;
508
- /**
509
- * Time Complexity: O(1)
510
- * Space Complexity: O(1)
511
- *
512
- * The `_deleteNode` function removes a node from a doubly linked list and updates the head and tail
513
- * pointers if necessary.
514
- * @param node - The `node` parameter is an instance of the `HashMapLinkedNode` class, which
515
- * represents a node in a linked list. It contains a key-value pair and references to the previous
516
- * and next nodes in the list.
517
- */
330
+ clone(): any;
331
+ filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): any;
332
+ /**
333
+ * Map each entry to a new [key, value] pair and preserve order.
334
+ * @remarks Time O(N), Space O(N)
335
+ * @template MK
336
+ * @template MV
337
+ * @param callback - Mapping function (key, value, index, map) → [newKey, newValue].
338
+ * @param [thisArg] - Value for `this` inside the callback.
339
+ * @returns A new map of the same class with transformed entries.
340
+ */
341
+ map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: any): any;
342
+ protected _getIterator(): IterableIterator<[K, V]>;
518
343
  protected _deleteNode(node: HashMapLinkedNode<K, V | undefined>): boolean;
344
+ protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries?: Iterable<[TK, TV] | TR>, options?: any): any;
519
345
  }