avl-tree-typed 1.54.2 → 2.0.0
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/README.md +64 -0
- package/dist/data-structures/base/iterable-element-base.d.ts +14 -40
- package/dist/data-structures/base/iterable-element-base.js +14 -11
- package/dist/data-structures/base/linear-base.d.ts +277 -0
- package/dist/data-structures/base/linear-base.js +552 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
- package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
- package/dist/data-structures/binary-tree/avl-tree.js +76 -8
- package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
- package/dist/data-structures/binary-tree/binary-tree.js +244 -149
- package/dist/data-structures/binary-tree/bst.d.ts +62 -56
- package/dist/data-structures/binary-tree/bst.js +89 -133
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
- package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/data-structures/binary-tree/tree-counter.js +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
- package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/heap/heap.d.ts +3 -11
- package/dist/data-structures/heap/heap.js +0 -10
- package/dist/data-structures/heap/max-heap.d.ts +2 -2
- package/dist/data-structures/heap/min-heap.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
- package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
- package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
- package/dist/data-structures/queue/deque.d.ts +130 -91
- package/dist/data-structures/queue/deque.js +269 -169
- package/dist/data-structures/queue/queue.d.ts +84 -40
- package/dist/data-structures/queue/queue.js +134 -50
- package/dist/data-structures/stack/stack.d.ts +3 -11
- package/dist/data-structures/stack/stack.js +0 -10
- package/dist/data-structures/trie/trie.d.ts +4 -3
- package/dist/data-structures/trie/trie.js +3 -0
- package/dist/types/data-structures/base/base.d.ts +9 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/queue/deque.d.ts +2 -3
- package/dist/types/data-structures/queue/queue.d.ts +2 -2
- package/dist/utils/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +29 -20
- package/src/data-structures/base/linear-base.ts +649 -0
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
- package/src/data-structures/binary-tree/avl-tree.ts +99 -29
- package/src/data-structures/binary-tree/binary-tree.ts +474 -257
- package/src/data-structures/binary-tree/bst.ts +150 -152
- package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
- package/src/data-structures/binary-tree/tree-counter.ts +33 -27
- package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/heap/heap.ts +3 -14
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/heap/min-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
- package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +286 -183
- package/src/data-structures/queue/queue.ts +149 -63
- package/src/data-structures/stack/stack.ts +3 -18
- package/src/data-structures/trie/trie.ts +7 -3
- package/src/types/data-structures/base/base.ts +17 -8
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
- package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/types/data-structures/queue/deque.ts +2 -3
- package/src/types/data-structures/queue/queue.ts +2 -2
- package/src/utils/utils.ts +2 -2
package/README.md
CHANGED
|
@@ -232,6 +232,70 @@ lastBFSNodes[0].id // 12
|
|
|
232
232
|
|
|
233
233
|
[//]: # (No deletion!!! Start of Example Replace Section)
|
|
234
234
|
|
|
235
|
+
### Find elements in a range
|
|
236
|
+
```typescript
|
|
237
|
+
type Datum = { timestamp: Date; temperature: number };
|
|
238
|
+
// Fixed dataset of CPU temperature readings
|
|
239
|
+
const cpuData: Datum[] = [
|
|
240
|
+
{ timestamp: new Date('2024-12-02T00:00:00'), temperature: 55.1 },
|
|
241
|
+
{ timestamp: new Date('2024-12-02T00:01:00'), temperature: 56.3 },
|
|
242
|
+
{ timestamp: new Date('2024-12-02T00:02:00'), temperature: 54.8 },
|
|
243
|
+
{ timestamp: new Date('2024-12-02T00:03:00'), temperature: 57.2 },
|
|
244
|
+
{ timestamp: new Date('2024-12-02T00:04:00'), temperature: 58.0 },
|
|
245
|
+
{ timestamp: new Date('2024-12-02T00:05:00'), temperature: 59.4 },
|
|
246
|
+
{ timestamp: new Date('2024-12-02T00:06:00'), temperature: 60.1 },
|
|
247
|
+
{ timestamp: new Date('2024-12-02T00:07:00'), temperature: 61.3 },
|
|
248
|
+
{ timestamp: new Date('2024-12-02T00:08:00'), temperature: 62.0 },
|
|
249
|
+
{ timestamp: new Date('2024-12-02T00:09:00'), temperature: 63.5 },
|
|
250
|
+
{ timestamp: new Date('2024-12-02T00:10:00'), temperature: 64.0 },
|
|
251
|
+
{ timestamp: new Date('2024-12-02T00:11:00'), temperature: 62.8 },
|
|
252
|
+
{ timestamp: new Date('2024-12-02T00:12:00'), temperature: 61.5 },
|
|
253
|
+
{ timestamp: new Date('2024-12-02T00:13:00'), temperature: 60.2 },
|
|
254
|
+
{ timestamp: new Date('2024-12-02T00:14:00'), temperature: 59.8 },
|
|
255
|
+
{ timestamp: new Date('2024-12-02T00:15:00'), temperature: 58.6 },
|
|
256
|
+
{ timestamp: new Date('2024-12-02T00:16:00'), temperature: 57.4 },
|
|
257
|
+
{ timestamp: new Date('2024-12-02T00:17:00'), temperature: 56.2 },
|
|
258
|
+
{ timestamp: new Date('2024-12-02T00:18:00'), temperature: 55.7 },
|
|
259
|
+
{ timestamp: new Date('2024-12-02T00:19:00'), temperature: 54.5 },
|
|
260
|
+
{ timestamp: new Date('2024-12-02T00:20:00'), temperature: 53.2 },
|
|
261
|
+
{ timestamp: new Date('2024-12-02T00:21:00'), temperature: 52.8 },
|
|
262
|
+
{ timestamp: new Date('2024-12-02T00:22:00'), temperature: 51.9 },
|
|
263
|
+
{ timestamp: new Date('2024-12-02T00:23:00'), temperature: 50.5 },
|
|
264
|
+
{ timestamp: new Date('2024-12-02T00:24:00'), temperature: 49.8 },
|
|
265
|
+
{ timestamp: new Date('2024-12-02T00:25:00'), temperature: 48.7 },
|
|
266
|
+
{ timestamp: new Date('2024-12-02T00:26:00'), temperature: 47.5 },
|
|
267
|
+
{ timestamp: new Date('2024-12-02T00:27:00'), temperature: 46.3 },
|
|
268
|
+
{ timestamp: new Date('2024-12-02T00:28:00'), temperature: 45.9 },
|
|
269
|
+
{ timestamp: new Date('2024-12-02T00:29:00'), temperature: 45.0 }
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
// Create an AVL tree to store CPU temperature data
|
|
273
|
+
const cpuTemperatureTree = new AVLTree<Date, number, Datum>(cpuData, {
|
|
274
|
+
toEntryFn: ({ timestamp, temperature }) => [timestamp, temperature]
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Query a specific time range (e.g., from 00:05 to 00:15)
|
|
278
|
+
const rangeStart = new Date('2024-12-02T00:05:00');
|
|
279
|
+
const rangeEnd = new Date('2024-12-02T00:15:00');
|
|
280
|
+
const rangeResults = cpuTemperatureTree.rangeSearch([rangeStart, rangeEnd], node => ({
|
|
281
|
+
minute: node ? node.key.getMinutes() : 0,
|
|
282
|
+
temperature: cpuTemperatureTree.get(node ? node.key : undefined)
|
|
283
|
+
}));
|
|
284
|
+
|
|
285
|
+
console.log(rangeResults); // [
|
|
286
|
+
// { minute: 5, temperature: 59.4 },
|
|
287
|
+
// { minute: 6, temperature: 60.1 },
|
|
288
|
+
// { minute: 7, temperature: 61.3 },
|
|
289
|
+
// { minute: 8, temperature: 62 },
|
|
290
|
+
// { minute: 9, temperature: 63.5 },
|
|
291
|
+
// { minute: 10, temperature: 64 },
|
|
292
|
+
// { minute: 11, temperature: 62.8 },
|
|
293
|
+
// { minute: 12, temperature: 61.5 },
|
|
294
|
+
// { minute: 13, temperature: 60.2 },
|
|
295
|
+
// { minute: 14, temperature: 59.8 },
|
|
296
|
+
// { minute: 15, temperature: 58.6 }
|
|
297
|
+
// ]
|
|
298
|
+
```
|
|
235
299
|
|
|
236
300
|
[//]: # (No deletion!!! End of Example Replace Section)
|
|
237
301
|
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
|
|
2
|
-
export declare abstract class IterableElementBase<E, R
|
|
2
|
+
export declare abstract class IterableElementBase<E, R> {
|
|
3
3
|
/**
|
|
4
4
|
* The protected constructor initializes the options for the IterableElementBase class, including the
|
|
5
5
|
* toElementFn function.
|
|
6
6
|
* @param [options] - An optional object that contains the following properties:
|
|
7
7
|
*/
|
|
8
8
|
protected constructor(options?: IterableElementBaseOptions<E, R>);
|
|
9
|
-
abstract get size(): number;
|
|
10
9
|
protected _toElementFn?: (rawElement: R) => E;
|
|
11
|
-
/**
|
|
12
|
-
* The function returns the _toElementFn property, which is a function that converts a raw element to
|
|
13
|
-
* a specific type.
|
|
14
|
-
* @returns The function `get toElementFn()` is returning either a function that takes a raw element
|
|
15
|
-
* `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
|
|
16
|
-
* `_toElementFn`.
|
|
17
|
-
*/
|
|
18
10
|
get toElementFn(): ((rawElement: R) => E) | undefined;
|
|
19
11
|
/**
|
|
20
12
|
* Time Complexity: O(n)
|
|
@@ -47,7 +39,7 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
47
39
|
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
48
40
|
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
49
41
|
*/
|
|
50
|
-
every(predicate: ElementCallback<E, R, boolean
|
|
42
|
+
every(predicate: ElementCallback<E, R, boolean>, thisArg?: any): boolean;
|
|
51
43
|
/**
|
|
52
44
|
* Time Complexity: O(n)
|
|
53
45
|
* Space Complexity: O(1)
|
|
@@ -62,7 +54,7 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
62
54
|
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
63
55
|
* in the collection, and false otherwise.
|
|
64
56
|
*/
|
|
65
|
-
some(predicate: ElementCallback<E, R, boolean
|
|
57
|
+
some(predicate: ElementCallback<E, R, boolean>, thisArg?: any): boolean;
|
|
66
58
|
/**
|
|
67
59
|
* Time Complexity: O(n)
|
|
68
60
|
* Space Complexity: O(1)
|
|
@@ -76,24 +68,9 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
76
68
|
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
77
69
|
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
78
70
|
*/
|
|
79
|
-
forEach(callbackfn: ElementCallback<E, R, void
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* Space Complexity: O(1)
|
|
83
|
-
*
|
|
84
|
-
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
85
|
-
* element that satisfies the provided callback function.
|
|
86
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
87
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
88
|
-
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
89
|
-
* current element matches the desired condition.
|
|
90
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
91
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
92
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
93
|
-
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
94
|
-
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
95
|
-
*/
|
|
96
|
-
find(callbackfn: ElementCallback<E, R, boolean, C>, thisArg?: any): E | undefined;
|
|
71
|
+
forEach(callbackfn: ElementCallback<E, R, void>, thisArg?: any): void;
|
|
72
|
+
find<S extends E>(predicate: ElementCallback<E, R, S>, thisArg?: any): S | undefined;
|
|
73
|
+
find(predicate: ElementCallback<E, R, unknown>, thisArg?: any): E | undefined;
|
|
97
74
|
/**
|
|
98
75
|
* Time Complexity: O(n)
|
|
99
76
|
* Space Complexity: O(1)
|
|
@@ -105,20 +82,17 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
105
82
|
* otherwise.
|
|
106
83
|
*/
|
|
107
84
|
has(element: E): boolean;
|
|
85
|
+
reduce(callbackfn: ReduceElementCallback<E, R>): E;
|
|
86
|
+
reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
|
|
87
|
+
reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
|
|
108
88
|
/**
|
|
109
89
|
* Time Complexity: O(n)
|
|
110
|
-
* Space Complexity: O(
|
|
90
|
+
* Space Complexity: O(n)
|
|
111
91
|
*
|
|
112
|
-
* The `
|
|
113
|
-
*
|
|
114
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
115
|
-
* the array. It takes four arguments:
|
|
116
|
-
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
117
|
-
* is the value that the accumulator starts with before the reduction operation begins.
|
|
118
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
119
|
-
* all the elements in the array and applying the callback function to each element.
|
|
92
|
+
* The `toArray` function converts a linked list into an array.
|
|
93
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
120
94
|
*/
|
|
121
|
-
|
|
95
|
+
toArray(): E[];
|
|
122
96
|
/**
|
|
123
97
|
* Time Complexity: O(n)
|
|
124
98
|
* Space Complexity: O(n)
|
|
@@ -135,7 +109,7 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
135
109
|
print(): void;
|
|
136
110
|
abstract isEmpty(): boolean;
|
|
137
111
|
abstract clear(): void;
|
|
138
|
-
abstract clone():
|
|
112
|
+
abstract clone(): IterableElementBase<E, R>;
|
|
139
113
|
abstract map(...args: any[]): any;
|
|
140
114
|
abstract filter(...args: any[]): any;
|
|
141
115
|
protected abstract _getIterator(...args: any[]): IterableIterator<E>;
|
|
@@ -16,13 +16,6 @@ class IterableElementBase {
|
|
|
16
16
|
throw new TypeError('toElementFn must be a function type');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* The function returns the _toElementFn property, which is a function that converts a raw element to
|
|
21
|
-
* a specific type.
|
|
22
|
-
* @returns The function `get toElementFn()` is returning either a function that takes a raw element
|
|
23
|
-
* `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
|
|
24
|
-
* `_toElementFn`.
|
|
25
|
-
*/
|
|
26
19
|
get toElementFn() {
|
|
27
20
|
return this._toElementFn;
|
|
28
21
|
}
|
|
@@ -120,7 +113,7 @@ class IterableElementBase {
|
|
|
120
113
|
*
|
|
121
114
|
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
122
115
|
* element that satisfies the provided callback function.
|
|
123
|
-
* @param
|
|
116
|
+
* @param predicate - The predicate parameter is a function that will be called for each element in
|
|
124
117
|
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
125
118
|
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
126
119
|
* current element matches the desired condition.
|
|
@@ -130,10 +123,10 @@ class IterableElementBase {
|
|
|
130
123
|
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
131
124
|
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
132
125
|
*/
|
|
133
|
-
find(
|
|
126
|
+
find(predicate, thisArg) {
|
|
134
127
|
let index = 0;
|
|
135
128
|
for (const item of this) {
|
|
136
|
-
if (
|
|
129
|
+
if (predicate.call(thisArg, item, index++, this))
|
|
137
130
|
return item;
|
|
138
131
|
}
|
|
139
132
|
return;
|
|
@@ -169,13 +162,23 @@ class IterableElementBase {
|
|
|
169
162
|
* all the elements in the array and applying the callback function to each element.
|
|
170
163
|
*/
|
|
171
164
|
reduce(callbackfn, initialValue) {
|
|
172
|
-
let accumulator = initialValue;
|
|
165
|
+
let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : 0;
|
|
173
166
|
let index = 0;
|
|
174
167
|
for (const item of this) {
|
|
175
168
|
accumulator = callbackfn(accumulator, item, index++, this);
|
|
176
169
|
}
|
|
177
170
|
return accumulator;
|
|
178
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Time Complexity: O(n)
|
|
174
|
+
* Space Complexity: O(n)
|
|
175
|
+
*
|
|
176
|
+
* The `toArray` function converts a linked list into an array.
|
|
177
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
178
|
+
*/
|
|
179
|
+
toArray() {
|
|
180
|
+
return [...this];
|
|
181
|
+
}
|
|
179
182
|
/**
|
|
180
183
|
* Time Complexity: O(n)
|
|
181
184
|
* Space Complexity: O(n)
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { ElementCallback, LinearBaseOptions, ReduceLinearCallback } from '../../types';
|
|
2
|
+
import { IterableElementBase } from './iterable-element-base';
|
|
3
|
+
export declare class LinkedListNode<E = any> {
|
|
4
|
+
constructor(value: E);
|
|
5
|
+
protected _value: E;
|
|
6
|
+
get value(): E;
|
|
7
|
+
set value(value: E);
|
|
8
|
+
protected _next: LinkedListNode<E> | undefined;
|
|
9
|
+
get next(): LinkedListNode<E> | undefined;
|
|
10
|
+
set next(value: LinkedListNode<E> | undefined);
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class LinearBase<E, R = any, NODE extends LinkedListNode<E> = LinkedListNode<E>> extends IterableElementBase<E, R> {
|
|
13
|
+
/**
|
|
14
|
+
* The constructor initializes the LinearBase class with optional options, setting the maximum length
|
|
15
|
+
* if provided.
|
|
16
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
17
|
+
* constructor. It is of type `LinearBaseOptions<E, R>`. The constructor checks if the `options`
|
|
18
|
+
* object is provided and then extracts the `maxLen` property from it. If `maxLen` is a
|
|
19
|
+
*/
|
|
20
|
+
protected constructor(options?: LinearBaseOptions<E, R>);
|
|
21
|
+
abstract get length(): number;
|
|
22
|
+
protected _maxLen: number;
|
|
23
|
+
get maxLen(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Time Complexity: O(n)
|
|
26
|
+
* Space Complexity: O(1)
|
|
27
|
+
*
|
|
28
|
+
* The function indexOf searches for a specified element starting from a given index in an array-like
|
|
29
|
+
* object and returns the index of the first occurrence, or -1 if not found.
|
|
30
|
+
* @param {E} searchElement - The `searchElement` parameter in the `indexOf` function represents the
|
|
31
|
+
* element that you want to find within the array. The function will search for this element starting
|
|
32
|
+
* from the `fromIndex` (if provided) up to the end of the array. If the `searchElement` is found
|
|
33
|
+
* within the
|
|
34
|
+
* @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` function represents the
|
|
35
|
+
* index at which to start searching for the `searchElement` within the array. If provided, the
|
|
36
|
+
* search will begin at this index and continue to the end of the array. If `fromIndex` is not
|
|
37
|
+
* specified, the default
|
|
38
|
+
* @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
|
|
39
|
+
* array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
|
|
40
|
+
*/
|
|
41
|
+
indexOf(searchElement: E, fromIndex?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Time Complexity: O(n)
|
|
44
|
+
* Space Complexity: O(1)
|
|
45
|
+
*
|
|
46
|
+
* The function `lastIndexOf` in TypeScript returns the index of the last occurrence of a specified
|
|
47
|
+
* element in an array.
|
|
48
|
+
* @param {E} searchElement - The `searchElement` parameter is the element that you want to find the
|
|
49
|
+
* last index of within the array. The `lastIndexOf` method will search the array starting from the
|
|
50
|
+
* `fromIndex` (or the end of the array if not specified) and return the index of the last occurrence
|
|
51
|
+
* of the
|
|
52
|
+
* @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
|
|
53
|
+
* index at which to start searching for the `searchElement` in the array. By default, it starts
|
|
54
|
+
* searching from the last element of the array (`this.length - 1`). If a specific `fromIndex` is
|
|
55
|
+
* provided
|
|
56
|
+
* @returns The last index of the `searchElement` in the array is being returned. If the
|
|
57
|
+
* `searchElement` is not found in the array, -1 is returned.
|
|
58
|
+
*/
|
|
59
|
+
lastIndexOf(searchElement: E, fromIndex?: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Time Complexity: O(n)
|
|
62
|
+
* Space Complexity: O(1)
|
|
63
|
+
*
|
|
64
|
+
* The `findIndex` function iterates over an array and returns the index of the first element that
|
|
65
|
+
* satisfies the provided predicate function.
|
|
66
|
+
* @param predicate - The `predicate` parameter in the `findIndex` function is a callback function
|
|
67
|
+
* that takes three arguments: `item`, `index`, and the array `this`. It should return a boolean
|
|
68
|
+
* value indicating whether the current element satisfies the condition being checked for.
|
|
69
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `findIndex` function is an optional
|
|
70
|
+
* parameter that specifies the value to use as `this` when executing the `predicate` function. If
|
|
71
|
+
* provided, the `predicate` function will be called with `thisArg` as its `this` value. If `
|
|
72
|
+
* @returns The `findIndex` method is returning the index of the first element in the array that
|
|
73
|
+
* satisfies the provided predicate function. If no such element is found, it returns -1.
|
|
74
|
+
*/
|
|
75
|
+
findIndex(predicate: ElementCallback<E, R, boolean>, thisArg?: any): number;
|
|
76
|
+
concat(...items: this[]): this;
|
|
77
|
+
/**
|
|
78
|
+
* Time Complexity: O(n log n)
|
|
79
|
+
* Space Complexity: O(n)
|
|
80
|
+
*
|
|
81
|
+
* The `sort` function in TypeScript sorts the elements of a collection using a specified comparison
|
|
82
|
+
* function.
|
|
83
|
+
* @param [compareFn] - The `compareFn` parameter is a function that defines the sort order. It takes
|
|
84
|
+
* two elements `a` and `b` as input and returns a number indicating their relative order. If the
|
|
85
|
+
* returned value is negative, `a` comes before `b`. If the returned value is positive, `
|
|
86
|
+
* @returns The `sort` method is returning the instance of the object on which it is called (this),
|
|
87
|
+
* after sorting the elements based on the provided comparison function (compareFn).
|
|
88
|
+
*/
|
|
89
|
+
sort(compareFn?: (a: E, b: E) => number): this;
|
|
90
|
+
/**
|
|
91
|
+
* Time Complexity: O(n + m)
|
|
92
|
+
* Space Complexity: O(m)
|
|
93
|
+
*
|
|
94
|
+
* The `splice` function in TypeScript removes elements from an array and optionally inserts new
|
|
95
|
+
* elements at the specified index.
|
|
96
|
+
* @param {number} start - The `start` parameter in the `splice` method indicates the index at which
|
|
97
|
+
* to start modifying the array. If `start` is a negative number, it will count from the end of the
|
|
98
|
+
* array.
|
|
99
|
+
* @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
|
|
100
|
+
* number of elements to remove from the array starting at the specified `start` index. If
|
|
101
|
+
* `deleteCount` is not provided or is 0, no elements are removed, and only new elements are inserted
|
|
102
|
+
* at the `start`
|
|
103
|
+
* @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
|
|
104
|
+
* will be inserted into the array at the specified `start` index. These elements can be of any type
|
|
105
|
+
* and you can pass multiple elements separated by commas. The `splice` method will insert these
|
|
106
|
+
* items into the array at the
|
|
107
|
+
* @returns The `splice` method returns a list of elements that were removed from the original list
|
|
108
|
+
* during the operation.
|
|
109
|
+
*/
|
|
110
|
+
splice(start: number, deleteCount?: number, ...items: E[]): this;
|
|
111
|
+
/**
|
|
112
|
+
* Time Complexity: O(n)
|
|
113
|
+
* Space Complexity: O(1)
|
|
114
|
+
*
|
|
115
|
+
* The `join` function in TypeScript returns a string by joining the elements of an array with a
|
|
116
|
+
* specified separator.
|
|
117
|
+
* @param {string} [separator=,] - The `separator` parameter is a string that specifies the character
|
|
118
|
+
* or characters that will be used to separate each element when joining them into a single string.
|
|
119
|
+
* By default, the separator is set to a comma (`,`), but you can provide a different separator if
|
|
120
|
+
* needed.
|
|
121
|
+
* @returns The `join` method is being returned, which takes an optional `separator` parameter
|
|
122
|
+
* (defaulting to a comma) and returns a string created by joining all elements of the array after
|
|
123
|
+
* converting it to an array.
|
|
124
|
+
*/
|
|
125
|
+
join(separator?: string): string;
|
|
126
|
+
/**
|
|
127
|
+
* Time Complexity: O(n)
|
|
128
|
+
* Space Complexity: O(n)
|
|
129
|
+
*
|
|
130
|
+
* The function `toReversedArray` takes an array and returns a new array with its elements in reverse
|
|
131
|
+
* order.
|
|
132
|
+
* @returns The `toReversedArray()` function returns an array of elements of type `E` in reverse
|
|
133
|
+
* order.
|
|
134
|
+
*/
|
|
135
|
+
toReversedArray(): E[];
|
|
136
|
+
reduceRight(callbackfn: ReduceLinearCallback<E>): E;
|
|
137
|
+
reduceRight(callbackfn: ReduceLinearCallback<E>, initialValue: E): E;
|
|
138
|
+
reduceRight<U>(callbackfn: ReduceLinearCallback<E, U>, initialValue: U): U;
|
|
139
|
+
/**
|
|
140
|
+
* Time Complexity: O(m)
|
|
141
|
+
* Space Complexity: O(m)
|
|
142
|
+
*
|
|
143
|
+
* The `slice` function in TypeScript creates a new instance by extracting a portion of elements from
|
|
144
|
+
* the original instance based on the specified start and end indices.
|
|
145
|
+
* @param {number} [start=0] - The `start` parameter in the `slice` method represents the index at
|
|
146
|
+
* which to begin extracting elements from an array-like object. If no `start` parameter is provided,
|
|
147
|
+
* the default value is 0, meaning the extraction will start from the beginning of the array.
|
|
148
|
+
* @param {number} end - The `end` parameter in the `slice` method represents the index at which to
|
|
149
|
+
* end the slicing. By default, if no `end` parameter is provided, it will slice until the end of the
|
|
150
|
+
* array (i.e., `this.length`).
|
|
151
|
+
* @returns The `slice` method is returning a new instance of the object with elements sliced from
|
|
152
|
+
* the specified start index (default is 0) to the specified end index (default is the length of the
|
|
153
|
+
* object).
|
|
154
|
+
*/
|
|
155
|
+
slice(start?: number, end?: number): this;
|
|
156
|
+
/**
|
|
157
|
+
* Time Complexity: O(n)
|
|
158
|
+
* Space Complexity: O(1)
|
|
159
|
+
*
|
|
160
|
+
* The `fill` function in TypeScript fills a specified range in an array-like object with a given
|
|
161
|
+
* value.
|
|
162
|
+
* @param {E} value - The `value` parameter in the `fill` method represents the element that will be
|
|
163
|
+
* used to fill the specified range in the array.
|
|
164
|
+
* @param [start=0] - The `start` parameter specifies the index at which to start filling the array
|
|
165
|
+
* with the specified value. If not provided, it defaults to 0, indicating the beginning of the
|
|
166
|
+
* array.
|
|
167
|
+
* @param end - The `end` parameter in the `fill` function represents the index at which the filling
|
|
168
|
+
* of values should stop. It specifies the end of the range within the array where the `value` should
|
|
169
|
+
* be filled.
|
|
170
|
+
* @returns The `fill` method is returning the modified object (`this`) after filling the specified
|
|
171
|
+
* range with the provided value.
|
|
172
|
+
*/
|
|
173
|
+
fill(value: E, start?: number, end?: number): this;
|
|
174
|
+
abstract setAt(index: number, value: E): boolean;
|
|
175
|
+
abstract clone(): this;
|
|
176
|
+
abstract reverse(): this;
|
|
177
|
+
abstract push(elementOrNode: E | NODE): boolean;
|
|
178
|
+
abstract pushMany(elements: Iterable<E> | Iterable<R> | Iterable<NODE>): boolean[];
|
|
179
|
+
abstract delete(elementOrNode: E | NODE | undefined): boolean;
|
|
180
|
+
abstract at(index: number): E | undefined;
|
|
181
|
+
abstract deleteAt(pos: number): E | undefined;
|
|
182
|
+
abstract addAt(index: number, newElementOrNode: E | NODE): boolean;
|
|
183
|
+
protected abstract _createInstance(options?: LinearBaseOptions<E, R>): this;
|
|
184
|
+
protected abstract _getReverseIterator(...args: any[]): IterableIterator<E>;
|
|
185
|
+
}
|
|
186
|
+
export declare abstract class LinearLinkedBase<E, R = any, NODE extends LinkedListNode<E> = LinkedListNode<E>> extends LinearBase<E, R, NODE> {
|
|
187
|
+
/**
|
|
188
|
+
* The constructor initializes the LinearBase class with optional options, setting the maximum length
|
|
189
|
+
* if provided and valid.
|
|
190
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
191
|
+
* constructor. It is of type `LinearBaseOptions<E, R>`. This object may contain properties such as
|
|
192
|
+
* `maxLen`, which is a number representing the maximum length. If `maxLen` is a positive integer,
|
|
193
|
+
*/
|
|
194
|
+
protected constructor(options?: LinearBaseOptions<E, R>);
|
|
195
|
+
/**
|
|
196
|
+
* Time Complexity: O(n)
|
|
197
|
+
* Space Complexity: O(1)
|
|
198
|
+
*
|
|
199
|
+
* The function overrides the indexOf method to improve performance by searching for an element in a
|
|
200
|
+
* custom array implementation starting from a specified index.
|
|
201
|
+
* @param {E} searchElement - The `searchElement` parameter is the element that you are searching for
|
|
202
|
+
* within the array. The `indexOf` method will return the index of the first occurrence of this
|
|
203
|
+
* element within the array.
|
|
204
|
+
* @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` method specifies the
|
|
205
|
+
* index in the array at which to start the search for the `searchElement`. If provided, the search
|
|
206
|
+
* will begin at the specified index and continue to the end of the array. If not provided, the
|
|
207
|
+
* search will start at index
|
|
208
|
+
* @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
|
|
209
|
+
* array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
|
|
210
|
+
*/
|
|
211
|
+
indexOf(searchElement: E, fromIndex?: number): number;
|
|
212
|
+
/**
|
|
213
|
+
* Time Complexity: O(n)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*
|
|
216
|
+
* The function overrides the lastIndexOf method in TypeScript to improve performance by searching
|
|
217
|
+
* for an element in reverse order starting from a specified index.
|
|
218
|
+
* @param {E} searchElement - The `searchElement` parameter is the element that you want to find
|
|
219
|
+
* within the array. The `lastIndexOf` method searches the array for this element starting from the
|
|
220
|
+
* end of the array (or from the specified `fromIndex` if provided) and returns the index of the last
|
|
221
|
+
* occurrence of the element
|
|
222
|
+
* @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
|
|
223
|
+
* index at which to start searching for the `searchElement` in the array. If provided, the search
|
|
224
|
+
* will begin at this index and move towards the beginning of the array. If not provided, the search
|
|
225
|
+
* will start at the
|
|
226
|
+
* @returns The `lastIndexOf` method is being overridden to search for the `searchElement` starting
|
|
227
|
+
* from the specified `fromIndex` (defaulting to the end of the array). It iterates over the array in
|
|
228
|
+
* reverse order using a custom iterator `_getReverseIterator` and returns the index of the last
|
|
229
|
+
* occurrence of the `searchElement` if found, or -1 if not found.
|
|
230
|
+
*/
|
|
231
|
+
lastIndexOf(searchElement: E, fromIndex?: number): number;
|
|
232
|
+
concat(...items: LinearBase<E, R>[]): this;
|
|
233
|
+
/**
|
|
234
|
+
* Time Complexity: O(m)
|
|
235
|
+
* Space Complexity: O(m)
|
|
236
|
+
*
|
|
237
|
+
* The `slice` method is overridden to improve performance by creating a new instance and iterating
|
|
238
|
+
* through the array to extract a subset based on the specified start and end indices.
|
|
239
|
+
* @param {number} [start=0] - The `start` parameter in the `slice` method specifies the index at
|
|
240
|
+
* which to begin extracting elements from the array. If no `start` parameter is provided, the
|
|
241
|
+
* default value is 0, indicating that extraction should start from the beginning of the array.
|
|
242
|
+
* @param {number} end - The `end` parameter in the `slice` method represents the index at which to
|
|
243
|
+
* end the slicing of the array. If not provided, it defaults to the length of the array.
|
|
244
|
+
* @returns The `slice` method is returning a new instance of the array implementation with elements
|
|
245
|
+
* sliced from the original array based on the `start` and `end` parameters.
|
|
246
|
+
*/
|
|
247
|
+
slice(start?: number, end?: number): this;
|
|
248
|
+
/**
|
|
249
|
+
* Time Complexity: O(n + m)
|
|
250
|
+
* Space Complexity: O(m)
|
|
251
|
+
*
|
|
252
|
+
* The function overrides the splice method to handle deletion and insertion of elements in a data
|
|
253
|
+
* structure while returning the removed elements.
|
|
254
|
+
* @param {number} start - The `start` parameter in the `splice` method indicates the index at which
|
|
255
|
+
* to start modifying the array.
|
|
256
|
+
* @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
|
|
257
|
+
* number of elements to remove from the array starting at the specified `start` index. If
|
|
258
|
+
* `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
|
|
259
|
+
* elements can still be inserted at
|
|
260
|
+
* @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
|
|
261
|
+
* will be inserted into the array at the specified `start` index. These elements can be of any type
|
|
262
|
+
* and there can be multiple elements passed as arguments to be inserted into the array.
|
|
263
|
+
* @returns The `splice` method is returning a new instance of the data structure that was modified
|
|
264
|
+
* by removing elements specified by the `start` and `deleteCount` parameters, and inserting new
|
|
265
|
+
* elements provided in the `items` array.
|
|
266
|
+
*/
|
|
267
|
+
splice(start: number, deleteCount?: number, ...items: E[]): this;
|
|
268
|
+
reduceRight(callbackfn: ReduceLinearCallback<E>): E;
|
|
269
|
+
reduceRight(callbackfn: ReduceLinearCallback<E>, initialValue: E): E;
|
|
270
|
+
reduceRight<U>(callbackfn: ReduceLinearCallback<E, U>, initialValue: U): U;
|
|
271
|
+
abstract delete(elementOrNode: E | NODE | undefined): boolean;
|
|
272
|
+
abstract addBefore(existingElementOrNode: E | NODE, newElementOrNode: E | NODE): boolean;
|
|
273
|
+
abstract addAfter(existingElementOrNode: E | NODE, newElementOrNode: E | NODE): boolean;
|
|
274
|
+
abstract getNodeAt(index: number): NODE | undefined;
|
|
275
|
+
protected abstract _getNodeIterator(...args: any[]): IterableIterator<NODE>;
|
|
276
|
+
protected abstract _getPrevNode(node: NODE): NODE | undefined;
|
|
277
|
+
}
|