min-heap-typed 2.0.4 → 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.
- package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +612 -879
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +6 -6
- package/dist/utils/utils.d.ts +110 -49
- package/dist/utils/utils.js +148 -73
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
- package/src/data-structures/binary-tree/avl-tree.ts +239 -206
- package/src/data-structures/binary-tree/binary-tree.ts +681 -905
- package/src/data-structures/binary-tree/bst.ts +568 -570
- package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
- package/src/data-structures/binary-tree/tree-counter.ts +199 -218
- package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +9 -5
- package/src/utils/utils.ts +152 -86
|
@@ -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
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param entryOrRawElements -
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
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
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
*
|
|
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
|
-
*
|
|
86
|
-
* @
|
|
87
|
-
*
|
|
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
|
-
*
|
|
93
|
-
* @
|
|
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
|
-
*
|
|
99
|
-
* @
|
|
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
|
-
*
|
|
105
|
-
*
|
|
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
|
-
*
|
|
112
|
-
*
|
|
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
|
-
*
|
|
130
|
-
*
|
|
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
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* @param
|
|
146
|
-
*
|
|
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
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
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
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
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
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
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
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
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
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
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
|
-
|
|
176
|
+
setHashFn(fn: (key: K) => string): this;
|
|
241
177
|
/**
|
|
242
|
-
*
|
|
243
|
-
* @
|
|
244
|
-
* @returns
|
|
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
|
-
|
|
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
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* @param
|
|
251
|
-
*
|
|
252
|
-
* @returns
|
|
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
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
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
|
-
*
|
|
265
|
-
* @
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
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
|
-
*
|
|
282
|
-
* @
|
|
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
|
-
*
|
|
288
|
-
* @
|
|
289
|
-
*
|
|
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
|
-
*
|
|
302
|
-
* @
|
|
303
|
-
*
|
|
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
|
-
*
|
|
309
|
-
* @
|
|
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
|
-
*
|
|
326
|
-
*
|
|
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
|
-
*
|
|
335
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
348
|
-
*
|
|
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
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
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
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
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
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
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
|
-
|
|
319
|
+
deleteWhere(predicate: (key: K, value: V | undefined, index: number, map: this) => boolean): boolean;
|
|
433
320
|
/**
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
* @
|
|
463
|
-
*
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
}
|