data-structure-typed 1.50.1 → 1.50.2
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/CHANGELOG.md +2 -1
- package/README.md +26 -26
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +153 -159
- package/dist/cjs/data-structures/base/iterable-base.d.ts +114 -9
- package/dist/cjs/data-structures/base/iterable-base.js +143 -7
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/cjs/data-structures/binary-tree/bst.js +30 -71
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +26 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/cjs/data-structures/graph/map-graph.js +14 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +25 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/cjs/data-structures/hash/hash-map.js +160 -25
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +66 -6
- package/dist/cjs/data-structures/heap/heap.js +66 -6
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/cjs/data-structures/matrix/matrix.js +50 -11
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +49 -19
- package/dist/cjs/data-structures/queue/deque.js +101 -47
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +39 -5
- package/dist/cjs/data-structures/queue/queue.js +47 -5
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +16 -0
- package/dist/cjs/data-structures/stack/stack.js +22 -0
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +38 -1
- package/dist/cjs/data-structures/trie/trie.js +41 -0
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/cjs/types/utils/utils.d.ts +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +114 -9
- package/dist/mjs/data-structures/base/iterable-base.js +143 -7
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/mjs/data-structures/binary-tree/bst.js +30 -71
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +26 -0
- package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/mjs/data-structures/graph/map-graph.js +14 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/mjs/data-structures/graph/undirected-graph.js +25 -0
- package/dist/mjs/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/mjs/data-structures/hash/hash-map.js +160 -25
- package/dist/mjs/data-structures/heap/heap.d.ts +66 -6
- package/dist/mjs/data-structures/heap/heap.js +66 -6
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/mjs/data-structures/matrix/matrix.js +50 -11
- package/dist/mjs/data-structures/queue/deque.d.ts +49 -19
- package/dist/mjs/data-structures/queue/deque.js +101 -47
- package/dist/mjs/data-structures/queue/queue.d.ts +39 -5
- package/dist/mjs/data-structures/queue/queue.js +47 -5
- package/dist/mjs/data-structures/stack/stack.d.ts +16 -0
- package/dist/mjs/data-structures/stack/stack.js +22 -0
- package/dist/mjs/data-structures/trie/trie.d.ts +38 -1
- package/dist/mjs/data-structures/trie/trie.js +41 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/mjs/types/utils/utils.d.ts +1 -0
- package/dist/umd/data-structure-typed.js +1730 -1042
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +8 -3
- package/src/data-structures/base/iterable-base.ts +172 -19
- package/src/data-structures/binary-tree/avl-tree.ts +97 -97
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +89 -131
- package/src/data-structures/binary-tree/rb-tree.ts +127 -155
- package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +28 -0
- package/src/data-structures/hash/hash-map.ts +175 -34
- package/src/data-structures/heap/heap.ts +66 -6
- package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
- package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/queue/deque.ts +108 -49
- package/src/data-structures/queue/queue.ts +51 -5
- package/src/data-structures/stack/stack.ts +24 -0
- package/src/data-structures/trie/trie.ts +45 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +3 -3
- package/test/performance/data-structures/queue/deque.test.ts +26 -25
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
- package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
- package/test/unit/data-structures/graph/abstract-graph.test.ts +8 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +249 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
- package/test/unit/data-structures/heap/heap.test.ts +18 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +65 -5
- package/test/unit/data-structures/queue/queue.test.ts +22 -5
- package/test/unit/data-structures/stack/stack.test.ts +17 -0
- package/test/unit/data-structures/trie/trie.test.ts +17 -0
|
@@ -24,6 +24,10 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
24
24
|
*/
|
|
25
25
|
constructor(elements?: Iterable<E>);
|
|
26
26
|
protected _elements: E[];
|
|
27
|
+
/**
|
|
28
|
+
* The elements function returns the elements of this set.
|
|
29
|
+
* @return An array of elements
|
|
30
|
+
*/
|
|
27
31
|
get elements(): E[];
|
|
28
32
|
/**
|
|
29
33
|
* Time Complexity: O(n), where n is the number of elements in the input array. Similar to the constructor, it requires iterating through each element.
|
|
@@ -87,6 +91,18 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
87
91
|
* array is empty, it returns `undefined`.
|
|
88
92
|
*/
|
|
89
93
|
pop(): E | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* The delete function removes an element from the stack.
|
|
96
|
+
* @param element: E Specify the element to be deleted
|
|
97
|
+
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
98
|
+
*/
|
|
99
|
+
delete(element: E): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* The deleteAt function deletes the element at a given index.
|
|
102
|
+
* @param index: number Determine the index of the element to be deleted
|
|
103
|
+
* @return A boolean value
|
|
104
|
+
*/
|
|
105
|
+
deleteAt(index: number): boolean;
|
|
90
106
|
/**
|
|
91
107
|
* Time Complexity: O(n)
|
|
92
108
|
* Space Complexity: O(n)
|
|
@@ -25,6 +25,10 @@ class Stack extends base_1.IterableElementBase {
|
|
|
25
25
|
this.push(el);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The elements function returns the elements of this set.
|
|
30
|
+
* @return An array of elements
|
|
31
|
+
*/
|
|
28
32
|
get elements() {
|
|
29
33
|
return this._elements;
|
|
30
34
|
}
|
|
@@ -107,6 +111,24 @@ class Stack extends base_1.IterableElementBase {
|
|
|
107
111
|
return;
|
|
108
112
|
return this.elements.pop();
|
|
109
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The delete function removes an element from the stack.
|
|
116
|
+
* @param element: E Specify the element to be deleted
|
|
117
|
+
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
118
|
+
*/
|
|
119
|
+
delete(element) {
|
|
120
|
+
const index = this.elements.indexOf(element);
|
|
121
|
+
return this.deleteAt(index);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The deleteAt function deletes the element at a given index.
|
|
125
|
+
* @param index: number Determine the index of the element to be deleted
|
|
126
|
+
* @return A boolean value
|
|
127
|
+
*/
|
|
128
|
+
deleteAt(index) {
|
|
129
|
+
const spliced = this.elements.splice(index, 1);
|
|
130
|
+
return spliced.length === 1;
|
|
131
|
+
}
|
|
110
132
|
/**
|
|
111
133
|
* Time Complexity: O(n)
|
|
112
134
|
* Space Complexity: O(n)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;;;;;GAOG;AACH,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG;IACH,YAAY,WAAwB,EAAE;QACpC,KAAK,EAAE,CAAC;QAMA,cAAS,GAAQ,EAAE,CAAC;QAL5B,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,EAAE,IAAI,QAAQ;gBAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IAEH;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAI,QAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACH,IAAI;QACF,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,SAAS,CAAC;QAErC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,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|
31
31
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
32
32
|
*/
|
|
33
|
-
export declare class Trie extends IterableElementBase<string> {
|
|
33
|
+
export declare class Trie extends IterableElementBase<string, Trie> {
|
|
34
|
+
/**
|
|
35
|
+
* The constructor function for the Trie class.
|
|
36
|
+
* @param words: Iterable string Initialize the trie with a set of words
|
|
37
|
+
* @param options?: TrieOptions Allow the user to pass in options for the trie
|
|
38
|
+
* @return This
|
|
39
|
+
*/
|
|
34
40
|
constructor(words?: Iterable<string>, options?: TrieOptions);
|
|
35
41
|
protected _size: number;
|
|
42
|
+
/**
|
|
43
|
+
* The size function returns the size of the stack.
|
|
44
|
+
* @return The number of elements in the list
|
|
45
|
+
*/
|
|
36
46
|
get size(): number;
|
|
37
47
|
protected _caseSensitive: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
|
|
50
|
+
*
|
|
51
|
+
* @return The value of the _casesensitive private variable
|
|
52
|
+
*/
|
|
38
53
|
get caseSensitive(): boolean;
|
|
39
54
|
protected _root: TrieNode;
|
|
55
|
+
/**
|
|
56
|
+
* The root function returns the root node of the tree.
|
|
57
|
+
* @return The root node
|
|
58
|
+
*/
|
|
40
59
|
get root(): TrieNode;
|
|
41
60
|
/**
|
|
42
61
|
* Time Complexity: O(M), where M is the length of the word being added.
|
|
@@ -64,6 +83,11 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
64
83
|
* @returns {boolean} True if the word is present in the Trie.
|
|
65
84
|
*/
|
|
66
85
|
has(word: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* The isEmpty function checks if the size of the queue is 0.
|
|
88
|
+
* @return True if the size of the queue is 0
|
|
89
|
+
*/
|
|
90
|
+
isEmpty(): boolean;
|
|
67
91
|
/**
|
|
68
92
|
* Time Complexity: O(M), where M is the length of the word being deleted.
|
|
69
93
|
* Space Complexity: O(M) - Due to the recursive DFS approach.
|
|
@@ -154,6 +178,19 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
154
178
|
* @returns {string[]} an array of strings.
|
|
155
179
|
*/
|
|
156
180
|
getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
|
|
181
|
+
/**
|
|
182
|
+
* Time Complexity: O(n)
|
|
183
|
+
* Space Complexity: O(n)
|
|
184
|
+
*/
|
|
185
|
+
/**
|
|
186
|
+
* Time Complexity: O(n)
|
|
187
|
+
* Space Complexity: O(n)
|
|
188
|
+
*
|
|
189
|
+
* The `clone` function returns a new instance of the Trie class with the same values and case
|
|
190
|
+
* sensitivity as the original Trie.
|
|
191
|
+
* @returns A new instance of the Trie class is being returned.
|
|
192
|
+
*/
|
|
193
|
+
clone(): Trie;
|
|
157
194
|
/**
|
|
158
195
|
* Time Complexity: O(n)
|
|
159
196
|
* Space Complexity: O(n)
|
|
@@ -28,6 +28,12 @@ exports.TrieNode = TrieNode;
|
|
|
28
28
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
29
29
|
*/
|
|
30
30
|
class Trie extends base_1.IterableElementBase {
|
|
31
|
+
/**
|
|
32
|
+
* The constructor function for the Trie class.
|
|
33
|
+
* @param words: Iterable string Initialize the trie with a set of words
|
|
34
|
+
* @param options?: TrieOptions Allow the user to pass in options for the trie
|
|
35
|
+
* @return This
|
|
36
|
+
*/
|
|
31
37
|
constructor(words = [], options) {
|
|
32
38
|
super();
|
|
33
39
|
this._size = 0;
|
|
@@ -43,12 +49,25 @@ class Trie extends base_1.IterableElementBase {
|
|
|
43
49
|
this.add(word);
|
|
44
50
|
}
|
|
45
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* The size function returns the size of the stack.
|
|
54
|
+
* @return The number of elements in the list
|
|
55
|
+
*/
|
|
46
56
|
get size() {
|
|
47
57
|
return this._size;
|
|
48
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
|
|
61
|
+
*
|
|
62
|
+
* @return The value of the _casesensitive private variable
|
|
63
|
+
*/
|
|
49
64
|
get caseSensitive() {
|
|
50
65
|
return this._caseSensitive;
|
|
51
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The root function returns the root node of the tree.
|
|
69
|
+
* @return The root node
|
|
70
|
+
*/
|
|
52
71
|
get root() {
|
|
53
72
|
return this._root;
|
|
54
73
|
}
|
|
@@ -106,6 +125,13 @@ class Trie extends base_1.IterableElementBase {
|
|
|
106
125
|
}
|
|
107
126
|
return cur.isEnd;
|
|
108
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* The isEmpty function checks if the size of the queue is 0.
|
|
130
|
+
* @return True if the size of the queue is 0
|
|
131
|
+
*/
|
|
132
|
+
isEmpty() {
|
|
133
|
+
return this.size === 0;
|
|
134
|
+
}
|
|
109
135
|
/**
|
|
110
136
|
* Time Complexity: O(M), where M is the length of the word being deleted.
|
|
111
137
|
* Space Complexity: O(M) - Due to the recursive DFS approach.
|
|
@@ -326,6 +352,21 @@ class Trie extends base_1.IterableElementBase {
|
|
|
326
352
|
dfs(startNode, prefix);
|
|
327
353
|
return words;
|
|
328
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Time Complexity: O(n)
|
|
357
|
+
* Space Complexity: O(n)
|
|
358
|
+
*/
|
|
359
|
+
/**
|
|
360
|
+
* Time Complexity: O(n)
|
|
361
|
+
* Space Complexity: O(n)
|
|
362
|
+
*
|
|
363
|
+
* The `clone` function returns a new instance of the Trie class with the same values and case
|
|
364
|
+
* sensitivity as the original Trie.
|
|
365
|
+
* @returns A new instance of the Trie class is being returned.
|
|
366
|
+
*/
|
|
367
|
+
clone() {
|
|
368
|
+
return new Trie(this.values(), { caseSensitive: this.caseSensitive });
|
|
369
|
+
}
|
|
329
370
|
/**
|
|
330
371
|
* Time Complexity: O(n)
|
|
331
372
|
* Space Complexity: O(n)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;GAGG;AACH,MAAa,QAAQ;IAKnB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,CAAC;CACF;AAVD,4BAUC;AAED;;;;;;;;;;;;GAYG;AACH,MAAa,IAAK,SAAQ,
|
|
1
|
+
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;GAGG;AACH,MAAa,QAAQ;IAKnB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,CAAC;CACF;AAVD,4BAUC;AAED;;;;;;;;;;;;GAYG;AACH,MAAa,IAAK,SAAQ,0BAAiC;IACzD;;;;;OAKG;IACH,YAAY,QAA0B,EAAE,EAAE,OAAqB;QAC7D,KAAK,EAAE,CAAC;QAUA,UAAK,GAAW,CAAC,CAAC;QAUlB,mBAAc,GAAY,IAAI,CAAC;QAW/B,UAAK,GAAa,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC;QA9B3C,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;YAClC,IAAI,aAAa,KAAK,SAAS;gBAAE,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACvE,CAAC;QACD,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAID;;;OAGG;IACH,I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OAGG;IAEH;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,QAAyC,EAAE,OAAa;QAC1D,MAAM,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACvD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEQ,CAAE,YAAY;QACrB,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAc,EAAE,IAAY;YACzC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC;YACb,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC9C,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;QAED,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY,CAAC,GAAW;QAChC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,+CAA+C;QAC1E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAhcD,oBAgcC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType } from "../../common";
|
|
3
3
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
-
export type BinaryTreeNested<K, V,
|
|
4
|
+
export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeOptions<K> = {
|
|
6
6
|
iterationType?: IterationType;
|
|
7
7
|
extractor?: (key: K) => number;
|
|
@@ -4,13 +4,14 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
4
4
|
next: HashMapLinkedNode<K, V>;
|
|
5
5
|
prev: HashMapLinkedNode<K, V>;
|
|
6
6
|
};
|
|
7
|
-
export type LinkedHashMapOptions<K> = {
|
|
7
|
+
export type LinkedHashMapOptions<K, V, R> = {
|
|
8
8
|
hashFn?: (key: K) => string;
|
|
9
9
|
objHashFn?: (key: K) => object;
|
|
10
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
10
11
|
};
|
|
11
|
-
export type HashMapOptions<K, V,
|
|
12
|
+
export type HashMapOptions<K, V, R> = {
|
|
12
13
|
hashFn?: (key: K) => string;
|
|
13
|
-
toEntryFn?: (rawElement:
|
|
14
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
14
15
|
};
|
|
15
16
|
export type HashMapStoreItem<K, V> = {
|
|
16
17
|
key: K;
|
|
@@ -5,3 +5,4 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
|
5
5
|
export type TrlFn = (...args: any[]) => any;
|
|
6
6
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
7
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
+
export type Any = string | number | boolean | object | null | undefined | symbol;
|
|
@@ -105,6 +105,72 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
105
105
|
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
106
106
|
*/
|
|
107
107
|
forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void;
|
|
108
|
+
/**
|
|
109
|
+
* Time Complexity: O(n)
|
|
110
|
+
* Space Complexity: O(1)
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Time Complexity: O(n)
|
|
114
|
+
* Space Complexity: O(1)
|
|
115
|
+
*
|
|
116
|
+
* The `find` function iterates over the entries of a collection and returns the first value for
|
|
117
|
+
* which the callback function returns true.
|
|
118
|
+
* @param callbackfn - The callback function that will be called for each entry in the collection. It
|
|
119
|
+
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
|
|
120
|
+
* the collection. It should return a boolean value indicating whether the current entry matches the
|
|
121
|
+
* desired condition.
|
|
122
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
123
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
124
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
125
|
+
* @returns The method `find` returns the value of the first element in the iterable that satisfies
|
|
126
|
+
* the provided callback function. If no element satisfies the callback function, `undefined` is
|
|
127
|
+
* returned.
|
|
128
|
+
*/
|
|
129
|
+
find(callbackfn: EntryCallback<K, V, [K, V]>, thisArg?: any): [K, V] | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Time Complexity: O(n)
|
|
132
|
+
* Space Complexity: O(1)
|
|
133
|
+
*/
|
|
134
|
+
/**
|
|
135
|
+
* Time Complexity: O(n)
|
|
136
|
+
* Space Complexity: O(1)
|
|
137
|
+
*
|
|
138
|
+
* The function checks if a given key exists in a collection.
|
|
139
|
+
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
|
|
140
|
+
* the key that we want to check for existence in the data structure.
|
|
141
|
+
* @returns a boolean value. It returns true if the key is found in the collection, and false
|
|
142
|
+
* otherwise.
|
|
143
|
+
*/
|
|
144
|
+
has(key: K): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Time Complexity: O(n)
|
|
147
|
+
* Space Complexity: O(1)
|
|
148
|
+
*/
|
|
149
|
+
/**
|
|
150
|
+
* Time Complexity: O(n)
|
|
151
|
+
* Space Complexity: O(1)
|
|
152
|
+
*
|
|
153
|
+
* The function checks if a given value exists in a collection.
|
|
154
|
+
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
|
|
155
|
+
* collection.
|
|
156
|
+
* @returns a boolean value, either true or false.
|
|
157
|
+
*/
|
|
158
|
+
hasValue(value: V): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Time Complexity: O(n)
|
|
161
|
+
* Space Complexity: O(1)
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* Time Complexity: O(n)
|
|
165
|
+
* Space Complexity: O(1)
|
|
166
|
+
*
|
|
167
|
+
* The `get` function retrieves the value associated with a given key from a collection.
|
|
168
|
+
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
|
|
169
|
+
* searched for in the collection.
|
|
170
|
+
* @returns The `get` method returns the value associated with the specified key if it exists in the
|
|
171
|
+
* collection, otherwise it returns `undefined`.
|
|
172
|
+
*/
|
|
173
|
+
get(key: K): V | undefined;
|
|
108
174
|
/**
|
|
109
175
|
* Time Complexity: O(n)
|
|
110
176
|
* Space Complexity: O(1)
|
|
@@ -126,15 +192,16 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
126
192
|
* all the elements in the collection.
|
|
127
193
|
*/
|
|
128
194
|
reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
|
|
129
|
-
hasValue(value: V): boolean;
|
|
130
195
|
/**
|
|
131
196
|
* Time Complexity: O(n)
|
|
132
197
|
* Space Complexity: O(n)
|
|
133
198
|
*/
|
|
134
199
|
print(): void;
|
|
200
|
+
abstract isEmpty(): boolean;
|
|
201
|
+
abstract clone(): any;
|
|
135
202
|
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
136
203
|
}
|
|
137
|
-
export declare abstract class IterableElementBase<
|
|
204
|
+
export declare abstract class IterableElementBase<E = any, C = any> {
|
|
138
205
|
/**
|
|
139
206
|
* Time Complexity: O(n)
|
|
140
207
|
* Space Complexity: O(1)
|
|
@@ -148,7 +215,7 @@ export declare abstract class IterableElementBase<V> {
|
|
|
148
215
|
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
149
216
|
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
150
217
|
*/
|
|
151
|
-
[Symbol.iterator](...args: any[]): IterableIterator<
|
|
218
|
+
[Symbol.iterator](...args: any[]): IterableIterator<E>;
|
|
152
219
|
/**
|
|
153
220
|
* Time Complexity: O(n)
|
|
154
221
|
* Space Complexity: O(n)
|
|
@@ -159,7 +226,7 @@ export declare abstract class IterableElementBase<V> {
|
|
|
159
226
|
*
|
|
160
227
|
* The function returns an iterator that yields all the values in the object.
|
|
161
228
|
*/
|
|
162
|
-
values(): IterableIterator<
|
|
229
|
+
values(): IterableIterator<E>;
|
|
163
230
|
/**
|
|
164
231
|
* Time Complexity: O(n)
|
|
165
232
|
* Space Complexity: O(1)
|
|
@@ -178,7 +245,7 @@ export declare abstract class IterableElementBase<V> {
|
|
|
178
245
|
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
179
246
|
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
180
247
|
*/
|
|
181
|
-
every(predicate: ElementCallback<
|
|
248
|
+
every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
|
|
182
249
|
/**
|
|
183
250
|
* Time Complexity: O(n)
|
|
184
251
|
* Space Complexity: O(1)
|
|
@@ -197,7 +264,7 @@ export declare abstract class IterableElementBase<V> {
|
|
|
197
264
|
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
198
265
|
* in the collection, and false otherwise.
|
|
199
266
|
*/
|
|
200
|
-
some(predicate: ElementCallback<
|
|
267
|
+
some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
|
|
201
268
|
/**
|
|
202
269
|
* Time Complexity: O(n)
|
|
203
270
|
* Space Complexity: O(1)
|
|
@@ -215,7 +282,43 @@ export declare abstract class IterableElementBase<V> {
|
|
|
215
282
|
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
216
283
|
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
217
284
|
*/
|
|
218
|
-
forEach(callbackfn: ElementCallback<
|
|
285
|
+
forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void;
|
|
286
|
+
/**
|
|
287
|
+
* Time Complexity: O(n)
|
|
288
|
+
* Space Complexity: O(1)
|
|
289
|
+
*/
|
|
290
|
+
/**
|
|
291
|
+
* Time Complexity: O(n)
|
|
292
|
+
* Space Complexity: O(1)
|
|
293
|
+
*
|
|
294
|
+
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
295
|
+
* element that satisfies the provided callback function.
|
|
296
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
297
|
+
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
298
|
+
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
299
|
+
* current element matches the desired condition.
|
|
300
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
301
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
302
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
303
|
+
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
304
|
+
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
305
|
+
*/
|
|
306
|
+
find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined;
|
|
307
|
+
/**
|
|
308
|
+
* Time Complexity: O(n)
|
|
309
|
+
* Space Complexity: O(1)
|
|
310
|
+
*/
|
|
311
|
+
/**
|
|
312
|
+
* Time Complexity: O(n)
|
|
313
|
+
* Space Complexity: O(1)
|
|
314
|
+
*
|
|
315
|
+
* The function checks if a given element exists in a collection.
|
|
316
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
|
|
317
|
+
* represents the element that we want to check for existence in the collection.
|
|
318
|
+
* @returns a boolean value. It returns true if the element is found in the collection, and false
|
|
319
|
+
* otherwise.
|
|
320
|
+
*/
|
|
321
|
+
has(element: E): boolean;
|
|
219
322
|
/**
|
|
220
323
|
* Time Complexity: O(n)
|
|
221
324
|
* Space Complexity: O(1)
|
|
@@ -233,11 +336,13 @@ export declare abstract class IterableElementBase<V> {
|
|
|
233
336
|
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
234
337
|
* all the elements in the array and applying the callback function to each element.
|
|
235
338
|
*/
|
|
236
|
-
reduce<U>(callbackfn: ReduceElementCallback<
|
|
339
|
+
reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U;
|
|
237
340
|
/**
|
|
238
341
|
* Time Complexity: O(n)
|
|
239
342
|
* Space Complexity: O(n)
|
|
240
343
|
*/
|
|
241
344
|
print(): void;
|
|
242
|
-
|
|
345
|
+
abstract isEmpty(): boolean;
|
|
346
|
+
abstract clone(): C;
|
|
347
|
+
protected abstract _getIterator(...args: any[]): IterableIterator<E>;
|
|
243
348
|
}
|
|
@@ -140,6 +140,100 @@ export class IterableEntryBase {
|
|
|
140
140
|
callbackfn.call(thisArg, value, key, index++, this);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Time Complexity: O(n)
|
|
145
|
+
* Space Complexity: O(1)
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* Time Complexity: O(n)
|
|
149
|
+
* Space Complexity: O(1)
|
|
150
|
+
*
|
|
151
|
+
* The `find` function iterates over the entries of a collection and returns the first value for
|
|
152
|
+
* which the callback function returns true.
|
|
153
|
+
* @param callbackfn - The callback function that will be called for each entry in the collection. It
|
|
154
|
+
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
|
|
155
|
+
* the collection. It should return a boolean value indicating whether the current entry matches the
|
|
156
|
+
* desired condition.
|
|
157
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
158
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
159
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
160
|
+
* @returns The method `find` returns the value of the first element in the iterable that satisfies
|
|
161
|
+
* the provided callback function. If no element satisfies the callback function, `undefined` is
|
|
162
|
+
* returned.
|
|
163
|
+
*/
|
|
164
|
+
find(callbackfn, thisArg) {
|
|
165
|
+
let index = 0;
|
|
166
|
+
for (const item of this) {
|
|
167
|
+
const [key, value] = item;
|
|
168
|
+
if (callbackfn.call(thisArg, value, key, index++, this))
|
|
169
|
+
return item;
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Time Complexity: O(n)
|
|
175
|
+
* Space Complexity: O(1)
|
|
176
|
+
*/
|
|
177
|
+
/**
|
|
178
|
+
* Time Complexity: O(n)
|
|
179
|
+
* Space Complexity: O(1)
|
|
180
|
+
*
|
|
181
|
+
* The function checks if a given key exists in a collection.
|
|
182
|
+
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
|
|
183
|
+
* the key that we want to check for existence in the data structure.
|
|
184
|
+
* @returns a boolean value. It returns true if the key is found in the collection, and false
|
|
185
|
+
* otherwise.
|
|
186
|
+
*/
|
|
187
|
+
has(key) {
|
|
188
|
+
for (const item of this) {
|
|
189
|
+
const [itemKey] = item;
|
|
190
|
+
if (itemKey === key)
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Time Complexity: O(n)
|
|
197
|
+
* Space Complexity: O(1)
|
|
198
|
+
*/
|
|
199
|
+
/**
|
|
200
|
+
* Time Complexity: O(n)
|
|
201
|
+
* Space Complexity: O(1)
|
|
202
|
+
*
|
|
203
|
+
* The function checks if a given value exists in a collection.
|
|
204
|
+
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
|
|
205
|
+
* collection.
|
|
206
|
+
* @returns a boolean value, either true or false.
|
|
207
|
+
*/
|
|
208
|
+
hasValue(value) {
|
|
209
|
+
for (const [, elementValue] of this) {
|
|
210
|
+
if (elementValue === value)
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Time Complexity: O(n)
|
|
217
|
+
* Space Complexity: O(1)
|
|
218
|
+
*/
|
|
219
|
+
/**
|
|
220
|
+
* Time Complexity: O(n)
|
|
221
|
+
* Space Complexity: O(1)
|
|
222
|
+
*
|
|
223
|
+
* The `get` function retrieves the value associated with a given key from a collection.
|
|
224
|
+
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
|
|
225
|
+
* searched for in the collection.
|
|
226
|
+
* @returns The `get` method returns the value associated with the specified key if it exists in the
|
|
227
|
+
* collection, otherwise it returns `undefined`.
|
|
228
|
+
*/
|
|
229
|
+
get(key) {
|
|
230
|
+
for (const item of this) {
|
|
231
|
+
const [itemKey, value] = item;
|
|
232
|
+
if (itemKey === key)
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
143
237
|
/**
|
|
144
238
|
* Time Complexity: O(n)
|
|
145
239
|
* Space Complexity: O(1)
|
|
@@ -169,13 +263,6 @@ export class IterableEntryBase {
|
|
|
169
263
|
}
|
|
170
264
|
return accumulator;
|
|
171
265
|
}
|
|
172
|
-
hasValue(value) {
|
|
173
|
-
for (const [, elementValue] of this) {
|
|
174
|
-
if (elementValue === value)
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
266
|
/**
|
|
180
267
|
* Time Complexity: O(n)
|
|
181
268
|
* Space Complexity: O(n)
|
|
@@ -293,6 +380,55 @@ export class IterableElementBase {
|
|
|
293
380
|
callbackfn.call(thisArg, item, index++, this);
|
|
294
381
|
}
|
|
295
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Time Complexity: O(n)
|
|
385
|
+
* Space Complexity: O(1)
|
|
386
|
+
*/
|
|
387
|
+
/**
|
|
388
|
+
* Time Complexity: O(n)
|
|
389
|
+
* Space Complexity: O(1)
|
|
390
|
+
*
|
|
391
|
+
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
392
|
+
* element that satisfies the provided callback function.
|
|
393
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
394
|
+
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
395
|
+
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
396
|
+
* current element matches the desired condition.
|
|
397
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
398
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
399
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
400
|
+
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
401
|
+
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
402
|
+
*/
|
|
403
|
+
find(callbackfn, thisArg) {
|
|
404
|
+
let index = 0;
|
|
405
|
+
for (const item of this) {
|
|
406
|
+
if (callbackfn.call(thisArg, item, index++, this))
|
|
407
|
+
return item;
|
|
408
|
+
}
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Time Complexity: O(n)
|
|
413
|
+
* Space Complexity: O(1)
|
|
414
|
+
*/
|
|
415
|
+
/**
|
|
416
|
+
* Time Complexity: O(n)
|
|
417
|
+
* Space Complexity: O(1)
|
|
418
|
+
*
|
|
419
|
+
* The function checks if a given element exists in a collection.
|
|
420
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
|
|
421
|
+
* represents the element that we want to check for existence in the collection.
|
|
422
|
+
* @returns a boolean value. It returns true if the element is found in the collection, and false
|
|
423
|
+
* otherwise.
|
|
424
|
+
*/
|
|
425
|
+
has(element) {
|
|
426
|
+
for (const ele of this) {
|
|
427
|
+
if (ele === element)
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
296
432
|
/**
|
|
297
433
|
* Time Complexity: O(n)
|
|
298
434
|
* Space Complexity: O(1)
|