linked-list-typed 1.51.7 → 1.51.9
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/binary-tree/avl-tree-multi-map.d.ts +103 -74
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
- package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/data-structures/binary-tree/avl-tree.js +90 -71
- package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
- package/dist/data-structures/binary-tree/binary-tree.js +492 -392
- package/dist/data-structures/binary-tree/bst.d.ts +204 -251
- package/dist/data-structures/binary-tree/bst.js +256 -358
- package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
- package/dist/data-structures/binary-tree/rb-tree.js +111 -119
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/data-structures/graph/abstract-graph.js +10 -15
- package/dist/data-structures/hash/hash-map.d.ts +31 -38
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/heap/heap.d.ts +1 -3
- package/dist/data-structures/queue/deque.d.ts +2 -3
- package/dist/data-structures/queue/deque.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +1 -1
- package/dist/data-structures/trie/trie.js +1 -1
- package/dist/interfaces/binary-tree.d.ts +7 -7
- package/dist/types/common.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +10 -1
- package/dist/utils/utils.d.ts +2 -1
- package/dist/utils/utils.js +27 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
- package/src/data-structures/binary-tree/avl-tree.ts +109 -80
- package/src/data-structures/binary-tree/binary-tree.ts +556 -433
- package/src/data-structures/binary-tree/bst.ts +286 -375
- package/src/data-structures/binary-tree/rb-tree.ts +132 -125
- package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +42 -49
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/trie/trie.ts +2 -2
- package/src/interfaces/binary-tree.ts +11 -9
- package/src/types/common.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
- package/src/types/data-structures/binary-tree/bst.ts +6 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
|
@@ -397,9 +397,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
397
397
|
}
|
|
398
398
|
/**
|
|
399
399
|
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
/**
|
|
400
|
+
*/
|
|
401
|
+
/**
|
|
403
402
|
* Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
|
|
404
403
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
405
404
|
*/
|
|
@@ -525,9 +524,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
525
524
|
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
|
|
526
525
|
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
527
526
|
*
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
/**
|
|
527
|
+
*/
|
|
528
|
+
/**
|
|
531
529
|
* Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
|
|
532
530
|
* Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
|
|
533
531
|
*/
|
|
@@ -651,9 +649,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
651
649
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
652
650
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
653
651
|
* one to rest pairs
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
/**
|
|
652
|
+
*/
|
|
653
|
+
/**
|
|
657
654
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
658
655
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
659
656
|
*
|
|
@@ -758,9 +755,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
758
755
|
}
|
|
759
756
|
/**
|
|
760
757
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
/**
|
|
758
|
+
*/
|
|
759
|
+
/**
|
|
764
760
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
765
761
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
766
762
|
*/
|
|
@@ -776,9 +772,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
776
772
|
* Not support graph with negative weight cycle
|
|
777
773
|
* all pairs
|
|
778
774
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
/**
|
|
775
|
+
*/
|
|
776
|
+
/**
|
|
782
777
|
* Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
|
|
783
778
|
* Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
|
|
784
779
|
*
|
|
@@ -8,20 +8,21 @@
|
|
|
8
8
|
import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
|
|
9
9
|
import { IterableEntryBase } from '../base';
|
|
10
10
|
/**
|
|
11
|
-
* 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key
|
|
11
|
+
* 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key map to a value.
|
|
12
12
|
* 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
|
|
13
|
-
* 3. Unique Keys: Keys are unique.
|
|
13
|
+
* 3. Unique Keys: Keys are unique.
|
|
14
|
+
* If you try to insert another entry with the same key, the new one will replace the old entry.
|
|
14
15
|
* 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
|
|
15
16
|
*/
|
|
16
17
|
export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
|
|
17
18
|
/**
|
|
18
19
|
* The constructor function initializes a HashMap object with an optional initial collection and
|
|
19
20
|
* options.
|
|
20
|
-
* @param
|
|
21
|
+
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
|
|
21
22
|
* `T`. It is an optional parameter and its default value is an empty array `[]`.
|
|
22
23
|
* @param [options] - The `options` parameter is an optional object that can contain two properties:
|
|
23
24
|
*/
|
|
24
|
-
constructor(
|
|
25
|
+
constructor(entryOrRawElements?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
|
|
25
26
|
protected _store: {
|
|
26
27
|
[key: string]: HashMapStoreItem<K, V>;
|
|
27
28
|
};
|
|
@@ -40,12 +41,12 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
40
41
|
* `object` and values of type `V`.
|
|
41
42
|
*/
|
|
42
43
|
get objMap(): Map<object, V>;
|
|
43
|
-
protected _toEntryFn
|
|
44
|
+
protected _toEntryFn?: (rawElement: R) => [K, V];
|
|
44
45
|
/**
|
|
45
46
|
* The function returns the value of the _toEntryFn property.
|
|
46
47
|
* @returns The function being returned is `this._toEntryFn`.
|
|
47
48
|
*/
|
|
48
|
-
get toEntryFn(): (rawElement: R) => [K, V];
|
|
49
|
+
get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
|
|
49
50
|
protected _size: number;
|
|
50
51
|
/**
|
|
51
52
|
* The function returns the size of an object.
|
|
@@ -90,11 +91,11 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
90
91
|
/**
|
|
91
92
|
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value
|
|
92
93
|
* pair using a mapping function, and sets each key-value pair in the current object.
|
|
93
|
-
* @param
|
|
94
|
+
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
|
|
94
95
|
* `T`.
|
|
95
96
|
* @returns The `setMany` function is returning an array of booleans.
|
|
96
97
|
*/
|
|
97
|
-
setMany(
|
|
98
|
+
setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
|
|
98
99
|
/**
|
|
99
100
|
* The `get` function retrieves a value from a map based on a given key, either from an object map or
|
|
100
101
|
* a string map.
|
|
@@ -205,14 +206,14 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
205
206
|
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
206
207
|
/**
|
|
207
208
|
* The constructor initializes a LinkedHashMap object with an optional raw collection and options.
|
|
208
|
-
* @param
|
|
209
|
+
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements. It is
|
|
209
210
|
* used to initialize the HashMapLinked instance with key-value pairs. Each element in the
|
|
210
|
-
* `
|
|
211
|
+
* `entryOrRawElements` is converted to a key-value pair using the `toEntryFn` function (if provided) and
|
|
211
212
|
* then added to the HashMap
|
|
212
213
|
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
213
214
|
* properties:
|
|
214
215
|
*/
|
|
215
|
-
constructor(
|
|
216
|
+
constructor(entryOrRawElements?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
|
|
216
217
|
protected _hashFn: (key: K) => string;
|
|
217
218
|
/**
|
|
218
219
|
* The function returns the hash function used for generating a hash value for a given key.
|
|
@@ -243,7 +244,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
243
244
|
/**
|
|
244
245
|
* The function returns the head node of a HashMapLinkedNode.
|
|
245
246
|
* @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
|
|
246
|
-
* value type `V | undefined`.
|
|
247
|
+
* a value type `V | undefined`.
|
|
247
248
|
*/
|
|
248
249
|
get head(): HashMapLinkedNode<K, V | undefined>;
|
|
249
250
|
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
@@ -320,11 +321,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
320
321
|
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
|
|
321
322
|
* using a provided function, and sets each key-value pair in the current object, returning an array
|
|
322
323
|
* of booleans indicating the success of each set operation.
|
|
323
|
-
* @param
|
|
324
|
+
* @param entryOrRawElements - The entryOrRawElements parameter is an iterable collection of elements of type
|
|
324
325
|
* R.
|
|
325
326
|
* @returns The `setMany` function returns an array of booleans.
|
|
326
327
|
*/
|
|
327
|
-
setMany(
|
|
328
|
+
setMany(entryOrRawElements: Iterable<R>): boolean[];
|
|
328
329
|
/**
|
|
329
330
|
* The function checks if a given key exists in a map, using different logic depending on whether the
|
|
330
331
|
* key is a weak key or not.
|
|
@@ -353,9 +354,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
353
354
|
/**
|
|
354
355
|
* Time Complexity: O(n)
|
|
355
356
|
* Space Complexity: O(1)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
/**
|
|
357
|
+
*/
|
|
358
|
+
/**
|
|
359
359
|
* Time Complexity: O(n)
|
|
360
360
|
* Space Complexity: O(1)
|
|
361
361
|
*
|
|
@@ -370,9 +370,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
370
370
|
/**
|
|
371
371
|
* Time Complexity: O(1)
|
|
372
372
|
* Space Complexity: O(1)
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
/**
|
|
373
|
+
*/
|
|
374
|
+
/**
|
|
376
375
|
* Time Complexity: O(1)
|
|
377
376
|
* Space Complexity: O(1)
|
|
378
377
|
*
|
|
@@ -386,9 +385,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
386
385
|
/**
|
|
387
386
|
* Time Complexity: O(n)
|
|
388
387
|
* Space Complexity: O(1)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
/**
|
|
388
|
+
*/
|
|
389
|
+
/**
|
|
392
390
|
* Time Complexity: O(n)
|
|
393
391
|
* Space Complexity: O(1)
|
|
394
392
|
*
|
|
@@ -401,9 +399,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
401
399
|
/**
|
|
402
400
|
* Time Complexity: O(1)
|
|
403
401
|
* Space Complexity: O(1)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
/**
|
|
402
|
+
*/
|
|
403
|
+
/**
|
|
407
404
|
* Time Complexity: O(1)
|
|
408
405
|
* Space Complexity: O(1)
|
|
409
406
|
*
|
|
@@ -422,9 +419,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
422
419
|
/**
|
|
423
420
|
* Time Complexity: O(1)
|
|
424
421
|
* Space Complexity: O(1)
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
/**
|
|
422
|
+
*/
|
|
423
|
+
/**
|
|
428
424
|
* Time Complexity: O(1)
|
|
429
425
|
* Space Complexity: O(1)
|
|
430
426
|
*
|
|
@@ -448,9 +444,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
448
444
|
/**
|
|
449
445
|
* Time Complexity: O(n)
|
|
450
446
|
* Space Complexity: O(n)
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
/**
|
|
447
|
+
*/
|
|
448
|
+
/**
|
|
454
449
|
* Time Complexity: O(n)
|
|
455
450
|
* Space Complexity: O(n)
|
|
456
451
|
*
|
|
@@ -469,9 +464,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
469
464
|
/**
|
|
470
465
|
* Time Complexity: O(n)
|
|
471
466
|
* Space Complexity: O(n)
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
/**
|
|
467
|
+
*/
|
|
468
|
+
/**
|
|
475
469
|
* Time Complexity: O(n)
|
|
476
470
|
* Space Complexity: O(n)
|
|
477
471
|
*
|
|
@@ -509,9 +503,8 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
509
503
|
* Time Complexity: O(n)
|
|
510
504
|
* Space Complexity: O(1)
|
|
511
505
|
* where n is the number of entries in the LinkedHashMap.
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
/**
|
|
506
|
+
*/
|
|
507
|
+
/**
|
|
515
508
|
* Time Complexity: O(n)
|
|
516
509
|
* Space Complexity: O(1)
|
|
517
510
|
* where n is the number of entries in the LinkedHashMap.
|
|
@@ -4,32 +4,24 @@ exports.LinkedHashMap = exports.HashMap = void 0;
|
|
|
4
4
|
const base_1 = require("../base");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
/**
|
|
7
|
-
* 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key
|
|
7
|
+
* 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key map to a value.
|
|
8
8
|
* 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
|
|
9
|
-
* 3. Unique Keys: Keys are unique.
|
|
9
|
+
* 3. Unique Keys: Keys are unique.
|
|
10
|
+
* If you try to insert another entry with the same key, the new one will replace the old entry.
|
|
10
11
|
* 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
|
|
11
12
|
*/
|
|
12
13
|
class HashMap extends base_1.IterableEntryBase {
|
|
13
14
|
/**
|
|
14
15
|
* The constructor function initializes a HashMap object with an optional initial collection and
|
|
15
16
|
* options.
|
|
16
|
-
* @param
|
|
17
|
+
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
|
|
17
18
|
* `T`. It is an optional parameter and its default value is an empty array `[]`.
|
|
18
19
|
* @param [options] - The `options` parameter is an optional object that can contain two properties:
|
|
19
20
|
*/
|
|
20
|
-
constructor(
|
|
21
|
+
constructor(entryOrRawElements = [], options) {
|
|
21
22
|
super();
|
|
22
23
|
this._store = {};
|
|
23
24
|
this._objMap = new Map();
|
|
24
|
-
this._toEntryFn = (rawElement) => {
|
|
25
|
-
if (this.isEntry(rawElement)) {
|
|
26
|
-
// TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
|
|
27
|
-
return rawElement;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new Error("If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
25
|
this._size = 0;
|
|
34
26
|
this._hashFn = (key) => String(key);
|
|
35
27
|
if (options) {
|
|
@@ -41,8 +33,8 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
41
33
|
this._toEntryFn = toEntryFn;
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
|
-
if (
|
|
45
|
-
this.setMany(
|
|
36
|
+
if (entryOrRawElements) {
|
|
37
|
+
this.setMany(entryOrRawElements);
|
|
46
38
|
}
|
|
47
39
|
}
|
|
48
40
|
/**
|
|
@@ -137,24 +129,25 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
137
129
|
/**
|
|
138
130
|
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value
|
|
139
131
|
* pair using a mapping function, and sets each key-value pair in the current object.
|
|
140
|
-
* @param
|
|
132
|
+
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
|
|
141
133
|
* `T`.
|
|
142
134
|
* @returns The `setMany` function is returning an array of booleans.
|
|
143
135
|
*/
|
|
144
|
-
setMany(
|
|
136
|
+
setMany(entryOrRawElements) {
|
|
145
137
|
const results = [];
|
|
146
|
-
for (const rawEle of
|
|
138
|
+
for (const rawEle of entryOrRawElements) {
|
|
147
139
|
let key, value;
|
|
148
140
|
if (this.isEntry(rawEle)) {
|
|
149
141
|
key = rawEle[0];
|
|
150
142
|
value = rawEle[1];
|
|
151
143
|
}
|
|
152
|
-
else {
|
|
144
|
+
else if (this.toEntryFn) {
|
|
153
145
|
const item = this.toEntryFn(rawEle);
|
|
154
146
|
key = item[0];
|
|
155
147
|
value = item[1];
|
|
156
148
|
}
|
|
157
|
-
|
|
149
|
+
if (key !== undefined && value !== undefined)
|
|
150
|
+
results.push(this.set(key, value));
|
|
158
151
|
}
|
|
159
152
|
return results;
|
|
160
153
|
}
|
|
@@ -347,14 +340,14 @@ exports.HashMap = HashMap;
|
|
|
347
340
|
class LinkedHashMap extends base_1.IterableEntryBase {
|
|
348
341
|
/**
|
|
349
342
|
* The constructor initializes a LinkedHashMap object with an optional raw collection and options.
|
|
350
|
-
* @param
|
|
343
|
+
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements. It is
|
|
351
344
|
* used to initialize the HashMapLinked instance with key-value pairs. Each element in the
|
|
352
|
-
* `
|
|
345
|
+
* `entryOrRawElements` is converted to a key-value pair using the `toEntryFn` function (if provided) and
|
|
353
346
|
* then added to the HashMap
|
|
354
347
|
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
355
348
|
* properties:
|
|
356
349
|
*/
|
|
357
|
-
constructor(
|
|
350
|
+
constructor(entryOrRawElements = [], options) {
|
|
358
351
|
super();
|
|
359
352
|
this._hashFn = (key) => String(key);
|
|
360
353
|
this._objHashFn = (key) => key;
|
|
@@ -366,7 +359,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
366
359
|
return rawElement;
|
|
367
360
|
}
|
|
368
361
|
else {
|
|
369
|
-
throw new Error("If the provided
|
|
362
|
+
throw new Error("If the provided entryOrRawElements does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
|
|
370
363
|
}
|
|
371
364
|
};
|
|
372
365
|
this._size = 0;
|
|
@@ -382,8 +375,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
382
375
|
this._toEntryFn = toEntryFn;
|
|
383
376
|
}
|
|
384
377
|
}
|
|
385
|
-
if (
|
|
386
|
-
for (const el of
|
|
378
|
+
if (entryOrRawElements) {
|
|
379
|
+
for (const el of entryOrRawElements) {
|
|
387
380
|
const [key, value] = this.toEntryFn(el);
|
|
388
381
|
this.set(key, value);
|
|
389
382
|
}
|
|
@@ -422,7 +415,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
422
415
|
/**
|
|
423
416
|
* The function returns the head node of a HashMapLinkedNode.
|
|
424
417
|
* @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
|
|
425
|
-
* value type `V | undefined`.
|
|
418
|
+
* a value type `V | undefined`.
|
|
426
419
|
*/
|
|
427
420
|
get head() {
|
|
428
421
|
return this._head;
|
|
@@ -526,7 +519,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
526
519
|
const hash = this.objHashFn(key);
|
|
527
520
|
node = this.objMap.get(hash);
|
|
528
521
|
if (!node && isNewKey) {
|
|
529
|
-
// Create new node
|
|
522
|
+
// Create a new node
|
|
530
523
|
node = { key: hash, value, prev: this.tail, next: this._sentinel };
|
|
531
524
|
this.objMap.set(hash, node);
|
|
532
525
|
}
|
|
@@ -566,13 +559,13 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
566
559
|
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
|
|
567
560
|
* using a provided function, and sets each key-value pair in the current object, returning an array
|
|
568
561
|
* of booleans indicating the success of each set operation.
|
|
569
|
-
* @param
|
|
562
|
+
* @param entryOrRawElements - The entryOrRawElements parameter is an iterable collection of elements of type
|
|
570
563
|
* R.
|
|
571
564
|
* @returns The `setMany` function returns an array of booleans.
|
|
572
565
|
*/
|
|
573
|
-
setMany(
|
|
566
|
+
setMany(entryOrRawElements) {
|
|
574
567
|
const results = [];
|
|
575
|
-
for (const rawEle of
|
|
568
|
+
for (const rawEle of entryOrRawElements) {
|
|
576
569
|
const [key, value] = this.toEntryFn(rawEle);
|
|
577
570
|
results.push(this.set(key, value));
|
|
578
571
|
}
|
|
@@ -626,9 +619,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
626
619
|
/**
|
|
627
620
|
* Time Complexity: O(n)
|
|
628
621
|
* Space Complexity: O(1)
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
/**
|
|
622
|
+
*/
|
|
623
|
+
/**
|
|
632
624
|
* Time Complexity: O(n)
|
|
633
625
|
* Space Complexity: O(1)
|
|
634
626
|
*
|
|
@@ -650,9 +642,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
650
642
|
/**
|
|
651
643
|
* Time Complexity: O(1)
|
|
652
644
|
* Space Complexity: O(1)
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
/**
|
|
645
|
+
*/
|
|
646
|
+
/**
|
|
656
647
|
* Time Complexity: O(1)
|
|
657
648
|
* Space Complexity: O(1)
|
|
658
649
|
*
|
|
@@ -691,9 +682,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
691
682
|
/**
|
|
692
683
|
* Time Complexity: O(n)
|
|
693
684
|
* Space Complexity: O(1)
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
/**
|
|
685
|
+
*/
|
|
686
|
+
/**
|
|
697
687
|
* Time Complexity: O(n)
|
|
698
688
|
* Space Complexity: O(1)
|
|
699
689
|
*
|
|
@@ -713,9 +703,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
713
703
|
/**
|
|
714
704
|
* Time Complexity: O(1)
|
|
715
705
|
* Space Complexity: O(1)
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
/**
|
|
706
|
+
*/
|
|
707
|
+
/**
|
|
719
708
|
* Time Complexity: O(1)
|
|
720
709
|
* Space Complexity: O(1)
|
|
721
710
|
*
|
|
@@ -738,9 +727,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
738
727
|
/**
|
|
739
728
|
* Time Complexity: O(1)
|
|
740
729
|
* Space Complexity: O(1)
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
/**
|
|
730
|
+
*/
|
|
731
|
+
/**
|
|
744
732
|
* Time Complexity: O(1)
|
|
745
733
|
* Space Complexity: O(1)
|
|
746
734
|
*
|
|
@@ -775,9 +763,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
775
763
|
/**
|
|
776
764
|
* Time Complexity: O(n)
|
|
777
765
|
* Space Complexity: O(n)
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
/**
|
|
766
|
+
*/
|
|
767
|
+
/**
|
|
781
768
|
* Time Complexity: O(n)
|
|
782
769
|
* Space Complexity: O(n)
|
|
783
770
|
*
|
|
@@ -806,9 +793,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
806
793
|
/**
|
|
807
794
|
* Time Complexity: O(n)
|
|
808
795
|
* Space Complexity: O(n)
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
/**
|
|
796
|
+
*/
|
|
797
|
+
/**
|
|
812
798
|
* Time Complexity: O(n)
|
|
813
799
|
* Space Complexity: O(n)
|
|
814
800
|
*
|
|
@@ -857,9 +843,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
|
|
|
857
843
|
* Time Complexity: O(n)
|
|
858
844
|
* Space Complexity: O(1)
|
|
859
845
|
* where n is the number of entries in the LinkedHashMap.
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
/**
|
|
846
|
+
*/
|
|
847
|
+
/**
|
|
863
848
|
* Time Complexity: O(n)
|
|
864
849
|
* Space Complexity: O(1)
|
|
865
850
|
* where n is the number of entries in the LinkedHashMap.
|
|
@@ -57,9 +57,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
57
57
|
* @param elements
|
|
58
58
|
* @param options
|
|
59
59
|
*/
|
|
60
|
-
static heapify<E>(elements: Iterable<E>, options:
|
|
61
|
-
comparator: Comparator<E>;
|
|
62
|
-
}): Heap<E>;
|
|
60
|
+
static heapify<E>(elements: Iterable<E>, options: HeapOptions<E>): Heap<E>;
|
|
63
61
|
/**
|
|
64
62
|
* Time Complexity: O(log n)
|
|
65
63
|
* Space Complexity: O(1)
|
|
@@ -64,7 +64,7 @@ export declare class TrieNode {
|
|
|
64
64
|
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
65
65
|
* 9. Spell Check: Checking the spelling of words.
|
|
66
66
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
67
|
-
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
67
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
68
68
|
*/
|
|
69
69
|
export declare class Trie extends IterableElementBase<string, Trie> {
|
|
70
70
|
/**
|
|
@@ -73,7 +73,7 @@ exports.TrieNode = TrieNode;
|
|
|
73
73
|
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
74
74
|
* 9. Spell Check: Checking the spelling of words.
|
|
75
75
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
76
|
-
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
76
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
77
77
|
*/
|
|
78
78
|
class Trie extends base_1.IterableElementBase {
|
|
79
79
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, KeyOrNodeOrEntry } from '../types';
|
|
3
|
-
export interface IBinaryTree<K
|
|
4
|
-
createNode(key: K, value?:
|
|
5
|
-
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
6
|
-
add(
|
|
7
|
-
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V,
|
|
8
|
-
delete<C extends BTNCallback<
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, Comparable, KeyOrNodeOrEntry } from '../types';
|
|
3
|
+
export interface IBinaryTree<K extends Comparable, V = any, R = [K, V], NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
|
|
4
|
+
createNode(key: K, value?: NODE['value']): NODE;
|
|
5
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
6
|
+
add(keyOrNodeOrEntryOrRawElement: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
7
|
+
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
|
+
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
9
9
|
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type CP = 'LT' | 'EQ' | 'GT';
|
|
1
|
+
export type CP = 1 | -1 | 0;
|
|
3
2
|
/**
|
|
4
3
|
* Enum representing different loop types.
|
|
5
4
|
*
|
|
@@ -28,7 +27,7 @@ export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
|
|
|
28
27
|
export type BTNKeyOrNode<K, N> = K | null | undefined | N;
|
|
29
28
|
export type KeyOrNodeOrEntry<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
|
|
30
29
|
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
31
|
-
export type
|
|
30
|
+
export type BTNPureKeyOrNodeOrEntry<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
32
31
|
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
|
33
32
|
export type BinaryTreeDeleteResult<N> = {
|
|
34
33
|
deleted: N | null | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type AVLTreeMultiMapNodeNested<K extends Comparable, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeMultiMapNested<K extends Comparable, V, R, NODE extends AVLTreeMultiMapNode<K, V, NODE>> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type AVLTreeNodeNested<K extends Comparable, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeNested<K extends Comparable, V, R, NODE extends AVLTreeNode<K, V, NODE>> = AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|