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.
Files changed (186) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  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 +3 -3
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +4 -4
  19. package/dist/cjs/data-structures/binary-tree/binary-tree.js +5 -3
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/bst.d.ts +3 -11
  22. package/dist/cjs/data-structures/binary-tree/bst.js +2 -10
  23. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
  25. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
  27. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  28. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  29. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  30. package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
  31. package/dist/cjs/data-structures/heap/heap.js +59 -127
  32. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  33. package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
  34. package/dist/cjs/data-structures/heap/max-heap.js +76 -10
  35. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  36. package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
  37. package/dist/cjs/data-structures/heap/min-heap.js +68 -11
  38. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  39. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  40. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  41. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  42. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  43. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  45. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  46. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
  47. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  48. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  49. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  50. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  51. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  52. package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
  53. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  54. package/dist/cjs/data-structures/queue/deque.d.ts +20 -18
  55. package/dist/cjs/data-structures/queue/deque.js +27 -20
  56. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  57. package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
  58. package/dist/cjs/data-structures/queue/queue.js +15 -31
  59. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  60. package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
  61. package/dist/cjs/data-structures/stack/stack.js +25 -24
  62. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  63. package/dist/cjs/data-structures/trie/trie.d.ts +18 -13
  64. package/dist/cjs/data-structures/trie/trie.js +26 -15
  65. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  66. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  67. package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
  68. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  69. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  70. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  71. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -3
  72. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  73. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  74. package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
  75. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  76. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  77. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  78. package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
  79. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
  80. package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
  81. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
  82. package/dist/mjs/data-structures/base/index.d.ts +2 -1
  83. package/dist/mjs/data-structures/base/index.js +2 -1
  84. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
  85. package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
  86. package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  87. package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
  88. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -3
  89. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
  90. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +4 -4
  91. package/dist/mjs/data-structures/binary-tree/binary-tree.js +5 -3
  92. package/dist/mjs/data-structures/binary-tree/bst.d.ts +3 -11
  93. package/dist/mjs/data-structures/binary-tree/bst.js +2 -10
  94. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
  95. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
  96. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  97. package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
  98. package/dist/mjs/data-structures/heap/heap.js +60 -128
  99. package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
  100. package/dist/mjs/data-structures/heap/max-heap.js +79 -10
  101. package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
  102. package/dist/mjs/data-structures/heap/min-heap.js +68 -11
  103. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  104. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  105. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  106. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
  107. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  108. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
  109. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  110. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  111. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  112. package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
  113. package/dist/mjs/data-structures/queue/deque.d.ts +20 -18
  114. package/dist/mjs/data-structures/queue/deque.js +27 -20
  115. package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
  116. package/dist/mjs/data-structures/queue/queue.js +15 -31
  117. package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
  118. package/dist/mjs/data-structures/stack/stack.js +25 -24
  119. package/dist/mjs/data-structures/trie/trie.d.ts +18 -13
  120. package/dist/mjs/data-structures/trie/trie.js +26 -15
  121. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  122. package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
  123. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  124. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  125. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  126. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -3
  127. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  128. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  129. package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
  130. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  131. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  132. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  133. package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
  134. package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
  135. package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
  136. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
  137. package/dist/umd/data-structure-typed.js +628 -319
  138. package/dist/umd/data-structure-typed.min.js +2 -2
  139. package/dist/umd/data-structure-typed.min.js.map +1 -1
  140. package/package.json +6 -6
  141. package/src/data-structures/base/index.ts +2 -1
  142. package/src/data-structures/base/iterable-element-base.ts +250 -0
  143. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  144. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  145. package/src/data-structures/binary-tree/avl-tree.ts +2 -3
  146. package/src/data-structures/binary-tree/binary-tree.ts +6 -6
  147. package/src/data-structures/binary-tree/bst.ts +8 -19
  148. package/src/data-structures/binary-tree/rb-tree.ts +2 -3
  149. package/src/data-structures/binary-tree/tree-multi-map.ts +2 -3
  150. package/src/data-structures/hash/hash-map.ts +4 -4
  151. package/src/data-structures/heap/heap.ts +71 -152
  152. package/src/data-structures/heap/max-heap.ts +88 -13
  153. package/src/data-structures/heap/min-heap.ts +78 -15
  154. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  155. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  156. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  157. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  158. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  159. package/src/data-structures/queue/deque.ts +35 -24
  160. package/src/data-structures/queue/queue.ts +23 -36
  161. package/src/data-structures/stack/stack.ts +31 -26
  162. package/src/data-structures/trie/trie.ts +33 -18
  163. package/src/interfaces/binary-tree.ts +1 -2
  164. package/src/types/data-structures/base/base.ts +14 -6
  165. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  166. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
  167. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -4
  168. package/src/types/data-structures/binary-tree/bst.ts +2 -3
  169. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
  170. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
  171. package/src/types/data-structures/heap/heap.ts +4 -1
  172. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  173. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  174. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  175. package/src/types/data-structures/queue/deque.ts +3 -1
  176. package/src/types/data-structures/queue/queue.ts +3 -1
  177. package/src/types/data-structures/stack/stack.ts +3 -1
  178. package/src/types/data-structures/trie/trie.ts +3 -1
  179. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +1 -1
  180. package/test/unit/data-structures/heap/heap.test.ts +80 -0
  181. package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
  182. package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
  183. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
  184. package/test/unit/data-structures/queue/deque.test.ts +30 -0
  185. package/test/unit/data-structures/queue/queue.test.ts +56 -0
  186. package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, Comparable, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { IterableEntryBase } from '../base';
11
11
  /**
@@ -13,7 +13,7 @@ import { IterableEntryBase } from '../base';
13
13
  * @template V - The type of data stored in the node.
14
14
  * @template NODE - The type of the family relationship in the binary tree.
15
15
  */
16
- export declare class BinaryTreeNode<K extends Comparable, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
16
+ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
17
17
  key: K;
18
18
  value?: V;
19
19
  parent?: NODE;
@@ -65,11 +65,11 @@ export declare class BinaryTreeNode<K extends Comparable, V = any, NODE extends
65
65
  * 4. Subtrees: Each child of a node forms the root of a subtree.
66
66
  * 5. Leaf Nodes: Nodes without children are leaves.
67
67
  */
68
- export declare class BinaryTree<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
68
+ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
69
69
  iterationType: IterationType;
70
70
  /**
71
71
  * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
72
- * @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
72
+ * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of KeyOrNodeOrEntry objects. These objects represent the
73
73
  * nodes to be added to the binary tree.
74
74
  * @param [options] - The `options` parameter is an optional object that can contain additional
75
75
  * configuration options for the binary tree. In this case, it is of type
@@ -98,7 +98,7 @@ export class BinaryTree extends IterableEntryBase {
98
98
  iterationType = 'ITERATIVE';
99
99
  /**
100
100
  * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
101
- * @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
101
+ * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of KeyOrNodeOrEntry objects. These objects represent the
102
102
  * nodes to be added to the binary tree.
103
103
  * @param [options] - The `options` parameter is an optional object that can contain additional
104
104
  * configuration options for the binary tree. In this case, it is of type
@@ -113,6 +113,8 @@ export class BinaryTree extends IterableEntryBase {
113
113
  this.iterationType = iterationType;
114
114
  if (typeof toEntryFn === 'function')
115
115
  this._toEntryFn = toEntryFn;
116
+ else if (toEntryFn)
117
+ throw TypeError('toEntryFn must be a function type');
116
118
  }
117
119
  if (keysOrNodesOrEntriesOrRawElements)
118
120
  this.addMany(keysOrNodesOrEntriesOrRawElements);
@@ -1698,12 +1700,12 @@ export class BinaryTree extends IterableEntryBase {
1698
1700
  }
1699
1701
  else if (node !== null && node !== undefined) {
1700
1702
  // Display logic of normal nodes
1701
- const key = node.key, line = this.isNIL(node) ? 'S' : key.toString(), width = line.length;
1703
+ const key = node.key, line = this.isNIL(node) ? 'S' : String(key), width = line.length;
1702
1704
  return _buildNodeDisplay(line, width, this._displayAux(node.left, options), this._displayAux(node.right, options));
1703
1705
  }
1704
1706
  else {
1705
1707
  // For cases where none of the conditions are met, null, undefined, and NaN nodes are not displayed
1706
- const line = node === undefined ? 'U' : 'NODE', width = line.length;
1708
+ const line = node === undefined ? 'U' : 'N', width = line.length;
1707
1709
  return _buildNodeDisplay(line, width, [[''], 1, 0, 0], [[''], 1, 0, 0]);
1708
1710
  }
1709
1711
  function _buildNodeDisplay(line, width, left, right) {
@@ -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 { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparable, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
8
+ import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
9
9
  import { BTNEntry } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
12
- export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
12
+ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
13
13
  parent?: NODE;
14
14
  constructor(key: K, value?: V);
15
15
  protected _left?: NODE;
@@ -47,7 +47,7 @@ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode
47
47
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
48
48
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
49
49
  */
50
- export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
50
+ export declare class BST<K = any, V = any, R = BTNEntry<K, V>, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
51
51
  /**
52
52
  * This is the constructor function for a Binary Search Tree class in TypeScript.
53
53
  * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
@@ -349,15 +349,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
349
349
  * @returns a boolean value.
350
350
  */
351
351
  isAVLBalanced(iterationType?: IterationType): boolean;
352
- /**
353
- * Time complexity: O(n)
354
- * Space complexity: O(n)
355
- */
356
352
  protected _DEFAULT_COMPARATOR: (a: K, b: K) => number;
357
- /**
358
- * Time complexity: O(n)
359
- * Space complexity: O(n)
360
- */
361
353
  protected _comparator: Comparator<K>;
362
354
  /**
363
355
  * Time Complexity: O(n)
@@ -687,13 +687,9 @@ export class BST extends BinaryTree {
687
687
  }
688
688
  return balanced;
689
689
  }
690
- /**
691
- * Time complexity: O(n)
692
- * Space complexity: O(n)
693
- */
694
690
  _DEFAULT_COMPARATOR = (a, b) => {
695
- if (typeof a === 'object' && typeof b === 'object' && this.comparator === this._DEFAULT_COMPARATOR) {
696
- throw TypeError('When comparing two object types, it is necessary to customize a [comparator] function of options parameter during the instantiation of the data structure.');
691
+ if (typeof a === 'object' || typeof b === 'object') {
692
+ throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
697
693
  }
698
694
  if (a > b)
699
695
  return 1;
@@ -701,10 +697,6 @@ export class BST extends BinaryTree {
701
697
  return -1;
702
698
  return 0;
703
699
  };
704
- /**
705
- * Time complexity: O(n)
706
- * Space complexity: O(n)
707
- */
708
700
  _comparator = this._DEFAULT_COMPARATOR;
709
701
  /**
710
702
  * Time Complexity: O(n)
@@ -1,8 +1,8 @@
1
- import type { BinaryTreeDeleteResult, BTNCallback, Comparable, CRUD, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
1
+ import type { BinaryTreeDeleteResult, BTNCallback, CRUD, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
2
2
  import { BTNEntry } from '../../types';
3
3
  import { BST, BSTNode } from './bst';
4
4
  import { IBinaryTree } from '../../interfaces';
5
- export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
5
+ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
6
6
  /**
7
7
  * The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
8
8
  * color.
@@ -27,7 +27,7 @@ export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extend
27
27
  */
28
28
  set color(value: RBTNColor);
29
29
  }
30
- export declare class RedBlackTree<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
30
+ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
31
31
  /**
32
32
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
33
33
  * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
@@ -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 { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
9
9
  import { BTNEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
12
- export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
12
+ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
13
13
  /**
14
14
  * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
15
15
  * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
@@ -36,7 +36,7 @@ export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extend
36
36
  */
37
37
  set count(value: number);
38
38
  }
39
- export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
39
+ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
40
40
  /**
41
41
  * The constructor function initializes a TreeMultiMap object with optional initial data.
42
42
  * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
@@ -150,7 +150,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
150
150
  * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
151
151
  * the provided callback function.
152
152
  */
153
- map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
153
+ map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): HashMap<K, VM>;
154
154
  /**
155
155
  * Time Complexity: O(n)
156
156
  * Space Complexity: O(n)
@@ -482,7 +482,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
482
482
  * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
483
483
  * function.
484
484
  */
485
- map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
485
+ map<VM>(callback: EntryCallback<K, V, VM>, thisArg?: any): LinkedHashMap<K, VM>;
486
486
  /**
487
487
  * Time Complexity: O(1)
488
488
  * Space Complexity: O(1)
@@ -16,30 +16,27 @@ import { IterableElementBase } from '../base';
16
16
  * 5. Managing Dynamic Data Sets: Heaps effectively manage dynamic data sets, especially when frequent access to the largest or smallest elements is required.
17
17
  * 6. Non-linear Search: While a heap allows rapid access to its largest or smallest element, it is less efficient for other operations, such as searching for a specific element, as it is not designed for these tasks.
18
18
  * 7. Efficient Sorting Algorithms: For example, heap sort. Heap sort uses the properties of a heap to sort elements.
19
- * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
19
+ * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prime's minimum-spanning tree algorithm, which use heaps to improve performance.
20
20
  */
21
- export declare class Heap<E = any> extends IterableElementBase<E> {
21
+ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, Heap<E, R>> {
22
22
  /**
23
23
  * The constructor initializes a heap data structure with optional elements and options.
24
24
  * @param elements - The `elements` parameter is an iterable object that contains the initial
25
- * elements to be added to the heap. It is an optional parameter and if not provided, the heap will
25
+ * elements to be added to the heap.
26
+ * It is an optional parameter, and if not provided, the heap will
26
27
  * be initialized as empty.
27
28
  * @param [options] - The `options` parameter is an optional object that can contain additional
28
- * configuration options for the heap. In this case, it is used to specify a custom comparator
29
- * function for comparing elements in the heap. The comparator function is used to determine the
29
+ * configuration options for the heap.
30
+ * In this case, it is used to specify a custom comparator
31
+ * function for comparing elements in the heap.
32
+ * The comparator function is used to determine the
30
33
  * order of elements in the heap.
31
34
  */
32
- constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
33
- protected _comparator: (a: E, b: E) => number;
34
- /**
35
- * The function returns the value of the _comparator property.
36
- * @returns The `_comparator` property is being returned.
37
- */
38
- get comparator(): (a: E, b: E) => number;
35
+ constructor(elements?: Iterable<E> | Iterable<R>, options?: HeapOptions<E, R>);
39
36
  protected _elements: E[];
40
37
  /**
41
38
  * The function returns an array of elements.
42
- * @returns The elements array is being returned.
39
+ * @returns The element array is being returned.
43
40
  */
44
41
  get elements(): E[];
45
42
  /**
@@ -57,12 +54,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
57
54
  * @param elements
58
55
  * @param options
59
56
  */
60
- static heapify<E>(elements: Iterable<E>, options: HeapOptions<E>): Heap<E>;
61
- /**
62
- * Time Complexity: O(log n)
63
- * Space Complexity: O(1)
64
- * where n is the number of elements in the heap.
65
- */
57
+ static heapify<E = any, R = any>(elements: Iterable<E>, options: HeapOptions<E, R>): Heap<E>;
66
58
  /**
67
59
  * Time Complexity: O(log n)
68
60
  * Space Complexity: O(1)
@@ -71,23 +63,14 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
71
63
  * @param element - The element to be inserted.
72
64
  */
73
65
  add(element: E): boolean;
74
- /**
75
- * Time Complexity: O(log n)
76
- * Space Complexity: O(1)
77
- * where n is the number of elements in the heap.
78
- */
79
66
  /**
80
67
  * Time Complexity: O(log n)
81
68
  * Space Complexity: O(1)
82
69
  *
83
- * Remove and return the top element (smallest or largest element) from the heap.
70
+ * Remove and return the top element (the smallest or largest element) from the heap.
84
71
  * @returns The top element or undefined if the heap is empty.
85
72
  */
86
73
  poll(): E | undefined;
87
- /**
88
- * Time Complexity: O(1)
89
- * Space Complexity: O(1)
90
- */
91
74
  /**
92
75
  * Time Complexity: O(1)
93
76
  * Space Complexity: O(1)
@@ -105,10 +88,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
105
88
  * Reset the elements of the heap. Make the elements empty.
106
89
  */
107
90
  clear(): void;
108
- /**
109
- * Time Complexity: O(n)
110
- * Space Complexity: O(n)
111
- */
112
91
  /**
113
92
  * Time Complexity: O(n)
114
93
  * Space Complexity: O(n)
@@ -117,10 +96,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
117
96
  * @param elements
118
97
  */
119
98
  refill(elements: E[]): boolean[];
120
- /**
121
- * Time Complexity: O(n)
122
- * Space Complexity: O(1)
123
- */
124
99
  /**
125
100
  * Time Complexity: O(n)
126
101
  * Space Complexity: O(1)
@@ -131,12 +106,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
131
106
  */
132
107
  has(element: E): boolean;
133
108
  /**
134
- * Time Complexity: O(n)
135
- * Space Complexity: O(1)
136
- * The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
137
- */
138
- /**
139
- * Time Complexity: O(n)
109
+ * Time Complexity: O(n)
140
110
  * Space Complexity: O(1)
141
111
  *
142
112
  * The `delete` function removes an element from an array-like data structure, maintaining the order
@@ -147,11 +117,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
147
117
  * successfully deleted from the array, and `false` if the element was not found in the array.
148
118
  */
149
119
  delete(element: E): boolean;
150
- /**
151
- * Time Complexity: O(n)
152
- * Space Complexity: O(log n)
153
- * where log n is the height of the heap.
154
- */
155
120
  /**
156
121
  * Time Complexity: O(n)
157
122
  * Space Complexity: O(log n)
@@ -161,10 +126,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
161
126
  * @returns An array containing elements traversed in the specified order.
162
127
  */
163
128
  dfs(order?: DFSOrderPattern): E[];
164
- /**
165
- * Time Complexity: O(n)
166
- * Space Complexity: O(n)
167
- */
168
129
  /**
169
130
  * Time Complexity: O(n)
170
131
  * Space Complexity: O(n)
@@ -173,10 +134,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
173
134
  * @returns An array containing the elements of the heap.
174
135
  */
175
136
  toArray(): E[];
176
- /**
177
- * Time Complexity: O(n)
178
- * Space Complexity: O(n)
179
- */
180
137
  /**
181
138
  * Time Complexity: O(n)
182
139
  * Space Complexity: O(n)
@@ -184,11 +141,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
184
141
  * Clone the heap, creating a new heap with the same elements.
185
142
  * @returns A new Heap instance containing the same elements.
186
143
  */
187
- clone(): Heap<E>;
188
- /**
189
- * Time Complexity: O(n log n)
190
- * Space Complexity: O(n)
191
- */
144
+ clone(): Heap<E, R>;
192
145
  /**
193
146
  * Time Complexity: O(n log n)
194
147
  * Space Complexity: O(n)
@@ -197,10 +150,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
197
150
  * @returns An array containing the elements sorted in ascending order.
198
151
  */
199
152
  sort(): E[];
200
- /**
201
- * Time Complexity: O(n log n)
202
- * Space Complexity: O(n)
203
- */
204
153
  /**
205
154
  * Time Complexity: O(n log n)
206
155
  * Space Complexity: O(n)
@@ -208,10 +157,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
208
157
  * Fix the entire heap to maintain heap properties.
209
158
  */
210
159
  fix(): boolean[];
211
- /**
212
- * Time Complexity: O(n)
213
- * Space Complexity: O(n)
214
- */
215
160
  /**
216
161
  * Time Complexity: O(n)
217
162
  * Space Complexity: O(n)
@@ -228,40 +173,40 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
228
173
  * @returns The `filter` method is returning a new `Heap` object that contains the elements that pass
229
174
  * the filter condition specified by the `callback` function.
230
175
  */
231
- filter(callback: ElementCallback<E, boolean>, thisArg?: any): Heap<E>;
232
- /**
233
- * Time Complexity: O(n)
234
- * Space Complexity: O(n)
235
- */
176
+ filter(callback: ElementCallback<E, R, boolean, Heap<E, R>>, thisArg?: any): Heap<E, R>;
236
177
  /**
237
- * Time Complexity: O(n)
178
+ * Time Complexity: O(n log n)
238
179
  * Space Complexity: O(n)
239
180
  *
240
181
  * The `map` function creates a new heap by applying a callback function to each element of the
241
182
  * original heap.
242
- * @param callback - The callback parameter is a function that will be called for each element in the
243
- * original heap. It takes three arguments: the current element, the index of the current element,
244
- * and the original heap itself. The callback function should return a value of type T, which will be
245
- * added to the mapped heap.
246
- * @param comparator - The `comparator` parameter is a function that is used to compare elements in
247
- * the heap. It takes two arguments, `a` and `b`, and returns a negative number if `a` is less than
248
- * `b`, a positive number if `a` is greater than `b`, or
183
+ * @param callback - The `callback` parameter is a function that will be called for each element in
184
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
185
+ * element), and `this` (the heap itself). The callback function should return a value of
186
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
187
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
188
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
189
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
190
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
191
+ * returns a value of type `T`. This function is used to transform the elements of the original
249
192
  * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
250
- * specify the value of `this` within the callback function. It is used when you want to bind a
251
- * specific object as the context for the callback function. If `thisArg` is not provided,
252
- * `undefined` is used as
253
- * @returns a new instance of the Heap class, which is created using the mapped elements from the
254
- * original Heap.
193
+ * specify the value of `this` within the callback function. It is used to set the context or scope
194
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
195
+ * value of
196
+ * @returns a new instance of the `Heap` class with the mapped elements.
255
197
  */
256
- map<T>(callback: ElementCallback<E, T>, comparator: Comparator<T>, thisArg?: any): Heap<T>;
198
+ map<EM, RM>(callback: ElementCallback<E, R, EM, Heap<E, R>>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): Heap<EM, RM>;
199
+ protected _DEFAULT_COMPARATOR: (a: E, b: E) => number;
200
+ protected _comparator: Comparator<E>;
257
201
  /**
258
- * The function `_getIterator` returns an iterable iterator for the elements in the class.
202
+ * The function returns the value of the _comparator property.
203
+ * @returns The `_comparator` property is being returned.
259
204
  */
260
- protected _getIterator(): IterableIterator<E>;
205
+ get comparator(): Comparator<E>;
261
206
  /**
262
- * Time Complexity: O(log n)
263
- * Space Complexity: O(1)
207
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
264
208
  */
209
+ protected _getIterator(): IterableIterator<E>;
265
210
  /**
266
211
  * Time Complexity: O(log n)
267
212
  * Space Complexity: O(1)
@@ -270,10 +215,6 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
270
215
  * @param index - The index of the newly added element.
271
216
  */
272
217
  protected _bubbleUp(index: number): boolean;
273
- /**
274
- * Time Complexity: O(log n)
275
- * Space Complexity: O(1)
276
- */
277
218
  /**
278
219
  * Time Complexity: O(log n)
279
220
  * Space Complexity: O(1)
@@ -343,10 +284,6 @@ export declare class FibonacciHeap<E> {
343
284
  * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
344
285
  */
345
286
  clear(): void;
346
- /**
347
- * Time Complexity: O(1)
348
- * Space Complexity: O(1)
349
- */
350
287
  /**
351
288
  * Time Complexity: O(1)
352
289
  * Space Complexity: O(1)
@@ -356,10 +293,6 @@ export declare class FibonacciHeap<E> {
356
293
  * @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
357
294
  */
358
295
  add(element: E): FibonacciHeap<E>;
359
- /**
360
- * Time Complexity: O(1)
361
- * Space Complexity: O(1)
362
- */
363
296
  /**
364
297
  * Time Complexity: O(1)
365
298
  * Space Complexity: O(1)
@@ -369,10 +302,6 @@ export declare class FibonacciHeap<E> {
369
302
  * @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
370
303
  */
371
304
  push(element: E): FibonacciHeap<E>;
372
- /**
373
- * Time Complexity: O(1)
374
- * Space Complexity: O(1)
375
- */
376
305
  /**
377
306
  * Time Complexity: O(1)
378
307
  * Space Complexity: O(1)
@@ -412,7 +341,7 @@ export declare class FibonacciHeap<E> {
412
341
  * Time Complexity: O(log n)
413
342
  * Space Complexity: O(1)
414
343
  *
415
- * Remove and return the top element (smallest or largest element) from the heap.
344
+ * Remove and return the top element (the smallest or largest element) from the heap.
416
345
  * @returns The top element or undefined if the heap is empty.
417
346
  */
418
347
  poll(): E | undefined;
@@ -424,7 +353,7 @@ export declare class FibonacciHeap<E> {
424
353
  * Time Complexity: O(log n)
425
354
  * Space Complexity: O(1)
426
355
  *
427
- * Remove and return the top element (smallest or largest element) from the heap.
356
+ * Remove and return the top element (the smallest or largest element) from the heap.
428
357
  * @returns The top element or undefined if the heap is empty.
429
358
  */
430
359
  pop(): E | undefined;
@@ -472,8 +401,8 @@ export declare class FibonacciHeap<E> {
472
401
  /**
473
402
  * Time Complexity: O(1)
474
403
  * Space Complexity: O(1)
475
- *.
476
- * Remove and return the top element (smallest or largest element) from the heap.
404
+ *
405
+ * Remove and return the top element (the smallest or largest element) from the heap.
477
406
  * @param node - The node to be removed.
478
407
  * @protected
479
408
  */
@@ -486,7 +415,7 @@ export declare class FibonacciHeap<E> {
486
415
  * Time Complexity: O(1)
487
416
  * Space Complexity: O(1)
488
417
  *
489
- * Remove and return the top element (smallest or largest element) from the heap.
418
+ * Remove and return the top element (the smallest or largest element) from the heap.
490
419
  * @param y
491
420
  * @param x
492
421
  * @protected
@@ -500,7 +429,7 @@ export declare class FibonacciHeap<E> {
500
429
  * Time Complexity: O(n log n)
501
430
  * Space Complexity: O(n)
502
431
  *
503
- * Remove and return the top element (smallest or largest element) from the heap.
432
+ * Remove and return the top element (the smallest or largest element) from the heap.
504
433
  * @protected
505
434
  */
506
435
  protected _consolidate(): void;