min-heap-typed 1.50.2 → 1.50.3
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-base.d.ts +6 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +46 -13
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +73 -15
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +35 -2
- package/dist/data-structures/binary-tree/tree-multimap.js +38 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +46 -13
- package/src/data-structures/binary-tree/rb-tree.ts +79 -18
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +42 -3
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
|
@@ -29,7 +29,7 @@ class UndirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
|
29
29
|
*/
|
|
30
30
|
constructor(v1, v2, weight, value) {
|
|
31
31
|
super(weight, value);
|
|
32
|
-
this.
|
|
32
|
+
this.endpoints = [v1, v2];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.UndirectedEdge = UndirectedEdge;
|
|
@@ -80,7 +80,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
80
80
|
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
81
81
|
* Space Complexity: O(1)
|
|
82
82
|
*
|
|
83
|
-
* The function `getEdge` returns the first edge that connects two
|
|
83
|
+
* The function `getEdge` returns the first edge that connects two endpoints, or undefined if no such edge exists.
|
|
84
84
|
* @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
85
85
|
* object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
86
86
|
* @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
@@ -94,7 +94,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
94
94
|
const vertex1 = this._getVertex(v1);
|
|
95
95
|
const vertex2 = this._getVertex(v2);
|
|
96
96
|
if (vertex1 && vertex2) {
|
|
97
|
-
edgeMap = (_a = this._edgeMap.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.
|
|
97
|
+
edgeMap = (_a = this._edgeMap.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.endpoints.includes(vertex2.key));
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
return edgeMap ? edgeMap[0] || undefined : undefined;
|
|
@@ -111,7 +111,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
111
111
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
112
112
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
113
113
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
114
|
-
* @returns the removed edge (EO) if it exists, or undefined if either of the
|
|
114
|
+
* @returns the removed edge (EO) if it exists, or undefined if either of the endpoints (VO) does not exist.
|
|
115
115
|
*/
|
|
116
116
|
deleteEdgeBetween(v1, v2) {
|
|
117
117
|
const vertex1 = this._getVertex(v1);
|
|
@@ -122,11 +122,11 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
122
122
|
const v1Edges = this._edgeMap.get(vertex1);
|
|
123
123
|
let removed = undefined;
|
|
124
124
|
if (v1Edges) {
|
|
125
|
-
removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.
|
|
125
|
+
removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.endpoints.includes(vertex2.key))[0] || undefined;
|
|
126
126
|
}
|
|
127
127
|
const v2Edges = this._edgeMap.get(vertex2);
|
|
128
128
|
if (v2Edges) {
|
|
129
|
-
(0, utils_1.arrayRemove)(v2Edges, (e) => e.
|
|
129
|
+
(0, utils_1.arrayRemove)(v2Edges, (e) => e.endpoints.includes(vertex1.key));
|
|
130
130
|
}
|
|
131
131
|
return removed;
|
|
132
132
|
}
|
|
@@ -138,7 +138,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
138
138
|
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
139
139
|
* Space Complexity: O(1)
|
|
140
140
|
*
|
|
141
|
-
* The function `deleteEdge` deletes an edge between two
|
|
141
|
+
* The function `deleteEdge` deletes an edge between two endpoints in a graph.
|
|
142
142
|
* @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
|
|
143
143
|
* either an edge object or a vertex key.
|
|
144
144
|
* @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
|
|
@@ -159,8 +159,8 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
|
-
oneSide = this._getVertex(edgeOrOneSideVertexKey.
|
|
163
|
-
otherSide = this._getVertex(edgeOrOneSideVertexKey.
|
|
162
|
+
oneSide = this._getVertex(edgeOrOneSideVertexKey.endpoints[0]);
|
|
163
|
+
otherSide = this._getVertex(edgeOrOneSideVertexKey.endpoints[1]);
|
|
164
164
|
}
|
|
165
165
|
if (oneSide && otherSide) {
|
|
166
166
|
return this.deleteEdgeBetween(oneSide, otherSide);
|
|
@@ -199,7 +199,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
199
199
|
const neighborEdges = this._edgeMap.get(neighbor);
|
|
200
200
|
if (neighborEdges) {
|
|
201
201
|
const restEdges = neighborEdges.filter(edge => {
|
|
202
|
-
return !edge.
|
|
202
|
+
return !edge.endpoints.includes(vertexKey);
|
|
203
203
|
});
|
|
204
204
|
this._edgeMap.set(neighbor, restEdges);
|
|
205
205
|
}
|
|
@@ -282,7 +282,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
282
282
|
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
283
283
|
* Space Complexity: O(|E|)
|
|
284
284
|
*
|
|
285
|
-
* The function "getNeighbors" returns an array of neighboring
|
|
285
|
+
* The function "getNeighbors" returns an array of neighboring endpoints for a given vertex or vertex ID.
|
|
286
286
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
287
287
|
* (`VertexKey`).
|
|
288
288
|
* @returns an array of vertexMap (VO[]).
|
|
@@ -293,7 +293,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
293
293
|
if (vertex) {
|
|
294
294
|
const neighborEdges = this.edgesOf(vertex);
|
|
295
295
|
for (const edge of neighborEdges) {
|
|
296
|
-
const neighbor = this._getVertex(edge.
|
|
296
|
+
const neighbor = this._getVertex(edge.endpoints.filter(e => e !== vertex.key)[0]);
|
|
297
297
|
if (neighbor) {
|
|
298
298
|
neighbors.push(neighbor);
|
|
299
299
|
}
|
|
@@ -309,18 +309,18 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
309
309
|
* Time Complexity: O(1)
|
|
310
310
|
* Space Complexity: O(1)
|
|
311
311
|
*
|
|
312
|
-
* The function "getEndsOfEdge" returns the
|
|
312
|
+
* The function "getEndsOfEdge" returns the endpoints at the ends of an edge if the edge exists in the graph, otherwise
|
|
313
313
|
* it returns undefined.
|
|
314
314
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
315
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
315
|
+
* @returns The function `getEndsOfEdge` returns an array containing two endpoints `[VO, VO]` if the edge exists in the
|
|
316
316
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
317
317
|
*/
|
|
318
318
|
getEndsOfEdge(edge) {
|
|
319
|
-
if (!this.hasEdge(edge.
|
|
319
|
+
if (!this.hasEdge(edge.endpoints[0], edge.endpoints[1])) {
|
|
320
320
|
return undefined;
|
|
321
321
|
}
|
|
322
|
-
const v1 = this._getVertex(edge.
|
|
323
|
-
const v2 = this._getVertex(edge.
|
|
322
|
+
const v1 = this._getVertex(edge.endpoints[0]);
|
|
323
|
+
const v2 = this._getVertex(edge.endpoints[1]);
|
|
324
324
|
if (v1 && v2) {
|
|
325
325
|
return [v1, v2];
|
|
326
326
|
}
|
|
@@ -335,6 +335,20 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
335
335
|
isEmpty() {
|
|
336
336
|
return this.vertexMap.size === 0 && this.edgeMap.size === 0;
|
|
337
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Time Complexity: O(1)
|
|
340
|
+
* Space Complexity: O(1)
|
|
341
|
+
*/
|
|
342
|
+
/**
|
|
343
|
+
* Time Complexity: O(1)
|
|
344
|
+
* Space Complexity: O(1)
|
|
345
|
+
*
|
|
346
|
+
* The clear function resets the vertex and edge maps to empty maps.
|
|
347
|
+
*/
|
|
348
|
+
clear() {
|
|
349
|
+
this._vertexMap = new Map();
|
|
350
|
+
this._edgeMap = new Map();
|
|
351
|
+
}
|
|
338
352
|
/**
|
|
339
353
|
* The clone function creates a new UndirectedGraph object and copies the
|
|
340
354
|
* vertexMap and edgeMap from this graph to the new one. This is done by
|
|
@@ -354,6 +368,100 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
354
368
|
* Time Complexity: O(1)
|
|
355
369
|
* Space Complexity: O(1)
|
|
356
370
|
*/
|
|
371
|
+
/**
|
|
372
|
+
* Time Complexity: O(V + E)
|
|
373
|
+
* Space Complexity: O(V)
|
|
374
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
375
|
+
* 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
|
|
376
|
+
*
|
|
377
|
+
* The function `tarjan` implements the Tarjan's algorithm to find bridges and cut vertices in a
|
|
378
|
+
* graph.
|
|
379
|
+
* @returns The function `tarjan()` returns an object with the following properties:
|
|
380
|
+
*/
|
|
381
|
+
tarjan() {
|
|
382
|
+
const dfnMap = new Map();
|
|
383
|
+
const lowMap = new Map();
|
|
384
|
+
const bridges = [];
|
|
385
|
+
const cutVertices = [];
|
|
386
|
+
let time = 0;
|
|
387
|
+
const dfs = (vertex, parent) => {
|
|
388
|
+
dfnMap.set(vertex, time);
|
|
389
|
+
lowMap.set(vertex, time);
|
|
390
|
+
time++;
|
|
391
|
+
const neighbors = this.getNeighbors(vertex);
|
|
392
|
+
let childCount = 0;
|
|
393
|
+
for (const neighbor of neighbors) {
|
|
394
|
+
if (!dfnMap.has(neighbor)) {
|
|
395
|
+
childCount++;
|
|
396
|
+
dfs(neighbor, vertex);
|
|
397
|
+
lowMap.set(vertex, Math.min(lowMap.get(vertex), lowMap.get(neighbor)));
|
|
398
|
+
if (lowMap.get(neighbor) > dfnMap.get(vertex)) {
|
|
399
|
+
// Found a bridge
|
|
400
|
+
const edge = this.getEdge(vertex, neighbor);
|
|
401
|
+
if (edge) {
|
|
402
|
+
bridges.push(edge);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (parent !== undefined && lowMap.get(neighbor) >= dfnMap.get(vertex)) {
|
|
406
|
+
// Found an articulation point
|
|
407
|
+
cutVertices.push(vertex);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else if (neighbor !== parent) {
|
|
411
|
+
lowMap.set(vertex, Math.min(lowMap.get(vertex), dfnMap.get(neighbor)));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (parent === undefined && childCount > 1) {
|
|
415
|
+
// Special case for root in DFS tree
|
|
416
|
+
cutVertices.push(vertex);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
for (const vertex of this.vertexMap.values()) {
|
|
420
|
+
if (!dfnMap.has(vertex)) {
|
|
421
|
+
dfs(vertex, undefined);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
dfnMap,
|
|
426
|
+
lowMap,
|
|
427
|
+
bridges,
|
|
428
|
+
cutVertices
|
|
429
|
+
};
|
|
430
|
+
}
|
|
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
|
+
/**
|
|
438
|
+
* The function "getBridges" returns an array of bridges in a graph using the Tarjan's algorithm.
|
|
439
|
+
* @returns The function `getBridges()` is returning the bridges found using the Tarjan's algorithm.
|
|
440
|
+
*/
|
|
441
|
+
getBridges() {
|
|
442
|
+
return this.tarjan().bridges;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* The function "getCutVertices" returns an array of cut vertices using the Tarjan's algorithm.
|
|
446
|
+
* @returns the cut vertices found using the Tarjan's algorithm.
|
|
447
|
+
*/
|
|
448
|
+
getCutVertices() {
|
|
449
|
+
return this.tarjan().cutVertices;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* The function returns the dfnMap property of the result of the tarjan() function.
|
|
453
|
+
* @returns the `dfnMap` property of the result of calling the `tarjan()` function.
|
|
454
|
+
*/
|
|
455
|
+
getDFNMap() {
|
|
456
|
+
return this.tarjan().dfnMap;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* The function returns the lowMap property of the result of the tarjan() function.
|
|
460
|
+
* @returns the lowMap property of the result of calling the tarjan() function.
|
|
461
|
+
*/
|
|
462
|
+
getLowMap() {
|
|
463
|
+
return this.tarjan().lowMap;
|
|
464
|
+
}
|
|
357
465
|
/**
|
|
358
466
|
* Time Complexity: O(1)
|
|
359
467
|
* Space Complexity: O(1)
|
|
@@ -363,7 +471,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
363
471
|
* @returns a boolean value.
|
|
364
472
|
*/
|
|
365
473
|
_addEdge(edge) {
|
|
366
|
-
for (const end of edge.
|
|
474
|
+
for (const end of edge.endpoints) {
|
|
367
475
|
const endVertex = this._getVertex(end);
|
|
368
476
|
if (endVertex === undefined)
|
|
369
477
|
return false;
|
|
@@ -14,10 +14,6 @@ import { IterableEntryBase } from '../base';
|
|
|
14
14
|
* 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
|
|
15
15
|
*/
|
|
16
16
|
export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
|
|
17
|
-
protected _store: {
|
|
18
|
-
[key: string]: HashMapStoreItem<K, V>;
|
|
19
|
-
};
|
|
20
|
-
protected _objMap: Map<object, V>;
|
|
21
17
|
/**
|
|
22
18
|
* The constructor function initializes a HashMap object with an optional initial collection and
|
|
23
19
|
* options.
|
|
@@ -26,25 +22,44 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
26
22
|
* @param [options] - The `options` parameter is an optional object that can contain two properties:
|
|
27
23
|
*/
|
|
28
24
|
constructor(rawCollection?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
|
|
25
|
+
protected _store: {
|
|
26
|
+
[key: string]: HashMapStoreItem<K, V>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The function returns the store object, which is a dictionary of HashMapStoreItem objects.
|
|
30
|
+
* @returns The store property is being returned. It is a dictionary-like object with string keys and
|
|
31
|
+
* values of type HashMapStoreItem<K, V>.
|
|
32
|
+
*/
|
|
33
|
+
get store(): {
|
|
34
|
+
[p: string]: HashMapStoreItem<K, V>;
|
|
35
|
+
};
|
|
36
|
+
protected _objMap: Map<object, V>;
|
|
37
|
+
/**
|
|
38
|
+
* The function returns the object map.
|
|
39
|
+
* @returns The `objMap` property is being returned, which is a `Map` object with keys of type
|
|
40
|
+
* `object` and values of type `V`.
|
|
41
|
+
*/
|
|
42
|
+
get objMap(): Map<object, V>;
|
|
29
43
|
protected _toEntryFn: (rawElement: R) => [K, V];
|
|
30
44
|
/**
|
|
31
45
|
* The function returns the value of the _toEntryFn property.
|
|
32
46
|
* @returns The function being returned is `this._toEntryFn`.
|
|
33
47
|
*/
|
|
34
48
|
get toEntryFn(): (rawElement: R) => [K, V];
|
|
35
|
-
/**
|
|
36
|
-
* The hasFn function is a function that takes in an item and returns a boolean
|
|
37
|
-
* indicating whether the item is contained within the hash table.
|
|
38
|
-
*
|
|
39
|
-
* @return The hash function
|
|
40
|
-
*/
|
|
41
|
-
get hasFn(): (key: K) => string;
|
|
42
49
|
protected _size: number;
|
|
43
50
|
/**
|
|
44
51
|
* The function returns the size of an object.
|
|
45
52
|
* @returns The size of the object, which is a number.
|
|
46
53
|
*/
|
|
47
54
|
get size(): number;
|
|
55
|
+
protected _hashFn: (key: K) => string;
|
|
56
|
+
/**
|
|
57
|
+
* The hasFn function is a function that takes in an item and returns a boolean
|
|
58
|
+
* indicating whether the item is contained within the hash table.
|
|
59
|
+
*
|
|
60
|
+
* @return The hash function
|
|
61
|
+
*/
|
|
62
|
+
get hashFn(): (key: K) => string;
|
|
48
63
|
/**
|
|
49
64
|
* The function checks if a given element is an array with exactly two elements.
|
|
50
65
|
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
|
|
@@ -104,6 +119,10 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
104
119
|
* successfully deleted from the map, and `false` if the key was not found in the map.
|
|
105
120
|
*/
|
|
106
121
|
delete(key: K): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Time Complexity: O(n)
|
|
124
|
+
* Space Complexity: O(n)
|
|
125
|
+
*/
|
|
107
126
|
/**
|
|
108
127
|
* The clone function creates a new HashMap with the same key-value pairs as
|
|
109
128
|
* this one. The clone function is useful for creating a copy of an existing
|
|
@@ -131,10 +150,6 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
131
150
|
* the provided callback function.
|
|
132
151
|
*/
|
|
133
152
|
map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
|
|
134
|
-
/**
|
|
135
|
-
* Time Complexity: O(n)
|
|
136
|
-
* Space Complexity: O(n)
|
|
137
|
-
*/
|
|
138
153
|
/**
|
|
139
154
|
* Time Complexity: O(n)
|
|
140
155
|
* Space Complexity: O(n)
|
|
@@ -166,8 +181,19 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
166
181
|
* object map.
|
|
167
182
|
*/
|
|
168
183
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
169
|
-
|
|
184
|
+
/**
|
|
185
|
+
* The function checks if a given key is an object or a function.
|
|
186
|
+
* @param {any} key - The parameter "key" can be of any type.
|
|
187
|
+
* @returns a boolean value.
|
|
188
|
+
*/
|
|
170
189
|
protected _isObjKey(key: any): key is object | ((...args: any[]) => any);
|
|
190
|
+
/**
|
|
191
|
+
* The function `_getNoObjKey` takes a key and returns a string representation of the key, handling
|
|
192
|
+
* different types of keys.
|
|
193
|
+
* @param {K} key - The `key` parameter is of type `K`, which represents the type of the key being
|
|
194
|
+
* passed to the `_getNoObjKey` function.
|
|
195
|
+
* @returns a string value.
|
|
196
|
+
*/
|
|
171
197
|
protected _getNoObjKey(key: K): string;
|
|
172
198
|
}
|
|
173
199
|
/**
|
|
@@ -176,10 +202,6 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
176
202
|
* 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
|
|
177
203
|
*/
|
|
178
204
|
export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
|
|
179
|
-
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
|
|
180
|
-
protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
|
|
181
|
-
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
182
|
-
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
183
205
|
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
184
206
|
/**
|
|
185
207
|
* The constructor initializes a LinkedHashMap object with an optional raw collection and options.
|
|
@@ -191,6 +213,45 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
191
213
|
* properties:
|
|
192
214
|
*/
|
|
193
215
|
constructor(rawCollection?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
|
|
216
|
+
protected _hashFn: (key: K) => string;
|
|
217
|
+
/**
|
|
218
|
+
* The function returns the hash function used for generating a hash value for a given key.
|
|
219
|
+
* @returns The hash function that takes a key of type K and returns a string.
|
|
220
|
+
*/
|
|
221
|
+
get hashFn(): (key: K) => string;
|
|
222
|
+
protected _objHashFn: (key: K) => object;
|
|
223
|
+
/**
|
|
224
|
+
* The function returns the object hash function.
|
|
225
|
+
* @returns The function `objHashFn` is being returned.
|
|
226
|
+
*/
|
|
227
|
+
get objHashFn(): (key: K) => object;
|
|
228
|
+
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
|
|
229
|
+
/**
|
|
230
|
+
* The function returns a record of HashMapLinkedNode objects with string keys.
|
|
231
|
+
* @returns The method is returning a Record object, which is a TypeScript type that represents an
|
|
232
|
+
* object with string keys and values that are HashMapLinkedNode objects with keys of type K and
|
|
233
|
+
* values of type V or undefined.
|
|
234
|
+
*/
|
|
235
|
+
get noObjMap(): Record<string, HashMapLinkedNode<K, V | undefined>>;
|
|
236
|
+
protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
|
|
237
|
+
/**
|
|
238
|
+
* The function returns the WeakMap object used to map objects to HashMapLinkedNode instances.
|
|
239
|
+
* @returns The `objMap` property is being returned.
|
|
240
|
+
*/
|
|
241
|
+
get objMap(): WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
|
|
242
|
+
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
243
|
+
/**
|
|
244
|
+
* The function returns the head node of a HashMapLinkedNode.
|
|
245
|
+
* @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
|
|
246
|
+
* value type `V | undefined`.
|
|
247
|
+
*/
|
|
248
|
+
get head(): HashMapLinkedNode<K, V | undefined>;
|
|
249
|
+
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
250
|
+
/**
|
|
251
|
+
* The function returns the tail node of a HashMapLinkedNode.
|
|
252
|
+
* @returns The `_tail` property of type `HashMapLinkedNode<K, V | undefined>` is being returned.
|
|
253
|
+
*/
|
|
254
|
+
get tail(): HashMapLinkedNode<K, V | undefined>;
|
|
194
255
|
protected _toEntryFn: (rawElement: R) => [K, V];
|
|
195
256
|
/**
|
|
196
257
|
* The function returns the value of the _toEntryFn property.
|
|
@@ -203,6 +264,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
203
264
|
* @returns The size of the object.
|
|
204
265
|
*/
|
|
205
266
|
get size(): number;
|
|
267
|
+
/**
|
|
268
|
+
* Time Complexity: O(1)
|
|
269
|
+
* Space Complexity: O(1)
|
|
270
|
+
*/
|
|
206
271
|
/**
|
|
207
272
|
* Time Complexity: O(1)
|
|
208
273
|
* Space Complexity: O(1)
|
|
@@ -212,6 +277,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
212
277
|
* value (V).
|
|
213
278
|
*/
|
|
214
279
|
get first(): [K, V] | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Time Complexity: O(1)
|
|
282
|
+
* Space Complexity: O(1)
|
|
283
|
+
*/
|
|
215
284
|
/**
|
|
216
285
|
* Time Complexity: O(1)
|
|
217
286
|
* Space Complexity: O(1)
|
|
@@ -230,6 +299,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
230
299
|
* key and value.
|
|
231
300
|
*/
|
|
232
301
|
reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
|
|
302
|
+
/**
|
|
303
|
+
* Time Complexity: O(1)
|
|
304
|
+
* Space Complexity: O(1)
|
|
305
|
+
*/
|
|
233
306
|
/**
|
|
234
307
|
* Time Complexity: O(1)
|
|
235
308
|
* Space Complexity: O(1)
|
|
@@ -259,6 +332,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
259
332
|
* @returns The method `has` is returning a boolean value.
|
|
260
333
|
*/
|
|
261
334
|
has(key: K): boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Time Complexity: O(1)
|
|
337
|
+
* Space Complexity: O(1)
|
|
338
|
+
*/
|
|
262
339
|
/**
|
|
263
340
|
* Time Complexity: O(1)
|
|
264
341
|
* Space Complexity: O(1)
|
|
@@ -274,7 +351,12 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
274
351
|
*/
|
|
275
352
|
get(key: K): V | undefined;
|
|
276
353
|
/**
|
|
277
|
-
* Time Complexity: O(n)
|
|
354
|
+
* Time Complexity: O(n)
|
|
355
|
+
* Space Complexity: O(1)
|
|
356
|
+
* /
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Time Complexity: O(n)
|
|
278
360
|
* Space Complexity: O(1)
|
|
279
361
|
*
|
|
280
362
|
* The function `at` retrieves the key-value pair at a specified index in a linked list.
|
|
@@ -286,6 +368,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
286
368
|
*/
|
|
287
369
|
at(index: number): V | undefined;
|
|
288
370
|
/**
|
|
371
|
+
* Time Complexity: O(1)
|
|
372
|
+
* Space Complexity: O(1)
|
|
373
|
+
* /
|
|
374
|
+
|
|
375
|
+
/**
|
|
289
376
|
* Time Complexity: O(1)
|
|
290
377
|
* Space Complexity: O(1)
|
|
291
378
|
*
|
|
@@ -297,6 +384,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
297
384
|
*/
|
|
298
385
|
delete(key: K): boolean;
|
|
299
386
|
/**
|
|
387
|
+
* Time Complexity: O(n)
|
|
388
|
+
* Space Complexity: O(1)
|
|
389
|
+
* /
|
|
390
|
+
|
|
391
|
+
/**
|
|
300
392
|
* Time Complexity: O(n)
|
|
301
393
|
* Space Complexity: O(1)
|
|
302
394
|
*
|
|
@@ -307,6 +399,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
307
399
|
*/
|
|
308
400
|
deleteAt(index: number): boolean;
|
|
309
401
|
/**
|
|
402
|
+
* Time Complexity: O(1)
|
|
403
|
+
* Space Complexity: O(1)
|
|
404
|
+
* /
|
|
405
|
+
|
|
406
|
+
/**
|
|
310
407
|
* Time Complexity: O(1)
|
|
311
408
|
* Space Complexity: O(1)
|
|
312
409
|
*
|
|
@@ -323,6 +420,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
323
420
|
*/
|
|
324
421
|
isEntry(rawElement: any): rawElement is [K, V];
|
|
325
422
|
/**
|
|
423
|
+
* Time Complexity: O(1)
|
|
424
|
+
* Space Complexity: O(1)
|
|
425
|
+
* /
|
|
426
|
+
|
|
427
|
+
/**
|
|
326
428
|
* Time Complexity: O(1)
|
|
327
429
|
* Space Complexity: O(1)
|
|
328
430
|
*
|
|
@@ -344,6 +446,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
344
446
|
*/
|
|
345
447
|
clone(): LinkedHashMap<K, V>;
|
|
346
448
|
/**
|
|
449
|
+
* Time Complexity: O(n)
|
|
450
|
+
* Space Complexity: O(n)
|
|
451
|
+
* /
|
|
452
|
+
|
|
453
|
+
/**
|
|
347
454
|
* Time Complexity: O(n)
|
|
348
455
|
* Space Complexity: O(n)
|
|
349
456
|
*
|
|
@@ -360,6 +467,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
360
467
|
*/
|
|
361
468
|
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
|
|
362
469
|
/**
|
|
470
|
+
* Time Complexity: O(n)
|
|
471
|
+
* Space Complexity: O(n)
|
|
472
|
+
* /
|
|
473
|
+
|
|
474
|
+
/**
|
|
363
475
|
* Time Complexity: O(n)
|
|
364
476
|
* Space Complexity: O(n)
|
|
365
477
|
*
|
|
@@ -393,9 +505,13 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
393
505
|
* @returns The method is returning a boolean value.
|
|
394
506
|
*/
|
|
395
507
|
put(key: K, value: V): boolean;
|
|
396
|
-
protected _hashFn: (key: K) => string;
|
|
397
|
-
protected _objHashFn: (key: K) => object;
|
|
398
508
|
/**
|
|
509
|
+
* Time Complexity: O(n)
|
|
510
|
+
* Space Complexity: O(1)
|
|
511
|
+
* where n is the number of entries in the LinkedHashMap.
|
|
512
|
+
* /
|
|
513
|
+
|
|
514
|
+
/**
|
|
399
515
|
* Time Complexity: O(n)
|
|
400
516
|
* Space Complexity: O(1)
|
|
401
517
|
* where n is the number of entries in the LinkedHashMap.
|
|
@@ -403,6 +519,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
403
519
|
* The above function is an iterator that yields key-value pairs from a linked list.
|
|
404
520
|
*/
|
|
405
521
|
protected _getIterator(): Generator<[K, V], void, unknown>;
|
|
522
|
+
/**
|
|
523
|
+
* Time Complexity: O(1)
|
|
524
|
+
* Space Complexity: O(1)
|
|
525
|
+
*/
|
|
406
526
|
/**
|
|
407
527
|
* Time Complexity: O(1)
|
|
408
528
|
* Space Complexity: O(1)
|