data-structure-typed 1.51.9 → 1.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +141 -54
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +385 -13
  5. package/dist/cjs/data-structures/base/index.d.ts +2 -1
  6. package/dist/cjs/data-structures/base/index.js +2 -1
  7. package/dist/cjs/data-structures/base/index.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
  11. package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  12. package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +13 -13
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -6
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +99 -99
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.js +54 -52
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +37 -45
  24. package/dist/cjs/data-structures/binary-tree/bst.js +17 -25
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +10 -10
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
  30. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
  31. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/directed-graph.js +2 -1
  33. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  35. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  36. package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
  37. package/dist/cjs/data-structures/heap/heap.js +59 -127
  38. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  39. package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
  40. package/dist/cjs/data-structures/heap/max-heap.js +76 -10
  41. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
  43. package/dist/cjs/data-structures/heap/min-heap.js +68 -11
  44. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  45. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  46. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  48. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  49. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  51. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  52. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
  53. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  54. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  55. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  56. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  57. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  58. package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
  59. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  60. package/dist/cjs/data-structures/queue/deque.d.ts +27 -18
  61. package/dist/cjs/data-structures/queue/deque.js +43 -21
  62. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  63. package/dist/cjs/data-structures/queue/queue.d.ts +8 -29
  64. package/dist/cjs/data-structures/queue/queue.js +15 -32
  65. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  66. package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
  67. package/dist/cjs/data-structures/stack/stack.js +25 -24
  68. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  69. package/dist/cjs/data-structures/trie/trie.d.ts +18 -13
  70. package/dist/cjs/data-structures/trie/trie.js +26 -15
  71. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  72. package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
  73. package/dist/cjs/types/common.d.ts +1 -22
  74. package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
  75. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  76. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  77. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
  78. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +5 -3
  79. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  80. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  81. package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
  82. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  83. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  84. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  85. package/dist/cjs/types/data-structures/queue/deque.d.ts +4 -2
  86. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
  87. package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
  88. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
  89. package/dist/cjs/utils/number.js +1 -2
  90. package/dist/cjs/utils/number.js.map +1 -1
  91. package/dist/cjs/utils/utils.js +2 -2
  92. package/dist/cjs/utils/utils.js.map +1 -1
  93. package/dist/mjs/data-structures/base/index.d.ts +2 -1
  94. package/dist/mjs/data-structures/base/index.js +2 -1
  95. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
  96. package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
  97. package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  98. package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
  99. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
  100. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
  101. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +13 -13
  102. package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +99 -99
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +54 -52
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +37 -45
  106. package/dist/mjs/data-structures/binary-tree/bst.js +17 -25
  107. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +10 -10
  108. package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
  109. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
  110. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
  111. package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
  112. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  113. package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
  114. package/dist/mjs/data-structures/heap/heap.js +60 -128
  115. package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
  116. package/dist/mjs/data-structures/heap/max-heap.js +79 -10
  117. package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
  118. package/dist/mjs/data-structures/heap/min-heap.js +68 -11
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  120. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  122. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
  123. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  124. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
  125. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  126. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  127. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  128. package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
  129. package/dist/mjs/data-structures/queue/deque.d.ts +27 -18
  130. package/dist/mjs/data-structures/queue/deque.js +43 -21
  131. package/dist/mjs/data-structures/queue/queue.d.ts +8 -29
  132. package/dist/mjs/data-structures/queue/queue.js +15 -32
  133. package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
  134. package/dist/mjs/data-structures/stack/stack.js +25 -24
  135. package/dist/mjs/data-structures/trie/trie.d.ts +18 -13
  136. package/dist/mjs/data-structures/trie/trie.js +26 -15
  137. package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
  138. package/dist/mjs/types/common.d.ts +1 -22
  139. package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
  140. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  141. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  142. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
  143. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +5 -3
  144. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  145. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  146. package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
  147. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  148. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  149. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  150. package/dist/mjs/types/data-structures/queue/deque.d.ts +4 -2
  151. package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
  152. package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
  153. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
  154. package/dist/umd/data-structure-typed.js +732 -409
  155. package/dist/umd/data-structure-typed.min.js +2 -2
  156. package/dist/umd/data-structure-typed.min.js.map +1 -1
  157. package/package.json +7 -7
  158. package/src/data-structures/base/index.ts +2 -1
  159. package/src/data-structures/base/iterable-element-base.ts +250 -0
  160. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  161. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +14 -15
  162. package/src/data-structures/binary-tree/avl-tree.ts +13 -14
  163. package/src/data-structures/binary-tree/binary-tree.ts +156 -152
  164. package/src/data-structures/binary-tree/bst.ts +52 -60
  165. package/src/data-structures/binary-tree/rb-tree.ts +12 -13
  166. package/src/data-structures/binary-tree/tree-multi-map.ts +12 -13
  167. package/src/data-structures/graph/directed-graph.ts +2 -1
  168. package/src/data-structures/hash/hash-map.ts +4 -4
  169. package/src/data-structures/heap/heap.ts +71 -152
  170. package/src/data-structures/heap/max-heap.ts +88 -13
  171. package/src/data-structures/heap/min-heap.ts +78 -15
  172. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  173. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  174. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  175. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  176. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  177. package/src/data-structures/queue/deque.ts +50 -25
  178. package/src/data-structures/queue/queue.ts +23 -37
  179. package/src/data-structures/stack/stack.ts +31 -26
  180. package/src/data-structures/trie/trie.ts +33 -18
  181. package/src/interfaces/binary-tree.ts +4 -5
  182. package/src/types/common.ts +2 -24
  183. package/src/types/data-structures/base/base.ts +14 -6
  184. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  185. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
  186. package/src/types/data-structures/binary-tree/binary-tree.ts +24 -5
  187. package/src/types/data-structures/binary-tree/bst.ts +9 -3
  188. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
  189. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
  190. package/src/types/data-structures/heap/heap.ts +4 -1
  191. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  192. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  193. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  194. package/src/types/data-structures/queue/deque.ts +6 -1
  195. package/src/types/data-structures/queue/queue.ts +3 -1
  196. package/src/types/data-structures/stack/stack.ts +3 -1
  197. package/src/types/data-structures/trie/trie.ts +3 -1
  198. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +1 -1
  199. package/test/unit/data-structures/graph/directed-graph.test.ts +28 -0
  200. package/test/unit/data-structures/heap/heap.test.ts +100 -0
  201. package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
  202. package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
  203. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
  204. package/test/unit/data-structures/queue/deque.test.ts +49 -0
  205. package/test/unit/data-structures/queue/queue.test.ts +56 -0
  206. package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.51.9",
3
+ "version": "1.52.1",
4
4
  "description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/mjs/index.js",
@@ -66,11 +66,11 @@
66
66
  "@typescript-eslint/eslint-plugin": "^6.7.4",
67
67
  "@typescript-eslint/parser": "^6.7.4",
68
68
  "auto-changelog": "^2.4.0",
69
- "avl-tree-typed": "^1.51.8",
69
+ "avl-tree-typed": "^1.52.0",
70
70
  "benchmark": "^2.1.4",
71
- "binary-tree-typed": "^1.51.8",
72
- "bst-typed": "^1.51.8",
73
- "data-structure-typed": "^1.51.8",
71
+ "binary-tree-typed": "^1.52.0",
72
+ "bst-typed": "^1.52.0",
73
+ "data-structure-typed": "^1.52.0",
74
74
  "dependency-cruiser": "^14.1.0",
75
75
  "doctoc": "^2.2.1",
76
76
  "eslint": "^8.50.0",
@@ -79,7 +79,7 @@
79
79
  "eslint-import-resolver-typescript": "^3.6.1",
80
80
  "eslint-plugin-import": "^2.28.1",
81
81
  "fast-glob": "^3.3.1",
82
- "heap-typed": "^1.51.8",
82
+ "heap-typed": "^1.52.0",
83
83
  "istanbul-badges-readme": "^1.8.5",
84
84
  "jest": "^29.7.0",
85
85
  "js-sdsl": "^4.4.2",
@@ -88,7 +88,7 @@
88
88
  "ts-loader": "^9.4.4",
89
89
  "ts-node": "^10.9.1",
90
90
  "tsup": "^7.2.0",
91
- "typedoc": "^0.25.4",
91
+ "typedoc": "^0.26.5",
92
92
  "typescript": "^5.3.2"
93
93
  },
94
94
  "keywords": [
@@ -1 +1,2 @@
1
- export * from './iterable-base';
1
+ export * from './iterable-entry-base';
2
+ export * from './iterable-element-base';
@@ -0,0 +1,250 @@
1
+ import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
2
+
3
+ export abstract class IterableElementBase<E, R, C> {
4
+ /**
5
+ * The protected constructor initializes the options for the IterableElementBase class, including the
6
+ * toElementFn function.
7
+ * @param [options] - An optional object that contains the following properties:
8
+ */
9
+ protected constructor(options?: IterableElementBaseOptions<E, R>) {
10
+ if (options) {
11
+ const { toElementFn } = options;
12
+ if (typeof toElementFn === 'function') this._toElementFn = toElementFn;
13
+ else if (toElementFn) throw new TypeError('toElementFn must be a function type');
14
+ }
15
+ }
16
+
17
+ abstract get size(): number;
18
+
19
+ protected _toElementFn?: (rawElement: R) => E;
20
+
21
+ /**
22
+ * The function returns the _toElementFn property, which is a function that converts a raw element to
23
+ * a specific type.
24
+ * @returns The function `get toElementFn()` is returning either a function that takes a raw element
25
+ * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
26
+ * `_toElementFn`.
27
+ */
28
+ get toElementFn(): ((rawElement: R) => E) | undefined {
29
+ return this._toElementFn;
30
+ }
31
+
32
+ /**
33
+ * Time Complexity: O(n)
34
+ * Space Complexity: O(1)
35
+ */
36
+ /**
37
+ * Time Complexity: O(n)
38
+ * Space Complexity: O(1)
39
+ *
40
+ * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
41
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
42
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
43
+ * parameter is used to pass any number of arguments to the `_getIterator` method.
44
+ */
45
+ * [Symbol.iterator](...args: any[]): IterableIterator<E> {
46
+ yield* this._getIterator(...args);
47
+ }
48
+
49
+ /**
50
+ * Time Complexity: O(n)
51
+ * Space Complexity: O(n)
52
+ */
53
+ /**
54
+ * Time Complexity: O(n)
55
+ * Space Complexity: O(n)
56
+ *
57
+ * The function returns an iterator that yields all the values in the object.
58
+ */
59
+ * values(): IterableIterator<E> {
60
+ for (const item of this) {
61
+ yield item;
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Time Complexity: O(n)
67
+ * Space Complexity: O(1)
68
+ */
69
+ /**
70
+ * Time Complexity: O(n)
71
+ * Space Complexity: O(1)
72
+ *
73
+ * The `every` function checks if every element in the array satisfies a given predicate.
74
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
75
+ * the current element being processed, its index, and the array it belongs to. It should return a
76
+ * boolean value indicating whether the element satisfies a certain condition or not.
77
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
78
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
79
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
80
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
81
+ * the array satisfies the provided predicate function, and `false` otherwise.
82
+ */
83
+ every(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean {
84
+ let index = 0;
85
+ for (const item of this) {
86
+ if (!predicate.call(thisArg, item, index++, this)) {
87
+ return false;
88
+ }
89
+ }
90
+ return true;
91
+ }
92
+
93
+ /**
94
+ * Time Complexity: O(n)
95
+ * Space Complexity: O(1)
96
+ */
97
+
98
+ /**
99
+ * Time Complexity: O(n)
100
+ * Space Complexity: O(1)
101
+ */
102
+ /**
103
+ * Time Complexity: O(n)
104
+ * Space Complexity: O(1)
105
+ *
106
+ * The "some" function checks if at least one element in a collection satisfies a given predicate.
107
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
108
+ * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
109
+ * element satisfies the condition.
110
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
111
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
112
+ * it will be passed as the `this` value to the `predicate` function. If `thisArg
113
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
114
+ * in the collection, and false otherwise.
115
+ */
116
+ some(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean {
117
+ let index = 0;
118
+ for (const item of this) {
119
+ if (predicate.call(thisArg, item, index++, this)) {
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * Time Complexity: O(n)
128
+ * Space Complexity: O(1)
129
+ */
130
+
131
+ /**
132
+ * Time Complexity: O(n)
133
+ * Space Complexity: O(1)
134
+ *
135
+ * The `forEach` function iterates over each element in an array-like object and calls a callback
136
+ * function for each element.
137
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
138
+ * the array. It takes three arguments: the current element being processed, the index of the current
139
+ * element, and the array that forEach was called upon.
140
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
141
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
142
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
143
+ */
144
+ forEach(callbackfn: ElementCallback<E, R, void, C>, thisArg?: any): void {
145
+ let index = 0;
146
+ for (const item of this) {
147
+ callbackfn.call(thisArg, item, index++, this);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Time Complexity: O(n)
153
+ * Space Complexity: O(1)
154
+ */
155
+
156
+ /**
157
+ * Time Complexity: O(n)
158
+ * Space Complexity: O(1)
159
+ *
160
+ * The `find` function iterates over the elements of an array-like object and returns the first
161
+ * element that satisfies the provided callback function.
162
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
163
+ * the array. It takes three arguments: the current element being processed, the index of the current
164
+ * element, and the array itself. The function should return a boolean value indicating whether the
165
+ * current element matches the desired condition.
166
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
167
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
168
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
169
+ * @returns The `find` method returns the first element in the array that satisfies the provided
170
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
171
+ */
172
+ find(callbackfn: ElementCallback<E, R, boolean, C>, thisArg?: any): E | undefined {
173
+ let index = 0;
174
+ for (const item of this) {
175
+ if (callbackfn.call(thisArg, item, index++, this)) return item;
176
+ }
177
+
178
+ return;
179
+ }
180
+
181
+ /**
182
+ * Time Complexity: O(n)
183
+ * Space Complexity: O(1)
184
+ *
185
+ * The function checks if a given element exists in a collection.
186
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
187
+ * represents the element that we want to check for existence in the collection.
188
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
189
+ * otherwise.
190
+ */
191
+ has(element: E): boolean {
192
+ for (const ele of this) {
193
+ if (ele === element) return true;
194
+ }
195
+ return false;
196
+ }
197
+
198
+ /**
199
+ * Time Complexity: O(n)
200
+ * Space Complexity: O(1)
201
+ */
202
+ /**
203
+ * Time Complexity: O(n)
204
+ * Space Complexity: O(1)
205
+ *
206
+ * The `reduce` function iterates over the elements of an array-like object and applies a callback
207
+ * function to reduce them into a single value.
208
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
209
+ * the array. It takes four arguments:
210
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
211
+ * is the value that the accumulator starts with before the reduction operation begins.
212
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
213
+ * all the elements in the array and applying the callback function to each element.
214
+ */
215
+ reduce<U>(callbackfn: ReduceElementCallback<E, R, U, C>, initialValue: U): U {
216
+ let accumulator = initialValue;
217
+ let index = 0;
218
+ for (const item of this) {
219
+ accumulator = callbackfn(accumulator, item as E, index++, this);
220
+ }
221
+ return accumulator;
222
+ }
223
+
224
+ /**
225
+ * Time Complexity: O(n)
226
+ * Space Complexity: O(n)
227
+ */
228
+
229
+ /**
230
+ * Time Complexity: O(n)
231
+ * Space Complexity: O(n)
232
+ *
233
+ * The print function logs the elements of an array to the console.
234
+ */
235
+ print(): void {
236
+ console.log([...this]);
237
+ }
238
+
239
+ abstract isEmpty(): boolean;
240
+
241
+ abstract clear(): void;
242
+
243
+ abstract clone(): C;
244
+
245
+ abstract map(...args: any[]): any;
246
+
247
+ abstract filter(...args: any[]): any;
248
+
249
+ protected abstract _getIterator(...args: any[]): IterableIterator<E>;
250
+ }
@@ -1,6 +1,14 @@
1
- import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';
1
+ import { EntryCallback, ReduceEntryCallback } from '../../types';
2
2
 
3
3
  export abstract class IterableEntryBase<K = any, V = any> {
4
+ // protected constructor(options?: IterableEntryBaseOptions<K, V, R>) {
5
+ // if (options) {
6
+ // const { toEntryFn } = options;
7
+ // if (typeof toEntryFn === 'function') this._toEntryFn = toEntryFn
8
+ // else throw new TypeError('toEntryFn must be a function type');
9
+ // }
10
+ // }
11
+
4
12
  /**
5
13
  * Time Complexity: O(n)
6
14
  * Space Complexity: O(1)
@@ -8,6 +16,16 @@ export abstract class IterableEntryBase<K = any, V = any> {
8
16
 
9
17
  abstract get size(): number;
10
18
 
19
+ // protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
20
+ //
21
+ // /**
22
+ // * The function returns the value of the _toEntryFn property.
23
+ // * @returns The function being returned is `this._toEntryFn`.
24
+ // */
25
+ // get toEntryFn() {
26
+ // return this._toEntryFn;
27
+ // }
28
+
11
29
  /**
12
30
  * Time Complexity: O(n)
13
31
  * Space Complexity: O(1)
@@ -285,221 +303,12 @@ export abstract class IterableEntryBase<K = any, V = any> {
285
303
  * Time Complexity: O(n)
286
304
  * Space Complexity: O(n)
287
305
  */
288
- print(): void {
289
- console.log([...this]);
290
- }
291
-
292
- abstract isEmpty(): boolean;
293
-
294
- abstract clear(): void;
295
-
296
- abstract clone(): any;
297
-
298
- abstract map(...args: any[]): any;
299
-
300
- abstract filter(...args: any[]): any;
301
-
302
- protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
303
- }
304
-
305
- export abstract class IterableElementBase<E = any, C = any> {
306
- abstract get size(): number;
307
-
308
- /**
309
- * Time Complexity: O(n)
310
- * Space Complexity: O(1)
311
- */
312
- /**
313
- * Time Complexity: O(n)
314
- * Space Complexity: O(1)
315
- *
316
- * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
317
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
318
- * allows the function to accept any number of arguments as an array. In this case, the `args`
319
- * parameter is used to pass any number of arguments to the `_getIterator` method.
320
- */
321
- * [Symbol.iterator](...args: any[]): IterableIterator<E> {
322
- yield* this._getIterator(...args);
323
- }
324
306
 
325
307
  /**
326
308
  * Time Complexity: O(n)
327
309
  * Space Complexity: O(n)
328
- */
329
- /**
330
- * Time Complexity: O(n)
331
- * Space Complexity: O(n)
332
- *
333
- * The function returns an iterator that yields all the values in the object.
334
- */
335
- * values(): IterableIterator<E> {
336
- for (const item of this) {
337
- yield item;
338
- }
339
- }
340
-
341
- /**
342
- * Time Complexity: O(n)
343
- * Space Complexity: O(1)
344
- */
345
- /**
346
- * Time Complexity: O(n)
347
- * Space Complexity: O(1)
348
- *
349
- * The `every` function checks if every element in the array satisfies a given predicate.
350
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
351
- * the current element being processed, its index, and the array it belongs to. It should return a
352
- * boolean value indicating whether the element satisfies a certain condition or not.
353
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
354
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
355
- * passed as the `this` value to the `predicate` function. If `thisArg` is
356
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
357
- * the array satisfies the provided predicate function, and `false` otherwise.
358
- */
359
- every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean {
360
- let index = 0;
361
- for (const item of this) {
362
- if (!predicate.call(thisArg, item, index++, this)) {
363
- return false;
364
- }
365
- }
366
- return true;
367
- }
368
-
369
- /**
370
- * Time Complexity: O(n)
371
- * Space Complexity: O(1)
372
- */
373
-
374
- /**
375
- * Time Complexity: O(n)
376
- * Space Complexity: O(1)
377
- */
378
- /**
379
- * Time Complexity: O(n)
380
- * Space Complexity: O(1)
381
- *
382
- * The "some" function checks if at least one element in a collection satisfies a given predicate.
383
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
384
- * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
385
- * element satisfies the condition.
386
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
387
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
388
- * it will be passed as the `this` value to the `predicate` function. If `thisArg
389
- * @returns a boolean value. It returns true if the predicate function returns true for any element
390
- * in the collection, and false otherwise.
391
- */
392
- some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean {
393
- let index = 0;
394
- for (const item of this) {
395
- if (predicate.call(thisArg, item, index++, this)) {
396
- return true;
397
- }
398
- }
399
- return false;
400
- }
401
-
402
- /**
403
- * Time Complexity: O(n)
404
- * Space Complexity: O(1)
405
- */
406
-
407
- /**
408
- * Time Complexity: O(n)
409
- * Space Complexity: O(1)
410
- *
411
- * The `forEach` function iterates over each element in an array-like object and calls a callback
412
- * function for each element.
413
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
414
- * the array. It takes three arguments: the current element being processed, the index of the current
415
- * element, and the array that forEach was called upon.
416
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
417
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
418
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
419
- */
420
- forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void {
421
- let index = 0;
422
- for (const item of this) {
423
- callbackfn.call(thisArg, item, index++, this);
424
- }
425
- }
426
-
427
- /**
428
- * Time Complexity: O(n)
429
- * Space Complexity: O(1)
430
- */
431
-
432
- /**
433
- * Time Complexity: O(n)
434
- * Space Complexity: O(1)
435
- *
436
- * The `find` function iterates over the elements of an array-like object and returns the first
437
- * element that satisfies the provided callback function.
438
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
439
- * the array. It takes three arguments: the current element being processed, the index of the current
440
- * element, and the array itself. The function should return a boolean value indicating whether the
441
- * current element matches the desired condition.
442
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
443
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
444
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
445
- * @returns The `find` method returns the first element in the array that satisfies the provided
446
- * callback function. If no element satisfies the callback function, `undefined` is returned.
447
- */
448
- find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined {
449
- let index = 0;
450
- for (const item of this) {
451
- if (callbackfn.call(thisArg, item, index++, this)) return item;
452
- }
453
-
454
- return;
455
- }
456
-
457
- /**
458
- * Time Complexity: O(n)
459
- * Space Complexity: O(1)
460
- *
461
- * The function checks if a given element exists in a collection.
462
- * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
463
- * represents the element that we want to check for existence in the collection.
464
- * @returns a boolean value. It returns true if the element is found in the collection, and false
465
- * otherwise.
466
- */
467
- has(element: E): boolean {
468
- for (const ele of this) {
469
- if (ele === element) return true;
470
- }
471
- return false;
472
- }
473
-
474
- /**
475
- * Time Complexity: O(n)
476
- * Space Complexity: O(1)
477
- */
478
- /**
479
- * Time Complexity: O(n)
480
- * Space Complexity: O(1)
481
310
  *
482
- * The `reduce` function iterates over the elements of an array-like object and applies a callback
483
- * function to reduce them into a single value.
484
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
485
- * the array. It takes four arguments:
486
- * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
487
- * is the value that the accumulator starts with before the reduction operation begins.
488
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
489
- * all the elements in the array and applying the callback function to each element.
490
- */
491
- reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U {
492
- let accumulator = initialValue;
493
- let index = 0;
494
- for (const item of this) {
495
- accumulator = callbackfn(accumulator, item as E, index++, this);
496
- }
497
- return accumulator;
498
- }
499
-
500
- /**
501
- * Time Complexity: O(n)
502
- * Space Complexity: O(n)
311
+ * The print function logs the elements of an array to the console.
503
312
  */
504
313
  print(): void {
505
314
  console.log([...this]);
@@ -509,11 +318,11 @@ export abstract class IterableElementBase<E = any, C = any> {
509
318
 
510
319
  abstract clear(): void;
511
320
 
512
- abstract clone(): C;
321
+ abstract clone(): any;
513
322
 
514
323
  abstract map(...args: any[]): any;
515
324
 
516
325
  abstract filter(...args: any[]): any;
517
326
 
518
- protected abstract _getIterator(...args: any[]): IterableIterator<E>;
327
+ protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
519
328
  }
@@ -12,16 +12,15 @@ import type {
12
12
  BinaryTreeDeleteResult,
13
13
  BSTNKeyOrNode,
14
14
  BTNCallback,
15
- Comparable,
16
- IterationType,
17
- KeyOrNodeOrEntry
15
+ BTNKeyOrNodeOrEntry,
16
+ IterationType
18
17
  } from '../../types';
19
18
  import { BTNEntry } from '../../types';
20
19
  import { IBinaryTree } from '../../interfaces';
21
20
  import { AVLTree, AVLTreeNode } from './avl-tree';
22
21
 
23
22
  export class AVLTreeMultiMapNode<
24
- K extends Comparable,
23
+ K = any,
25
24
  V = any,
26
25
  NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
27
26
  > extends AVLTreeNode<K, V, NODE> {
@@ -64,7 +63,7 @@ export class AVLTreeMultiMapNode<
64
63
  * 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.
65
64
  */
66
65
  export class AVLTreeMultiMap<
67
- K extends Comparable,
66
+ K = any,
68
67
  V = any,
69
68
  R = BTNEntry<K, V>,
70
69
  NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
@@ -87,7 +86,7 @@ export class AVLTreeMultiMap<
87
86
  * `compareValues` functions to define custom comparison logic for keys and values, respectively.
88
87
  */
89
88
  constructor(
90
- keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>> = [],
89
+ keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
91
90
  options?: AVLTreeMultiMapOptions<K, V, R>
92
91
  ) {
93
92
  super([], options);
@@ -156,13 +155,13 @@ export class AVLTreeMultiMap<
156
155
 
157
156
  /**
158
157
  * The function checks if the input is an instance of AVLTreeMultiMapNode.
159
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
160
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
158
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
159
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
161
160
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
162
161
  * an instance of the `AVLTreeMultiMapNode` class.
163
162
  */
164
163
  override isNode(
165
- keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>
164
+ keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
166
165
  ): keyOrNodeOrEntryOrRawElement is NODE {
167
166
  return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
168
167
  }
@@ -170,8 +169,8 @@ export class AVLTreeMultiMap<
170
169
  /**
171
170
  * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
172
171
  * a node object.
173
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
174
- * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
172
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
173
+ * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
175
174
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
176
175
  * `override` function. It represents the value associated with the key in the data structure. If no
177
176
  * value is provided, it will default to `undefined`.
@@ -180,7 +179,7 @@ export class AVLTreeMultiMap<
180
179
  * @returns either a NODE object or undefined.
181
180
  */
182
181
  override keyValueOrEntryOrRawElementToNode(
183
- keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>,
182
+ keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
184
183
  value?: V,
185
184
  count = 1
186
185
  ): NODE | undefined {
@@ -214,9 +213,9 @@ export class AVLTreeMultiMap<
214
213
  *
215
214
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
216
215
  * and update the count.
217
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
216
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
218
217
  * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
219
- * can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
218
+ * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
220
219
  * entry, or raw element
221
220
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
222
221
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -225,7 +224,7 @@ export class AVLTreeMultiMap<
225
224
  * be added once. However, you can specify a different value for `count` if you want to add
226
225
  * @returns a boolean value.
227
226
  */
228
- override add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
227
+ override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
229
228
  const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
230
229
  if (newNode === undefined) return false;
231
230