bst-typed 2.0.5 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +602 -873
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
- package/src/data-structures/binary-tree/avl-tree.ts +237 -206
- package/src/data-structures/binary-tree/binary-tree.ts +665 -896
- package/src/data-structures/binary-tree/bst.ts +565 -572
- package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
- package/src/data-structures/binary-tree/tree-counter.ts +195 -219
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
|
@@ -1,277 +1,335 @@
|
|
|
1
|
-
import { ElementCallback, LinearBaseOptions, ReduceLinearCallback } from '../../types';
|
|
1
|
+
import type { ElementCallback, LinearBaseOptions, ReduceLinearCallback } from '../../types';
|
|
2
2
|
import { IterableElementBase } from './iterable-element-base';
|
|
3
|
+
/**
|
|
4
|
+
* Singly-linked list node.
|
|
5
|
+
* @template E - Element type.
|
|
6
|
+
* @remarks Time O(1), Space O(1)
|
|
7
|
+
*/
|
|
3
8
|
export declare class LinkedListNode<E = any> {
|
|
9
|
+
/**
|
|
10
|
+
* Initialize a node.
|
|
11
|
+
* @param value - Element value.
|
|
12
|
+
* @remarks Time O(1), Space O(1)
|
|
13
|
+
*/
|
|
4
14
|
constructor(value: E);
|
|
5
15
|
protected _value: E;
|
|
16
|
+
/**
|
|
17
|
+
* Element payload getter.
|
|
18
|
+
* @returns Element value.
|
|
19
|
+
* @remarks Time O(1), Space O(1)
|
|
20
|
+
*/
|
|
6
21
|
get value(): E;
|
|
22
|
+
/**
|
|
23
|
+
* Element payload setter.
|
|
24
|
+
* @param value - New value.
|
|
25
|
+
* @remarks Time O(1), Space O(1)
|
|
26
|
+
*/
|
|
7
27
|
set value(value: E);
|
|
8
28
|
protected _next: LinkedListNode<E> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Next node getter.
|
|
31
|
+
* @returns Next node or `undefined`.
|
|
32
|
+
* @remarks Time O(1), Space O(1)
|
|
33
|
+
*/
|
|
9
34
|
get next(): LinkedListNode<E> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Next node setter.
|
|
37
|
+
* @param value - Next node or `undefined`.
|
|
38
|
+
* @remarks Time O(1), Space O(1)
|
|
39
|
+
*/
|
|
10
40
|
set next(value: LinkedListNode<E> | undefined);
|
|
11
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Abstract linear container with array-like utilities.
|
|
44
|
+
* @template E - Element type.
|
|
45
|
+
* @template R - Return type for mapped/derived views.
|
|
46
|
+
* @template NODE - Linked node type used by some implementations.
|
|
47
|
+
* @remarks Time O(1), Space O(1)
|
|
48
|
+
*/
|
|
12
49
|
export declare abstract class LinearBase<E, R = any, NODE extends LinkedListNode<E> = LinkedListNode<E>> extends IterableElementBase<E, R> {
|
|
13
50
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
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
|
|
51
|
+
* Construct a linear container with runtime options.
|
|
52
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
53
|
+
* @remarks Time O(1), Space O(1)
|
|
19
54
|
*/
|
|
20
55
|
protected constructor(options?: LinearBaseOptions<E, R>);
|
|
56
|
+
/**
|
|
57
|
+
* Element count.
|
|
58
|
+
* @returns Number of elements.
|
|
59
|
+
* @remarks Time O(1), Space O(1)
|
|
60
|
+
*/
|
|
21
61
|
abstract get length(): number;
|
|
22
62
|
protected _maxLen: number;
|
|
63
|
+
/**
|
|
64
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
65
|
+
* @returns Maximum allowed length.
|
|
66
|
+
* @remarks Time O(1), Space O(1)
|
|
67
|
+
*/
|
|
23
68
|
get maxLen(): number;
|
|
24
69
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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.
|
|
70
|
+
* First index of a value from the left.
|
|
71
|
+
* @param searchElement - Value to match.
|
|
72
|
+
* @param fromIndex - Start position (supports negative index).
|
|
73
|
+
* @returns Index or `-1` if not found.
|
|
74
|
+
* @remarks Time O(n), Space O(1)
|
|
40
75
|
*/
|
|
41
76
|
indexOf(searchElement: E, fromIndex?: number): number;
|
|
42
77
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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.
|
|
78
|
+
* Last index of a value from the right.
|
|
79
|
+
* @param searchElement - Value to match.
|
|
80
|
+
* @param fromIndex - Start position (supports negative index).
|
|
81
|
+
* @returns Index or `-1` if not found.
|
|
82
|
+
* @remarks Time O(n), Space O(1)
|
|
58
83
|
*/
|
|
59
84
|
lastIndexOf(searchElement: E, fromIndex?: number): number;
|
|
60
85
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
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.
|
|
86
|
+
* Find the first index matching a predicate.
|
|
87
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
88
|
+
* @param thisArg - Optional `this` for callback.
|
|
89
|
+
* @returns Index or `-1`.
|
|
90
|
+
* @remarks Time O(n), Space O(1)
|
|
74
91
|
*/
|
|
75
92
|
findIndex(predicate: ElementCallback<E, R, boolean>, thisArg?: any): number;
|
|
93
|
+
/**
|
|
94
|
+
* Concatenate multiple containers of the same species.
|
|
95
|
+
* @param items - Other lists to append.
|
|
96
|
+
* @returns New container with combined elements (`this` type).
|
|
97
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
98
|
+
*/
|
|
76
99
|
concat(...items: this[]): this;
|
|
77
100
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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).
|
|
101
|
+
* In-place stable order via array sort semantics.
|
|
102
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
103
|
+
* @returns This container.
|
|
104
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
88
105
|
*/
|
|
89
106
|
sort(compareFn?: (a: E, b: E) => number): this;
|
|
90
107
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* elements
|
|
96
|
-
* @
|
|
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.
|
|
108
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
109
|
+
* @param start - Start index (supports negative index).
|
|
110
|
+
* @param deleteCount - How many to remove.
|
|
111
|
+
* @param items - Elements to insert.
|
|
112
|
+
* @returns Removed elements as a new list (`this` type).
|
|
113
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
109
114
|
*/
|
|
110
115
|
splice(start: number, deleteCount?: number, ...items: E[]): this;
|
|
111
116
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
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.
|
|
117
|
+
* Join all elements into a string.
|
|
118
|
+
* @param separator - Separator string.
|
|
119
|
+
* @returns Concatenated string.
|
|
120
|
+
* @remarks Time O(n), Space O(n)
|
|
124
121
|
*/
|
|
125
122
|
join(separator?: string): string;
|
|
126
123
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
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.
|
|
124
|
+
* Snapshot elements into a reversed array.
|
|
125
|
+
* @returns New reversed array.
|
|
126
|
+
* @remarks Time O(n), Space O(n)
|
|
134
127
|
*/
|
|
135
128
|
toReversedArray(): E[];
|
|
136
129
|
reduceRight(callbackfn: ReduceLinearCallback<E>): E;
|
|
137
130
|
reduceRight(callbackfn: ReduceLinearCallback<E>, initialValue: E): E;
|
|
131
|
+
/**
|
|
132
|
+
* Right-to-left reduction over elements.
|
|
133
|
+
* @param callbackfn - `(acc, element, index, self) => acc`.
|
|
134
|
+
* @param initialValue - Initial accumulator (optional generic overloads supported).
|
|
135
|
+
* @returns Final accumulator.
|
|
136
|
+
* @remarks Time O(n), Space O(1)
|
|
137
|
+
*/
|
|
138
138
|
reduceRight<U>(callbackfn: ReduceLinearCallback<E, U>, initialValue: U): U;
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
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).
|
|
140
|
+
* Create a shallow copy of a subrange.
|
|
141
|
+
* @param start - Inclusive start (supports negative index).
|
|
142
|
+
* @param end - Exclusive end (supports negative index).
|
|
143
|
+
* @returns New list with the range (`this` type).
|
|
144
|
+
* @remarks Time O(n), Space O(n)
|
|
154
145
|
*/
|
|
155
146
|
slice(start?: number, end?: number): this;
|
|
156
147
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* @
|
|
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.
|
|
148
|
+
* Fill a range with a value.
|
|
149
|
+
* @param value - Value to set.
|
|
150
|
+
* @param start - Inclusive start.
|
|
151
|
+
* @param end - Exclusive end.
|
|
152
|
+
* @returns This list.
|
|
153
|
+
* @remarks Time O(n), Space O(1)
|
|
172
154
|
*/
|
|
173
155
|
fill(value: E, start?: number, end?: number): this;
|
|
156
|
+
/**
|
|
157
|
+
* Set the value at an index.
|
|
158
|
+
* @param index - Position (0-based).
|
|
159
|
+
* @param value - New value.
|
|
160
|
+
* @returns `true` if updated.
|
|
161
|
+
* @remarks Time O(1) typical, Space O(1)
|
|
162
|
+
*/
|
|
174
163
|
abstract setAt(index: number, value: E): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Deep clone while preserving concrete subtype.
|
|
166
|
+
* @returns New list of the same species (`this` type).
|
|
167
|
+
* @remarks Time O(n), Space O(n)
|
|
168
|
+
*/
|
|
175
169
|
abstract clone(): this;
|
|
170
|
+
/**
|
|
171
|
+
* Reverse the order of elements in-place (or equivalent).
|
|
172
|
+
* @returns This list.
|
|
173
|
+
* @remarks Time O(n), Space O(1)
|
|
174
|
+
*/
|
|
176
175
|
abstract reverse(): this;
|
|
176
|
+
/**
|
|
177
|
+
* Append one element or node to the tail.
|
|
178
|
+
* @param elementOrNode - Element or node.
|
|
179
|
+
* @returns `true` if appended.
|
|
180
|
+
* @remarks Time O(1) amortized typical, Space O(1)
|
|
181
|
+
*/
|
|
177
182
|
abstract push(elementOrNode: E | NODE): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Append many elements/nodes at once.
|
|
185
|
+
* @param elements - Iterable of elements or nodes.
|
|
186
|
+
* @returns Array of booleans indicating append success.
|
|
187
|
+
* @remarks Time O(n), Space O(1)
|
|
188
|
+
*/
|
|
178
189
|
abstract pushMany(elements: Iterable<E> | Iterable<R> | Iterable<NODE>): boolean[];
|
|
190
|
+
/**
|
|
191
|
+
* Remove one element or node if present.
|
|
192
|
+
* @param elementOrNode - Element or node to delete.
|
|
193
|
+
* @returns `true` if removed.
|
|
194
|
+
* @remarks Time O(1)~O(n) depending on implementation, Space O(1)
|
|
195
|
+
*/
|
|
179
196
|
abstract delete(elementOrNode: E | NODE | undefined): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Get element at an index.
|
|
199
|
+
* @param index - Position (0-based).
|
|
200
|
+
* @returns Element or `undefined`.
|
|
201
|
+
* @remarks Time O(1)~O(n) depending on implementation, Space O(1)
|
|
202
|
+
*/
|
|
180
203
|
abstract at(index: number): E | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Remove element at a position.
|
|
206
|
+
* @param pos - Position (0-based).
|
|
207
|
+
* @returns Removed element or `undefined`.
|
|
208
|
+
* @remarks Time O(1)~O(n) depending on implementation, Space O(1)
|
|
209
|
+
*/
|
|
181
210
|
abstract deleteAt(pos: number): E | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Insert an element/node at a position.
|
|
213
|
+
* @param index - Position (0-based).
|
|
214
|
+
* @param newElementOrNode - Element or node to insert.
|
|
215
|
+
* @returns `true` if inserted.
|
|
216
|
+
* @remarks Time O(1)~O(n) depending on implementation, Space O(1)
|
|
217
|
+
*/
|
|
182
218
|
abstract addAt(index: number, newElementOrNode: E | NODE): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Create an empty list of the same species.
|
|
221
|
+
* @param options - Runtime options to carry.
|
|
222
|
+
* @returns Empty list (`this` type).
|
|
223
|
+
* @remarks Time O(1), Space O(1)
|
|
224
|
+
*/
|
|
183
225
|
protected abstract _createInstance(options?: LinearBaseOptions<E, R>): this;
|
|
226
|
+
/**
|
|
227
|
+
* Reverse-direction iterator over elements.
|
|
228
|
+
* @returns Iterator of elements from tail to head.
|
|
229
|
+
* @remarks Time O(n), Space O(1)
|
|
230
|
+
*/
|
|
184
231
|
protected abstract _getReverseIterator(...args: any[]): IterableIterator<E>;
|
|
185
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Linked-list specialized linear container.
|
|
235
|
+
* @template E - Element type.
|
|
236
|
+
* @template R - Return type for mapped/derived views.
|
|
237
|
+
* @template NODE - Linked node type.
|
|
238
|
+
* @remarks Time O(1), Space O(1)
|
|
239
|
+
*/
|
|
186
240
|
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
241
|
protected constructor(options?: LinearBaseOptions<E, R>);
|
|
195
242
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
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.
|
|
243
|
+
* Linked-list optimized `indexOf` (forwards scan).
|
|
244
|
+
* @param searchElement - Value to match.
|
|
245
|
+
* @param fromIndex - Start position.
|
|
246
|
+
* @returns Index or `-1`.
|
|
247
|
+
* @remarks Time O(n), Space O(1)
|
|
210
248
|
*/
|
|
211
249
|
indexOf(searchElement: E, fromIndex?: number): number;
|
|
212
250
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
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.
|
|
251
|
+
* Linked-list optimized `lastIndexOf` (reverse scan).
|
|
252
|
+
* @param searchElement - Value to match.
|
|
253
|
+
* @param fromIndex - Start position.
|
|
254
|
+
* @returns Index or `-1`.
|
|
255
|
+
* @remarks Time O(n), Space O(1)
|
|
230
256
|
*/
|
|
231
257
|
lastIndexOf(searchElement: E, fromIndex?: number): number;
|
|
258
|
+
/**
|
|
259
|
+
* Concatenate lists/elements preserving order.
|
|
260
|
+
* @param items - Elements or `LinearBase` instances.
|
|
261
|
+
* @returns New list with combined elements (`this` type).
|
|
262
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
263
|
+
*/
|
|
232
264
|
concat(...items: LinearBase<E, R>[]): this;
|
|
233
265
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
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.
|
|
266
|
+
* Slice via forward iteration (no random access required).
|
|
267
|
+
* @param start - Inclusive start (supports negative index).
|
|
268
|
+
* @param end - Exclusive end (supports negative index).
|
|
269
|
+
* @returns New list (`this` type).
|
|
270
|
+
* @remarks Time O(n), Space O(n)
|
|
246
271
|
*/
|
|
247
272
|
slice(start?: number, end?: number): this;
|
|
248
273
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* @
|
|
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.
|
|
274
|
+
* Splice by walking node iterators from the start index.
|
|
275
|
+
* @param start - Start index.
|
|
276
|
+
* @param deleteCount - How many elements to remove.
|
|
277
|
+
* @param items - Elements to insert after the splice point.
|
|
278
|
+
* @returns Removed elements as a new list (`this` type).
|
|
279
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
266
280
|
*/
|
|
267
281
|
splice(start: number, deleteCount?: number, ...items: E[]): this;
|
|
268
282
|
reduceRight(callbackfn: ReduceLinearCallback<E>): E;
|
|
269
283
|
reduceRight(callbackfn: ReduceLinearCallback<E>, initialValue: E): E;
|
|
284
|
+
/**
|
|
285
|
+
* Right-to-left reduction using reverse iterator.
|
|
286
|
+
* @param callbackfn - `(acc, element, index, self) => acc`.
|
|
287
|
+
* @param initialValue - Initial accumulator.
|
|
288
|
+
* @returns Final accumulator.
|
|
289
|
+
* @remarks Time O(n), Space O(1)
|
|
290
|
+
*/
|
|
270
291
|
reduceRight<U>(callbackfn: ReduceLinearCallback<E, U>, initialValue: U): U;
|
|
292
|
+
/**
|
|
293
|
+
* Delete by element or node in a linked list.
|
|
294
|
+
* @param elementOrNode - Element or node.
|
|
295
|
+
* @returns `true` if removed.
|
|
296
|
+
* @remarks Time O(1)~O(n) depending on availability of links, Space O(1)
|
|
297
|
+
*/
|
|
271
298
|
abstract delete(elementOrNode: E | NODE | undefined): boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Insert new element/node before an existing node.
|
|
301
|
+
* @param existingElementOrNode - Reference element/node.
|
|
302
|
+
* @param newElementOrNode - Element/node to insert.
|
|
303
|
+
* @returns `true` if inserted.
|
|
304
|
+
* @remarks Time O(1)~O(n) depending on reference access, Space O(1)
|
|
305
|
+
*/
|
|
272
306
|
abstract addBefore(existingElementOrNode: E | NODE, newElementOrNode: E | NODE): boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Insert new element/node after an existing node.
|
|
309
|
+
* @param existingElementOrNode - Reference element/node.
|
|
310
|
+
* @param newElementOrNode - Element/node to insert.
|
|
311
|
+
* @returns `true` if inserted.
|
|
312
|
+
* @remarks Time O(1)~O(n) depending on reference access, Space O(1)
|
|
313
|
+
*/
|
|
273
314
|
abstract addAfter(existingElementOrNode: E | NODE, newElementOrNode: E | NODE): boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Node at index (for random-access emulation).
|
|
317
|
+
* @param index - Position (0-based).
|
|
318
|
+
* @returns Node or `undefined`.
|
|
319
|
+
* @remarks Time O(n), Space O(1)
|
|
320
|
+
*/
|
|
274
321
|
abstract getNodeAt(index: number): NODE | undefined;
|
|
322
|
+
/**
|
|
323
|
+
* Iterate linked nodes from head to tail.
|
|
324
|
+
* @returns Iterator over nodes.
|
|
325
|
+
* @remarks Time O(n), Space O(1)
|
|
326
|
+
*/
|
|
275
327
|
protected abstract _getNodeIterator(...args: any[]): IterableIterator<NODE>;
|
|
328
|
+
/**
|
|
329
|
+
* Get previous node of a given node.
|
|
330
|
+
* @param node - Current node.
|
|
331
|
+
* @returns Previous node or `undefined`.
|
|
332
|
+
* @remarks Time O(1)~O(n) depending on list variant (singly vs doubly), Space O(1)
|
|
333
|
+
*/
|
|
276
334
|
protected abstract _getPrevNode(node: NODE): NODE | undefined;
|
|
277
335
|
}
|