data-structure-typed 1.51.9 → 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/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/benchmark/report.html +37 -1
- package/benchmark/report.json +385 -13
- package/dist/cjs/data-structures/base/index.d.ts +2 -1
- package/dist/cjs/data-structures/base/index.js +2 -1
- package/dist/cjs/data-structures/base/index.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
- package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +5 -3
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +3 -11
- package/dist/cjs/data-structures/binary-tree/bst.js +2 -10
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/cjs/data-structures/heap/heap.js +59 -127
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/cjs/data-structures/heap/max-heap.js +76 -10
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/cjs/data-structures/heap/min-heap.js +68 -11
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +20 -18
- package/dist/cjs/data-structures/queue/deque.js +27 -20
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/cjs/data-structures/queue/queue.js +15 -31
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/cjs/data-structures/stack/stack.js +25 -24
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +18 -13
- package/dist/cjs/data-structures/trie/trie.js +26 -15
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/mjs/data-structures/base/index.d.ts +2 -1
- package/dist/mjs/data-structures/base/index.js +2 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
- package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +5 -3
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +3 -11
- package/dist/mjs/data-structures/binary-tree/bst.js +2 -10
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/mjs/data-structures/heap/heap.js +60 -128
- package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/mjs/data-structures/heap/max-heap.js +79 -10
- package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/mjs/data-structures/heap/min-heap.js +68 -11
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +20 -18
- package/dist/mjs/data-structures/queue/deque.js +27 -20
- package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/mjs/data-structures/queue/queue.js +15 -31
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/mjs/data-structures/stack/stack.js +25 -24
- package/dist/mjs/data-structures/trie/trie.d.ts +18 -13
- package/dist/mjs/data-structures/trie/trie.js +26 -15
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/umd/data-structure-typed.js +628 -319
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- 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 +2 -3
- package/src/data-structures/binary-tree/avl-tree.ts +2 -3
- package/src/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/data-structures/binary-tree/bst.ts +8 -19
- package/src/data-structures/binary-tree/rb-tree.ts +2 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +2 -3
- package/src/data-structures/hash/hash-map.ts +4 -4
- 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 +35 -24
- 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 +33 -18
- package/src/interfaces/binary-tree.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 +2 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/bst.ts +2 -3
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
- 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/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +80 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
- package/test/unit/data-structures/queue/deque.test.ts +30 -0
- package/test/unit/data-structures/queue/queue.test.ts +56 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
export class IterableElementBase {
|
|
2
|
+
/**
|
|
3
|
+
* The protected constructor initializes the options for the IterableElementBase class, including the
|
|
4
|
+
* toElementFn function.
|
|
5
|
+
* @param [options] - An optional object that contains the following properties:
|
|
6
|
+
*/
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (options) {
|
|
9
|
+
const { toElementFn } = options;
|
|
10
|
+
if (typeof toElementFn === 'function')
|
|
11
|
+
this._toElementFn = toElementFn;
|
|
12
|
+
else if (toElementFn)
|
|
13
|
+
throw new TypeError('toElementFn must be a function type');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
_toElementFn;
|
|
17
|
+
/**
|
|
18
|
+
* The function returns the _toElementFn property, which is a function that converts a raw element to
|
|
19
|
+
* a specific type.
|
|
20
|
+
* @returns The function `get toElementFn()` is returning either a function that takes a raw element
|
|
21
|
+
* `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
|
|
22
|
+
* `_toElementFn`.
|
|
23
|
+
*/
|
|
24
|
+
get toElementFn() {
|
|
25
|
+
return this._toElementFn;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Time Complexity: O(n)
|
|
29
|
+
* Space Complexity: O(1)
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Time Complexity: O(n)
|
|
33
|
+
* Space Complexity: O(1)
|
|
34
|
+
*
|
|
35
|
+
* The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
|
|
36
|
+
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
37
|
+
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
38
|
+
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
39
|
+
*/
|
|
40
|
+
*[Symbol.iterator](...args) {
|
|
41
|
+
yield* this._getIterator(...args);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Time Complexity: O(n)
|
|
45
|
+
* Space Complexity: O(n)
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Time Complexity: O(n)
|
|
49
|
+
* Space Complexity: O(n)
|
|
50
|
+
*
|
|
51
|
+
* The function returns an iterator that yields all the values in the object.
|
|
52
|
+
*/
|
|
53
|
+
*values() {
|
|
54
|
+
for (const item of this) {
|
|
55
|
+
yield item;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Time Complexity: O(n)
|
|
60
|
+
* Space Complexity: O(1)
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Time Complexity: O(n)
|
|
64
|
+
* Space Complexity: O(1)
|
|
65
|
+
*
|
|
66
|
+
* The `every` function checks if every element in the array satisfies a given predicate.
|
|
67
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
68
|
+
* the current element being processed, its index, and the array it belongs to. It should return a
|
|
69
|
+
* boolean value indicating whether the element satisfies a certain condition or not.
|
|
70
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
71
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
72
|
+
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
73
|
+
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
74
|
+
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
75
|
+
*/
|
|
76
|
+
every(predicate, thisArg) {
|
|
77
|
+
let index = 0;
|
|
78
|
+
for (const item of this) {
|
|
79
|
+
if (!predicate.call(thisArg, item, index++, this)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Time Complexity: O(n)
|
|
87
|
+
* Space Complexity: O(1)
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Time Complexity: O(n)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* Time Complexity: O(n)
|
|
95
|
+
* Space Complexity: O(1)
|
|
96
|
+
*
|
|
97
|
+
* The "some" function checks if at least one element in a collection satisfies a given predicate.
|
|
98
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
99
|
+
* `value`, `index`, and `array`. It should return a boolean value indicating whether the current
|
|
100
|
+
* element satisfies the condition.
|
|
101
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
102
|
+
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
103
|
+
* it will be passed as the `this` value to the `predicate` function. If `thisArg
|
|
104
|
+
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
105
|
+
* in the collection, and false otherwise.
|
|
106
|
+
*/
|
|
107
|
+
some(predicate, thisArg) {
|
|
108
|
+
let index = 0;
|
|
109
|
+
for (const item of this) {
|
|
110
|
+
if (predicate.call(thisArg, item, index++, this)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Time Complexity: O(n)
|
|
118
|
+
* Space Complexity: O(1)
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* Time Complexity: O(n)
|
|
122
|
+
* Space Complexity: O(1)
|
|
123
|
+
*
|
|
124
|
+
* The `forEach` function iterates over each element in an array-like object and calls a callback
|
|
125
|
+
* function for each element.
|
|
126
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
127
|
+
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
128
|
+
* element, and the array that forEach was called upon.
|
|
129
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
130
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
131
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
132
|
+
*/
|
|
133
|
+
forEach(callbackfn, thisArg) {
|
|
134
|
+
let index = 0;
|
|
135
|
+
for (const item of this) {
|
|
136
|
+
callbackfn.call(thisArg, item, index++, this);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Time Complexity: O(n)
|
|
141
|
+
* Space Complexity: O(1)
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* Time Complexity: O(n)
|
|
145
|
+
* Space Complexity: O(1)
|
|
146
|
+
*
|
|
147
|
+
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
148
|
+
* element that satisfies the provided callback function.
|
|
149
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
150
|
+
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
151
|
+
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
152
|
+
* current element matches the desired condition.
|
|
153
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
154
|
+
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
155
|
+
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
156
|
+
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
157
|
+
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
158
|
+
*/
|
|
159
|
+
find(callbackfn, thisArg) {
|
|
160
|
+
let index = 0;
|
|
161
|
+
for (const item of this) {
|
|
162
|
+
if (callbackfn.call(thisArg, item, index++, this))
|
|
163
|
+
return item;
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Time Complexity: O(n)
|
|
169
|
+
* Space Complexity: O(1)
|
|
170
|
+
*
|
|
171
|
+
* The function checks if a given element exists in a collection.
|
|
172
|
+
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
|
|
173
|
+
* represents the element that we want to check for existence in the collection.
|
|
174
|
+
* @returns a boolean value. It returns true if the element is found in the collection, and false
|
|
175
|
+
* otherwise.
|
|
176
|
+
*/
|
|
177
|
+
has(element) {
|
|
178
|
+
for (const ele of this) {
|
|
179
|
+
if (ele === element)
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Time Complexity: O(n)
|
|
186
|
+
* Space Complexity: O(1)
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* Time Complexity: O(n)
|
|
190
|
+
* Space Complexity: O(1)
|
|
191
|
+
*
|
|
192
|
+
* The `reduce` function iterates over the elements of an array-like object and applies a callback
|
|
193
|
+
* function to reduce them into a single value.
|
|
194
|
+
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
195
|
+
* the array. It takes four arguments:
|
|
196
|
+
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
197
|
+
* is the value that the accumulator starts with before the reduction operation begins.
|
|
198
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
199
|
+
* all the elements in the array and applying the callback function to each element.
|
|
200
|
+
*/
|
|
201
|
+
reduce(callbackfn, initialValue) {
|
|
202
|
+
let accumulator = initialValue;
|
|
203
|
+
let index = 0;
|
|
204
|
+
for (const item of this) {
|
|
205
|
+
accumulator = callbackfn(accumulator, item, index++, this);
|
|
206
|
+
}
|
|
207
|
+
return accumulator;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Time Complexity: O(n)
|
|
211
|
+
* Space Complexity: O(n)
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* Time Complexity: O(n)
|
|
215
|
+
* Space Complexity: O(n)
|
|
216
|
+
*
|
|
217
|
+
* The print function logs the elements of an array to the console.
|
|
218
|
+
*/
|
|
219
|
+
print() {
|
|
220
|
+
console.log([...this]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntryCallback, ReduceEntryCallback } from '../../types';
|
|
2
2
|
export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
3
3
|
/**
|
|
4
4
|
* Time Complexity: O(n)
|
|
@@ -193,34 +193,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
193
193
|
* all the elements in the collection.
|
|
194
194
|
*/
|
|
195
195
|
reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
|
|
196
|
-
/**
|
|
197
|
-
* Time Complexity: O(n)
|
|
198
|
-
* Space Complexity: O(n)
|
|
199
|
-
*/
|
|
200
|
-
print(): void;
|
|
201
|
-
abstract isEmpty(): boolean;
|
|
202
|
-
abstract clear(): void;
|
|
203
|
-
abstract clone(): any;
|
|
204
|
-
abstract map(...args: any[]): any;
|
|
205
|
-
abstract filter(...args: any[]): any;
|
|
206
|
-
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
207
|
-
}
|
|
208
|
-
export declare abstract class IterableElementBase<E = any, C = any> {
|
|
209
|
-
abstract get size(): number;
|
|
210
|
-
/**
|
|
211
|
-
* Time Complexity: O(n)
|
|
212
|
-
* Space Complexity: O(1)
|
|
213
|
-
*/
|
|
214
|
-
/**
|
|
215
|
-
* Time Complexity: O(n)
|
|
216
|
-
* Space Complexity: O(1)
|
|
217
|
-
*
|
|
218
|
-
* The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
|
|
219
|
-
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
220
|
-
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
221
|
-
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
222
|
-
*/
|
|
223
|
-
[Symbol.iterator](...args: any[]): IterableIterator<E>;
|
|
224
196
|
/**
|
|
225
197
|
* Time Complexity: O(n)
|
|
226
198
|
* Space Complexity: O(n)
|
|
@@ -229,128 +201,13 @@ export declare abstract class IterableElementBase<E = any, C = any> {
|
|
|
229
201
|
* Time Complexity: O(n)
|
|
230
202
|
* Space Complexity: O(n)
|
|
231
203
|
*
|
|
232
|
-
* The function
|
|
233
|
-
*/
|
|
234
|
-
values(): IterableIterator<E>;
|
|
235
|
-
/**
|
|
236
|
-
* Time Complexity: O(n)
|
|
237
|
-
* Space Complexity: O(1)
|
|
238
|
-
*/
|
|
239
|
-
/**
|
|
240
|
-
* Time Complexity: O(n)
|
|
241
|
-
* Space Complexity: O(1)
|
|
242
|
-
*
|
|
243
|
-
* The `every` function checks if every element in the array satisfies a given predicate.
|
|
244
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
245
|
-
* the current element being processed, its index, and the array it belongs to. It should return a
|
|
246
|
-
* boolean value indicating whether the element satisfies a certain condition or not.
|
|
247
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
248
|
-
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
249
|
-
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
250
|
-
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
251
|
-
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
252
|
-
*/
|
|
253
|
-
every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
|
|
254
|
-
/**
|
|
255
|
-
* Time Complexity: O(n)
|
|
256
|
-
* Space Complexity: O(1)
|
|
257
|
-
*/
|
|
258
|
-
/**
|
|
259
|
-
* Time Complexity: O(n)
|
|
260
|
-
* Space Complexity: O(1)
|
|
261
|
-
*/
|
|
262
|
-
/**
|
|
263
|
-
* Time Complexity: O(n)
|
|
264
|
-
* Space Complexity: O(1)
|
|
265
|
-
*
|
|
266
|
-
* The "some" function checks if at least one element in a collection satisfies a given predicate.
|
|
267
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
268
|
-
* `value`, `index`, and `array`. It should return a boolean value indicating whether the current
|
|
269
|
-
* element satisfies the condition.
|
|
270
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
271
|
-
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
272
|
-
* it will be passed as the `this` value to the `predicate` function. If `thisArg
|
|
273
|
-
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
274
|
-
* in the collection, and false otherwise.
|
|
275
|
-
*/
|
|
276
|
-
some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
|
|
277
|
-
/**
|
|
278
|
-
* Time Complexity: O(n)
|
|
279
|
-
* Space Complexity: O(1)
|
|
280
|
-
*/
|
|
281
|
-
/**
|
|
282
|
-
* Time Complexity: O(n)
|
|
283
|
-
* Space Complexity: O(1)
|
|
284
|
-
*
|
|
285
|
-
* The `forEach` function iterates over each element in an array-like object and calls a callback
|
|
286
|
-
* function for each element.
|
|
287
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
288
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
289
|
-
* element, and the array that forEach was called upon.
|
|
290
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
291
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
292
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
293
|
-
*/
|
|
294
|
-
forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void;
|
|
295
|
-
/**
|
|
296
|
-
* Time Complexity: O(n)
|
|
297
|
-
* Space Complexity: O(1)
|
|
298
|
-
*/
|
|
299
|
-
/**
|
|
300
|
-
* Time Complexity: O(n)
|
|
301
|
-
* Space Complexity: O(1)
|
|
302
|
-
*
|
|
303
|
-
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
304
|
-
* element that satisfies the provided callback function.
|
|
305
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
306
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
307
|
-
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
308
|
-
* current element matches the desired condition.
|
|
309
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
310
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
311
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
312
|
-
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
313
|
-
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
314
|
-
*/
|
|
315
|
-
find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined;
|
|
316
|
-
/**
|
|
317
|
-
* Time Complexity: O(n)
|
|
318
|
-
* Space Complexity: O(1)
|
|
319
|
-
*
|
|
320
|
-
* The function checks if a given element exists in a collection.
|
|
321
|
-
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
|
|
322
|
-
* represents the element that we want to check for existence in the collection.
|
|
323
|
-
* @returns a boolean value. It returns true if the element is found in the collection, and false
|
|
324
|
-
* otherwise.
|
|
325
|
-
*/
|
|
326
|
-
has(element: E): boolean;
|
|
327
|
-
/**
|
|
328
|
-
* Time Complexity: O(n)
|
|
329
|
-
* Space Complexity: O(1)
|
|
330
|
-
*/
|
|
331
|
-
/**
|
|
332
|
-
* Time Complexity: O(n)
|
|
333
|
-
* Space Complexity: O(1)
|
|
334
|
-
*
|
|
335
|
-
* The `reduce` function iterates over the elements of an array-like object and applies a callback
|
|
336
|
-
* function to reduce them into a single value.
|
|
337
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
338
|
-
* the array. It takes four arguments:
|
|
339
|
-
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
340
|
-
* is the value that the accumulator starts with before the reduction operation begins.
|
|
341
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
342
|
-
* all the elements in the array and applying the callback function to each element.
|
|
343
|
-
*/
|
|
344
|
-
reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U;
|
|
345
|
-
/**
|
|
346
|
-
* Time Complexity: O(n)
|
|
347
|
-
* Space Complexity: O(n)
|
|
204
|
+
* The print function logs the elements of an array to the console.
|
|
348
205
|
*/
|
|
349
206
|
print(): void;
|
|
350
207
|
abstract isEmpty(): boolean;
|
|
351
208
|
abstract clear(): void;
|
|
352
|
-
abstract clone():
|
|
209
|
+
abstract clone(): any;
|
|
353
210
|
abstract map(...args: any[]): any;
|
|
354
211
|
abstract filter(...args: any[]): any;
|
|
355
|
-
protected abstract _getIterator(...args: any[]): IterableIterator<
|
|
212
|
+
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
356
213
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export class IterableEntryBase {
|
|
2
|
+
// protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
3
|
+
//
|
|
4
|
+
// /**
|
|
5
|
+
// * The function returns the value of the _toEntryFn property.
|
|
6
|
+
// * @returns The function being returned is `this._toEntryFn`.
|
|
7
|
+
// */
|
|
8
|
+
// get toEntryFn() {
|
|
9
|
+
// return this._toEntryFn;
|
|
10
|
+
// }
|
|
2
11
|
/**
|
|
3
12
|
* Time Complexity: O(n)
|
|
4
13
|
* Space Complexity: O(1)
|
|
@@ -263,196 +272,11 @@ export class IterableEntryBase {
|
|
|
263
272
|
* Time Complexity: O(n)
|
|
264
273
|
* Space Complexity: O(n)
|
|
265
274
|
*/
|
|
266
|
-
print() {
|
|
267
|
-
console.log([...this]);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
export class IterableElementBase {
|
|
271
|
-
/**
|
|
272
|
-
* Time Complexity: O(n)
|
|
273
|
-
* Space Complexity: O(1)
|
|
274
|
-
*/
|
|
275
|
-
/**
|
|
276
|
-
* Time Complexity: O(n)
|
|
277
|
-
* Space Complexity: O(1)
|
|
278
|
-
*
|
|
279
|
-
* The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
|
|
280
|
-
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
281
|
-
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
282
|
-
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
283
|
-
*/
|
|
284
|
-
*[Symbol.iterator](...args) {
|
|
285
|
-
yield* this._getIterator(...args);
|
|
286
|
-
}
|
|
287
275
|
/**
|
|
288
276
|
* Time Complexity: O(n)
|
|
289
277
|
* Space Complexity: O(n)
|
|
290
|
-
*/
|
|
291
|
-
/**
|
|
292
|
-
* Time Complexity: O(n)
|
|
293
|
-
* Space Complexity: O(n)
|
|
294
|
-
*
|
|
295
|
-
* The function returns an iterator that yields all the values in the object.
|
|
296
|
-
*/
|
|
297
|
-
*values() {
|
|
298
|
-
for (const item of this) {
|
|
299
|
-
yield item;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Time Complexity: O(n)
|
|
304
|
-
* Space Complexity: O(1)
|
|
305
|
-
*/
|
|
306
|
-
/**
|
|
307
|
-
* Time Complexity: O(n)
|
|
308
|
-
* Space Complexity: O(1)
|
|
309
278
|
*
|
|
310
|
-
* The
|
|
311
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
312
|
-
* the current element being processed, its index, and the array it belongs to. It should return a
|
|
313
|
-
* boolean value indicating whether the element satisfies a certain condition or not.
|
|
314
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
315
|
-
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
316
|
-
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
317
|
-
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
318
|
-
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
319
|
-
*/
|
|
320
|
-
every(predicate, thisArg) {
|
|
321
|
-
let index = 0;
|
|
322
|
-
for (const item of this) {
|
|
323
|
-
if (!predicate.call(thisArg, item, index++, this)) {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Time Complexity: O(n)
|
|
331
|
-
* Space Complexity: O(1)
|
|
332
|
-
*/
|
|
333
|
-
/**
|
|
334
|
-
* Time Complexity: O(n)
|
|
335
|
-
* Space Complexity: O(1)
|
|
336
|
-
*/
|
|
337
|
-
/**
|
|
338
|
-
* Time Complexity: O(n)
|
|
339
|
-
* Space Complexity: O(1)
|
|
340
|
-
*
|
|
341
|
-
* The "some" function checks if at least one element in a collection satisfies a given predicate.
|
|
342
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
343
|
-
* `value`, `index`, and `array`. It should return a boolean value indicating whether the current
|
|
344
|
-
* element satisfies the condition.
|
|
345
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
346
|
-
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
347
|
-
* it will be passed as the `this` value to the `predicate` function. If `thisArg
|
|
348
|
-
* @returns a boolean value. It returns true if the predicate function returns true for any element
|
|
349
|
-
* in the collection, and false otherwise.
|
|
350
|
-
*/
|
|
351
|
-
some(predicate, thisArg) {
|
|
352
|
-
let index = 0;
|
|
353
|
-
for (const item of this) {
|
|
354
|
-
if (predicate.call(thisArg, item, index++, this)) {
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Time Complexity: O(n)
|
|
362
|
-
* Space Complexity: O(1)
|
|
363
|
-
*/
|
|
364
|
-
/**
|
|
365
|
-
* Time Complexity: O(n)
|
|
366
|
-
* Space Complexity: O(1)
|
|
367
|
-
*
|
|
368
|
-
* The `forEach` function iterates over each element in an array-like object and calls a callback
|
|
369
|
-
* function for each element.
|
|
370
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
371
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
372
|
-
* element, and the array that forEach was called upon.
|
|
373
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
374
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
375
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
376
|
-
*/
|
|
377
|
-
forEach(callbackfn, thisArg) {
|
|
378
|
-
let index = 0;
|
|
379
|
-
for (const item of this) {
|
|
380
|
-
callbackfn.call(thisArg, item, index++, this);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Time Complexity: O(n)
|
|
385
|
-
* Space Complexity: O(1)
|
|
386
|
-
*/
|
|
387
|
-
/**
|
|
388
|
-
* Time Complexity: O(n)
|
|
389
|
-
* Space Complexity: O(1)
|
|
390
|
-
*
|
|
391
|
-
* The `find` function iterates over the elements of an array-like object and returns the first
|
|
392
|
-
* element that satisfies the provided callback function.
|
|
393
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
394
|
-
* the array. It takes three arguments: the current element being processed, the index of the current
|
|
395
|
-
* element, and the array itself. The function should return a boolean value indicating whether the
|
|
396
|
-
* current element matches the desired condition.
|
|
397
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
398
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
399
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
400
|
-
* @returns The `find` method returns the first element in the array that satisfies the provided
|
|
401
|
-
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
402
|
-
*/
|
|
403
|
-
find(callbackfn, thisArg) {
|
|
404
|
-
let index = 0;
|
|
405
|
-
for (const item of this) {
|
|
406
|
-
if (callbackfn.call(thisArg, item, index++, this))
|
|
407
|
-
return item;
|
|
408
|
-
}
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Time Complexity: O(n)
|
|
413
|
-
* Space Complexity: O(1)
|
|
414
|
-
*
|
|
415
|
-
* The function checks if a given element exists in a collection.
|
|
416
|
-
* @param {E} element - The parameter "element" is of type E, which means it can be any type. It
|
|
417
|
-
* represents the element that we want to check for existence in the collection.
|
|
418
|
-
* @returns a boolean value. It returns true if the element is found in the collection, and false
|
|
419
|
-
* otherwise.
|
|
420
|
-
*/
|
|
421
|
-
has(element) {
|
|
422
|
-
for (const ele of this) {
|
|
423
|
-
if (ele === element)
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Time Complexity: O(n)
|
|
430
|
-
* Space Complexity: O(1)
|
|
431
|
-
*/
|
|
432
|
-
/**
|
|
433
|
-
* Time Complexity: O(n)
|
|
434
|
-
* Space Complexity: O(1)
|
|
435
|
-
*
|
|
436
|
-
* The `reduce` function iterates over the elements of an array-like object and applies a callback
|
|
437
|
-
* function to reduce them into a single value.
|
|
438
|
-
* @param callbackfn - The callbackfn parameter is a function that will be called for each element in
|
|
439
|
-
* the array. It takes four arguments:
|
|
440
|
-
* @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
441
|
-
* is the value that the accumulator starts with before the reduction operation begins.
|
|
442
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
443
|
-
* all the elements in the array and applying the callback function to each element.
|
|
444
|
-
*/
|
|
445
|
-
reduce(callbackfn, initialValue) {
|
|
446
|
-
let accumulator = initialValue;
|
|
447
|
-
let index = 0;
|
|
448
|
-
for (const item of this) {
|
|
449
|
-
accumulator = callbackfn(accumulator, item, index++, this);
|
|
450
|
-
}
|
|
451
|
-
return accumulator;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Time Complexity: O(n)
|
|
455
|
-
* Space Complexity: O(n)
|
|
279
|
+
* The print function logs the elements of an array to the console.
|
|
456
280
|
*/
|
|
457
281
|
print() {
|
|
458
282
|
console.log([...this]);
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback,
|
|
8
|
+
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry } from '../../types';
|
|
9
9
|
import { BTNEntry } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
|
-
export declare class AVLTreeMultiMapNode<K
|
|
12
|
+
export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
13
13
|
/**
|
|
14
14
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
15
15
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -37,7 +37,7 @@ export declare class AVLTreeMultiMapNode<K extends Comparable, V = any, NODE ext
|
|
|
37
37
|
/**
|
|
38
38
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
39
39
|
*/
|
|
40
|
-
export declare class AVLTreeMultiMap<K
|
|
40
|
+
export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
41
41
|
/**
|
|
42
42
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
43
43
|
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback,
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
|
|
10
10
|
import { BTNEntry } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
export declare class AVLTreeNode<K
|
|
12
|
+
export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
13
13
|
/**
|
|
14
14
|
* The constructor function initializes a new instance of a class with a key and an optional value,
|
|
15
15
|
* and sets the height property to 0.
|
|
@@ -41,7 +41,7 @@ export declare class AVLTreeNode<K extends Comparable, V = any, NODE extends AVL
|
|
|
41
41
|
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
42
42
|
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
43
43
|
*/
|
|
44
|
-
export declare class AVLTree<K
|
|
44
|
+
export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
45
45
|
/**
|
|
46
46
|
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
|
|
47
47
|
* entries, or raw elements.
|