doubly-linked-list-typed 1.51.8 → 1.52.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/dist/data-structures/base/index.d.ts +2 -1
- package/dist/data-structures/base/index.js +2 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/data-structures/base/iterable-element-base.js +225 -0
- package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -226
- package/dist/data-structures/binary-tree/binary-tree.js +475 -363
- package/dist/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/data-structures/binary-tree/bst.js +207 -249
- package/dist/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/data-structures/graph/abstract-graph.js +10 -15
- package/dist/data-structures/hash/hash-map.d.ts +33 -40
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/heap/heap.d.ts +43 -114
- package/dist/data-structures/heap/heap.js +59 -127
- package/dist/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/data-structures/heap/max-heap.js +76 -10
- package/dist/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/data-structures/heap/min-heap.js +68 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/data-structures/queue/deque.d.ts +21 -20
- package/dist/data-structures/queue/deque.js +29 -23
- package/dist/data-structures/queue/queue.d.ts +8 -28
- package/dist/data-structures/queue/queue.js +15 -31
- package/dist/data-structures/stack/stack.d.ts +17 -22
- package/dist/data-structures/stack/stack.js +25 -24
- package/dist/data-structures/trie/trie.d.ts +19 -14
- package/dist/data-structures/trie/trie.js +27 -16
- package/dist/interfaces/binary-tree.d.ts +7 -7
- package/dist/types/common.d.ts +1 -2
- package/dist/types/data-structures/base/base.d.ts +5 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/utils/utils.js +3 -5
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
- package/src/data-structures/binary-tree/avl-tree.ts +96 -69
- package/src/data-structures/binary-tree/binary-tree.ts +535 -403
- package/src/data-structures/binary-tree/bst.ts +247 -277
- package/src/data-structures/binary-tree/rb-tree.ts +123 -103
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +46 -53
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +37 -26
- package/src/data-structures/queue/queue.ts +23 -36
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +35 -20
- package/src/interfaces/binary-tree.ts +9 -9
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/bst.ts +4 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +3 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
- package/src/utils/utils.ts +3 -3
|
@@ -16,9 +16,9 @@ import { calcMinUnitsRequired, rangeCheck } from '../../utils';
|
|
|
16
16
|
* 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
|
|
17
17
|
* 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
|
|
18
18
|
*/
|
|
19
|
-
export class Deque<E> extends IterableElementBase<E
|
|
19
|
+
export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E, R>> {
|
|
20
20
|
/**
|
|
21
|
-
* The constructor initializes a Deque object with
|
|
21
|
+
* The constructor initializes a Deque object with optional iterable of elements and options.
|
|
22
22
|
* @param elements - An iterable object (such as an array or a Set) that contains the initial
|
|
23
23
|
* elements to be added to the deque. It can also be an object with a `length` or `size` property
|
|
24
24
|
* that represents the number of elements in the iterable object. If no elements are provided, an
|
|
@@ -28,8 +28,8 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
28
28
|
* which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
|
|
29
29
|
* or is not a number
|
|
30
30
|
*/
|
|
31
|
-
constructor(elements: IterableWithSizeOrLength<E> = [], options?: DequeOptions) {
|
|
32
|
-
super();
|
|
31
|
+
constructor(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R> = [], options?: DequeOptions<E, R>) {
|
|
32
|
+
super(options);
|
|
33
33
|
|
|
34
34
|
if (options) {
|
|
35
35
|
const { bucketSize } = options;
|
|
@@ -53,8 +53,12 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
53
53
|
this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
|
|
54
54
|
this._firstInBucket = this._lastInBucket = (this._bucketSize - (_size % this._bucketSize)) >> 1;
|
|
55
55
|
|
|
56
|
-
for (const
|
|
57
|
-
this.
|
|
56
|
+
for (const el of elements) {
|
|
57
|
+
if (this.toElementFn) {
|
|
58
|
+
this.push(this.toElementFn(el as R));
|
|
59
|
+
} else {
|
|
60
|
+
this.push(el as E);
|
|
61
|
+
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
@@ -747,8 +751,8 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
747
751
|
* @returns The `clone()` method is returning a new instance of the `Deque` class with the same
|
|
748
752
|
* elements as the original deque (`this`) and the same bucket size.
|
|
749
753
|
*/
|
|
750
|
-
clone(): Deque<E> {
|
|
751
|
-
return new Deque<E>(
|
|
754
|
+
clone(): Deque<E, R> {
|
|
755
|
+
return new Deque<E, R>(this, { bucketSize: this.bucketSize, toElementFn: this.toElementFn });
|
|
752
756
|
}
|
|
753
757
|
|
|
754
758
|
/**
|
|
@@ -772,8 +776,8 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
772
776
|
* @returns The `filter` method is returning a new `Deque` object that contains the elements that
|
|
773
777
|
* satisfy the given predicate function.
|
|
774
778
|
*/
|
|
775
|
-
filter(predicate: ElementCallback<E, boolean
|
|
776
|
-
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
|
|
779
|
+
filter(predicate: ElementCallback<E, R, boolean, Deque<E, R>>, thisArg?: any): Deque<E, R> {
|
|
780
|
+
const newDeque = new Deque<E, R>([], { bucketSize: this._bucketSize, toElementFn: this.toElementFn });
|
|
777
781
|
let index = 0;
|
|
778
782
|
for (const el of this) {
|
|
779
783
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -788,21 +792,28 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
788
792
|
* Time Complexity: O(n)
|
|
789
793
|
* Space Complexity: O(n)
|
|
790
794
|
*/
|
|
795
|
+
|
|
791
796
|
/**
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
* @param
|
|
798
|
-
* the
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
797
|
+
* The `map` function takes a callback function and applies it to each element in the deque,
|
|
798
|
+
* returning a new deque with the results.
|
|
799
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
800
|
+
* deque. It takes three arguments: the current element, the index of the element, and the deque
|
|
801
|
+
* itself. It should return a value of type EM.
|
|
802
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
803
|
+
* transform the raw element (`RM`) into a new element (`EM`) before adding it to the new deque. If
|
|
804
|
+
* provided, this function will be called for each raw element in the original deque.
|
|
805
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
806
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
807
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
808
|
+
* value of
|
|
809
|
+
* @returns a new Deque object with elements of type EM and raw elements of type RM.
|
|
810
|
+
*/
|
|
811
|
+
map<EM, RM>(
|
|
812
|
+
callback: ElementCallback<E, R, EM, Deque<E, R>>,
|
|
813
|
+
toElementFn?: (rawElement: RM) => EM,
|
|
814
|
+
thisArg?: any
|
|
815
|
+
): Deque<EM, RM> {
|
|
816
|
+
const newDeque = new Deque<EM, RM>([], { bucketSize: this._bucketSize, toElementFn });
|
|
806
817
|
let index = 0;
|
|
807
818
|
for (const el of this) {
|
|
808
819
|
newDeque.push(callback.call(thisArg, el, index, this));
|
|
@@ -814,9 +825,9 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
814
825
|
/**
|
|
815
826
|
* Time Complexity: O(n)
|
|
816
827
|
* Space Complexity: O(1)
|
|
817
|
-
|
|
828
|
+
*/
|
|
818
829
|
|
|
819
|
-
|
|
830
|
+
/**
|
|
820
831
|
* Time Complexity: O(n)
|
|
821
832
|
* Space Complexity: O(1)
|
|
822
833
|
*
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
|
-
import type { ElementCallback } from '../../types';
|
|
6
|
+
import type { ElementCallback, QueueOptions } from '../../types';
|
|
7
7
|
import { IterableElementBase } from '../base';
|
|
8
8
|
import { SinglyLinkedList } from '../linked-list';
|
|
9
9
|
|
|
@@ -16,17 +16,14 @@ import { SinglyLinkedList } from '../linked-list';
|
|
|
16
16
|
* 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
|
|
17
17
|
* 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
|
|
18
18
|
*/
|
|
19
|
-
export class Queue<E = any> extends IterableElementBase<E
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
23
|
-
* will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
|
|
24
|
-
* initialized as an empty array.
|
|
25
|
-
*/
|
|
26
|
-
constructor(elements: Iterable<E> = []) {
|
|
27
|
-
super();
|
|
19
|
+
export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E, R>> {
|
|
20
|
+
constructor(elements: Iterable<E> | Iterable<R> = [], options?: QueueOptions<E, R>) {
|
|
21
|
+
super(options);
|
|
28
22
|
if (elements) {
|
|
29
|
-
for (const el of elements)
|
|
23
|
+
for (const el of elements) {
|
|
24
|
+
if (this.toElementFn) this.push(this.toElementFn(el as R));
|
|
25
|
+
else this.push(el as E);
|
|
26
|
+
}
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
29
|
|
|
@@ -190,7 +187,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
190
187
|
* @param index
|
|
191
188
|
*/
|
|
192
189
|
at(index: number): E | undefined {
|
|
193
|
-
return this.elements[index];
|
|
190
|
+
return this.elements[index + this._offset];
|
|
194
191
|
}
|
|
195
192
|
|
|
196
193
|
/**
|
|
@@ -254,8 +251,8 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
254
251
|
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
255
252
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
256
253
|
*/
|
|
257
|
-
clone(): Queue<E> {
|
|
258
|
-
return new Queue(this.elements.slice(this.offset));
|
|
254
|
+
clone(): Queue<E, R> {
|
|
255
|
+
return new Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn });
|
|
259
256
|
}
|
|
260
257
|
|
|
261
258
|
/**
|
|
@@ -279,8 +276,8 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
279
276
|
* @returns The `filter` method is returning a new `Queue` object that contains the elements that
|
|
280
277
|
* satisfy the given predicate function.
|
|
281
278
|
*/
|
|
282
|
-
filter(predicate: ElementCallback<E, boolean
|
|
283
|
-
const newDeque = new Queue<E>([]);
|
|
279
|
+
filter(predicate: ElementCallback<E, R, boolean, Queue<E, R>>, thisArg?: any): Queue<E, R> {
|
|
280
|
+
const newDeque = new Queue<E, R>([], { toElementFn: this.toElementFn });
|
|
284
281
|
let index = 0;
|
|
285
282
|
for (const el of this) {
|
|
286
283
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -296,22 +293,12 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
296
293
|
* Space Complexity: O(n)
|
|
297
294
|
*/
|
|
298
295
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
306
|
-
* queue. It takes three arguments: the current element, the index of the current element, and the
|
|
307
|
-
* queue itself. The callback function should return a new value that will be added to the new queue.
|
|
308
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
309
|
-
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
310
|
-
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
311
|
-
* @returns The `map` function is returning a new `Queue` object with the transformed elements.
|
|
312
|
-
*/
|
|
313
|
-
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Queue<T> {
|
|
314
|
-
const newDeque = new Queue<T>([]);
|
|
296
|
+
map<EM, RM>(
|
|
297
|
+
callback: ElementCallback<E, R, EM, Queue<E, R>>,
|
|
298
|
+
toElementFn?: (rawElement: RM) => EM,
|
|
299
|
+
thisArg?: any
|
|
300
|
+
): Queue<EM, RM> {
|
|
301
|
+
const newDeque = new Queue<EM, RM>([], { toElementFn });
|
|
315
302
|
let index = 0;
|
|
316
303
|
for (const el of this) {
|
|
317
304
|
newDeque.push(callback.call(thisArg, el, index, this));
|
|
@@ -332,7 +319,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
332
319
|
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
333
320
|
*/
|
|
334
321
|
protected* _getIterator(): IterableIterator<E> {
|
|
335
|
-
for (const item of this.elements) {
|
|
322
|
+
for (const item of this.elements.slice(this.offset)) {
|
|
336
323
|
yield item;
|
|
337
324
|
}
|
|
338
325
|
}
|
|
@@ -344,7 +331,7 @@ export class Queue<E = any> extends IterableElementBase<E> {
|
|
|
344
331
|
* 3. Memory Usage: Since each element requires additional space to store a pointer to the next element, linked lists may use more memory compared to arrays.
|
|
345
332
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
346
333
|
*/
|
|
347
|
-
export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
334
|
+
export class LinkedListQueue<E = any, R = any> extends SinglyLinkedList<E, R> {
|
|
348
335
|
/**
|
|
349
336
|
* Time Complexity: O(n)
|
|
350
337
|
* Space Complexity: O(n)
|
|
@@ -358,7 +345,7 @@ export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
358
345
|
* @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
|
|
359
346
|
* values as the original `LinkedListQueue`.
|
|
360
347
|
*/
|
|
361
|
-
clone(): LinkedListQueue<E> {
|
|
362
|
-
return new LinkedListQueue<E>(this.
|
|
348
|
+
override clone(): LinkedListQueue<E, R> {
|
|
349
|
+
return new LinkedListQueue<E, R>(this, { toElementFn: this.toElementFn });
|
|
363
350
|
}
|
|
364
351
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { ElementCallback } from '../../types';
|
|
8
|
+
import type { ElementCallback, StackOptions } from '../../types';
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -16,17 +16,17 @@ import { IterableElementBase } from '../base';
|
|
|
16
16
|
* 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
|
|
17
17
|
* 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
|
|
18
18
|
*/
|
|
19
|
-
export class Stack<E = any> extends IterableElementBase<E
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
23
|
-
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
24
|
-
* is provided and is an array, it is assigned to the `_elements
|
|
25
|
-
*/
|
|
26
|
-
constructor(elements: Iterable<E> = []) {
|
|
27
|
-
super();
|
|
19
|
+
export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E, R>> {
|
|
20
|
+
constructor(elements: Iterable<E> | Iterable<R> = [], options?: StackOptions<E, R>) {
|
|
21
|
+
super(options);
|
|
28
22
|
if (elements) {
|
|
29
|
-
for (const el of elements)
|
|
23
|
+
for (const el of elements) {
|
|
24
|
+
if (this.toElementFn) {
|
|
25
|
+
this.push(this.toElementFn(el as R));
|
|
26
|
+
} else {
|
|
27
|
+
this.push(el as E);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -192,8 +192,8 @@ export class Stack<E = any> extends IterableElementBase<E> {
|
|
|
192
192
|
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
193
193
|
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
194
194
|
*/
|
|
195
|
-
clone(): Stack<E> {
|
|
196
|
-
return new Stack(this.
|
|
195
|
+
clone(): Stack<E, R> {
|
|
196
|
+
return new Stack<E, R>(this, { toElementFn: this.toElementFn });
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
@@ -217,8 +217,8 @@ export class Stack<E = any> extends IterableElementBase<E> {
|
|
|
217
217
|
* @returns The `filter` method is returning a new `Stack` object that contains the elements that
|
|
218
218
|
* satisfy the given predicate function.
|
|
219
219
|
*/
|
|
220
|
-
filter(predicate: ElementCallback<E, boolean
|
|
221
|
-
const newStack = new Stack<E>();
|
|
220
|
+
filter(predicate: ElementCallback<E, R, boolean, Stack<E, R>>, thisArg?: any): Stack<E, R> {
|
|
221
|
+
const newStack = new Stack<E, R>([], { toElementFn: this.toElementFn });
|
|
222
222
|
let index = 0;
|
|
223
223
|
for (const el of this) {
|
|
224
224
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -235,20 +235,25 @@ export class Stack<E = any> extends IterableElementBase<E> {
|
|
|
235
235
|
*/
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
|
-
* Time Complexity: O(n)
|
|
239
|
-
* Space Complexity: O(n)
|
|
240
|
-
*
|
|
241
238
|
* The `map` function takes a callback function and applies it to each element in the stack,
|
|
242
239
|
* returning a new stack with the results.
|
|
243
|
-
* @param callback - The
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @
|
|
240
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
241
|
+
* stack. It takes three arguments: the current element, the index of the element, and the stack
|
|
242
|
+
* itself. It should return a new value that will be added to the new stack.
|
|
243
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
244
|
+
* transform the raw element (`RM`) into a new element (`EM`) before pushing it into the new stack.
|
|
245
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
246
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
247
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
248
|
+
* value of
|
|
249
|
+
* @returns a new Stack object with elements of type EM and raw elements of type RM.
|
|
249
250
|
*/
|
|
250
|
-
map<
|
|
251
|
-
|
|
251
|
+
map<EM, RM>(
|
|
252
|
+
callback: ElementCallback<E, R, EM, Stack<E, R>>,
|
|
253
|
+
toElementFn?: (rawElement: RM) => EM,
|
|
254
|
+
thisArg?: any
|
|
255
|
+
): Stack<EM, RM> {
|
|
256
|
+
const newStack = new Stack<EM, RM>([], { toElementFn });
|
|
252
257
|
let index = 0;
|
|
253
258
|
for (const el of this) {
|
|
254
259
|
newStack.push(callback.call(thisArg, el, index, this));
|
|
@@ -91,23 +91,29 @@ export class TrieNode {
|
|
|
91
91
|
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
92
92
|
* 9. Spell Check: Checking the spelling of words.
|
|
93
93
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
94
|
-
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
94
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
95
95
|
*/
|
|
96
|
-
export class Trie extends IterableElementBase<string, Trie
|
|
96
|
+
export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
97
97
|
/**
|
|
98
98
|
* The constructor function for the Trie class.
|
|
99
99
|
* @param words: Iterable string Initialize the trie with a set of words
|
|
100
100
|
* @param options?: TrieOptions Allow the user to pass in options for the trie
|
|
101
101
|
* @return This
|
|
102
102
|
*/
|
|
103
|
-
constructor(words: Iterable<string> = [], options?: TrieOptions) {
|
|
104
|
-
super();
|
|
103
|
+
constructor(words: Iterable<string> | Iterable<R> = [], options?: TrieOptions<R>) {
|
|
104
|
+
super(options);
|
|
105
105
|
if (options) {
|
|
106
106
|
const { caseSensitive } = options;
|
|
107
107
|
if (caseSensitive !== undefined) this._caseSensitive = caseSensitive;
|
|
108
108
|
}
|
|
109
109
|
if (words) {
|
|
110
|
-
for (const word of words)
|
|
110
|
+
for (const word of words) {
|
|
111
|
+
if (this.toElementFn) {
|
|
112
|
+
this.add(this.toElementFn(word as R));
|
|
113
|
+
} else {
|
|
114
|
+
this.add(word as string);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
|
|
@@ -187,7 +193,7 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
187
193
|
* @param {string} word - The word to check for.
|
|
188
194
|
* @returns {boolean} True if the word is present in the Trie.
|
|
189
195
|
*/
|
|
190
|
-
has(word: string): boolean {
|
|
196
|
+
override has(word: string): boolean {
|
|
191
197
|
word = this._caseProcess(word);
|
|
192
198
|
let cur = this.root;
|
|
193
199
|
for (const c of word) {
|
|
@@ -470,8 +476,8 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
470
476
|
* sensitivity as the original Trie.
|
|
471
477
|
* @returns A new instance of the Trie class is being returned.
|
|
472
478
|
*/
|
|
473
|
-
clone(): Trie {
|
|
474
|
-
return new Trie(this
|
|
479
|
+
clone(): Trie<R> {
|
|
480
|
+
return new Trie<R>(this, { caseSensitive: this.caseSensitive, toElementFn: this.toElementFn });
|
|
475
481
|
}
|
|
476
482
|
|
|
477
483
|
/**
|
|
@@ -493,8 +499,8 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
493
499
|
* specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
|
|
494
500
|
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
495
501
|
*/
|
|
496
|
-
filter(predicate: ElementCallback<string, boolean
|
|
497
|
-
const results
|
|
502
|
+
filter(predicate: ElementCallback<string, R, boolean, Trie<R>>, thisArg?: any): Trie<R> {
|
|
503
|
+
const results = new Trie<R>([], { toElementFn: this.toElementFn, caseSensitive: this.caseSensitive });
|
|
498
504
|
let index = 0;
|
|
499
505
|
for (const word of this) {
|
|
500
506
|
if (predicate.call(thisArg, word, index, this)) {
|
|
@@ -514,17 +520,26 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
514
520
|
* Time Complexity: O(n)
|
|
515
521
|
* Space Complexity: O(n)
|
|
516
522
|
*
|
|
517
|
-
* The `map` function creates a new Trie by applying a callback function to each element in the
|
|
523
|
+
* The `map` function creates a new Trie by applying a callback function to each element in the
|
|
524
|
+
* current Trie.
|
|
518
525
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
519
|
-
* Trie. It takes
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
* @
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
526
|
+
* Trie. It takes four arguments:
|
|
527
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
528
|
+
* convert the raw element (`RM`) into a string representation. This can be useful if the raw element
|
|
529
|
+
* is not already a string or if you want to customize how the element is converted into a string. If
|
|
530
|
+
* this parameter is
|
|
531
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
532
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
533
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
534
|
+
* value of
|
|
535
|
+
* @returns a new Trie object.
|
|
536
|
+
*/
|
|
537
|
+
map<RM>(
|
|
538
|
+
callback: ElementCallback<string, R, string, Trie<R>>,
|
|
539
|
+
toElementFn?: (rawElement: RM) => string,
|
|
540
|
+
thisArg?: any
|
|
541
|
+
): Trie<RM> {
|
|
542
|
+
const newTrie = new Trie<RM>([], { toElementFn, caseSensitive: this.caseSensitive });
|
|
528
543
|
let index = 0;
|
|
529
544
|
for (const word of this) {
|
|
530
545
|
newTrie.add(callback.call(thisArg, word, index, this));
|
|
@@ -5,23 +5,23 @@ import type {
|
|
|
5
5
|
BinaryTreeNodeNested,
|
|
6
6
|
BinaryTreeOptions,
|
|
7
7
|
BTNCallback,
|
|
8
|
-
Comparable,
|
|
9
8
|
KeyOrNodeOrEntry
|
|
10
9
|
} from '../types';
|
|
11
10
|
|
|
12
11
|
export interface IBinaryTree<
|
|
13
|
-
K
|
|
12
|
+
K = any,
|
|
14
13
|
V = any,
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
R = [K, V],
|
|
15
|
+
NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>,
|
|
16
|
+
TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>
|
|
17
17
|
> {
|
|
18
|
-
createNode(key: K, value?:
|
|
18
|
+
createNode(key: K, value?: NODE['value']): NODE;
|
|
19
19
|
|
|
20
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
20
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
21
21
|
|
|
22
|
-
add(
|
|
22
|
+
add(keyOrNodeOrEntryOrRawElement: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
23
23
|
|
|
24
|
-
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V,
|
|
24
|
+
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
25
25
|
|
|
26
|
-
delete<C extends BTNCallback<
|
|
26
|
+
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
27
27
|
}
|
package/src/types/common.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type BSTVariant = 'STANDARD' | 'INVERSE';
|
|
2
1
|
export type CP = 1 | -1 | 0;
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -39,7 +38,7 @@ export type KeyOrNodeOrEntry<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
|
|
|
39
38
|
|
|
40
39
|
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
41
40
|
|
|
42
|
-
export type
|
|
41
|
+
export type BTNPureKeyOrNodeOrEntry<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
43
42
|
|
|
44
43
|
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
|
45
44
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
2
|
|
|
3
3
|
export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
4
|
-
export type ElementCallback<
|
|
4
|
+
export type ElementCallback<E, R, RT, C> = (element: E, index: number, container: IterableElementBase<E, R, C>) => RT;
|
|
5
5
|
export type ReduceEntryCallback<K, V, R> = (
|
|
6
6
|
accumulator: R,
|
|
7
7
|
value: V,
|
|
@@ -9,9 +9,17 @@ export type ReduceEntryCallback<K, V, R> = (
|
|
|
9
9
|
index: number,
|
|
10
10
|
container: IterableEntryBase<K, V>
|
|
11
11
|
) => R;
|
|
12
|
-
export type ReduceElementCallback<
|
|
13
|
-
accumulator:
|
|
14
|
-
element:
|
|
12
|
+
export type ReduceElementCallback<E, R, RT, C> = (
|
|
13
|
+
accumulator: RT,
|
|
14
|
+
element: E,
|
|
15
15
|
index: number,
|
|
16
|
-
container: IterableElementBase<
|
|
17
|
-
) =>
|
|
16
|
+
container: IterableElementBase<E, R, C>
|
|
17
|
+
) => RT;
|
|
18
|
+
|
|
19
|
+
// export type IterableEntryBaseOptions<K, V, R> = {
|
|
20
|
+
// toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
21
|
+
// };
|
|
22
|
+
|
|
23
|
+
export type IterableElementBaseOptions<E, R> = {
|
|
24
|
+
toElementFn?: (rawElement: R) => E;
|
|
25
|
+
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
import { Comparable } from "../../utils";
|
|
4
3
|
|
|
5
|
-
export type AVLTreeMultiMapNodeNested<K
|
|
4
|
+
export type AVLTreeMultiMapNodeNested<K, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
6
5
|
|
|
7
|
-
export type AVLTreeMultiMapNested<K
|
|
6
|
+
export type AVLTreeMultiMapNested<K, V, R, NODE extends AVLTreeMultiMapNode<K, V, NODE>> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
8
7
|
|
|
9
|
-
export type AVLTreeMultiMapOptions<K> = AVLTreeOptions<K> & {}
|
|
8
|
+
export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
import { Comparable } from "../../utils";
|
|
4
3
|
|
|
5
|
-
export type AVLTreeNodeNested<K
|
|
4
|
+
export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
6
5
|
|
|
7
|
-
export type AVLTreeNested<K
|
|
6
|
+
export type AVLTreeNested<K, V, R, NODE extends AVLTreeNode<K, V, NODE>> = AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
8
7
|
|
|
9
|
-
export type AVLTreeOptions<K> = BSTOptions<K> & {};
|
|
8
|
+
export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
|
-
import { IterationType } from
|
|
3
|
-
import { Comparable } from "../../utils";
|
|
2
|
+
import { BTNEntry, IterationType } from '../../common';
|
|
4
3
|
|
|
5
|
-
export type BinaryTreeNodeNested<K
|
|
4
|
+
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
6
5
|
|
|
7
|
-
export type BinaryTreeNested<K
|
|
6
|
+
export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
8
7
|
|
|
9
|
-
export type BinaryTreeOptions = {
|
|
10
|
-
iterationType?: IterationType
|
|
8
|
+
export type BinaryTreeOptions<K, V, R> = {
|
|
9
|
+
iterationType?: IterationType;
|
|
10
|
+
toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
11
11
|
}
|