data-structure-typed 1.50.2 → 1.50.4

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 (203) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -13
  2. package/CHANGELOG.md +1 -1
  3. package/README.md +23 -21
  4. package/README_zh-CN.md +7 -7
  5. package/SPECIFICATION.md +56 -0
  6. package/SPONSOR-zh-CN.md +90 -0
  7. package/SPONSOR.md +54 -0
  8. package/benchmark/report.html +13 -13
  9. package/benchmark/report.json +149 -155
  10. package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
  11. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
  13. package/dist/cjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +50 -12
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
  15. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
  16. package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  19. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  20. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
  24. package/dist/cjs/data-structures/binary-tree/bst.js +51 -20
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -1
  27. package/dist/cjs/data-structures/binary-tree/index.js +2 -1
  28. package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
  30. package/dist/cjs/data-structures/binary-tree/rb-tree.js +90 -24
  31. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  33. package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
  34. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +400 -0
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -0
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
  42. package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
  45. package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
  46. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
  48. package/dist/cjs/data-structures/hash/hash-map.js +196 -62
  49. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  50. package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
  51. package/dist/cjs/data-structures/heap/heap.js +29 -20
  52. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
  54. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
  55. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
  57. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
  58. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  60. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
  61. package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
  62. package/dist/cjs/data-structures/matrix/matrix.js +1 -1
  63. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  64. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  65. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  66. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  67. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  70. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
  71. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  72. package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
  73. package/dist/cjs/data-structures/queue/deque.js +100 -16
  74. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  75. package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
  76. package/dist/cjs/data-structures/queue/queue.js +65 -45
  77. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  78. package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
  79. package/dist/cjs/data-structures/stack/stack.js +36 -22
  80. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  81. package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
  82. package/dist/cjs/data-structures/tree/tree.js +77 -11
  83. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  84. package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
  85. package/dist/cjs/data-structures/trie/trie.js +115 -36
  86. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  87. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
  88. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
  89. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
  90. package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -1
  91. package/dist/cjs/types/data-structures/binary-tree/index.js +2 -1
  92. package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
  93. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
  94. package/dist/cjs/types/data-structures/binary-tree/{tree-multimap.js → tree-multi-map.js} +1 -1
  95. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +1 -0
  96. package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
  97. package/dist/mjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
  98. package/dist/mjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +46 -9
  99. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
  100. package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
  101. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  102. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
  106. package/dist/mjs/data-structures/binary-tree/bst.js +51 -20
  107. package/dist/mjs/data-structures/binary-tree/index.d.ts +2 -1
  108. package/dist/mjs/data-structures/binary-tree/index.js +2 -1
  109. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
  110. package/dist/mjs/data-structures/binary-tree/rb-tree.js +91 -25
  111. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  112. package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
  113. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
  114. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +397 -0
  115. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
  116. package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
  117. package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
  118. package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
  119. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
  120. package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
  121. package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
  122. package/dist/mjs/data-structures/hash/hash-map.js +204 -70
  123. package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
  124. package/dist/mjs/data-structures/heap/heap.js +29 -20
  125. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
  126. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
  127. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
  128. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
  129. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  130. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
  131. package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
  132. package/dist/mjs/data-structures/matrix/matrix.js +1 -1
  133. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  134. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  135. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  136. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  137. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  138. package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
  139. package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
  140. package/dist/mjs/data-structures/queue/deque.js +105 -21
  141. package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
  142. package/dist/mjs/data-structures/queue/queue.js +65 -45
  143. package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
  144. package/dist/mjs/data-structures/stack/stack.js +36 -22
  145. package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
  146. package/dist/mjs/data-structures/tree/tree.js +80 -14
  147. package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
  148. package/dist/mjs/data-structures/trie/trie.js +118 -39
  149. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
  150. package/dist/mjs/types/data-structures/binary-tree/index.d.ts +2 -1
  151. package/dist/mjs/types/data-structures/binary-tree/index.js +2 -1
  152. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
  153. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.js +1 -0
  154. package/dist/umd/data-structure-typed.js +1876 -656
  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 +59 -58
  158. package/src/data-structures/base/iterable-base.ts +12 -0
  159. package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
  160. package/src/data-structures/binary-tree/avl-tree.ts +37 -3
  161. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  162. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  163. package/src/data-structures/binary-tree/bst.ts +51 -19
  164. package/src/data-structures/binary-tree/index.ts +2 -1
  165. package/src/data-structures/binary-tree/rb-tree.ts +99 -28
  166. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  167. package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
  168. package/src/data-structures/graph/abstract-graph.ts +0 -211
  169. package/src/data-structures/graph/directed-graph.ts +122 -0
  170. package/src/data-structures/graph/undirected-graph.ts +143 -19
  171. package/src/data-structures/hash/hash-map.ts +228 -76
  172. package/src/data-structures/heap/heap.ts +31 -20
  173. package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
  174. package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
  175. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  176. package/src/data-structures/matrix/matrix.ts +1 -1
  177. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  178. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  179. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  180. package/src/data-structures/queue/deque.ts +118 -22
  181. package/src/data-structures/queue/queue.ts +68 -45
  182. package/src/data-structures/stack/stack.ts +39 -23
  183. package/src/data-structures/tree/tree.ts +89 -15
  184. package/src/data-structures/trie/trie.ts +131 -40
  185. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
  186. package/src/types/data-structures/binary-tree/index.ts +2 -1
  187. package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
  188. package/test/integration/index.html +2 -2
  189. package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
  190. package/test/unit/data-structures/binary-tree/{tree-multimap.test.ts → avl-tree-multi-map.test.ts} +55 -55
  191. package/test/unit/data-structures/binary-tree/overall.test.ts +24 -25
  192. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +706 -0
  193. package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
  194. package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
  195. package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
  196. package/test/unit/data-structures/queue/queue.test.ts +2 -0
  197. package/test/unit/unrestricted-interconversion.test.ts +3 -3
  198. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +0 -1
  199. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
  200. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.js.map +0 -1
  201. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
  202. package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
  203. /package/dist/mjs/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
@@ -13,7 +13,7 @@ export class UndirectedVertex extends AbstractVertex {
13
13
  }
14
14
  }
15
15
  export class UndirectedEdge extends AbstractEdge {
16
- vertexMap;
16
+ endpoints;
17
17
  /**
18
18
  * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
19
19
  * value.
@@ -26,7 +26,7 @@ export class UndirectedEdge extends AbstractEdge {
26
26
  */
27
27
  constructor(v1, v2, weight, value) {
28
28
  super(weight, value);
29
- this.vertexMap = [v1, v2];
29
+ this.endpoints = [v1, v2];
30
30
  }
31
31
  }
32
32
  export class UndirectedGraph extends AbstractGraph {
@@ -77,7 +77,7 @@ export class UndirectedGraph extends AbstractGraph {
77
77
  * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
78
78
  * Space Complexity: O(1)
79
79
  *
80
- * The function `getEdge` returns the first edge that connects two vertexMap, or undefined if no such edge exists.
80
+ * The function `getEdge` returns the first edge that connects two endpoints, or undefined if no such edge exists.
81
81
  * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
82
82
  * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
83
83
  * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
@@ -90,7 +90,7 @@ export class UndirectedGraph extends AbstractGraph {
90
90
  const vertex1 = this._getVertex(v1);
91
91
  const vertex2 = this._getVertex(v2);
92
92
  if (vertex1 && vertex2) {
93
- edgeMap = this._edgeMap.get(vertex1)?.filter(e => e.vertexMap.includes(vertex2.key));
93
+ edgeMap = this._edgeMap.get(vertex1)?.filter(e => e.endpoints.includes(vertex2.key));
94
94
  }
95
95
  }
96
96
  return edgeMap ? edgeMap[0] || undefined : undefined;
@@ -107,7 +107,7 @@ export class UndirectedGraph extends AbstractGraph {
107
107
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
108
108
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
109
109
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
110
- * @returns the removed edge (EO) if it exists, or undefined if either of the vertexMap (VO) does not exist.
110
+ * @returns the removed edge (EO) if it exists, or undefined if either of the endpoints (VO) does not exist.
111
111
  */
112
112
  deleteEdgeBetween(v1, v2) {
113
113
  const vertex1 = this._getVertex(v1);
@@ -118,11 +118,11 @@ export class UndirectedGraph extends AbstractGraph {
118
118
  const v1Edges = this._edgeMap.get(vertex1);
119
119
  let removed = undefined;
120
120
  if (v1Edges) {
121
- removed = arrayRemove(v1Edges, (e) => e.vertexMap.includes(vertex2.key))[0] || undefined;
121
+ removed = arrayRemove(v1Edges, (e) => e.endpoints.includes(vertex2.key))[0] || undefined;
122
122
  }
123
123
  const v2Edges = this._edgeMap.get(vertex2);
124
124
  if (v2Edges) {
125
- arrayRemove(v2Edges, (e) => e.vertexMap.includes(vertex1.key));
125
+ arrayRemove(v2Edges, (e) => e.endpoints.includes(vertex1.key));
126
126
  }
127
127
  return removed;
128
128
  }
@@ -134,7 +134,7 @@ export class UndirectedGraph extends AbstractGraph {
134
134
  * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
135
135
  * Space Complexity: O(1)
136
136
  *
137
- * The function `deleteEdge` deletes an edge between two vertexMap in a graph.
137
+ * The function `deleteEdge` deletes an edge between two endpoints in a graph.
138
138
  * @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
139
139
  * either an edge object or a vertex key.
140
140
  * @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
@@ -155,8 +155,8 @@ export class UndirectedGraph extends AbstractGraph {
155
155
  }
156
156
  }
157
157
  else {
158
- oneSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[0]);
159
- otherSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[1]);
158
+ oneSide = this._getVertex(edgeOrOneSideVertexKey.endpoints[0]);
159
+ otherSide = this._getVertex(edgeOrOneSideVertexKey.endpoints[1]);
160
160
  }
161
161
  if (oneSide && otherSide) {
162
162
  return this.deleteEdgeBetween(oneSide, otherSide);
@@ -195,7 +195,7 @@ export class UndirectedGraph extends AbstractGraph {
195
195
  const neighborEdges = this._edgeMap.get(neighbor);
196
196
  if (neighborEdges) {
197
197
  const restEdges = neighborEdges.filter(edge => {
198
- return !edge.vertexMap.includes(vertexKey);
198
+ return !edge.endpoints.includes(vertexKey);
199
199
  });
200
200
  this._edgeMap.set(neighbor, restEdges);
201
201
  }
@@ -277,7 +277,7 @@ export class UndirectedGraph extends AbstractGraph {
277
277
  * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
278
278
  * Space Complexity: O(|E|)
279
279
  *
280
- * The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
280
+ * The function "getNeighbors" returns an array of neighboring endpoints for a given vertex or vertex ID.
281
281
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
282
282
  * (`VertexKey`).
283
283
  * @returns an array of vertexMap (VO[]).
@@ -288,7 +288,7 @@ export class UndirectedGraph extends AbstractGraph {
288
288
  if (vertex) {
289
289
  const neighborEdges = this.edgesOf(vertex);
290
290
  for (const edge of neighborEdges) {
291
- const neighbor = this._getVertex(edge.vertexMap.filter(e => e !== vertex.key)[0]);
291
+ const neighbor = this._getVertex(edge.endpoints.filter(e => e !== vertex.key)[0]);
292
292
  if (neighbor) {
293
293
  neighbors.push(neighbor);
294
294
  }
@@ -304,18 +304,18 @@ export class UndirectedGraph extends AbstractGraph {
304
304
  * Time Complexity: O(1)
305
305
  * Space Complexity: O(1)
306
306
  *
307
- * The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
307
+ * The function "getEndsOfEdge" returns the endpoints at the ends of an edge if the edge exists in the graph, otherwise
308
308
  * it returns undefined.
309
309
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
310
- * @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
310
+ * @returns The function `getEndsOfEdge` returns an array containing two endpoints `[VO, VO]` if the edge exists in the
311
311
  * graph. If the edge does not exist, it returns `undefined`.
312
312
  */
313
313
  getEndsOfEdge(edge) {
314
- if (!this.hasEdge(edge.vertexMap[0], edge.vertexMap[1])) {
314
+ if (!this.hasEdge(edge.endpoints[0], edge.endpoints[1])) {
315
315
  return undefined;
316
316
  }
317
- const v1 = this._getVertex(edge.vertexMap[0]);
318
- const v2 = this._getVertex(edge.vertexMap[1]);
317
+ const v1 = this._getVertex(edge.endpoints[0]);
318
+ const v2 = this._getVertex(edge.endpoints[1]);
319
319
  if (v1 && v2) {
320
320
  return [v1, v2];
321
321
  }
@@ -330,6 +330,20 @@ export class UndirectedGraph extends AbstractGraph {
330
330
  isEmpty() {
331
331
  return this.vertexMap.size === 0 && this.edgeMap.size === 0;
332
332
  }
333
+ /**
334
+ * Time Complexity: O(1)
335
+ * Space Complexity: O(1)
336
+ */
337
+ /**
338
+ * Time Complexity: O(1)
339
+ * Space Complexity: O(1)
340
+ *
341
+ * The clear function resets the vertex and edge maps to empty maps.
342
+ */
343
+ clear() {
344
+ this._vertexMap = new Map();
345
+ this._edgeMap = new Map();
346
+ }
333
347
  /**
334
348
  * The clone function creates a new UndirectedGraph object and copies the
335
349
  * vertexMap and edgeMap from this graph to the new one. This is done by
@@ -349,6 +363,100 @@ export class UndirectedGraph extends AbstractGraph {
349
363
  * Time Complexity: O(1)
350
364
  * Space Complexity: O(1)
351
365
  */
366
+ /**
367
+ * Time Complexity: O(V + E)
368
+ * Space Complexity: O(V)
369
+ * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
370
+ * 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
371
+ *
372
+ * The function `tarjan` implements the Tarjan's algorithm to find bridges and cut vertices in a
373
+ * graph.
374
+ * @returns The function `tarjan()` returns an object with the following properties:
375
+ */
376
+ tarjan() {
377
+ const dfnMap = new Map();
378
+ const lowMap = new Map();
379
+ const bridges = [];
380
+ const cutVertices = [];
381
+ let time = 0;
382
+ const dfs = (vertex, parent) => {
383
+ dfnMap.set(vertex, time);
384
+ lowMap.set(vertex, time);
385
+ time++;
386
+ const neighbors = this.getNeighbors(vertex);
387
+ let childCount = 0;
388
+ for (const neighbor of neighbors) {
389
+ if (!dfnMap.has(neighbor)) {
390
+ childCount++;
391
+ dfs(neighbor, vertex);
392
+ lowMap.set(vertex, Math.min(lowMap.get(vertex), lowMap.get(neighbor)));
393
+ if (lowMap.get(neighbor) > dfnMap.get(vertex)) {
394
+ // Found a bridge
395
+ const edge = this.getEdge(vertex, neighbor);
396
+ if (edge) {
397
+ bridges.push(edge);
398
+ }
399
+ }
400
+ if (parent !== undefined && lowMap.get(neighbor) >= dfnMap.get(vertex)) {
401
+ // Found an articulation point
402
+ cutVertices.push(vertex);
403
+ }
404
+ }
405
+ else if (neighbor !== parent) {
406
+ lowMap.set(vertex, Math.min(lowMap.get(vertex), dfnMap.get(neighbor)));
407
+ }
408
+ }
409
+ if (parent === undefined && childCount > 1) {
410
+ // Special case for root in DFS tree
411
+ cutVertices.push(vertex);
412
+ }
413
+ };
414
+ for (const vertex of this.vertexMap.values()) {
415
+ if (!dfnMap.has(vertex)) {
416
+ dfs(vertex, undefined);
417
+ }
418
+ }
419
+ return {
420
+ dfnMap,
421
+ lowMap,
422
+ bridges,
423
+ cutVertices
424
+ };
425
+ }
426
+ /**
427
+ * Time Complexity: O(V + E)
428
+ * Space Complexity: O(V)
429
+ * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
430
+ * 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
431
+ */
432
+ /**
433
+ * The function "getBridges" returns an array of bridges in a graph using the Tarjan's algorithm.
434
+ * @returns The function `getBridges()` is returning the bridges found using the Tarjan's algorithm.
435
+ */
436
+ getBridges() {
437
+ return this.tarjan().bridges;
438
+ }
439
+ /**
440
+ * The function "getCutVertices" returns an array of cut vertices using the Tarjan's algorithm.
441
+ * @returns the cut vertices found using the Tarjan's algorithm.
442
+ */
443
+ getCutVertices() {
444
+ return this.tarjan().cutVertices;
445
+ }
446
+ /**
447
+ * The function returns the dfnMap property of the result of the tarjan() function.
448
+ * @returns the `dfnMap` property of the result of calling the `tarjan()` function.
449
+ */
450
+ getDFNMap() {
451
+ return this.tarjan().dfnMap;
452
+ }
453
+ /**
454
+ * The function returns the lowMap property of the result of the tarjan() function.
455
+ * @returns the lowMap property of the result of calling the tarjan() function.
456
+ */
457
+ getLowMap() {
458
+ return this.tarjan().lowMap;
459
+ }
352
460
  /**
353
461
  * Time Complexity: O(1)
354
462
  * Space Complexity: O(1)
@@ -358,7 +466,7 @@ export class UndirectedGraph extends AbstractGraph {
358
466
  * @returns a boolean value.
359
467
  */
360
468
  _addEdge(edge) {
361
- for (const end of edge.vertexMap) {
469
+ for (const end of edge.endpoints) {
362
470
  const endVertex = this._getVertex(end);
363
471
  if (endVertex === undefined)
364
472
  return false;
@@ -14,10 +14,6 @@ import { IterableEntryBase } from '../base';
14
14
  * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
15
15
  */
16
16
  export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
17
- protected _store: {
18
- [key: string]: HashMapStoreItem<K, V>;
19
- };
20
- protected _objMap: Map<object, V>;
21
17
  /**
22
18
  * The constructor function initializes a HashMap object with an optional initial collection and
23
19
  * options.
@@ -26,25 +22,44 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
26
22
  * @param [options] - The `options` parameter is an optional object that can contain two properties:
27
23
  */
28
24
  constructor(rawCollection?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
25
+ protected _store: {
26
+ [key: string]: HashMapStoreItem<K, V>;
27
+ };
28
+ /**
29
+ * The function returns the store object, which is a dictionary of HashMapStoreItem objects.
30
+ * @returns The store property is being returned. It is a dictionary-like object with string keys and
31
+ * values of type HashMapStoreItem<K, V>.
32
+ */
33
+ get store(): {
34
+ [p: string]: HashMapStoreItem<K, V>;
35
+ };
36
+ protected _objMap: Map<object, V>;
37
+ /**
38
+ * The function returns the object map.
39
+ * @returns The `objMap` property is being returned, which is a `Map` object with keys of type
40
+ * `object` and values of type `V`.
41
+ */
42
+ get objMap(): Map<object, V>;
29
43
  protected _toEntryFn: (rawElement: R) => [K, V];
30
44
  /**
31
45
  * The function returns the value of the _toEntryFn property.
32
46
  * @returns The function being returned is `this._toEntryFn`.
33
47
  */
34
48
  get toEntryFn(): (rawElement: R) => [K, V];
35
- /**
36
- * The hasFn function is a function that takes in an item and returns a boolean
37
- * indicating whether the item is contained within the hash table.
38
- *
39
- * @return The hash function
40
- */
41
- get hasFn(): (key: K) => string;
42
49
  protected _size: number;
43
50
  /**
44
51
  * The function returns the size of an object.
45
52
  * @returns The size of the object, which is a number.
46
53
  */
47
54
  get size(): number;
55
+ protected _hashFn: (key: K) => string;
56
+ /**
57
+ * The hasFn function is a function that takes in an item and returns a boolean
58
+ * indicating whether the item is contained within the hash table.
59
+ *
60
+ * @return The hash function
61
+ */
62
+ get hashFn(): (key: K) => string;
48
63
  /**
49
64
  * The function checks if a given element is an array with exactly two elements.
50
65
  * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
@@ -104,6 +119,10 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
104
119
  * successfully deleted from the map, and `false` if the key was not found in the map.
105
120
  */
106
121
  delete(key: K): boolean;
122
+ /**
123
+ * Time Complexity: O(n)
124
+ * Space Complexity: O(n)
125
+ */
107
126
  /**
108
127
  * The clone function creates a new HashMap with the same key-value pairs as
109
128
  * this one. The clone function is useful for creating a copy of an existing
@@ -131,10 +150,6 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
131
150
  * the provided callback function.
132
151
  */
133
152
  map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
134
- /**
135
- * Time Complexity: O(n)
136
- * Space Complexity: O(n)
137
- */
138
153
  /**
139
154
  * Time Complexity: O(n)
140
155
  * Space Complexity: O(n)
@@ -166,8 +181,19 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
166
181
  * object map.
167
182
  */
168
183
  protected _getIterator(): IterableIterator<[K, V]>;
169
- protected _hashFn: (key: K) => string;
184
+ /**
185
+ * The function checks if a given key is an object or a function.
186
+ * @param {any} key - The parameter "key" can be of any type.
187
+ * @returns a boolean value.
188
+ */
170
189
  protected _isObjKey(key: any): key is object | ((...args: any[]) => any);
190
+ /**
191
+ * The function `_getNoObjKey` takes a key and returns a string representation of the key, handling
192
+ * different types of keys.
193
+ * @param {K} key - The `key` parameter is of type `K`, which represents the type of the key being
194
+ * passed to the `_getNoObjKey` function.
195
+ * @returns a string value.
196
+ */
171
197
  protected _getNoObjKey(key: K): string;
172
198
  }
173
199
  /**
@@ -176,10 +202,6 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
176
202
  * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
177
203
  */
178
204
  export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
179
- protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
180
- protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
181
- protected _head: HashMapLinkedNode<K, V | undefined>;
182
- protected _tail: HashMapLinkedNode<K, V | undefined>;
183
205
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
184
206
  /**
185
207
  * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
@@ -191,6 +213,45 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
191
213
  * properties:
192
214
  */
193
215
  constructor(rawCollection?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
216
+ protected _hashFn: (key: K) => string;
217
+ /**
218
+ * The function returns the hash function used for generating a hash value for a given key.
219
+ * @returns The hash function that takes a key of type K and returns a string.
220
+ */
221
+ get hashFn(): (key: K) => string;
222
+ protected _objHashFn: (key: K) => object;
223
+ /**
224
+ * The function returns the object hash function.
225
+ * @returns The function `objHashFn` is being returned.
226
+ */
227
+ get objHashFn(): (key: K) => object;
228
+ protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
229
+ /**
230
+ * The function returns a record of HashMapLinkedNode objects with string keys.
231
+ * @returns The method is returning a Record object, which is a TypeScript type that represents an
232
+ * object with string keys and values that are HashMapLinkedNode objects with keys of type K and
233
+ * values of type V or undefined.
234
+ */
235
+ get noObjMap(): Record<string, HashMapLinkedNode<K, V | undefined>>;
236
+ protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
237
+ /**
238
+ * The function returns the WeakMap object used to map objects to HashMapLinkedNode instances.
239
+ * @returns The `objMap` property is being returned.
240
+ */
241
+ get objMap(): WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
242
+ protected _head: HashMapLinkedNode<K, V | undefined>;
243
+ /**
244
+ * The function returns the head node of a HashMapLinkedNode.
245
+ * @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
246
+ * value type `V | undefined`.
247
+ */
248
+ get head(): HashMapLinkedNode<K, V | undefined>;
249
+ protected _tail: HashMapLinkedNode<K, V | undefined>;
250
+ /**
251
+ * The function returns the tail node of a HashMapLinkedNode.
252
+ * @returns The `_tail` property of type `HashMapLinkedNode<K, V | undefined>` is being returned.
253
+ */
254
+ get tail(): HashMapLinkedNode<K, V | undefined>;
194
255
  protected _toEntryFn: (rawElement: R) => [K, V];
195
256
  /**
196
257
  * The function returns the value of the _toEntryFn property.
@@ -203,6 +264,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
203
264
  * @returns The size of the object.
204
265
  */
205
266
  get size(): number;
267
+ /**
268
+ * Time Complexity: O(1)
269
+ * Space Complexity: O(1)
270
+ */
206
271
  /**
207
272
  * Time Complexity: O(1)
208
273
  * Space Complexity: O(1)
@@ -212,6 +277,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
212
277
  * value (V).
213
278
  */
214
279
  get first(): [K, V] | undefined;
280
+ /**
281
+ * Time Complexity: O(1)
282
+ * Space Complexity: O(1)
283
+ */
215
284
  /**
216
285
  * Time Complexity: O(1)
217
286
  * Space Complexity: O(1)
@@ -230,6 +299,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
230
299
  * key and value.
231
300
  */
232
301
  reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
302
+ /**
303
+ * Time Complexity: O(1)
304
+ * Space Complexity: O(1)
305
+ */
233
306
  /**
234
307
  * Time Complexity: O(1)
235
308
  * Space Complexity: O(1)
@@ -259,6 +332,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
259
332
  * @returns The method `has` is returning a boolean value.
260
333
  */
261
334
  has(key: K): boolean;
335
+ /**
336
+ * Time Complexity: O(1)
337
+ * Space Complexity: O(1)
338
+ */
262
339
  /**
263
340
  * Time Complexity: O(1)
264
341
  * Space Complexity: O(1)
@@ -274,7 +351,12 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
274
351
  */
275
352
  get(key: K): V | undefined;
276
353
  /**
277
- * Time Complexity: O(n), where n is the index.
354
+ * Time Complexity: O(n)
355
+ * Space Complexity: O(1)
356
+ * /
357
+
358
+ /**
359
+ * Time Complexity: O(n)
278
360
  * Space Complexity: O(1)
279
361
  *
280
362
  * The function `at` retrieves the key-value pair at a specified index in a linked list.
@@ -286,6 +368,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
286
368
  */
287
369
  at(index: number): V | undefined;
288
370
  /**
371
+ * Time Complexity: O(1)
372
+ * Space Complexity: O(1)
373
+ * /
374
+
375
+ /**
289
376
  * Time Complexity: O(1)
290
377
  * Space Complexity: O(1)
291
378
  *
@@ -297,6 +384,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
297
384
  */
298
385
  delete(key: K): boolean;
299
386
  /**
387
+ * Time Complexity: O(n)
388
+ * Space Complexity: O(1)
389
+ * /
390
+
391
+ /**
300
392
  * Time Complexity: O(n)
301
393
  * Space Complexity: O(1)
302
394
  *
@@ -307,6 +399,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
307
399
  */
308
400
  deleteAt(index: number): boolean;
309
401
  /**
402
+ * Time Complexity: O(1)
403
+ * Space Complexity: O(1)
404
+ * /
405
+
406
+ /**
310
407
  * Time Complexity: O(1)
311
408
  * Space Complexity: O(1)
312
409
  *
@@ -323,6 +420,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
323
420
  */
324
421
  isEntry(rawElement: any): rawElement is [K, V];
325
422
  /**
423
+ * Time Complexity: O(1)
424
+ * Space Complexity: O(1)
425
+ * /
426
+
427
+ /**
326
428
  * Time Complexity: O(1)
327
429
  * Space Complexity: O(1)
328
430
  *
@@ -344,6 +446,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
344
446
  */
345
447
  clone(): LinkedHashMap<K, V>;
346
448
  /**
449
+ * Time Complexity: O(n)
450
+ * Space Complexity: O(n)
451
+ * /
452
+
453
+ /**
347
454
  * Time Complexity: O(n)
348
455
  * Space Complexity: O(n)
349
456
  *
@@ -360,6 +467,11 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
360
467
  */
361
468
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
362
469
  /**
470
+ * Time Complexity: O(n)
471
+ * Space Complexity: O(n)
472
+ * /
473
+
474
+ /**
363
475
  * Time Complexity: O(n)
364
476
  * Space Complexity: O(n)
365
477
  *
@@ -393,9 +505,13 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
393
505
  * @returns The method is returning a boolean value.
394
506
  */
395
507
  put(key: K, value: V): boolean;
396
- protected _hashFn: (key: K) => string;
397
- protected _objHashFn: (key: K) => object;
398
508
  /**
509
+ * Time Complexity: O(n)
510
+ * Space Complexity: O(1)
511
+ * where n is the number of entries in the LinkedHashMap.
512
+ * /
513
+
514
+ /**
399
515
  * Time Complexity: O(n)
400
516
  * Space Complexity: O(1)
401
517
  * where n is the number of entries in the LinkedHashMap.
@@ -403,6 +519,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
403
519
  * The above function is an iterator that yields key-value pairs from a linked list.
404
520
  */
405
521
  protected _getIterator(): Generator<[K, V], void, unknown>;
522
+ /**
523
+ * Time Complexity: O(1)
524
+ * Space Complexity: O(1)
525
+ */
406
526
  /**
407
527
  * Time Complexity: O(1)
408
528
  * Space Complexity: O(1)