graph-typed 1.52.4 → 1.52.5
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 +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +27 -111
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +1 -54
- package/dist/data-structures/queue/queue.js +0 -53
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -72,10 +72,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
72
72
|
createEdge(v1, v2, weight, value) {
|
|
73
73
|
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, value);
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
77
|
-
* Space Complexity: O(1)
|
|
78
|
-
*/
|
|
79
75
|
/**
|
|
80
76
|
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
81
77
|
* Space Complexity: O(1)
|
|
@@ -99,10 +95,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
99
95
|
}
|
|
100
96
|
return edgeMap ? edgeMap[0] || undefined : undefined;
|
|
101
97
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
104
|
-
* Space Complexity: O(1)
|
|
105
|
-
*/
|
|
106
98
|
/**
|
|
107
99
|
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
108
100
|
* Space Complexity: O(1)
|
|
@@ -130,10 +122,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
130
122
|
}
|
|
131
123
|
return removed;
|
|
132
124
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
135
|
-
* Space Complexity: O(1)
|
|
136
|
-
*/
|
|
137
125
|
/**
|
|
138
126
|
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
139
127
|
* Space Complexity: O(1)
|
|
@@ -169,10 +157,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
169
157
|
return;
|
|
170
158
|
}
|
|
171
159
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
174
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
175
|
-
*/
|
|
176
160
|
/**
|
|
177
161
|
* Time Complexity: O(1) - Constant time for Map operations.
|
|
178
162
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -208,10 +192,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
208
192
|
}
|
|
209
193
|
return this._vertexMap.delete(vertexKey);
|
|
210
194
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Time Complexity: O(1)
|
|
213
|
-
* Space Complexity: O(1)
|
|
214
|
-
*/
|
|
215
195
|
/**
|
|
216
196
|
* Time Complexity: O(1)
|
|
217
197
|
* Space Complexity: O(1)
|
|
@@ -232,10 +212,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
232
212
|
return 0;
|
|
233
213
|
}
|
|
234
214
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Time Complexity: O(1)
|
|
237
|
-
* Space Complexity: O(1)
|
|
238
|
-
*/
|
|
239
215
|
/**
|
|
240
216
|
* Time Complexity: O(1)
|
|
241
217
|
* Space Complexity: O(1)
|
|
@@ -254,10 +230,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
254
230
|
return [];
|
|
255
231
|
}
|
|
256
232
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
259
|
-
* Space Complexity: O(|E|)
|
|
260
|
-
*/
|
|
261
233
|
/**
|
|
262
234
|
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
263
235
|
* Space Complexity: O(|E|)
|
|
@@ -274,10 +246,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
274
246
|
});
|
|
275
247
|
return [...edgeSet];
|
|
276
248
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
279
|
-
* Space Complexity: O(|E|)
|
|
280
|
-
*/
|
|
281
249
|
/**
|
|
282
250
|
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
283
251
|
* Space Complexity: O(|E|)
|
|
@@ -301,10 +269,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
301
269
|
}
|
|
302
270
|
return neighbors;
|
|
303
271
|
}
|
|
304
|
-
/**
|
|
305
|
-
* Time Complexity: O(1)
|
|
306
|
-
* Space Complexity: O(1)
|
|
307
|
-
*/
|
|
308
272
|
/**
|
|
309
273
|
* Time Complexity: O(1)
|
|
310
274
|
* Space Complexity: O(1)
|
|
@@ -335,10 +299,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
335
299
|
isEmpty() {
|
|
336
300
|
return this.vertexMap.size === 0 && this.edgeMap.size === 0;
|
|
337
301
|
}
|
|
338
|
-
/**
|
|
339
|
-
* Time Complexity: O(1)
|
|
340
|
-
* Space Complexity: O(1)
|
|
341
|
-
*/
|
|
342
302
|
/**
|
|
343
303
|
* Time Complexity: O(1)
|
|
344
304
|
* Space Complexity: O(1)
|
|
@@ -364,10 +324,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
364
324
|
cloned.edgeMap = new Map(this.edgeMap);
|
|
365
325
|
return cloned;
|
|
366
326
|
}
|
|
367
|
-
/**
|
|
368
|
-
* Time Complexity: O(1)
|
|
369
|
-
* Space Complexity: O(1)
|
|
370
|
-
*/
|
|
371
327
|
/**
|
|
372
328
|
* Time Complexity: O(V + E)
|
|
373
329
|
* Space Complexity: O(V)
|
|
@@ -428,12 +384,6 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
428
384
|
cutVertices
|
|
429
385
|
};
|
|
430
386
|
}
|
|
431
|
-
/**
|
|
432
|
-
* Time Complexity: O(V + E)
|
|
433
|
-
* Space Complexity: O(V)
|
|
434
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
435
|
-
* 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
|
|
436
|
-
*/
|
|
437
387
|
/**
|
|
438
388
|
* The function "getBridges" returns an array of bridges in a graph using the Tarjan's algorithm.
|
|
439
389
|
* @returns The function `getBridges()` is returning the bridges found using the Tarjan's algorithm.
|
|
@@ -123,8 +123,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
123
123
|
/**
|
|
124
124
|
* Time Complexity: O(n)
|
|
125
125
|
* Space Complexity: O(n)
|
|
126
|
-
|
|
127
|
-
/**
|
|
126
|
+
*
|
|
128
127
|
* The clone function creates a new HashMap with the same key-value pairs as
|
|
129
128
|
* this one. The clone function is useful for creating a copy of an existing
|
|
130
129
|
* HashMap, and then modifying that copy without affecting the original.
|
|
@@ -132,10 +131,6 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
132
131
|
* @return A new hashmap with the same values as this one
|
|
133
132
|
*/
|
|
134
133
|
clone(): HashMap<K, V, R>;
|
|
135
|
-
/**
|
|
136
|
-
* Time Complexity: O(n)
|
|
137
|
-
* Space Complexity: O(n)
|
|
138
|
-
*/
|
|
139
134
|
/**
|
|
140
135
|
* Time Complexity: O(n)
|
|
141
136
|
* Space Complexity: O(n)
|
|
@@ -168,15 +163,6 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
168
163
|
* from the original `HashMap` that pass the provided `predicate` function.
|
|
169
164
|
*/
|
|
170
165
|
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
|
|
171
|
-
/**
|
|
172
|
-
* The put function sets a value in a data structure using a specified key.
|
|
173
|
-
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
|
|
174
|
-
* to the function.
|
|
175
|
-
* @param {V} value - The value parameter represents the value that you want to associate with the
|
|
176
|
-
* specified key in the data structure.
|
|
177
|
-
* @returns The method is returning a boolean value.
|
|
178
|
-
*/
|
|
179
|
-
put(key: K, value: V): boolean;
|
|
180
166
|
/**
|
|
181
167
|
* The function returns an iterator that yields key-value pairs from both an object store and an
|
|
182
168
|
* object map.
|
|
@@ -213,7 +199,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
213
199
|
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
214
200
|
* properties:
|
|
215
201
|
*/
|
|
216
|
-
constructor(entryOrRawElements?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
|
|
202
|
+
constructor(entryOrRawElements?: Iterable<R | [K, V]>, options?: LinkedHashMapOptions<K, V, R>);
|
|
217
203
|
protected _hashFn: (key: K) => string;
|
|
218
204
|
/**
|
|
219
205
|
* The function returns the hash function used for generating a hash value for a given key.
|
|
@@ -253,22 +239,18 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
253
239
|
* @returns The `_tail` property of type `HashMapLinkedNode<K, V | undefined>` is being returned.
|
|
254
240
|
*/
|
|
255
241
|
get tail(): HashMapLinkedNode<K, V | undefined>;
|
|
256
|
-
protected _toEntryFn
|
|
242
|
+
protected _toEntryFn?: (rawElement: R) => [K, V];
|
|
257
243
|
/**
|
|
258
244
|
* The function returns the value of the _toEntryFn property.
|
|
259
245
|
* @returns The function being returned is `this._toEntryFn`.
|
|
260
246
|
*/
|
|
261
|
-
get toEntryFn(): (rawElement: R) => [K, V];
|
|
247
|
+
get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
|
|
262
248
|
protected _size: number;
|
|
263
249
|
/**
|
|
264
250
|
* The function returns the size of an object.
|
|
265
251
|
* @returns The size of the object.
|
|
266
252
|
*/
|
|
267
253
|
get size(): number;
|
|
268
|
-
/**
|
|
269
|
-
* Time Complexity: O(1)
|
|
270
|
-
* Space Complexity: O(1)
|
|
271
|
-
*/
|
|
272
254
|
/**
|
|
273
255
|
* Time Complexity: O(1)
|
|
274
256
|
* Space Complexity: O(1)
|
|
@@ -278,10 +260,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
278
260
|
* value (V).
|
|
279
261
|
*/
|
|
280
262
|
get first(): [K, V] | undefined;
|
|
281
|
-
/**
|
|
282
|
-
* Time Complexity: O(1)
|
|
283
|
-
* Space Complexity: O(1)
|
|
284
|
-
*/
|
|
285
263
|
/**
|
|
286
264
|
* Time Complexity: O(1)
|
|
287
265
|
* Space Complexity: O(1)
|
|
@@ -300,10 +278,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
300
278
|
* key and value.
|
|
301
279
|
*/
|
|
302
280
|
reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
|
|
303
|
-
/**
|
|
304
|
-
* Time Complexity: O(1)
|
|
305
|
-
* Space Complexity: O(1)
|
|
306
|
-
*/
|
|
307
281
|
/**
|
|
308
282
|
* Time Complexity: O(1)
|
|
309
283
|
* Space Complexity: O(1)
|
|
@@ -325,7 +299,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
325
299
|
* R.
|
|
326
300
|
* @returns The `setMany` function returns an array of booleans.
|
|
327
301
|
*/
|
|
328
|
-
setMany(entryOrRawElements: Iterable<R>): boolean[];
|
|
302
|
+
setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
|
|
329
303
|
/**
|
|
330
304
|
* The function checks if a given key exists in a map, using different logic depending on whether the
|
|
331
305
|
* key is a weak key or not.
|
|
@@ -333,10 +307,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
333
307
|
* @returns The method `has` is returning a boolean value.
|
|
334
308
|
*/
|
|
335
309
|
has(key: K): boolean;
|
|
336
|
-
/**
|
|
337
|
-
* Time Complexity: O(1)
|
|
338
|
-
* Space Complexity: O(1)
|
|
339
|
-
*/
|
|
340
310
|
/**
|
|
341
311
|
* Time Complexity: O(1)
|
|
342
312
|
* Space Complexity: O(1)
|
|
@@ -351,10 +321,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
351
321
|
* using the key itself. If the key is not found, `undefined` is
|
|
352
322
|
*/
|
|
353
323
|
get(key: K): V | undefined;
|
|
354
|
-
/**
|
|
355
|
-
* Time Complexity: O(n)
|
|
356
|
-
* Space Complexity: O(1)
|
|
357
|
-
*/
|
|
358
324
|
/**
|
|
359
325
|
* Time Complexity: O(n)
|
|
360
326
|
* Space Complexity: O(1)
|
|
@@ -367,10 +333,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
367
333
|
* where `K` is the key and `V` is the value.
|
|
368
334
|
*/
|
|
369
335
|
at(index: number): V | undefined;
|
|
370
|
-
/**
|
|
371
|
-
* Time Complexity: O(1)
|
|
372
|
-
* Space Complexity: O(1)
|
|
373
|
-
*/
|
|
374
336
|
/**
|
|
375
337
|
* Time Complexity: O(1)
|
|
376
338
|
* Space Complexity: O(1)
|
|
@@ -382,10 +344,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
382
344
|
* was not found.
|
|
383
345
|
*/
|
|
384
346
|
delete(key: K): boolean;
|
|
385
|
-
/**
|
|
386
|
-
* Time Complexity: O(n)
|
|
387
|
-
* Space Complexity: O(1)
|
|
388
|
-
*/
|
|
389
347
|
/**
|
|
390
348
|
* Time Complexity: O(n)
|
|
391
349
|
* Space Complexity: O(1)
|
|
@@ -396,10 +354,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
396
354
|
* @returns The size of the list after deleting the element at the specified index.
|
|
397
355
|
*/
|
|
398
356
|
deleteAt(index: number): boolean;
|
|
399
|
-
/**
|
|
400
|
-
* Time Complexity: O(1)
|
|
401
|
-
* Space Complexity: O(1)
|
|
402
|
-
*/
|
|
403
357
|
/**
|
|
404
358
|
* Time Complexity: O(1)
|
|
405
359
|
* Space Complexity: O(1)
|
|
@@ -416,10 +370,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
416
370
|
* @returns a boolean value.
|
|
417
371
|
*/
|
|
418
372
|
isEntry(rawElement: any): rawElement is [K, V];
|
|
419
|
-
/**
|
|
420
|
-
* Time Complexity: O(1)
|
|
421
|
-
* Space Complexity: O(1)
|
|
422
|
-
*/
|
|
423
373
|
/**
|
|
424
374
|
* Time Complexity: O(1)
|
|
425
375
|
* Space Complexity: O(1)
|
|
@@ -427,10 +377,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
427
377
|
* The `clear` function clears all the entries in a data structure and resets its properties.
|
|
428
378
|
*/
|
|
429
379
|
clear(): void;
|
|
430
|
-
/**
|
|
431
|
-
* Time Complexity: O(n)
|
|
432
|
-
* Space Complexity: O(n)
|
|
433
|
-
*/
|
|
434
380
|
/**
|
|
435
381
|
* Time Complexity: O(n)
|
|
436
382
|
* Space Complexity: O(n)
|
|
@@ -441,10 +387,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
441
387
|
* of the original `LinkedHashMap` object.
|
|
442
388
|
*/
|
|
443
389
|
clone(): LinkedHashMap<K, V>;
|
|
444
|
-
/**
|
|
445
|
-
* Time Complexity: O(n)
|
|
446
|
-
* Space Complexity: O(n)
|
|
447
|
-
*/
|
|
448
390
|
/**
|
|
449
391
|
* Time Complexity: O(n)
|
|
450
392
|
* Space Complexity: O(n)
|
|
@@ -461,10 +403,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
461
403
|
* `LinkedHashMap` object that satisfy the given predicate function.
|
|
462
404
|
*/
|
|
463
405
|
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
|
|
464
|
-
/**
|
|
465
|
-
* Time Complexity: O(n)
|
|
466
|
-
* Space Complexity: O(n)
|
|
467
|
-
*/
|
|
468
406
|
/**
|
|
469
407
|
* Time Complexity: O(n)
|
|
470
408
|
* Space Complexity: O(n)
|
|
@@ -483,27 +421,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
483
421
|
* function.
|
|
484
422
|
*/
|
|
485
423
|
map<VM>(callback: EntryCallback<K, V, VM>, thisArg?: any): LinkedHashMap<K, VM>;
|
|
486
|
-
/**
|
|
487
|
-
* Time Complexity: O(1)
|
|
488
|
-
* Space Complexity: O(1)
|
|
489
|
-
*/
|
|
490
|
-
/**
|
|
491
|
-
* Time Complexity: O(1)
|
|
492
|
-
* Space Complexity: O(1)
|
|
493
|
-
*
|
|
494
|
-
* The put function sets a value in a data structure using a specified key.
|
|
495
|
-
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
|
|
496
|
-
* to the function.
|
|
497
|
-
* @param {V} value - The value parameter represents the value that you want to associate with the
|
|
498
|
-
* specified key in the data structure.
|
|
499
|
-
* @returns The method is returning a boolean value.
|
|
500
|
-
*/
|
|
501
|
-
put(key: K, value: V): boolean;
|
|
502
|
-
/**
|
|
503
|
-
* Time Complexity: O(n)
|
|
504
|
-
* Space Complexity: O(1)
|
|
505
|
-
* where n is the number of entries in the LinkedHashMap.
|
|
506
|
-
*/
|
|
507
424
|
/**
|
|
508
425
|
* Time Complexity: O(n)
|
|
509
426
|
* Space Complexity: O(1)
|
|
@@ -512,10 +429,6 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
512
429
|
* The above function is an iterator that yields key-value pairs from a linked list.
|
|
513
430
|
*/
|
|
514
431
|
protected _getIterator(): Generator<[K, V], void, unknown>;
|
|
515
|
-
/**
|
|
516
|
-
* Time Complexity: O(1)
|
|
517
|
-
* Space Complexity: O(1)
|
|
518
|
-
*/
|
|
519
432
|
/**
|
|
520
433
|
* Time Complexity: O(1)
|
|
521
434
|
* Space Complexity: O(1)
|
|
@@ -139,8 +139,8 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
139
139
|
key = rawEle[0];
|
|
140
140
|
value = rawEle[1];
|
|
141
141
|
}
|
|
142
|
-
else if (this.
|
|
143
|
-
const item = this.
|
|
142
|
+
else if (this._toEntryFn) {
|
|
143
|
+
const item = this._toEntryFn(rawEle);
|
|
144
144
|
key = item[0];
|
|
145
145
|
value = item[1];
|
|
146
146
|
}
|
|
@@ -209,8 +209,7 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
209
209
|
/**
|
|
210
210
|
* Time Complexity: O(n)
|
|
211
211
|
* Space Complexity: O(n)
|
|
212
|
-
|
|
213
|
-
/**
|
|
212
|
+
*
|
|
214
213
|
* The clone function creates a new HashMap with the same key-value pairs as
|
|
215
214
|
* this one. The clone function is useful for creating a copy of an existing
|
|
216
215
|
* HashMap, and then modifying that copy without affecting the original.
|
|
@@ -218,12 +217,8 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
218
217
|
* @return A new hashmap with the same values as this one
|
|
219
218
|
*/
|
|
220
219
|
clone() {
|
|
221
|
-
return new HashMap(this, { hashFn: this.
|
|
220
|
+
return new HashMap(this, { hashFn: this._hashFn, toEntryFn: this._toEntryFn });
|
|
222
221
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Time Complexity: O(n)
|
|
225
|
-
* Space Complexity: O(n)
|
|
226
|
-
*/
|
|
227
222
|
/**
|
|
228
223
|
* Time Complexity: O(n)
|
|
229
224
|
* Space Complexity: O(n)
|
|
@@ -272,17 +267,6 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
272
267
|
}
|
|
273
268
|
return filteredMap;
|
|
274
269
|
}
|
|
275
|
-
/**
|
|
276
|
-
* The put function sets a value in a data structure using a specified key.
|
|
277
|
-
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
|
|
278
|
-
* to the function.
|
|
279
|
-
* @param {V} value - The value parameter represents the value that you want to associate with the
|
|
280
|
-
* specified key in the data structure.
|
|
281
|
-
* @returns The method is returning a boolean value.
|
|
282
|
-
*/
|
|
283
|
-
put(key, value) {
|
|
284
|
-
return this.set(key, value);
|
|
285
|
-
}
|
|
286
270
|
/**
|
|
287
271
|
* The function returns an iterator that yields key-value pairs from both an object store and an
|
|
288
272
|
* object map.
|
|
@@ -315,7 +299,7 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
315
299
|
const keyType = typeof key;
|
|
316
300
|
let strKey;
|
|
317
301
|
if (keyType !== 'string' && keyType !== 'number' && keyType !== 'symbol') {
|
|
318
|
-
strKey = this.
|
|
302
|
+
strKey = this._hashFn(key);
|
|
319
303
|
}
|
|
320
304
|
else {
|
|
321
305
|
if (keyType === 'number') {
|
|
@@ -374,10 +358,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
374
358
|
}
|
|
375
359
|
}
|
|
376
360
|
if (entryOrRawElements) {
|
|
377
|
-
|
|
378
|
-
const [key, value] = this.toEntryFn(el);
|
|
379
|
-
this.set(key, value);
|
|
380
|
-
}
|
|
361
|
+
this.setMany(entryOrRawElements);
|
|
381
362
|
}
|
|
382
363
|
}
|
|
383
364
|
/**
|
|
@@ -439,10 +420,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
439
420
|
get size() {
|
|
440
421
|
return this._size;
|
|
441
422
|
}
|
|
442
|
-
/**
|
|
443
|
-
* Time Complexity: O(1)
|
|
444
|
-
* Space Complexity: O(1)
|
|
445
|
-
*/
|
|
446
423
|
/**
|
|
447
424
|
* Time Complexity: O(1)
|
|
448
425
|
* Space Complexity: O(1)
|
|
@@ -456,10 +433,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
456
433
|
return;
|
|
457
434
|
return [this.head.key, this.head.value];
|
|
458
435
|
}
|
|
459
|
-
/**
|
|
460
|
-
* Time Complexity: O(1)
|
|
461
|
-
* Space Complexity: O(1)
|
|
462
|
-
*/
|
|
463
436
|
/**
|
|
464
437
|
* Time Complexity: O(1)
|
|
465
438
|
* Space Complexity: O(1)
|
|
@@ -494,10 +467,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
494
467
|
node = node.prev;
|
|
495
468
|
}
|
|
496
469
|
}
|
|
497
|
-
/**
|
|
498
|
-
* Time Complexity: O(1)
|
|
499
|
-
* Space Complexity: O(1)
|
|
500
|
-
*/
|
|
501
470
|
/**
|
|
502
471
|
* Time Complexity: O(1)
|
|
503
472
|
* Space Complexity: O(1)
|
|
@@ -514,7 +483,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
514
483
|
let node;
|
|
515
484
|
const isNewKey = !this.has(key); // Check if the key is new
|
|
516
485
|
if ((0, utils_1.isWeakKey)(key)) {
|
|
517
|
-
const hash = this.
|
|
486
|
+
const hash = this._objHashFn(key);
|
|
518
487
|
node = this.objMap.get(hash);
|
|
519
488
|
if (!node && isNewKey) {
|
|
520
489
|
// Create a new node
|
|
@@ -527,7 +496,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
527
496
|
}
|
|
528
497
|
}
|
|
529
498
|
else {
|
|
530
|
-
const hash = this.
|
|
499
|
+
const hash = this._hashFn(key);
|
|
531
500
|
node = this.noObjMap[hash];
|
|
532
501
|
if (!node && isNewKey) {
|
|
533
502
|
this.noObjMap[hash] = node = { key, value, prev: this.tail, next: this._sentinel };
|
|
@@ -564,8 +533,18 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
564
533
|
setMany(entryOrRawElements) {
|
|
565
534
|
const results = [];
|
|
566
535
|
for (const rawEle of entryOrRawElements) {
|
|
567
|
-
|
|
568
|
-
|
|
536
|
+
let key, value;
|
|
537
|
+
if (this.isEntry(rawEle)) {
|
|
538
|
+
key = rawEle[0];
|
|
539
|
+
value = rawEle[1];
|
|
540
|
+
}
|
|
541
|
+
else if (this._toEntryFn) {
|
|
542
|
+
const item = this._toEntryFn(rawEle);
|
|
543
|
+
key = item[0];
|
|
544
|
+
value = item[1];
|
|
545
|
+
}
|
|
546
|
+
if (key !== undefined && value !== undefined)
|
|
547
|
+
results.push(this.set(key, value));
|
|
569
548
|
}
|
|
570
549
|
return results;
|
|
571
550
|
}
|
|
@@ -577,18 +556,14 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
577
556
|
*/
|
|
578
557
|
has(key) {
|
|
579
558
|
if ((0, utils_1.isWeakKey)(key)) {
|
|
580
|
-
const hash = this.
|
|
559
|
+
const hash = this._objHashFn(key);
|
|
581
560
|
return this.objMap.has(hash);
|
|
582
561
|
}
|
|
583
562
|
else {
|
|
584
|
-
const hash = this.
|
|
563
|
+
const hash = this._hashFn(key);
|
|
585
564
|
return hash in this.noObjMap;
|
|
586
565
|
}
|
|
587
566
|
}
|
|
588
|
-
/**
|
|
589
|
-
* Time Complexity: O(1)
|
|
590
|
-
* Space Complexity: O(1)
|
|
591
|
-
*/
|
|
592
567
|
/**
|
|
593
568
|
* Time Complexity: O(1)
|
|
594
569
|
* Space Complexity: O(1)
|
|
@@ -604,20 +579,16 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
604
579
|
*/
|
|
605
580
|
get(key) {
|
|
606
581
|
if ((0, utils_1.isWeakKey)(key)) {
|
|
607
|
-
const hash = this.
|
|
582
|
+
const hash = this._objHashFn(key);
|
|
608
583
|
const node = this.objMap.get(hash);
|
|
609
584
|
return node ? node.value : undefined;
|
|
610
585
|
}
|
|
611
586
|
else {
|
|
612
|
-
const hash = this.
|
|
587
|
+
const hash = this._hashFn(key);
|
|
613
588
|
const node = this.noObjMap[hash];
|
|
614
589
|
return node ? node.value : undefined;
|
|
615
590
|
}
|
|
616
591
|
}
|
|
617
|
-
/**
|
|
618
|
-
* Time Complexity: O(n)
|
|
619
|
-
* Space Complexity: O(1)
|
|
620
|
-
*/
|
|
621
592
|
/**
|
|
622
593
|
* Time Complexity: O(n)
|
|
623
594
|
* Space Complexity: O(1)
|
|
@@ -637,10 +608,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
637
608
|
}
|
|
638
609
|
return node.value;
|
|
639
610
|
}
|
|
640
|
-
/**
|
|
641
|
-
* Time Complexity: O(1)
|
|
642
|
-
* Space Complexity: O(1)
|
|
643
|
-
*/
|
|
644
611
|
/**
|
|
645
612
|
* Time Complexity: O(1)
|
|
646
613
|
* Space Complexity: O(1)
|
|
@@ -654,7 +621,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
654
621
|
delete(key) {
|
|
655
622
|
let node;
|
|
656
623
|
if ((0, utils_1.isWeakKey)(key)) {
|
|
657
|
-
const hash = this.
|
|
624
|
+
const hash = this._objHashFn(key);
|
|
658
625
|
// Get nodes from WeakMap
|
|
659
626
|
node = this.objMap.get(hash);
|
|
660
627
|
if (!node) {
|
|
@@ -664,7 +631,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
664
631
|
this.objMap.delete(hash);
|
|
665
632
|
}
|
|
666
633
|
else {
|
|
667
|
-
const hash = this.
|
|
634
|
+
const hash = this._hashFn(key);
|
|
668
635
|
// Get nodes from noObjMap
|
|
669
636
|
node = this.noObjMap[hash];
|
|
670
637
|
if (!node) {
|
|
@@ -677,10 +644,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
677
644
|
this._deleteNode(node);
|
|
678
645
|
return true;
|
|
679
646
|
}
|
|
680
|
-
/**
|
|
681
|
-
* Time Complexity: O(n)
|
|
682
|
-
* Space Complexity: O(1)
|
|
683
|
-
*/
|
|
684
647
|
/**
|
|
685
648
|
* Time Complexity: O(n)
|
|
686
649
|
* Space Complexity: O(1)
|
|
@@ -698,10 +661,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
698
661
|
}
|
|
699
662
|
return this._deleteNode(node);
|
|
700
663
|
}
|
|
701
|
-
/**
|
|
702
|
-
* Time Complexity: O(1)
|
|
703
|
-
* Space Complexity: O(1)
|
|
704
|
-
*/
|
|
705
664
|
/**
|
|
706
665
|
* Time Complexity: O(1)
|
|
707
666
|
* Space Complexity: O(1)
|
|
@@ -722,10 +681,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
722
681
|
isEntry(rawElement) {
|
|
723
682
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
724
683
|
}
|
|
725
|
-
/**
|
|
726
|
-
* Time Complexity: O(1)
|
|
727
|
-
* Space Complexity: O(1)
|
|
728
|
-
*/
|
|
729
684
|
/**
|
|
730
685
|
* Time Complexity: O(1)
|
|
731
686
|
* Space Complexity: O(1)
|
|
@@ -737,10 +692,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
737
692
|
this._size = 0;
|
|
738
693
|
this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
|
|
739
694
|
}
|
|
740
|
-
/**
|
|
741
|
-
* Time Complexity: O(n)
|
|
742
|
-
* Space Complexity: O(n)
|
|
743
|
-
*/
|
|
744
695
|
/**
|
|
745
696
|
* Time Complexity: O(n)
|
|
746
697
|
* Space Complexity: O(n)
|
|
@@ -751,17 +702,13 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
751
702
|
* of the original `LinkedHashMap` object.
|
|
752
703
|
*/
|
|
753
704
|
clone() {
|
|
754
|
-
const cloned = new LinkedHashMap([], { hashFn: this.
|
|
705
|
+
const cloned = new LinkedHashMap([], { hashFn: this._hashFn, objHashFn: this._objHashFn });
|
|
755
706
|
for (const entry of this) {
|
|
756
707
|
const [key, value] = entry;
|
|
757
708
|
cloned.set(key, value);
|
|
758
709
|
}
|
|
759
710
|
return cloned;
|
|
760
711
|
}
|
|
761
|
-
/**
|
|
762
|
-
* Time Complexity: O(n)
|
|
763
|
-
* Space Complexity: O(n)
|
|
764
|
-
*/
|
|
765
712
|
/**
|
|
766
713
|
* Time Complexity: O(n)
|
|
767
714
|
* Space Complexity: O(n)
|
|
@@ -788,10 +735,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
788
735
|
}
|
|
789
736
|
return filteredMap;
|
|
790
737
|
}
|
|
791
|
-
/**
|
|
792
|
-
* Time Complexity: O(n)
|
|
793
|
-
* Space Complexity: O(n)
|
|
794
|
-
*/
|
|
795
738
|
/**
|
|
796
739
|
* Time Complexity: O(n)
|
|
797
740
|
* Space Complexity: O(n)
|
|
@@ -819,29 +762,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
819
762
|
}
|
|
820
763
|
return mappedMap;
|
|
821
764
|
}
|
|
822
|
-
/**
|
|
823
|
-
* Time Complexity: O(1)
|
|
824
|
-
* Space Complexity: O(1)
|
|
825
|
-
*/
|
|
826
|
-
/**
|
|
827
|
-
* Time Complexity: O(1)
|
|
828
|
-
* Space Complexity: O(1)
|
|
829
|
-
*
|
|
830
|
-
* The put function sets a value in a data structure using a specified key.
|
|
831
|
-
* @param {K} key - The key parameter is of type K, which represents the type of the key being passed
|
|
832
|
-
* to the function.
|
|
833
|
-
* @param {V} value - The value parameter represents the value that you want to associate with the
|
|
834
|
-
* specified key in the data structure.
|
|
835
|
-
* @returns The method is returning a boolean value.
|
|
836
|
-
*/
|
|
837
|
-
put(key, value) {
|
|
838
|
-
return this.set(key, value);
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Time Complexity: O(n)
|
|
842
|
-
* Space Complexity: O(1)
|
|
843
|
-
* where n is the number of entries in the LinkedHashMap.
|
|
844
|
-
*/
|
|
845
765
|
/**
|
|
846
766
|
* Time Complexity: O(n)
|
|
847
767
|
* Space Complexity: O(1)
|
|
@@ -856,10 +776,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
856
776
|
node = node.next;
|
|
857
777
|
}
|
|
858
778
|
}
|
|
859
|
-
/**
|
|
860
|
-
* Time Complexity: O(1)
|
|
861
|
-
* Space Complexity: O(1)
|
|
862
|
-
*/
|
|
863
779
|
/**
|
|
864
780
|
* Time Complexity: O(1)
|
|
865
781
|
* Space Complexity: O(1)
|