deque-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.
Files changed (106) hide show
  1. package/dist/data-structures/base/index.d.ts +2 -1
  2. package/dist/data-structures/base/index.js +2 -1
  3. package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
  4. package/dist/data-structures/base/iterable-element-base.js +225 -0
  5. package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  6. package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  10. package/dist/data-structures/binary-tree/avl-tree.js +78 -59
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -226
  12. package/dist/data-structures/binary-tree/binary-tree.js +475 -363
  13. package/dist/data-structures/binary-tree/bst.d.ts +192 -202
  14. package/dist/data-structures/binary-tree/bst.js +207 -249
  15. package/dist/data-structures/binary-tree/rb-tree.d.ts +73 -74
  16. package/dist/data-structures/binary-tree/rb-tree.js +107 -98
  17. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  18. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  19. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  20. package/dist/data-structures/graph/abstract-graph.js +10 -15
  21. package/dist/data-structures/hash/hash-map.d.ts +33 -40
  22. package/dist/data-structures/hash/hash-map.js +40 -55
  23. package/dist/data-structures/heap/heap.d.ts +43 -114
  24. package/dist/data-structures/heap/heap.js +59 -127
  25. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  26. package/dist/data-structures/heap/max-heap.js +76 -10
  27. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  28. package/dist/data-structures/heap/min-heap.js +68 -11
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  32. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  33. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  34. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  35. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  36. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  37. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  38. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  39. package/dist/data-structures/queue/deque.d.ts +21 -20
  40. package/dist/data-structures/queue/deque.js +29 -23
  41. package/dist/data-structures/queue/queue.d.ts +8 -28
  42. package/dist/data-structures/queue/queue.js +15 -31
  43. package/dist/data-structures/stack/stack.d.ts +17 -22
  44. package/dist/data-structures/stack/stack.js +25 -24
  45. package/dist/data-structures/trie/trie.d.ts +19 -14
  46. package/dist/data-structures/trie/trie.js +27 -16
  47. package/dist/interfaces/binary-tree.d.ts +7 -7
  48. package/dist/types/common.d.ts +1 -2
  49. package/dist/types/data-structures/base/base.d.ts +5 -2
  50. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  51. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  52. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  53. package/dist/types/data-structures/binary-tree/bst.d.ts +4 -5
  54. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  55. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  56. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  57. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  58. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  59. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  60. package/dist/types/data-structures/queue/deque.d.ts +3 -2
  61. package/dist/types/data-structures/queue/queue.d.ts +2 -1
  62. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  63. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  64. package/dist/utils/utils.js +3 -5
  65. package/package.json +2 -2
  66. package/src/data-structures/base/index.ts +2 -1
  67. package/src/data-structures/base/iterable-element-base.ts +250 -0
  68. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  69. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
  70. package/src/data-structures/binary-tree/avl-tree.ts +96 -69
  71. package/src/data-structures/binary-tree/binary-tree.ts +535 -403
  72. package/src/data-structures/binary-tree/bst.ts +247 -277
  73. package/src/data-structures/binary-tree/rb-tree.ts +123 -103
  74. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
  75. package/src/data-structures/graph/abstract-graph.ts +10 -10
  76. package/src/data-structures/hash/hash-map.ts +46 -53
  77. package/src/data-structures/heap/heap.ts +71 -152
  78. package/src/data-structures/heap/max-heap.ts +88 -13
  79. package/src/data-structures/heap/min-heap.ts +78 -15
  80. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  81. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  82. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  83. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  84. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  85. package/src/data-structures/queue/deque.ts +37 -26
  86. package/src/data-structures/queue/queue.ts +23 -36
  87. package/src/data-structures/stack/stack.ts +31 -26
  88. package/src/data-structures/trie/trie.ts +35 -20
  89. package/src/interfaces/binary-tree.ts +9 -9
  90. package/src/types/common.ts +1 -2
  91. package/src/types/data-structures/base/base.ts +14 -6
  92. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  93. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  94. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
  95. package/src/types/data-structures/binary-tree/bst.ts +4 -5
  96. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  97. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  98. package/src/types/data-structures/heap/heap.ts +4 -1
  99. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  100. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  101. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  102. package/src/types/data-structures/queue/deque.ts +3 -1
  103. package/src/types/data-structures/queue/queue.ts +3 -1
  104. package/src/types/data-structures/stack/stack.ts +3 -1
  105. package/src/types/data-structures/trie/trie.ts +3 -1
  106. package/src/utils/utils.ts +3 -3
@@ -1 +1,2 @@
1
- export * from './iterable-base';
1
+ export * from './iterable-entry-base';
2
+ export * from './iterable-element-base';
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./iterable-base"), exports);
17
+ __exportStar(require("./iterable-entry-base"), exports);
18
+ __exportStar(require("./iterable-element-base"), exports);
@@ -0,0 +1,171 @@
1
+ import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
2
+ export declare abstract class IterableElementBase<E, R, C> {
3
+ /**
4
+ * The protected constructor initializes the options for the IterableElementBase class, including the
5
+ * toElementFn function.
6
+ * @param [options] - An optional object that contains the following properties:
7
+ */
8
+ protected constructor(options?: IterableElementBaseOptions<E, R>);
9
+ abstract get size(): number;
10
+ protected _toElementFn?: (rawElement: R) => E;
11
+ /**
12
+ * The function returns the _toElementFn property, which is a function that converts a raw element to
13
+ * a specific type.
14
+ * @returns The function `get toElementFn()` is returning either a function that takes a raw element
15
+ * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
16
+ * `_toElementFn`.
17
+ */
18
+ get toElementFn(): ((rawElement: R) => E) | undefined;
19
+ /**
20
+ * Time Complexity: O(n)
21
+ * Space Complexity: O(1)
22
+ */
23
+ /**
24
+ * Time Complexity: O(n)
25
+ * Space Complexity: O(1)
26
+ *
27
+ * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
28
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
29
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
30
+ * parameter is used to pass any number of arguments to the `_getIterator` method.
31
+ */
32
+ [Symbol.iterator](...args: any[]): IterableIterator<E>;
33
+ /**
34
+ * Time Complexity: O(n)
35
+ * Space Complexity: O(n)
36
+ */
37
+ /**
38
+ * Time Complexity: O(n)
39
+ * Space Complexity: O(n)
40
+ *
41
+ * The function returns an iterator that yields all the values in the object.
42
+ */
43
+ values(): IterableIterator<E>;
44
+ /**
45
+ * Time Complexity: O(n)
46
+ * Space Complexity: O(1)
47
+ */
48
+ /**
49
+ * Time Complexity: O(n)
50
+ * Space Complexity: O(1)
51
+ *
52
+ * The `every` function checks if every element in the array satisfies a given predicate.
53
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
54
+ * the current element being processed, its index, and the array it belongs to. It should return a
55
+ * boolean value indicating whether the element satisfies a certain condition or not.
56
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
57
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
58
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
59
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
60
+ * the array satisfies the provided predicate function, and `false` otherwise.
61
+ */
62
+ every(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean;
63
+ /**
64
+ * Time Complexity: O(n)
65
+ * Space Complexity: O(1)
66
+ */
67
+ /**
68
+ * Time Complexity: O(n)
69
+ * Space Complexity: O(1)
70
+ */
71
+ /**
72
+ * Time Complexity: O(n)
73
+ * Space Complexity: O(1)
74
+ *
75
+ * The "some" function checks if at least one element in a collection satisfies a given predicate.
76
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
77
+ * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
78
+ * element satisfies the condition.
79
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
80
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
81
+ * it will be passed as the `this` value to the `predicate` function. If `thisArg
82
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
83
+ * in the collection, and false otherwise.
84
+ */
85
+ some(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean;
86
+ /**
87
+ * Time Complexity: O(n)
88
+ * Space Complexity: O(1)
89
+ */
90
+ /**
91
+ * Time Complexity: O(n)
92
+ * Space Complexity: O(1)
93
+ *
94
+ * The `forEach` function iterates over each element in an array-like object and calls a callback
95
+ * function for each element.
96
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
97
+ * the array. It takes three arguments: the current element being processed, the index of the current
98
+ * element, and the array that forEach was called upon.
99
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
100
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
101
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
102
+ */
103
+ forEach(callbackfn: ElementCallback<E, R, void, C>, thisArg?: any): void;
104
+ /**
105
+ * Time Complexity: O(n)
106
+ * Space Complexity: O(1)
107
+ */
108
+ /**
109
+ * Time Complexity: O(n)
110
+ * Space Complexity: O(1)
111
+ *
112
+ * The `find` function iterates over the elements of an array-like object and returns the first
113
+ * element that satisfies the provided callback function.
114
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
115
+ * the array. It takes three arguments: the current element being processed, the index of the current
116
+ * element, and the array itself. The function should return a boolean value indicating whether the
117
+ * current element matches the desired condition.
118
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
119
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
120
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
121
+ * @returns The `find` method returns the first element in the array that satisfies the provided
122
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
123
+ */
124
+ find(callbackfn: ElementCallback<E, R, boolean, C>, thisArg?: any): E | undefined;
125
+ /**
126
+ * Time Complexity: O(n)
127
+ * Space Complexity: O(1)
128
+ *
129
+ * The function checks if a given element exists in a collection.
130
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
131
+ * represents the element that we want to check for existence in the collection.
132
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
133
+ * otherwise.
134
+ */
135
+ has(element: E): boolean;
136
+ /**
137
+ * Time Complexity: O(n)
138
+ * Space Complexity: O(1)
139
+ */
140
+ /**
141
+ * Time Complexity: O(n)
142
+ * Space Complexity: O(1)
143
+ *
144
+ * The `reduce` function iterates over the elements of an array-like object and applies a callback
145
+ * function to reduce them into a single value.
146
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
147
+ * the array. It takes four arguments:
148
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
149
+ * is the value that the accumulator starts with before the reduction operation begins.
150
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
151
+ * all the elements in the array and applying the callback function to each element.
152
+ */
153
+ reduce<U>(callbackfn: ReduceElementCallback<E, R, U, C>, initialValue: U): U;
154
+ /**
155
+ * Time Complexity: O(n)
156
+ * Space Complexity: O(n)
157
+ */
158
+ /**
159
+ * Time Complexity: O(n)
160
+ * Space Complexity: O(n)
161
+ *
162
+ * The print function logs the elements of an array to the console.
163
+ */
164
+ print(): void;
165
+ abstract isEmpty(): boolean;
166
+ abstract clear(): void;
167
+ abstract clone(): C;
168
+ abstract map(...args: any[]): any;
169
+ abstract filter(...args: any[]): any;
170
+ protected abstract _getIterator(...args: any[]): IterableIterator<E>;
171
+ }
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IterableElementBase = void 0;
4
+ class IterableElementBase {
5
+ /**
6
+ * The protected constructor initializes the options for the IterableElementBase class, including the
7
+ * toElementFn function.
8
+ * @param [options] - An optional object that contains the following properties:
9
+ */
10
+ constructor(options) {
11
+ if (options) {
12
+ const { toElementFn } = options;
13
+ if (typeof toElementFn === 'function')
14
+ this._toElementFn = toElementFn;
15
+ else if (toElementFn)
16
+ throw new TypeError('toElementFn must be a function type');
17
+ }
18
+ }
19
+ /**
20
+ * The function returns the _toElementFn property, which is a function that converts a raw element to
21
+ * a specific type.
22
+ * @returns The function `get toElementFn()` is returning either a function that takes a raw element
23
+ * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
24
+ * `_toElementFn`.
25
+ */
26
+ get toElementFn() {
27
+ return this._toElementFn;
28
+ }
29
+ /**
30
+ * Time Complexity: O(n)
31
+ * Space Complexity: O(1)
32
+ */
33
+ /**
34
+ * Time Complexity: O(n)
35
+ * Space Complexity: O(1)
36
+ *
37
+ * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
38
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
39
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
40
+ * parameter is used to pass any number of arguments to the `_getIterator` method.
41
+ */
42
+ *[Symbol.iterator](...args) {
43
+ yield* this._getIterator(...args);
44
+ }
45
+ /**
46
+ * Time Complexity: O(n)
47
+ * Space Complexity: O(n)
48
+ */
49
+ /**
50
+ * Time Complexity: O(n)
51
+ * Space Complexity: O(n)
52
+ *
53
+ * The function returns an iterator that yields all the values in the object.
54
+ */
55
+ *values() {
56
+ for (const item of this) {
57
+ yield item;
58
+ }
59
+ }
60
+ /**
61
+ * Time Complexity: O(n)
62
+ * Space Complexity: O(1)
63
+ */
64
+ /**
65
+ * Time Complexity: O(n)
66
+ * Space Complexity: O(1)
67
+ *
68
+ * The `every` function checks if every element in the array satisfies a given predicate.
69
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
70
+ * the current element being processed, its index, and the array it belongs to. It should return a
71
+ * boolean value indicating whether the element satisfies a certain condition or not.
72
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
73
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
74
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
75
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
76
+ * the array satisfies the provided predicate function, and `false` otherwise.
77
+ */
78
+ every(predicate, thisArg) {
79
+ let index = 0;
80
+ for (const item of this) {
81
+ if (!predicate.call(thisArg, item, index++, this)) {
82
+ return false;
83
+ }
84
+ }
85
+ return true;
86
+ }
87
+ /**
88
+ * Time Complexity: O(n)
89
+ * Space Complexity: O(1)
90
+ */
91
+ /**
92
+ * Time Complexity: O(n)
93
+ * Space Complexity: O(1)
94
+ */
95
+ /**
96
+ * Time Complexity: O(n)
97
+ * Space Complexity: O(1)
98
+ *
99
+ * The "some" function checks if at least one element in a collection satisfies a given predicate.
100
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
101
+ * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
102
+ * element satisfies the condition.
103
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
104
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
105
+ * it will be passed as the `this` value to the `predicate` function. If `thisArg
106
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
107
+ * in the collection, and false otherwise.
108
+ */
109
+ some(predicate, thisArg) {
110
+ let index = 0;
111
+ for (const item of this) {
112
+ if (predicate.call(thisArg, item, index++, this)) {
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ /**
119
+ * Time Complexity: O(n)
120
+ * Space Complexity: O(1)
121
+ */
122
+ /**
123
+ * Time Complexity: O(n)
124
+ * Space Complexity: O(1)
125
+ *
126
+ * The `forEach` function iterates over each element in an array-like object and calls a callback
127
+ * function for each element.
128
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
129
+ * the array. It takes three arguments: the current element being processed, the index of the current
130
+ * element, and the array that forEach was called upon.
131
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
132
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
133
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
134
+ */
135
+ forEach(callbackfn, thisArg) {
136
+ let index = 0;
137
+ for (const item of this) {
138
+ callbackfn.call(thisArg, item, index++, this);
139
+ }
140
+ }
141
+ /**
142
+ * Time Complexity: O(n)
143
+ * Space Complexity: O(1)
144
+ */
145
+ /**
146
+ * Time Complexity: O(n)
147
+ * Space Complexity: O(1)
148
+ *
149
+ * The `find` function iterates over the elements of an array-like object and returns the first
150
+ * element that satisfies the provided callback function.
151
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
152
+ * the array. It takes three arguments: the current element being processed, the index of the current
153
+ * element, and the array itself. The function should return a boolean value indicating whether the
154
+ * current element matches the desired condition.
155
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
156
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
157
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
158
+ * @returns The `find` method returns the first element in the array that satisfies the provided
159
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
160
+ */
161
+ find(callbackfn, thisArg) {
162
+ let index = 0;
163
+ for (const item of this) {
164
+ if (callbackfn.call(thisArg, item, index++, this))
165
+ return item;
166
+ }
167
+ return;
168
+ }
169
+ /**
170
+ * Time Complexity: O(n)
171
+ * Space Complexity: O(1)
172
+ *
173
+ * The function checks if a given element exists in a collection.
174
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
175
+ * represents the element that we want to check for existence in the collection.
176
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
177
+ * otherwise.
178
+ */
179
+ has(element) {
180
+ for (const ele of this) {
181
+ if (ele === element)
182
+ return true;
183
+ }
184
+ return false;
185
+ }
186
+ /**
187
+ * Time Complexity: O(n)
188
+ * Space Complexity: O(1)
189
+ */
190
+ /**
191
+ * Time Complexity: O(n)
192
+ * Space Complexity: O(1)
193
+ *
194
+ * The `reduce` function iterates over the elements of an array-like object and applies a callback
195
+ * function to reduce them into a single value.
196
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
197
+ * the array. It takes four arguments:
198
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
199
+ * is the value that the accumulator starts with before the reduction operation begins.
200
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
201
+ * all the elements in the array and applying the callback function to each element.
202
+ */
203
+ reduce(callbackfn, initialValue) {
204
+ let accumulator = initialValue;
205
+ let index = 0;
206
+ for (const item of this) {
207
+ accumulator = callbackfn(accumulator, item, index++, this);
208
+ }
209
+ return accumulator;
210
+ }
211
+ /**
212
+ * Time Complexity: O(n)
213
+ * Space Complexity: O(n)
214
+ */
215
+ /**
216
+ * Time Complexity: O(n)
217
+ * Space Complexity: O(n)
218
+ *
219
+ * The print function logs the elements of an array to the console.
220
+ */
221
+ print() {
222
+ console.log([...this]);
223
+ }
224
+ }
225
+ exports.IterableElementBase = IterableElementBase;
@@ -1,4 +1,4 @@
1
- import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';
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 returns an iterator that yields all the values in the object.
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(): C;
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<E>;
212
+ protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
356
213
  }