data-structure-typed 1.50.0 → 1.50.2

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 (156) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +204 -212
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +370 -22
  5. package/dist/cjs/data-structures/base/iterable-base.d.ts +114 -9
  6. package/dist/cjs/data-structures/base/iterable-base.js +143 -7
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +68 -71
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +54 -74
  15. package/dist/cjs/data-structures/binary-tree/bst.js +30 -71
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +84 -89
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +64 -85
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.d.ts +14 -0
  27. package/dist/cjs/data-structures/graph/directed-graph.js +26 -0
  28. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
  30. package/dist/cjs/data-structures/graph/map-graph.js +14 -0
  31. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +16 -0
  33. package/dist/cjs/data-structures/graph/undirected-graph.js +25 -0
  34. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +121 -15
  36. package/dist/cjs/data-structures/hash/hash-map.js +160 -25
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +66 -6
  39. package/dist/cjs/data-structures/heap/heap.js +66 -6
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  42. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  43. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  45. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +130 -112
  46. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  48. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
  49. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
  51. package/dist/cjs/data-structures/matrix/matrix.js +50 -11
  52. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  53. package/dist/cjs/data-structures/queue/deque.d.ts +49 -19
  54. package/dist/cjs/data-structures/queue/deque.js +101 -47
  55. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  56. package/dist/cjs/data-structures/queue/queue.d.ts +39 -5
  57. package/dist/cjs/data-structures/queue/queue.js +47 -5
  58. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  59. package/dist/cjs/data-structures/stack/stack.d.ts +16 -0
  60. package/dist/cjs/data-structures/stack/stack.js +22 -0
  61. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  62. package/dist/cjs/data-structures/trie/trie.d.ts +38 -1
  63. package/dist/cjs/data-structures/trie/trie.js +41 -0
  64. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  65. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  66. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
  67. package/dist/cjs/types/utils/utils.d.ts +1 -0
  68. package/dist/mjs/data-structures/base/iterable-base.d.ts +114 -9
  69. package/dist/mjs/data-structures/base/iterable-base.js +143 -7
  70. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  71. package/dist/mjs/data-structures/binary-tree/avl-tree.js +68 -71
  72. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  73. package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
  74. package/dist/mjs/data-structures/binary-tree/bst.d.ts +54 -74
  75. package/dist/mjs/data-structures/binary-tree/bst.js +30 -71
  76. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  77. package/dist/mjs/data-structures/binary-tree/rb-tree.js +84 -89
  78. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  79. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +64 -85
  80. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  81. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  82. package/dist/mjs/data-structures/graph/directed-graph.d.ts +14 -0
  83. package/dist/mjs/data-structures/graph/directed-graph.js +26 -0
  84. package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
  85. package/dist/mjs/data-structures/graph/map-graph.js +14 -0
  86. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +16 -0
  87. package/dist/mjs/data-structures/graph/undirected-graph.js +25 -0
  88. package/dist/mjs/data-structures/hash/hash-map.d.ts +121 -15
  89. package/dist/mjs/data-structures/hash/hash-map.js +160 -25
  90. package/dist/mjs/data-structures/heap/heap.d.ts +66 -6
  91. package/dist/mjs/data-structures/heap/heap.js +66 -6
  92. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  93. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  94. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  95. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +130 -112
  96. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  97. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
  98. package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
  99. package/dist/mjs/data-structures/matrix/matrix.js +50 -11
  100. package/dist/mjs/data-structures/queue/deque.d.ts +49 -19
  101. package/dist/mjs/data-structures/queue/deque.js +101 -47
  102. package/dist/mjs/data-structures/queue/queue.d.ts +39 -5
  103. package/dist/mjs/data-structures/queue/queue.js +47 -5
  104. package/dist/mjs/data-structures/stack/stack.d.ts +16 -0
  105. package/dist/mjs/data-structures/stack/stack.js +22 -0
  106. package/dist/mjs/data-structures/trie/trie.d.ts +38 -1
  107. package/dist/mjs/data-structures/trie/trie.js +41 -0
  108. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  109. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
  110. package/dist/mjs/types/utils/utils.d.ts +1 -0
  111. package/dist/umd/data-structure-typed.js +1730 -1042
  112. package/dist/umd/data-structure-typed.min.js +3 -3
  113. package/dist/umd/data-structure-typed.min.js.map +1 -1
  114. package/package.json +16 -40
  115. package/src/data-structures/base/iterable-base.ts +172 -19
  116. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  117. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  118. package/src/data-structures/binary-tree/bst.ts +89 -131
  119. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  120. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  121. package/src/data-structures/graph/abstract-graph.ts +4 -0
  122. package/src/data-structures/graph/directed-graph.ts +30 -0
  123. package/src/data-structures/graph/map-graph.ts +15 -0
  124. package/src/data-structures/graph/undirected-graph.ts +28 -0
  125. package/src/data-structures/hash/hash-map.ts +175 -34
  126. package/src/data-structures/heap/heap.ts +66 -6
  127. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  128. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  129. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  130. package/src/data-structures/matrix/matrix.ts +52 -12
  131. package/src/data-structures/queue/deque.ts +108 -49
  132. package/src/data-structures/queue/queue.ts +51 -5
  133. package/src/data-structures/stack/stack.ts +24 -0
  134. package/src/data-structures/trie/trie.ts +45 -1
  135. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  136. package/src/types/data-structures/hash/hash-map.ts +4 -3
  137. package/src/types/utils/utils.ts +2 -0
  138. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -3
  139. package/test/performance/data-structures/queue/deque.test.ts +26 -25
  140. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
  141. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
  142. package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
  143. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
  144. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
  145. package/test/unit/data-structures/graph/abstract-graph.test.ts +8 -0
  146. package/test/unit/data-structures/graph/directed-graph.test.ts +249 -0
  147. package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
  148. package/test/unit/data-structures/heap/heap.test.ts +18 -1
  149. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
  150. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
  151. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  152. package/test/unit/data-structures/queue/deque.test.ts +71 -10
  153. package/test/unit/data-structures/queue/queue.test.ts +23 -6
  154. package/test/unit/data-structures/stack/stack.test.ts +17 -0
  155. package/test/unit/data-structures/trie/trie.test.ts +17 -0
  156. package/test/unit/unrestricted-interconversion.test.ts +143 -10
@@ -9,7 +9,7 @@ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEnt
9
9
  import { IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
- export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNodeNested<K, V>> extends AVLTreeNode<K, V, N> {
12
+ export declare class TreeMultimapNode<K = any, V = any, NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
13
13
  count: number;
14
14
  /**
15
15
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
@@ -26,44 +26,43 @@ export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNo
26
26
  /**
27
27
  * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
28
28
  */
29
- export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>> extends AVLTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
30
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: TreeMultimapOptions<K>);
29
+ export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, NODE, TREE> = TreeMultimap<K, V, NODE, TreeMultimapNested<K, V, NODE>>> extends AVLTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
30
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultimapOptions<K>);
31
31
  private _count;
32
32
  get count(): number;
33
33
  /**
34
34
  * The function creates a new BSTNode with the given key, value, and count.
35
35
  * @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
36
36
  * distinguish one node from another in the tree.
37
- * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
37
+ * @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
38
38
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
39
39
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
40
40
  * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
41
41
  */
42
- createNode(key: K, value?: V, count?: number): N;
42
+ createNode(key: K, value?: V, count?: number): NODE;
43
43
  createTree(options?: TreeMultimapOptions<K>): TREE;
44
44
  /**
45
- * The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
46
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
45
+ * The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
46
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
47
47
  * can be one of the following:
48
48
  * @param {V} [value] - The `value` parameter is an optional argument that represents the value
49
49
  * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
50
50
  * it defaults to `undefined`.
51
51
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
52
52
  * times the value should be added to the node. If not provided, it defaults to 1.
53
- * @returns a node of type `N` or `undefined`.
53
+ * @returns a node of type `NODE` or `undefined`.
54
54
  */
55
- exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): N | undefined;
55
+ keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
56
56
  /**
57
57
  * The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
58
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
58
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
59
59
  * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
60
60
  * class.
61
61
  */
62
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
62
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
63
63
  /**
64
64
  * Time Complexity: O(log n)
65
65
  * Space Complexity: O(1)
66
- * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
67
66
  */
68
67
  /**
69
68
  * Time Complexity: O(log n)
@@ -81,47 +80,13 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
81
80
  * @returns The method is returning either the newly inserted node or `undefined` if the insertion
82
81
  * was not successful.
83
82
  */
84
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
83
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
85
84
  /**
86
- * Time Complexity: O(k log n)
87
- * Space Complexity: O(1)
88
- * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
89
- */
90
- /**
91
- * Time Complexity: O(k log n)
92
- * Space Complexity: O(1)
93
- *
94
- * The function overrides the addMany method to add multiple keys, nodes, or entries to a data
95
- * structure.
96
- * @param keysOrNodesOrEntries - The parameter `keysOrNodesOrEntries` is an iterable that can contain
97
- * either keys, nodes, or entries.
98
- * @returns The method is returning an array of type `N | undefined`.
99
- */
100
- addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>): boolean[];
101
- /**
102
- * Time Complexity: O(n log n)
103
- * Space Complexity: O(n)
104
- * logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
105
- */
106
- /**
107
- * Time Complexity: O(n log n)
108
- * Space Complexity: O(n)
109
- *
110
- * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
111
- * tree using either a recursive or iterative approach.
112
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
113
- * type of iteration to use when building the balanced binary search tree. It can have two possible
114
- * values:
115
- * @returns a boolean value.
116
- */
117
- perfectlyBalance(iterationType?: IterationType): boolean;
118
- /**
119
- * Time Complexity: O(k log n)
85
+ * Time Complexity: O(log n)
120
86
  * Space Complexity: O(1)
121
- * logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
122
87
  */
123
88
  /**
124
- * Time Complexity: O(k log n)
89
+ * Time Complexity: O(log n)
125
90
  * Space Complexity: O(1)
126
91
  *
127
92
  * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
@@ -137,9 +102,9 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
137
102
  * being deleted. If set to true, the count of the node will not be considered and the node will be
138
103
  * deleted regardless of its count. If set to false (default), the count of the node will be
139
104
  * decremented by 1 and
140
- * @returns an array of `BinaryTreeDeleteResult<N>`.
105
+ * @returns an array of `BinaryTreeDeleteResult<NODE>`.
141
106
  */
142
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<N>[];
107
+ delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
143
108
  /**
144
109
  * Time Complexity: O(1)
145
110
  * Space Complexity: O(1)
@@ -151,6 +116,22 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
151
116
  * The clear() function clears the contents of a data structure and sets the count to zero.
152
117
  */
153
118
  clear(): void;
119
+ /**
120
+ * Time Complexity: O(n log n)
121
+ * Space Complexity: O(log n)
122
+ */
123
+ /**
124
+ * Time Complexity: O(n log n)
125
+ * Space Complexity: O(log n)
126
+ *
127
+ * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
128
+ * tree using either a recursive or iterative approach.
129
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
130
+ * type of iteration to use when building the balanced binary search tree. It can have two possible
131
+ * values:
132
+ * @returns a boolean value.
133
+ */
134
+ perfectlyBalance(iterationType?: IterationType): boolean;
154
135
  /**
155
136
  * Time complexity: O(n)
156
137
  * Space complexity: O(n)
@@ -165,13 +146,13 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
165
146
  clone(): TREE;
166
147
  /**
167
148
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
168
- * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
169
- * which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
170
- * @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
149
+ * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
150
+ * which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
151
+ * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
171
152
  * node where the values from the source node will be swapped to.
172
153
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
173
154
  * if either `srcNode` or `destNode` is undefined.
174
155
  */
175
- protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
176
- protected _replaceNode(oldNode: N, newNode: N): N;
156
+ protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
157
+ protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
177
158
  }
@@ -37,7 +37,7 @@ export class TreeMultimap extends AVLTree {
37
37
  * The function creates a new BSTNode with the given key, value, and count.
38
38
  * @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
39
39
  * distinguish one node from another in the tree.
40
- * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
40
+ * @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
41
41
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
42
42
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
43
43
  * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
@@ -53,17 +53,17 @@ export class TreeMultimap extends AVLTree {
53
53
  });
54
54
  }
55
55
  /**
56
- * The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
57
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
56
+ * The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
57
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
58
58
  * can be one of the following:
59
59
  * @param {V} [value] - The `value` parameter is an optional argument that represents the value
60
60
  * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
61
61
  * it defaults to `undefined`.
62
62
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
63
63
  * times the value should be added to the node. If not provided, it defaults to 1.
64
- * @returns a node of type `N` or `undefined`.
64
+ * @returns a node of type `NODE` or `undefined`.
65
65
  */
66
- exemplarToNode(keyOrNodeOrEntry, value, count = 1) {
66
+ keyValueOrEntryToNode(keyOrNodeOrEntry, value, count = 1) {
67
67
  let node;
68
68
  if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {
69
69
  return;
@@ -90,7 +90,7 @@ export class TreeMultimap extends AVLTree {
90
90
  }
91
91
  /**
92
92
  * The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
93
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
93
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
94
94
  * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
95
95
  * class.
96
96
  */
@@ -100,7 +100,6 @@ export class TreeMultimap extends AVLTree {
100
100
  /**
101
101
  * Time Complexity: O(log n)
102
102
  * Space Complexity: O(1)
103
- * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
104
103
  */
105
104
  /**
106
105
  * Time Complexity: O(log n)
@@ -119,7 +118,7 @@ export class TreeMultimap extends AVLTree {
119
118
  * was not successful.
120
119
  */
121
120
  add(keyOrNodeOrEntry, value, count = 1) {
122
- const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
121
+ const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
123
122
  if (newNode === undefined)
124
123
  return false;
125
124
  const orgNodeCount = newNode?.count || 0;
@@ -130,82 +129,11 @@ export class TreeMultimap extends AVLTree {
130
129
  return true;
131
130
  }
132
131
  /**
133
- * Time Complexity: O(k log n)
134
- * Space Complexity: O(1)
135
- * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
136
- */
137
- /**
138
- * Time Complexity: O(k log n)
139
- * Space Complexity: O(1)
140
- *
141
- * The function overrides the addMany method to add multiple keys, nodes, or entries to a data
142
- * structure.
143
- * @param keysOrNodesOrEntries - The parameter `keysOrNodesOrEntries` is an iterable that can contain
144
- * either keys, nodes, or entries.
145
- * @returns The method is returning an array of type `N | undefined`.
146
- */
147
- addMany(keysOrNodesOrEntries) {
148
- return super.addMany(keysOrNodesOrEntries);
149
- }
150
- /**
151
- * Time Complexity: O(n log n)
152
- * Space Complexity: O(n)
153
- * logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
154
- */
155
- /**
156
- * Time Complexity: O(n log n)
157
- * Space Complexity: O(n)
158
- *
159
- * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
160
- * tree using either a recursive or iterative approach.
161
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
162
- * type of iteration to use when building the balanced binary search tree. It can have two possible
163
- * values:
164
- * @returns a boolean value.
165
- */
166
- perfectlyBalance(iterationType = this.iterationType) {
167
- const sorted = this.dfs(node => node, 'in'), n = sorted.length;
168
- if (sorted.length < 1)
169
- return false;
170
- this.clear();
171
- if (iterationType === IterationType.RECURSIVE) {
172
- const buildBalanceBST = (l, r) => {
173
- if (l > r)
174
- return;
175
- const m = l + Math.floor((r - l) / 2);
176
- const midNode = sorted[m];
177
- this.add(midNode.key, midNode.value, midNode.count);
178
- buildBalanceBST(l, m - 1);
179
- buildBalanceBST(m + 1, r);
180
- };
181
- buildBalanceBST(0, n - 1);
182
- return true;
183
- }
184
- else {
185
- const stack = [[0, n - 1]];
186
- while (stack.length > 0) {
187
- const popped = stack.pop();
188
- if (popped) {
189
- const [l, r] = popped;
190
- if (l <= r) {
191
- const m = l + Math.floor((r - l) / 2);
192
- const midNode = sorted[m];
193
- this.add(midNode.key, midNode.value, midNode.count);
194
- stack.push([m + 1, r]);
195
- stack.push([l, m - 1]);
196
- }
197
- }
198
- }
199
- return true;
200
- }
201
- }
202
- /**
203
- * Time Complexity: O(k log n)
132
+ * Time Complexity: O(log n)
204
133
  * Space Complexity: O(1)
205
- * logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
206
134
  */
207
135
  /**
208
- * Time Complexity: O(k log n)
136
+ * Time Complexity: O(log n)
209
137
  * Space Complexity: O(1)
210
138
  *
211
139
  * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
@@ -221,7 +149,7 @@ export class TreeMultimap extends AVLTree {
221
149
  * being deleted. If set to true, the count of the node will not be considered and the node will be
222
150
  * deleted regardless of its count. If set to false (default), the count of the node will be
223
151
  * decremented by 1 and
224
- * @returns an array of `BinaryTreeDeleteResult<N>`.
152
+ * @returns an array of `BinaryTreeDeleteResult<NODE>`.
225
153
  */
226
154
  delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
227
155
  const deletedResult = [];
@@ -294,6 +222,57 @@ export class TreeMultimap extends AVLTree {
294
222
  super.clear();
295
223
  this._count = 0;
296
224
  }
225
+ /**
226
+ * Time Complexity: O(n log n)
227
+ * Space Complexity: O(log n)
228
+ */
229
+ /**
230
+ * Time Complexity: O(n log n)
231
+ * Space Complexity: O(log n)
232
+ *
233
+ * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
234
+ * tree using either a recursive or iterative approach.
235
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
236
+ * type of iteration to use when building the balanced binary search tree. It can have two possible
237
+ * values:
238
+ * @returns a boolean value.
239
+ */
240
+ perfectlyBalance(iterationType = this.iterationType) {
241
+ const sorted = this.dfs(node => node, 'in'), n = sorted.length;
242
+ if (sorted.length < 1)
243
+ return false;
244
+ this.clear();
245
+ if (iterationType === IterationType.RECURSIVE) {
246
+ const buildBalanceBST = (l, r) => {
247
+ if (l > r)
248
+ return;
249
+ const m = l + Math.floor((r - l) / 2);
250
+ const midNode = sorted[m];
251
+ this.add(midNode.key, midNode.value, midNode.count);
252
+ buildBalanceBST(l, m - 1);
253
+ buildBalanceBST(m + 1, r);
254
+ };
255
+ buildBalanceBST(0, n - 1);
256
+ return true;
257
+ }
258
+ else {
259
+ const stack = [[0, n - 1]];
260
+ while (stack.length > 0) {
261
+ const popped = stack.pop();
262
+ if (popped) {
263
+ const [l, r] = popped;
264
+ if (l <= r) {
265
+ const m = l + Math.floor((r - l) / 2);
266
+ const midNode = sorted[m];
267
+ this.add(midNode.key, midNode.value, midNode.count);
268
+ stack.push([m + 1, r]);
269
+ stack.push([l, m - 1]);
270
+ }
271
+ }
272
+ }
273
+ return true;
274
+ }
275
+ }
297
276
  /**
298
277
  * Time complexity: O(n)
299
278
  * Space complexity: O(n)
@@ -312,9 +291,9 @@ export class TreeMultimap extends AVLTree {
312
291
  }
313
292
  /**
314
293
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
315
- * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
316
- * which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
317
- * @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
294
+ * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
295
+ * which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
296
+ * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
318
297
  * node where the values from the source node will be swapped to.
319
298
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
320
299
  * if either `srcNode` or `destNode` is undefined.
@@ -40,6 +40,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
40
40
  constructor();
41
41
  protected _vertexMap: Map<VertexKey, VO>;
42
42
  get vertexMap(): Map<VertexKey, VO>;
43
+ set vertexMap(v: Map<VertexKey, VO>);
43
44
  /**
44
45
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
45
46
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
@@ -47,6 +47,9 @@ export class AbstractGraph extends IterableEntryBase {
47
47
  get vertexMap() {
48
48
  return this._vertexMap;
49
49
  }
50
+ set vertexMap(v) {
51
+ this._vertexMap = v;
52
+ }
50
53
  /**
51
54
  * Time Complexity: O(1) - Constant time for Map lookup.
52
55
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -41,8 +41,10 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
41
41
  constructor();
42
42
  protected _outEdgeMap: Map<VO, EO[]>;
43
43
  get outEdgeMap(): Map<VO, EO[]>;
44
+ set outEdgeMap(v: Map<VO, EO[]>);
44
45
  protected _inEdgeMap: Map<VO, EO[]>;
45
46
  get inEdgeMap(): Map<VO, EO[]>;
47
+ set inEdgeMap(v: Map<VO, EO[]>);
46
48
  /**
47
49
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
48
50
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
@@ -327,6 +329,18 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
327
329
  * graph. If the edge does not exist, it returns `undefined`.
328
330
  */
329
331
  getEndsOfEdge(edge: EO): [VO, VO] | undefined;
332
+ /**
333
+ * The isEmpty function checks if the graph is empty.
334
+ *
335
+ * @return A boolean value
336
+ */
337
+ isEmpty(): boolean;
338
+ /**
339
+ * The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
340
+ *
341
+ * @return A new instance of the directedgraph class
342
+ */
343
+ clone(): DirectedGraph<V, E, VO, EO>;
330
344
  /**
331
345
  * Time Complexity: O(1)
332
346
  * Space Complexity: O(1)
@@ -43,10 +43,16 @@ export class DirectedGraph extends AbstractGraph {
43
43
  get outEdgeMap() {
44
44
  return this._outEdgeMap;
45
45
  }
46
+ set outEdgeMap(v) {
47
+ this._outEdgeMap = v;
48
+ }
46
49
  _inEdgeMap = new Map();
47
50
  get inEdgeMap() {
48
51
  return this._inEdgeMap;
49
52
  }
53
+ set inEdgeMap(v) {
54
+ this._inEdgeMap = v;
55
+ }
50
56
  /**
51
57
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
52
58
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
@@ -524,6 +530,26 @@ export class DirectedGraph extends AbstractGraph {
524
530
  return undefined;
525
531
  }
526
532
  }
533
+ /**
534
+ * The isEmpty function checks if the graph is empty.
535
+ *
536
+ * @return A boolean value
537
+ */
538
+ isEmpty() {
539
+ return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
540
+ }
541
+ /**
542
+ * The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
543
+ *
544
+ * @return A new instance of the directedgraph class
545
+ */
546
+ clone() {
547
+ const cloned = new DirectedGraph();
548
+ cloned.vertexMap = new Map(this.vertexMap);
549
+ cloned.inEdgeMap = new Map(this.inEdgeMap);
550
+ cloned.outEdgeMap = new Map(this.outEdgeMap);
551
+ return cloned;
552
+ }
527
553
  /**
528
554
  * Time Complexity: O(1)
529
555
  * Space Complexity: O(1)
@@ -70,4 +70,12 @@ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVer
70
70
  * @returns a new instance of the `MapEdge` class, cast as type `EO`.
71
71
  */
72
72
  createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
73
+ /**
74
+ * The override function is used to override the default behavior of a function.
75
+ * In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
76
+ * The clone() function returns a new graph that is an exact copy of the original graph.
77
+ *
78
+ * @return A mapgraph&lt;v, e, vo, eo&gt;
79
+ */
80
+ clone(): MapGraph<V, E, VO, EO>;
73
81
  }
@@ -87,4 +87,18 @@ export class MapGraph extends DirectedGraph {
87
87
  createEdge(src, dest, weight, value) {
88
88
  return new MapEdge(src, dest, weight, value);
89
89
  }
90
+ /**
91
+ * The override function is used to override the default behavior of a function.
92
+ * In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
93
+ * The clone() function returns a new graph that is an exact copy of the original graph.
94
+ *
95
+ * @return A mapgraph&lt;v, e, vo, eo&gt;
96
+ */
97
+ clone() {
98
+ const cloned = new MapGraph(this.originCoord, this.bottomRight);
99
+ cloned.vertexMap = new Map(this.vertexMap);
100
+ cloned.inEdgeMap = new Map(this.inEdgeMap);
101
+ cloned.outEdgeMap = new Map(this.outEdgeMap);
102
+ return cloned;
103
+ }
90
104
  }
@@ -39,6 +39,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
39
39
  constructor();
40
40
  protected _edgeMap: Map<VO, EO[]>;
41
41
  get edgeMap(): Map<VO, EO[]>;
42
+ set edgeMap(v: Map<VO, EO[]>);
42
43
  /**
43
44
  * The function creates a new vertex with an optional value and returns it.
44
45
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
@@ -193,6 +194,21 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
193
194
  * graph. If the edge does not exist, it returns `undefined`.
194
195
  */
195
196
  getEndsOfEdge(edge: EO): [VO, VO] | undefined;
197
+ /**
198
+ * The isEmpty function checks if the graph is empty.
199
+ * @return True if the graph is empty and false otherwise
200
+ */
201
+ isEmpty(): boolean;
202
+ /**
203
+ * The clone function creates a new UndirectedGraph object and copies the
204
+ * vertexMap and edgeMap from this graph to the new one. This is done by
205
+ * assigning each of these properties to their respective counterparts in the
206
+ * cloned graph. The clone function returns a reference to this newly created,
207
+ * cloned UndirectedGraph object.
208
+ *
209
+ * @return A new instance of the undirectedgraph class
210
+ */
211
+ clone(): UndirectedGraph<V, E, VO, EO>;
196
212
  /**
197
213
  * Time Complexity: O(1)
198
214
  * Space Complexity: O(1)
@@ -41,6 +41,9 @@ export class UndirectedGraph extends AbstractGraph {
41
41
  get edgeMap() {
42
42
  return this._edgeMap;
43
43
  }
44
+ set edgeMap(v) {
45
+ this._edgeMap = v;
46
+ }
44
47
  /**
45
48
  * The function creates a new vertex with an optional value and returns it.
46
49
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
@@ -320,6 +323,28 @@ export class UndirectedGraph extends AbstractGraph {
320
323
  return undefined;
321
324
  }
322
325
  }
326
+ /**
327
+ * The isEmpty function checks if the graph is empty.
328
+ * @return True if the graph is empty and false otherwise
329
+ */
330
+ isEmpty() {
331
+ return this.vertexMap.size === 0 && this.edgeMap.size === 0;
332
+ }
333
+ /**
334
+ * The clone function creates a new UndirectedGraph object and copies the
335
+ * vertexMap and edgeMap from this graph to the new one. This is done by
336
+ * assigning each of these properties to their respective counterparts in the
337
+ * cloned graph. The clone function returns a reference to this newly created,
338
+ * cloned UndirectedGraph object.
339
+ *
340
+ * @return A new instance of the undirectedgraph class
341
+ */
342
+ clone() {
343
+ const cloned = new UndirectedGraph();
344
+ cloned.vertexMap = new Map(this.vertexMap);
345
+ cloned.edgeMap = new Map(this.edgeMap);
346
+ return cloned;
347
+ }
323
348
  /**
324
349
  * Time Complexity: O(1)
325
350
  * Space Complexity: O(1)