avl-tree-typed 1.48.1 → 1.48.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/index.d.ts +1 -0
- package/dist/data-structures/base/index.js +17 -0
- package/dist/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/data-structures/base/iterable-base.js +312 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/data-structures/binary-tree/binary-tree.d.ts +121 -152
- package/dist/data-structures/binary-tree/binary-tree.js +140 -182
- package/dist/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/data-structures/binary-tree/bst.js +54 -57
- package/dist/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/data-structures/graph/abstract-graph.js +50 -27
- package/dist/data-structures/hash/hash-map.d.ts +59 -100
- package/dist/data-structures/hash/hash-map.js +69 -173
- package/dist/data-structures/heap/heap.d.ts +50 -7
- package/dist/data-structures/heap/heap.js +60 -30
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/data-structures/queue/deque.d.ts +29 -51
- package/dist/data-structures/queue/deque.js +36 -71
- package/dist/data-structures/queue/queue.d.ts +49 -48
- package/dist/data-structures/queue/queue.js +69 -82
- package/dist/data-structures/stack/stack.d.ts +43 -10
- package/dist/data-structures/stack/stack.js +50 -31
- package/dist/data-structures/trie/trie.d.ts +41 -6
- package/dist/data-structures/trie/trie.js +53 -32
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +11 -8
- package/dist/types/common.js +6 -1
- package/dist/types/data-structures/base/base.d.ts +5 -0
- package/dist/types/data-structures/base/base.js +2 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/index.js +17 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/types/data-structures/index.d.ts +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/avl-tree.ts +20 -21
- package/src/data-structures/binary-tree/binary-tree.ts +222 -267
- package/src/data-structures/binary-tree/bst.ts +86 -82
- package/src/data-structures/binary-tree/rb-tree.ts +25 -26
- package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
- package/src/data-structures/graph/abstract-graph.ts +55 -28
- package/src/data-structures/hash/hash-map.ts +76 -185
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
- package/src/data-structures/queue/deque.ts +40 -82
- package/src/data-structures/queue/queue.ts +72 -87
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/src/types/data-structures/index.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './iterable-base';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./iterable-base"), exports);
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { ElementCallback, PairCallback, ReduceElementCallback, ReducePairCallback } from "../../types";
|
|
2
|
+
export declare abstract class IterablePairBase<K = any, V = any> {
|
|
3
|
+
/**
|
|
4
|
+
* Time Complexity: O(n)
|
|
5
|
+
* Space Complexity: O(1)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Time Complexity: O(n)
|
|
9
|
+
* Space Complexity: O(1)
|
|
10
|
+
*
|
|
11
|
+
* The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
|
|
12
|
+
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
13
|
+
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
14
|
+
* parameter is used to pass any additional arguments to the `_getIterator` method.
|
|
15
|
+
*/
|
|
16
|
+
[Symbol.iterator](...args: any[]): IterableIterator<[K, V]>;
|
|
17
|
+
/**
|
|
18
|
+
* Time Complexity: O(n)
|
|
19
|
+
* Space Complexity: O(n)
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Time Complexity: O(n)
|
|
23
|
+
* Space Complexity: O(n)
|
|
24
|
+
*
|
|
25
|
+
* The function returns an iterator that yields key-value pairs from the object, where the value can
|
|
26
|
+
* be undefined.
|
|
27
|
+
*/
|
|
28
|
+
entries(): IterableIterator<[K, V | undefined]>;
|
|
29
|
+
/**
|
|
30
|
+
* Time Complexity: O(n)
|
|
31
|
+
* Space Complexity: O(n)
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Time Complexity: O(n)
|
|
35
|
+
* Space Complexity: O(n)
|
|
36
|
+
*
|
|
37
|
+
* The function returns an iterator that yields the keys of a data structure.
|
|
38
|
+
*/
|
|
39
|
+
keys(): IterableIterator<K>;
|
|
40
|
+
/**
|
|
41
|
+
* Time Complexity: O(n)
|
|
42
|
+
* Space Complexity: O(n)
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Time Complexity: O(n)
|
|
46
|
+
* Space Complexity: O(n)
|
|
47
|
+
*
|
|
48
|
+
* The function returns an iterator that yields the values of a collection.
|
|
49
|
+
*/
|
|
50
|
+
values(): IterableIterator<V>;
|
|
51
|
+
/**
|
|
52
|
+
* Time Complexity: O(n)
|
|
53
|
+
* Space Complexity: O(1)
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Time Complexity: O(n)
|
|
57
|
+
* Space Complexity: O(1)
|
|
58
|
+
*
|
|
59
|
+
* The `every` function checks if every element in a collection satisfies a given condition.
|
|
60
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
61
|
+
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
62
|
+
* met for the current element in the iteration.
|
|
63
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
64
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
65
|
+
* passed as the first argument to the `predicate` function. If `thisArg` is not provided
|
|
66
|
+
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
67
|
+
* the collection satisfies the provided predicate function, and `false` otherwise.
|
|
68
|
+
*/
|
|
69
|
+
every(predicate: PairCallback<K, V, boolean>, thisArg?: any): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Time Complexity: O(n)
|
|
72
|
+
* Space Complexity: O(1)
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* Time Complexity: O(n)
|
|
76
|
+
* Space Complexity: O(1)
|
|
77
|
+
*
|
|
78
|
+
* The "some" function iterates over a collection and returns true if at least one element satisfies
|
|
79
|
+
* a given predicate.
|
|
80
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
81
|
+
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
82
|
+
* met for the current element in the iteration.
|
|
83
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
84
|
+
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
85
|
+
* it will be passed as the first argument to the `predicate` function. If `thisArg` is
|
|
86
|
+
* @returns a boolean value. It returns true if the predicate function returns true for any pair in
|
|
87
|
+
* the collection, and false otherwise.
|
|
88
|
+
*/
|
|
89
|
+
some(predicate: PairCallback<K, V, boolean>, thisArg?: any): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Time Complexity: O(n)
|
|
92
|
+
* Space Complexity: O(1)
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Time Complexity: O(n)
|
|
96
|
+
* Space Complexity: O(1)
|
|
97
|
+
*
|
|
98
|
+
* The `forEach` function iterates over each key-value pair in a collection and executes a callback
|
|
99
|
+
* function for each pair.
|
|
100
|
+
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
101
|
+
* It takes four parameters: the value of the current element, the key of the current element, the
|
|
102
|
+
* index of the current element, and the collection itself.
|
|
103
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
104
|
+
* specify the value of `this` within the callback function. If `thisArg` is provided, it will be
|
|
105
|
+
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
106
|
+
*/
|
|
107
|
+
forEach(callbackfn: PairCallback<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 `reduce` function iterates over key-value pairs and applies a callback function to each pair,
|
|
117
|
+
* accumulating a single value.
|
|
118
|
+
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
119
|
+
* It takes four arguments: the current accumulator value, the current value of the element, the key
|
|
120
|
+
* of the element, and the index of the element in the collection. It should return the updated
|
|
121
|
+
* accumulator value.
|
|
122
|
+
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
123
|
+
* is the value that will be used as the first argument to the `callbackfn` function when reducing
|
|
124
|
+
* the elements of the collection.
|
|
125
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
126
|
+
* all the elements in the collection.
|
|
127
|
+
*/
|
|
128
|
+
reduce<U>(callbackfn: ReducePairCallback<K, V, U>, initialValue: U): U;
|
|
129
|
+
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
130
|
+
}
|
|
131
|
+
export declare abstract class IterableElementBase<V> {
|
|
132
|
+
/**
|
|
133
|
+
* Time Complexity: O(n)
|
|
134
|
+
* Space Complexity: O(1)
|
|
135
|
+
*/
|
|
136
|
+
/**
|
|
137
|
+
* Time Complexity: O(n)
|
|
138
|
+
* Space Complexity: O(1)
|
|
139
|
+
*
|
|
140
|
+
* The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
|
|
141
|
+
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
142
|
+
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
143
|
+
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
144
|
+
*/
|
|
145
|
+
[Symbol.iterator](...args: any[]): IterableIterator<V>;
|
|
146
|
+
/**
|
|
147
|
+
* Time Complexity: O(n)
|
|
148
|
+
* Space Complexity: O(n)
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Time Complexity: O(n)
|
|
152
|
+
* Space Complexity: O(n)
|
|
153
|
+
*
|
|
154
|
+
* The function returns an iterator that yields all the values in the object.
|
|
155
|
+
*/
|
|
156
|
+
values(): IterableIterator<V>;
|
|
157
|
+
/**
|
|
158
|
+
* Time Complexity: O(n)
|
|
159
|
+
* Space Complexity: O(1)
|
|
160
|
+
*/
|
|
161
|
+
/**
|
|
162
|
+
* Time Complexity: O(n)
|
|
163
|
+
* Space Complexity: O(1)
|
|
164
|
+
*
|
|
165
|
+
* The `every` function checks if every element in the array satisfies a given predicate.
|
|
166
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
167
|
+
* the current element being processed, its index, and the array it belongs to. It should return a
|
|
168
|
+
* boolean value indicating whether the element satisfies a certain condition or not.
|
|
169
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
170
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
171
|
+
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
172
|
+
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
173
|
+
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
174
|
+
*/
|
|
175
|
+
every(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Time Complexity: O(n)
|
|
178
|
+
* Space Complexity: O(1)
|
|
179
|
+
*/
|
|
180
|
+
/**
|
|
181
|
+
* Time Complexity: O(n)
|
|
182
|
+
* Space Complexity: O(1)
|
|
183
|
+
*
|
|
184
|
+
* The "some" function checks if at least one element in a collection satisfies a given predicate.
|
|
185
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
186
|
+
* `value`, `index`, and `array`. It should return a boolean value indicating whether the current
|
|
187
|
+
* element satisfies the condition.
|
|
188
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
189
|
+
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
190
|
+
* it will be passed as the `this` value to the `predicate` function. If `thisArg
|
|
191
|
+
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
192
|
+
* in the collection, and false otherwise.
|
|
193
|
+
*/
|
|
194
|
+
some(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean;
|
|
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 `forEach` function iterates over each element in an array-like object and calls a callback
|
|
204
|
+
* function for each element.
|
|
205
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
206
|
+
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
207
|
+
* element, and the array that forEach was called upon.
|
|
208
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
209
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
210
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
211
|
+
*/
|
|
212
|
+
forEach(callbackfn: ElementCallback<V, void>, thisArg?: any): void;
|
|
213
|
+
/**
|
|
214
|
+
* Time Complexity: O(n)
|
|
215
|
+
* Space Complexity: O(1)
|
|
216
|
+
*/
|
|
217
|
+
/**
|
|
218
|
+
* Time Complexity: O(n)
|
|
219
|
+
* Space Complexity: O(1)
|
|
220
|
+
*
|
|
221
|
+
* The `reduce` function iterates over the elements of an array-like object and applies a callback
|
|
222
|
+
* function to reduce them into a single value.
|
|
223
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
224
|
+
* the array. It takes four arguments:
|
|
225
|
+
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
226
|
+
* is the value that the accumulator starts with before the reduction operation begins.
|
|
227
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
228
|
+
* all the elements in the array and applying the callback function to each element.
|
|
229
|
+
*/
|
|
230
|
+
reduce<U>(callbackfn: ReduceElementCallback<V, U>, initialValue: U): U;
|
|
231
|
+
protected abstract _getIterator(...args: any[]): IterableIterator<V>;
|
|
232
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IterableElementBase = exports.IterablePairBase = void 0;
|
|
4
|
+
class IterablePairBase {
|
|
5
|
+
/**
|
|
6
|
+
* Time Complexity: O(n)
|
|
7
|
+
* Space Complexity: O(1)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Time Complexity: O(n)
|
|
11
|
+
* Space Complexity: O(1)
|
|
12
|
+
*
|
|
13
|
+
* The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
|
|
14
|
+
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
15
|
+
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
16
|
+
* parameter is used to pass any additional arguments to the `_getIterator` method.
|
|
17
|
+
*/
|
|
18
|
+
*[Symbol.iterator](...args) {
|
|
19
|
+
yield* this._getIterator(...args);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Time Complexity: O(n)
|
|
23
|
+
* Space Complexity: O(n)
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Time Complexity: O(n)
|
|
27
|
+
* Space Complexity: O(n)
|
|
28
|
+
*
|
|
29
|
+
* The function returns an iterator that yields key-value pairs from the object, where the value can
|
|
30
|
+
* be undefined.
|
|
31
|
+
*/
|
|
32
|
+
*entries() {
|
|
33
|
+
for (const item of this) {
|
|
34
|
+
yield item;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Time Complexity: O(n)
|
|
39
|
+
* Space Complexity: O(n)
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Time Complexity: O(n)
|
|
43
|
+
* Space Complexity: O(n)
|
|
44
|
+
*
|
|
45
|
+
* The function returns an iterator that yields the keys of a data structure.
|
|
46
|
+
*/
|
|
47
|
+
*keys() {
|
|
48
|
+
for (const item of this) {
|
|
49
|
+
yield item[0];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Time Complexity: O(n)
|
|
54
|
+
* Space Complexity: O(n)
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Time Complexity: O(n)
|
|
58
|
+
* Space Complexity: O(n)
|
|
59
|
+
*
|
|
60
|
+
* The function returns an iterator that yields the values of a collection.
|
|
61
|
+
*/
|
|
62
|
+
*values() {
|
|
63
|
+
for (const item of this) {
|
|
64
|
+
yield item[1];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Time Complexity: O(n)
|
|
69
|
+
* Space Complexity: O(1)
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* Time Complexity: O(n)
|
|
73
|
+
* Space Complexity: O(1)
|
|
74
|
+
*
|
|
75
|
+
* The `every` function checks if every element in a collection satisfies a given condition.
|
|
76
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
77
|
+
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
78
|
+
* met for the current element in the iteration.
|
|
79
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
80
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
81
|
+
* passed as the first argument to the `predicate` function. If `thisArg` is not provided
|
|
82
|
+
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
83
|
+
* the collection satisfies the provided predicate function, and `false` otherwise.
|
|
84
|
+
*/
|
|
85
|
+
every(predicate, thisArg) {
|
|
86
|
+
let index = 0;
|
|
87
|
+
for (const item of this) {
|
|
88
|
+
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Time Complexity: O(n)
|
|
96
|
+
* Space Complexity: O(1)
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* Time Complexity: O(n)
|
|
100
|
+
* Space Complexity: O(1)
|
|
101
|
+
*
|
|
102
|
+
* The "some" function iterates over a collection and returns true if at least one element satisfies
|
|
103
|
+
* a given predicate.
|
|
104
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
105
|
+
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
106
|
+
* met for the current element in the iteration.
|
|
107
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
108
|
+
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
109
|
+
* it will be passed as the first argument to the `predicate` function. If `thisArg` is
|
|
110
|
+
* @returns a boolean value. It returns true if the predicate function returns true for any pair in
|
|
111
|
+
* the collection, and false otherwise.
|
|
112
|
+
*/
|
|
113
|
+
some(predicate, thisArg) {
|
|
114
|
+
let index = 0;
|
|
115
|
+
for (const item of this) {
|
|
116
|
+
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Time Complexity: O(n)
|
|
124
|
+
* Space Complexity: O(1)
|
|
125
|
+
*/
|
|
126
|
+
/**
|
|
127
|
+
* Time Complexity: O(n)
|
|
128
|
+
* Space Complexity: O(1)
|
|
129
|
+
*
|
|
130
|
+
* The `forEach` function iterates over each key-value pair in a collection and executes a callback
|
|
131
|
+
* function for each pair.
|
|
132
|
+
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
133
|
+
* It takes four parameters: the value of the current element, the key of the current element, the
|
|
134
|
+
* index of the current element, and the collection itself.
|
|
135
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
136
|
+
* specify the value of `this` within the callback function. If `thisArg` is provided, it will be
|
|
137
|
+
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
138
|
+
*/
|
|
139
|
+
forEach(callbackfn, thisArg) {
|
|
140
|
+
let index = 0;
|
|
141
|
+
for (const item of this) {
|
|
142
|
+
const [key, value] = item;
|
|
143
|
+
callbackfn.call(thisArg, value, key, index++, this);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Time Complexity: O(n)
|
|
148
|
+
* Space Complexity: O(1)
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Time Complexity: O(n)
|
|
152
|
+
* Space Complexity: O(1)
|
|
153
|
+
*
|
|
154
|
+
* The `reduce` function iterates over key-value pairs and applies a callback function to each pair,
|
|
155
|
+
* accumulating a single value.
|
|
156
|
+
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
157
|
+
* It takes four arguments: the current accumulator value, the current value of the element, the key
|
|
158
|
+
* of the element, and the index of the element in the collection. It should return the updated
|
|
159
|
+
* accumulator value.
|
|
160
|
+
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
161
|
+
* is the value that will be used as the first argument to the `callbackfn` function when reducing
|
|
162
|
+
* the elements of the collection.
|
|
163
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
164
|
+
* all the elements in the collection.
|
|
165
|
+
*/
|
|
166
|
+
reduce(callbackfn, initialValue) {
|
|
167
|
+
let accumulator = initialValue;
|
|
168
|
+
let index = 0;
|
|
169
|
+
for (const item of this) {
|
|
170
|
+
const [key, value] = item;
|
|
171
|
+
accumulator = callbackfn(accumulator, value, key, index++, this);
|
|
172
|
+
}
|
|
173
|
+
return accumulator;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.IterablePairBase = IterablePairBase;
|
|
177
|
+
class IterableElementBase {
|
|
178
|
+
/**
|
|
179
|
+
* Time Complexity: O(n)
|
|
180
|
+
* Space Complexity: O(1)
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* Time Complexity: O(n)
|
|
184
|
+
* Space Complexity: O(1)
|
|
185
|
+
*
|
|
186
|
+
* The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
|
|
187
|
+
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
188
|
+
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
189
|
+
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
190
|
+
*/
|
|
191
|
+
*[Symbol.iterator](...args) {
|
|
192
|
+
yield* this._getIterator(...args);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Time Complexity: O(n)
|
|
196
|
+
* Space Complexity: O(n)
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Time Complexity: O(n)
|
|
200
|
+
* Space Complexity: O(n)
|
|
201
|
+
*
|
|
202
|
+
* The function returns an iterator that yields all the values in the object.
|
|
203
|
+
*/
|
|
204
|
+
*values() {
|
|
205
|
+
for (const item of this) {
|
|
206
|
+
yield item;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Time Complexity: O(n)
|
|
211
|
+
* Space Complexity: O(1)
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* Time Complexity: O(n)
|
|
215
|
+
* Space Complexity: O(1)
|
|
216
|
+
*
|
|
217
|
+
* The `every` function checks if every element in the array satisfies a given predicate.
|
|
218
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
219
|
+
* the current element being processed, its index, and the array it belongs to. It should return a
|
|
220
|
+
* boolean value indicating whether the element satisfies a certain condition or not.
|
|
221
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
222
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
223
|
+
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
224
|
+
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
225
|
+
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
226
|
+
*/
|
|
227
|
+
every(predicate, thisArg) {
|
|
228
|
+
let index = 0;
|
|
229
|
+
for (const item of this) {
|
|
230
|
+
if (!predicate.call(thisArg, item, index++, this)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Time Complexity: O(n)
|
|
238
|
+
* Space Complexity: O(1)
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Time Complexity: O(n)
|
|
242
|
+
* Space Complexity: O(1)
|
|
243
|
+
*
|
|
244
|
+
* The "some" function checks if at least one element in a collection satisfies a given predicate.
|
|
245
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
246
|
+
* `value`, `index`, and `array`. It should return a boolean value indicating whether the current
|
|
247
|
+
* element satisfies the condition.
|
|
248
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
249
|
+
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
250
|
+
* it will be passed as the `this` value to the `predicate` function. If `thisArg
|
|
251
|
+
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
252
|
+
* in the collection, and false otherwise.
|
|
253
|
+
*/
|
|
254
|
+
some(predicate, thisArg) {
|
|
255
|
+
let index = 0;
|
|
256
|
+
for (const item of this) {
|
|
257
|
+
if (predicate.call(thisArg, item, index++, this)) {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Time Complexity: O(n)
|
|
265
|
+
* Space Complexity: O(1)
|
|
266
|
+
*/
|
|
267
|
+
/**
|
|
268
|
+
* Time Complexity: O(n)
|
|
269
|
+
* Space Complexity: O(1)
|
|
270
|
+
*
|
|
271
|
+
* The `forEach` function iterates over each element in an array-like object and calls a callback
|
|
272
|
+
* function for each element.
|
|
273
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
274
|
+
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
275
|
+
* element, and the array that forEach was called upon.
|
|
276
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
277
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
278
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
279
|
+
*/
|
|
280
|
+
forEach(callbackfn, thisArg) {
|
|
281
|
+
let index = 0;
|
|
282
|
+
for (const item of this) {
|
|
283
|
+
callbackfn.call(thisArg, item, index++, this);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
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 `reduce` function iterates over the elements of an array-like object and applies a callback
|
|
295
|
+
* function to reduce them into a single value.
|
|
296
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
297
|
+
* the array. It takes four arguments:
|
|
298
|
+
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
299
|
+
* is the value that the accumulator starts with before the reduction operation begins.
|
|
300
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
301
|
+
* all the elements in the array and applying the callback function to each element.
|
|
302
|
+
*/
|
|
303
|
+
reduce(callbackfn, initialValue) {
|
|
304
|
+
let accumulator = initialValue;
|
|
305
|
+
let index = 0;
|
|
306
|
+
for (const item of this) {
|
|
307
|
+
accumulator = callbackfn(accumulator, item, index++, this);
|
|
308
|
+
}
|
|
309
|
+
return accumulator;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
exports.IterableElementBase = IterableElementBase;
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BSTNodeKeyOrNode,
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BSTNodeKeyOrNode, BTNodeExemplar } from '../../types';
|
|
10
10
|
import { BTNCallback } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
12
|
+
export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
|
|
13
13
|
height: number;
|
|
14
|
-
constructor(key:
|
|
14
|
+
constructor(key: K, value?: V);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
|
|
@@ -23,27 +23,27 @@ export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeN
|
|
|
23
23
|
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
24
24
|
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
|
|
25
25
|
*/
|
|
26
|
-
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>, TREE extends AVLTree<V, N, TREE> = AVLTree<V, N, AVLTreeNested<V, N>>> extends BST<V, N, TREE> implements IBinaryTree<V, N, TREE> {
|
|
26
|
+
export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
|
|
27
27
|
/**
|
|
28
28
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
29
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
29
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
30
30
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
31
31
|
* initialization.
|
|
32
32
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
33
33
|
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
34
34
|
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
35
35
|
*/
|
|
36
|
-
constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<AVLTreeOptions
|
|
36
|
+
constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
|
|
37
37
|
/**
|
|
38
38
|
* The function creates a new AVL tree node with the specified key and value.
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
40
40
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
41
41
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
42
42
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
43
43
|
* node type `N`.
|
|
44
44
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
45
45
|
*/
|
|
46
|
-
createNode(key:
|
|
46
|
+
createNode(key: K, value?: V): N;
|
|
47
47
|
/**
|
|
48
48
|
* The function creates a new AVL tree with the specified options and returns it.
|
|
49
49
|
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
|
|
@@ -51,13 +51,13 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
51
51
|
* being created.
|
|
52
52
|
* @returns a new AVLTree object.
|
|
53
53
|
*/
|
|
54
|
-
createTree(options?: AVLTreeOptions): TREE;
|
|
54
|
+
createTree(options?: AVLTreeOptions<K>): TREE;
|
|
55
55
|
/**
|
|
56
56
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
57
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
57
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
58
58
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
59
59
|
*/
|
|
60
|
-
isNode(exemplar: BTNodeExemplar<V, N>): exemplar is N;
|
|
60
|
+
isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
|
|
61
61
|
/**
|
|
62
62
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
63
63
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -72,7 +72,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
72
72
|
* entry.
|
|
73
73
|
* @returns The method is returning either the inserted node or `undefined`.
|
|
74
74
|
*/
|
|
75
|
-
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | undefined;
|
|
75
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
78
78
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -96,14 +96,14 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
96
96
|
/**
|
|
97
97
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
98
98
|
* tree.
|
|
99
|
-
* @param {
|
|
100
|
-
* needs to be swapped with the destination node. It can be of type `
|
|
101
|
-
* @param {
|
|
99
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
100
|
+
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
|
|
101
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
102
102
|
* node where the values from the source node will be swapped to.
|
|
103
103
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
104
104
|
* if either `srcNode` or `destNode` is undefined.
|
|
105
105
|
*/
|
|
106
|
-
protected _swapProperties(srcNode: BSTNodeKeyOrNode<N>, destNode: BSTNodeKeyOrNode<N>): N | undefined;
|
|
106
|
+
protected _swapProperties(srcNode: BSTNodeKeyOrNode<K, N>, destNode: BSTNodeKeyOrNode<K, N>): N | undefined;
|
|
107
107
|
/**
|
|
108
108
|
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
109
109
|
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|