data-structure-typed 1.18.0 → 1.18.5

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 (268) hide show
  1. package/README.md +193 -66
  2. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  3. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  4. package/backup/recursive-type/src/assets/logo.png +0 -0
  5. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  6. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +3 -0
  7. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
  8. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
  9. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
  10. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
  11. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
  12. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  13. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  14. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  15. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +11 -0
  16. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
  17. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
  18. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
  19. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
  20. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  21. package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
  22. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
  23. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  24. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  25. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  26. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  27. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  28. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  29. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  30. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  31. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  32. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  33. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  34. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  35. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  36. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  37. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +478 -0
  38. package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
  39. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
  40. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
  41. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
  42. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
  43. package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
  44. package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
  45. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
  46. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
  47. package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
  48. package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
  49. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
  50. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
  51. package/backup/recursive-type/src/data-structures/index.ts +15 -0
  52. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
  53. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
  54. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
  55. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
  56. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
  57. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
  58. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
  59. package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
  60. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
  61. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
  62. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
  63. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
  64. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
  65. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
  66. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  67. package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
  68. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
  69. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  70. package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
  71. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
  72. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
  73. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
  74. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
  75. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
  76. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
  77. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
  78. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
  79. package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
  80. package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
  81. package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
  82. package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
  83. package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
  84. package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
  85. package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
  86. package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
  87. package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
  88. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
  89. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
  90. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
  91. package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
  92. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
  93. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
  94. package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
  95. package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
  96. package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
  97. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
  98. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
  99. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
  100. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
  101. package/backup/recursive-type/src/index.ts +1 -0
  102. package/backup/recursive-type/src/utils/index.ts +2 -0
  103. package/backup/recursive-type/src/utils/types/index.ts +1 -0
  104. package/backup/recursive-type/src/utils/types/utils.ts +6 -0
  105. package/backup/recursive-type/src/utils/utils.ts +78 -0
  106. package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
  107. package/dist/data-structures/binary-tree/avl-tree.js +8 -16
  108. package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -98
  109. package/dist/data-structures/binary-tree/binary-tree.js +70 -65
  110. package/dist/data-structures/binary-tree/bst.d.ts +21 -21
  111. package/dist/data-structures/binary-tree/bst.js +15 -17
  112. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  113. package/dist/data-structures/binary-tree/rb-tree.js +68 -5
  114. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
  115. package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
  116. package/dist/data-structures/graph/abstract-graph.d.ts +56 -58
  117. package/dist/data-structures/graph/abstract-graph.js +84 -68
  118. package/dist/data-structures/graph/directed-graph.d.ts +127 -96
  119. package/dist/data-structures/graph/directed-graph.js +161 -109
  120. package/dist/data-structures/graph/undirected-graph.d.ts +82 -59
  121. package/dist/data-structures/graph/undirected-graph.js +99 -72
  122. package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
  123. package/dist/data-structures/index.d.ts +1 -0
  124. package/dist/data-structures/index.js +1 -0
  125. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  126. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  127. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  128. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  129. package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
  130. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  131. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  132. package/dist/data-structures/interfaces/bst.js +2 -0
  133. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  134. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  135. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  136. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  137. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  138. package/dist/data-structures/interfaces/heap.js +2 -0
  139. package/dist/data-structures/interfaces/index.d.ts +13 -0
  140. package/dist/data-structures/interfaces/index.js +29 -0
  141. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  142. package/dist/data-structures/interfaces/navigator.js +2 -0
  143. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  144. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  145. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  146. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  147. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  148. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  149. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  150. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  151. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  152. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  153. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  154. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  155. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  156. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  157. package/dist/data-structures/queue/deque.d.ts +5 -5
  158. package/dist/data-structures/queue/deque.js +6 -6
  159. package/dist/data-structures/queue/queue.d.ts +1 -1
  160. package/dist/data-structures/stack/stack.d.ts +1 -1
  161. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  162. package/dist/data-structures/types/avl-tree.d.ts +5 -4
  163. package/dist/data-structures/types/binary-tree.d.ts +6 -5
  164. package/dist/data-structures/types/bst.d.ts +4 -3
  165. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  166. package/dist/data-structures/types/directed-graph.js +7 -0
  167. package/dist/data-structures/types/heap.d.ts +2 -2
  168. package/dist/data-structures/types/index.d.ts +0 -1
  169. package/dist/data-structures/types/index.js +0 -1
  170. package/dist/data-structures/types/navigator.d.ts +2 -2
  171. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  172. package/dist/data-structures/types/tree-multiset.d.ts +3 -4
  173. package/docs/assets/search.js +1 -1
  174. package/docs/classes/AVLTree.html +288 -287
  175. package/docs/classes/AVLTreeNode.html +106 -63
  176. package/docs/classes/AaTree.html +14 -12
  177. package/docs/classes/AbstractEdge.html +68 -34
  178. package/docs/classes/AbstractGraph.html +219 -114
  179. package/docs/classes/AbstractVertex.html +71 -30
  180. package/docs/classes/ArrayDeque.html +27 -25
  181. package/docs/classes/BST.html +279 -273
  182. package/docs/classes/BSTNode.html +106 -57
  183. package/docs/classes/BTree.html +14 -12
  184. package/docs/classes/BinaryIndexedTree.html +22 -20
  185. package/docs/classes/BinaryTree.html +283 -277
  186. package/docs/classes/BinaryTreeNode.html +111 -63
  187. package/docs/classes/Character.html +17 -15
  188. package/docs/classes/CoordinateMap.html +22 -20
  189. package/docs/classes/CoordinateSet.html +23 -21
  190. package/docs/classes/Deque.html +47 -45
  191. package/docs/classes/DirectedEdge.html +74 -41
  192. package/docs/classes/DirectedGraph.html +444 -208
  193. package/docs/classes/DirectedVertex.html +63 -36
  194. package/docs/classes/DoublyLinkedList.html +52 -50
  195. package/docs/classes/DoublyLinkedListNode.html +24 -22
  196. package/docs/classes/HashTable.html +14 -12
  197. package/docs/classes/Heap.html +29 -27
  198. package/docs/classes/HeapItem.html +21 -19
  199. package/docs/classes/Matrix2D.html +29 -27
  200. package/docs/classes/MatrixNTI2D.html +17 -15
  201. package/docs/classes/MaxHeap.html +29 -27
  202. package/docs/classes/MaxPriorityQueue.html +67 -60
  203. package/docs/classes/MinHeap.html +29 -27
  204. package/docs/classes/MinPriorityQueue.html +67 -60
  205. package/docs/classes/Navigator.html +24 -22
  206. package/docs/classes/ObjectDeque.html +62 -50
  207. package/docs/classes/Pair.html +14 -12
  208. package/docs/classes/PriorityQueue.html +62 -55
  209. package/docs/classes/Queue.html +29 -27
  210. package/docs/classes/SegmentTree.html +30 -28
  211. package/docs/classes/SegmentTreeNode.html +33 -31
  212. package/docs/classes/SinglyLinkedList.html +49 -47
  213. package/docs/classes/SinglyLinkedListNode.html +21 -19
  214. package/docs/classes/SkipLinkedList.html +14 -12
  215. package/docs/classes/SplayTree.html +14 -12
  216. package/docs/classes/Stack.html +27 -25
  217. package/docs/classes/TreeMap.html +14 -12
  218. package/docs/classes/TreeMultiSet.html +277 -270
  219. package/docs/classes/TreeNode.html +29 -27
  220. package/docs/classes/TreeSet.html +14 -12
  221. package/docs/classes/Trie.html +26 -24
  222. package/docs/classes/TrieNode.html +24 -22
  223. package/docs/classes/TwoThreeTree.html +14 -12
  224. package/docs/classes/UndirectedEdge.html +70 -51
  225. package/docs/classes/UndirectedGraph.html +344 -161
  226. package/docs/classes/UndirectedVertex.html +63 -36
  227. package/docs/classes/Vector2D.html +41 -39
  228. package/docs/enums/CP.html +17 -15
  229. package/docs/enums/FamilyPosition.html +17 -15
  230. package/docs/enums/LoopType.html +16 -14
  231. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +43 -43
  232. package/docs/index.html +195 -68
  233. package/docs/interfaces/{HeapOptions.html → IBinaryTree.html} +39 -32
  234. package/docs/interfaces/IBinaryTreeNode.html +383 -0
  235. package/docs/interfaces/IDirectedGraph.html +20 -18
  236. package/docs/interfaces/IGraph.html +118 -88
  237. package/docs/interfaces/{PriorityQueueOptions.html → IUNDirectedGraph.html} +22 -53
  238. package/docs/modules.html +25 -21
  239. package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +27 -21
  240. package/docs/types/BSTComparator.html +14 -12
  241. package/docs/types/BSTDeletedResult.html +19 -17
  242. package/docs/types/BinaryTreeDeleted.html +19 -17
  243. package/docs/types/BinaryTreeNodeId.html +14 -12
  244. package/docs/types/BinaryTreeNodePropertyName.html +14 -12
  245. package/docs/types/DFSOrderPattern.html +14 -12
  246. package/docs/types/DijkstraResult.html +14 -12
  247. package/docs/types/Direction.html +14 -12
  248. package/docs/types/{TrlFn.html → EdgeId.html} +18 -29
  249. package/docs/types/{TrlAsyncFn.html → HeapOptions.html} +29 -19
  250. package/docs/types/NavigatorParams.html +164 -0
  251. package/docs/types/NodeOrPropertyName.html +14 -12
  252. package/docs/types/PriorityQueueComparator.html +14 -12
  253. package/docs/types/PriorityQueueDFSOrderPattern.html +14 -12
  254. package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +28 -19
  255. package/docs/types/RecursiveAVLTreeNode.html +135 -0
  256. package/docs/types/{Thunk.html → RecursiveBSTNode.html} +23 -24
  257. package/docs/types/RecursiveBinaryTreeNode.html +135 -0
  258. package/docs/types/ResultByProperty.html +17 -15
  259. package/docs/types/ResultsByProperty.html +17 -15
  260. package/docs/types/SegmentTreeNodeVal.html +14 -12
  261. package/docs/types/TopologicalStatus.html +14 -12
  262. package/docs/types/TreeMultiSetDeletedResult.html +19 -17
  263. package/docs/types/Turning.html +14 -12
  264. package/docs/types/VertexId.html +14 -12
  265. package/notes/note.md +8 -1
  266. package/package.json +10 -2
  267. package/docs/classes/RBTree.html +0 -153
  268. package/docs/interfaces/NavigatorParams.html +0 -200
@@ -1,9 +1,72 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RBTree = void 0;
4
- var RBTree = /** @class */ (function () {
5
- function RBTree() {
18
+ var binary_tree_1 = require("./binary-tree");
19
+ var RBColor;
20
+ (function (RBColor) {
21
+ RBColor[RBColor["Red"] = 0] = "Red";
22
+ RBColor[RBColor["Black"] = 1] = "Black";
23
+ })(RBColor || (RBColor = {}));
24
+ var RBNode = /** @class */ (function (_super) {
25
+ __extends(RBNode, _super);
26
+ // override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
27
+ // return val !== null ? new RBNode<T>(id, val, count) : null;
28
+ // }
29
+ function RBNode(id, val, count) {
30
+ var _this = _super.call(this, id, val, count) || this;
31
+ _this._color = RBColor.Red;
32
+ return _this;
6
33
  }
34
+ Object.defineProperty(RBNode.prototype, "color", {
35
+ get: function () {
36
+ return this._color;
37
+ },
38
+ set: function (value) {
39
+ this._color = value;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ return RBNode;
45
+ }(binary_tree_1.BinaryTreeNode));
46
+ var RBTree = /** @class */ (function (_super) {
47
+ __extends(RBTree, _super);
48
+ function RBTree(options) {
49
+ return _super.call(this, options) || this;
50
+ }
51
+ // override _createNode(id: BinaryTreeNodeId, val: N | null, count?: number): RBNode<N> | null {
52
+ // return val !== null ? new RBNode<N>(id, val, count) : null;
53
+ // }
54
+ // private override _root: BinaryTreeNode<N> | null = null;
55
+ //
56
+ // override get root(): BinaryTreeNode<N> | null {
57
+ // return this._root;
58
+ // }
59
+ RBTree.prototype.insert = function (id, val) {
60
+ };
61
+ RBTree.prototype.leftRotate = function (node) {
62
+ };
63
+ RBTree.prototype.rightRotate = function (node) {
64
+ };
65
+ RBTree.prototype.insertFixup = function (node) {
66
+ };
67
+ RBTree.prototype.deleteFixup = function (node) {
68
+ };
69
+ RBTree.prototype.transplant = function (u, v) {
70
+ };
7
71
  return RBTree;
8
- }());
9
- exports.RBTree = RBTree;
72
+ }(binary_tree_1.BinaryTree));
@@ -7,27 +7,28 @@
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
10
- export declare class TreeMultiSet<T> extends BST<T> {
10
+ import { IBinaryTree } from '../interfaces';
11
+ export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBinaryTree<N> {
11
12
  /**
12
13
  * The function creates a new BSTNode with the given id, value, and count.
13
14
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
14
15
  * distinguish one node from another in the tree.
15
- * @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
16
+ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
16
17
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
17
18
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
18
19
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
19
20
  */
20
- createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
21
+ _createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N;
21
22
  /**
22
23
  * The function overrides the add method of the BinarySearchTree class in TypeScript.
23
24
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
24
- * @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
25
- * can be of type `T` (the generic type) or `null`.
25
+ * @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
26
+ * can be of type `N` (the generic type) or `null`.
26
27
  * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
27
28
  * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
28
- * @returns The `add` method is returning a `BSTNode<T>` object or `null`.
29
+ * @returns The `add` method is returning a `BSTNode<N>` object or `null`.
29
30
  */
30
- add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
31
+ add(id: BinaryTreeNodeId, val: N | null, count?: number): N | null;
31
32
  /**
32
33
  * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
33
34
  * method.
@@ -38,5 +39,5 @@ export declare class TreeMultiSet<T> extends BST<T> {
38
39
  * set to `true`, the left sum of all nodes will be recalculated. If it
39
40
  * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
40
41
  */
41
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
42
+ remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<N>[];
42
43
  }
@@ -33,22 +33,23 @@ var TreeMultiSet = /** @class */ (function (_super) {
33
33
  * The function creates a new BSTNode with the given id, value, and count.
34
34
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
35
35
  * distinguish one node from another in the tree.
36
- * @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
36
+ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
37
37
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
38
38
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
39
39
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
40
40
  */
41
- TreeMultiSet.prototype.createNode = function (id, val, count) {
42
- return new bst_1.BSTNode(id, val, count);
41
+ TreeMultiSet.prototype._createNode = function (id, val, count) {
42
+ var node = new bst_1.BSTNode(id, val, count);
43
+ return node;
43
44
  };
44
45
  /**
45
46
  * The function overrides the add method of the BinarySearchTree class in TypeScript.
46
47
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
47
- * @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
48
- * can be of type `T` (the generic type) or `null`.
48
+ * @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
49
+ * can be of type `N` (the generic type) or `null`.
49
50
  * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
50
51
  * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
51
- * @returns The `add` method is returning a `BSTNode<T>` object or `null`.
52
+ * @returns The `add` method is returning a `BSTNode<N>` object or `null`.
52
53
  */
53
54
  TreeMultiSet.prototype.add = function (id, val, count) {
54
55
  return _super.prototype.add.call(this, id, val, count);
@@ -1,44 +1,50 @@
1
- import type { DijkstraResult, IGraph, VertexId } from '../types';
2
- export declare class AbstractVertex {
3
- constructor(id: VertexId);
4
- protected _id: VertexId;
1
+ import type { DijkstraResult, VertexId } from '../types';
2
+ import { IGraph } from '../interfaces';
3
+ export declare abstract class AbstractVertex<T = number> {
4
+ protected constructor(id: VertexId, val?: T);
5
+ private _id;
5
6
  get id(): VertexId;
6
7
  set id(v: VertexId);
8
+ private _val;
9
+ get val(): T | undefined;
10
+ set val(value: T | undefined);
7
11
  }
8
- export declare abstract class AbstractEdge {
9
- /**
10
- * The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
11
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
12
- * no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
13
- */
14
- protected constructor(weight?: number);
15
- protected _weight: number;
12
+ export declare abstract class AbstractEdge<T = number> {
13
+ protected constructor(weight?: number, val?: T);
14
+ private _val;
15
+ get val(): T | undefined;
16
+ set val(value: T | undefined);
17
+ private _weight;
16
18
  get weight(): number;
17
19
  set weight(v: number);
18
20
  protected _hashCode: string;
19
21
  get hashCode(): string;
20
22
  protected _setHashCode(v: string): void;
21
23
  }
22
- export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements IGraph<V, E> {
23
- protected _vertices: Map<VertexId, V>;
24
- abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
25
- abstract removeEdge(edge: E): E | null;
24
+ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IGraph<V, E> {
25
+ private _vertices;
26
+ get vertices(): Map<VertexId, V>;
26
27
  /**
27
- * The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
28
- * does not exist.
29
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
30
- * @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
31
- * If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
28
+ * 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.
29
+ * 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.
30
+ * @param id
31
+ * @param val
32
32
  */
33
- getVertex(vertexOrId: VertexId | V): V | null;
33
+ abstract _createVertex(id: VertexId, val?: V): V;
34
34
  /**
35
- * The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
36
- * a `VertexId`.
37
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
38
- * (`VertexId`).
39
- * @returns the id of the vertex.
35
+ * 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.
36
+ * 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.
37
+ * @param srcOrV1
38
+ * @param destOrV2
39
+ * @param weight
40
+ * @param val
40
41
  */
41
- getVertexId(vertexOrId: V | VertexId): VertexId;
42
+ abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
43
+ abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
44
+ abstract removeEdge(edge: E): E | null;
45
+ _getVertex(vertexOrId: VertexId | V): V | null;
46
+ getVertex(vertexId: VertexId): V | null;
47
+ _getVertexId(vertexOrId: V | VertexId): VertexId;
42
48
  /**
43
49
  * The function checks if a vertex exists in a graph.
44
50
  * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
@@ -46,18 +52,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
46
52
  * @returns The method `hasVertex` returns a boolean value.
47
53
  */
48
54
  hasVertex(vertexOrId: V | VertexId): boolean;
49
- /**
50
- * The function `vertexSet()` returns a map of vertices.
51
- * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
52
- */
53
- vertexSet(): Map<VertexId, V>;
54
- abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
55
- /**
56
- * The addVertex function adds a new vertex to a graph if it does not already exist.
57
- * @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
58
- * @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
59
- * false. Otherwise, it will add the newVertex to the graph and return true.
60
- */
55
+ abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
56
+ createAddVertex(id: VertexId, val?: V['val']): boolean;
61
57
  addVertex(newVertex: V): boolean;
62
58
  /**
63
59
  * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
@@ -87,6 +83,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
87
83
  * vertices `v1` and `v2`, and `false` otherwise.
88
84
  */
89
85
  hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
86
+ createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E['val']): boolean;
90
87
  abstract addEdge(edge: E): boolean;
91
88
  /**
92
89
  * The function sets the weight of an edge between two vertices in a graph.
@@ -163,15 +160,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
163
160
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
164
161
  */
165
162
  dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
166
- /**
167
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
168
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
169
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
170
- */
171
- /**
172
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
173
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
174
- */
175
163
  /**
176
164
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
177
165
  * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
@@ -191,13 +179,16 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
191
179
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
192
180
  */
193
181
  dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
194
- abstract getEndsOfEdge(edge: E): [V, V] | null;
195
182
  /**
196
- * BellmanFord time:O(VE) space:O(V)
197
- * one to rest pairs
198
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
199
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
183
+ * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
184
+ * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
185
+ * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
186
+ */
187
+ /**
188
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
189
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
200
190
  */
191
+ abstract getEndsOfEdge(edge: E): [V, V] | null;
201
192
  /**
202
193
  * BellmanFord time:O(VE) space:O(V)
203
194
  * one to rest pairs
@@ -223,9 +214,10 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
223
214
  minPath: V[];
224
215
  };
225
216
  /**
226
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
227
- * all pairs
228
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
217
+ * BellmanFord time:O(VE) space:O(V)
218
+ * one to rest pairs
219
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
220
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
229
221
  */
230
222
  /**
231
223
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
@@ -242,7 +234,11 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
242
234
  costs: number[][];
243
235
  predecessor: (V | null)[][];
244
236
  };
245
- /**--- start find cycles --- */
237
+ /**
238
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
239
+ * all pairs
240
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
241
+ */
246
242
  /**
247
243
  * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
248
244
  * Tarjan can find cycles in directed or undirected graph
@@ -272,4 +268,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
272
268
  SCCs: Map<number, V[]>;
273
269
  cycles: Map<number, V[]>;
274
270
  };
271
+ /**--- start find cycles --- */
272
+ protected _setVertices(value: Map<VertexId, V>): void;
275
273
  }
@@ -47,8 +47,9 @@ exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
47
47
  var utils_1 = require("../../utils");
48
48
  var priority_queue_1 = require("../priority-queue");
49
49
  var AbstractVertex = /** @class */ (function () {
50
- function AbstractVertex(id) {
50
+ function AbstractVertex(id, val) {
51
51
  this._id = id;
52
+ this._val = val;
52
53
  }
53
54
  Object.defineProperty(AbstractVertex.prototype, "id", {
54
55
  get: function () {
@@ -60,19 +61,35 @@ var AbstractVertex = /** @class */ (function () {
60
61
  enumerable: false,
61
62
  configurable: true
62
63
  });
64
+ Object.defineProperty(AbstractVertex.prototype, "val", {
65
+ get: function () {
66
+ return this._val;
67
+ },
68
+ set: function (value) {
69
+ this._val = value;
70
+ },
71
+ enumerable: false,
72
+ configurable: true
73
+ });
63
74
  return AbstractVertex;
64
75
  }());
65
76
  exports.AbstractVertex = AbstractVertex;
66
77
  var AbstractEdge = /** @class */ (function () {
67
- /**
68
- * The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
69
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
70
- * no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
71
- */
72
- function AbstractEdge(weight) {
78
+ function AbstractEdge(weight, val) {
73
79
  this._weight = weight !== undefined ? weight : 1;
80
+ this._val = val;
74
81
  this._hashCode = (0, utils_1.uuidV4)();
75
82
  }
83
+ Object.defineProperty(AbstractEdge.prototype, "val", {
84
+ get: function () {
85
+ return this._val;
86
+ },
87
+ set: function (value) {
88
+ this._val = value;
89
+ },
90
+ enumerable: false,
91
+ configurable: true
92
+ });
76
93
  Object.defineProperty(AbstractEdge.prototype, "weight", {
77
94
  get: function () {
78
95
  return this._weight;
@@ -90,6 +107,15 @@ var AbstractEdge = /** @class */ (function () {
90
107
  enumerable: false,
91
108
  configurable: true
92
109
  });
110
+ // /**
111
+ // * 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.
112
+ // * 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.
113
+ // * @param srcOrV1
114
+ // * @param destOrV2
115
+ // * @param weight
116
+ // * @param val
117
+ // */
118
+ // abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
93
119
  AbstractEdge.prototype._setHashCode = function (v) {
94
120
  this._hashCode = v;
95
121
  };
@@ -104,25 +130,21 @@ var AbstractGraph = /** @class */ (function () {
104
130
  /**--- end find cycles --- */
105
131
  // Minimum Spanning Tree
106
132
  }
107
- /**
108
- * The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
109
- * does not exist.
110
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
111
- * @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
112
- * If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
113
- */
114
- AbstractGraph.prototype.getVertex = function (vertexOrId) {
115
- var vertexId = this.getVertexId(vertexOrId);
133
+ Object.defineProperty(AbstractGraph.prototype, "vertices", {
134
+ get: function () {
135
+ return this._vertices;
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ AbstractGraph.prototype._getVertex = function (vertexOrId) {
141
+ var vertexId = this._getVertexId(vertexOrId);
116
142
  return this._vertices.get(vertexId) || null;
117
143
  };
118
- /**
119
- * The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
120
- * a `VertexId`.
121
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
122
- * (`VertexId`).
123
- * @returns the id of the vertex.
124
- */
125
- AbstractGraph.prototype.getVertexId = function (vertexOrId) {
144
+ AbstractGraph.prototype.getVertex = function (vertexId) {
145
+ return this._vertices.get(vertexId) || null;
146
+ };
147
+ AbstractGraph.prototype._getVertexId = function (vertexOrId) {
126
148
  return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
127
149
  };
128
150
  /**
@@ -132,24 +154,16 @@ var AbstractGraph = /** @class */ (function () {
132
154
  * @returns The method `hasVertex` returns a boolean value.
133
155
  */
134
156
  AbstractGraph.prototype.hasVertex = function (vertexOrId) {
135
- return this._vertices.has(this.getVertexId(vertexOrId));
157
+ return this._vertices.has(this._getVertexId(vertexOrId));
136
158
  };
137
- /**
138
- * The function `vertexSet()` returns a map of vertices.
139
- * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
140
- */
141
- AbstractGraph.prototype.vertexSet = function () {
142
- return this._vertices;
159
+ AbstractGraph.prototype.createAddVertex = function (id, val) {
160
+ var newVertex = this._createVertex(id, val);
161
+ return this.addVertex(newVertex);
143
162
  };
144
- /**
145
- * The addVertex function adds a new vertex to a graph if it does not already exist.
146
- * @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
147
- * @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
148
- * false. Otherwise, it will add the newVertex to the graph and return true.
149
- */
150
163
  AbstractGraph.prototype.addVertex = function (newVertex) {
151
164
  if (this.hasVertex(newVertex)) {
152
165
  return false;
166
+ // throw (new Error('Duplicated vertex id is not allowed'));
153
167
  }
154
168
  this._vertices.set(newVertex.id, newVertex);
155
169
  return true;
@@ -161,7 +175,7 @@ var AbstractGraph = /** @class */ (function () {
161
175
  * @returns The method `removeVertex` returns a boolean value.
162
176
  */
163
177
  AbstractGraph.prototype.removeVertex = function (vertexOrId) {
164
- var vertexId = this.getVertexId(vertexOrId);
178
+ var vertexId = this._getVertexId(vertexOrId);
165
179
  return this._vertices.delete(vertexId);
166
180
  };
167
181
  /**
@@ -202,6 +216,14 @@ var AbstractGraph = /** @class */ (function () {
202
216
  var edge = this.getEdge(v1, v2);
203
217
  return !!edge;
204
218
  };
219
+ AbstractGraph.prototype.createAddEdge = function (src, dest, weight, val) {
220
+ if (src instanceof AbstractVertex)
221
+ src = src.id;
222
+ if (dest instanceof AbstractVertex)
223
+ dest = dest.id;
224
+ var newEdge = this._createEdge(src, dest, weight, val);
225
+ return this.addEdge(newEdge);
226
+ };
205
227
  /**
206
228
  * The function sets the weight of an edge between two vertices in a graph.
207
229
  * @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
@@ -235,8 +257,8 @@ var AbstractGraph = /** @class */ (function () {
235
257
  AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
236
258
  var _this = this;
237
259
  var paths = [];
238
- var vertex1 = this.getVertex(v1);
239
- var vertex2 = this.getVertex(v2);
260
+ var vertex1 = this._getVertex(v1);
261
+ var vertex2 = this._getVertex(v2);
240
262
  if (!(vertex1 && vertex2)) {
241
263
  return [];
242
264
  }
@@ -323,8 +345,8 @@ var AbstractGraph = /** @class */ (function () {
323
345
  }
324
346
  else {
325
347
  // BFS
326
- var vertex2 = this.getVertex(v2);
327
- var vertex1 = this.getVertex(v1);
348
+ var vertex2 = this._getVertex(v2);
349
+ var vertex1 = this._getVertex(v1);
328
350
  if (!(vertex1 && vertex2)) {
329
351
  return null;
330
352
  }
@@ -409,8 +431,8 @@ var AbstractGraph = /** @class */ (function () {
409
431
  else {
410
432
  // BFS
411
433
  var minPath_1 = [];
412
- var vertex1_1 = this.getVertex(v1);
413
- var vertex2 = this.getVertex(v2);
434
+ var vertex1_1 = this._getVertex(v1);
435
+ var vertex2 = this._getVertex(v2);
414
436
  if (!(vertex1_1 && vertex2)) {
415
437
  return [];
416
438
  }
@@ -481,8 +503,8 @@ var AbstractGraph = /** @class */ (function () {
481
503
  var distMap = new Map();
482
504
  var seen = new Set();
483
505
  var preMap = new Map(); // predecessor
484
- var srcVertex = this.getVertex(src);
485
- var destVertex = dest ? this.getVertex(dest) : null;
506
+ var srcVertex = this._getVertex(src);
507
+ var destVertex = dest ? this._getVertex(dest) : null;
486
508
  if (!srcVertex) {
487
509
  return null;
488
510
  }
@@ -609,15 +631,6 @@ var AbstractGraph = /** @class */ (function () {
609
631
  genPaths && getPaths(minDest);
610
632
  return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
611
633
  };
612
- /**
613
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
614
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
615
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
616
- */
617
- /**
618
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
619
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
620
- */
621
634
  /**
622
635
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
623
636
  * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
@@ -653,8 +666,8 @@ var AbstractGraph = /** @class */ (function () {
653
666
  var distMap = new Map();
654
667
  var seen = new Set();
655
668
  var preMap = new Map(); // predecessor
656
- var srcVertex = this.getVertex(src);
657
- var destVertex = dest ? this.getVertex(dest) : null;
669
+ var srcVertex = this._getVertex(src);
670
+ var destVertex = dest ? this._getVertex(dest) : null;
658
671
  if (!srcVertex) {
659
672
  return null;
660
673
  }
@@ -766,12 +779,6 @@ var AbstractGraph = /** @class */ (function () {
766
779
  }
767
780
  return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
768
781
  };
769
- /**
770
- * BellmanFord time:O(VE) space:O(V)
771
- * one to rest pairs
772
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
773
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
774
- */
775
782
  /**
776
783
  * BellmanFord time:O(VE) space:O(V)
777
784
  * one to rest pairs
@@ -794,7 +801,7 @@ var AbstractGraph = /** @class */ (function () {
794
801
  getMin = false;
795
802
  if (genPath === undefined)
796
803
  genPath = false;
797
- var srcVertex = this.getVertex(src);
804
+ var srcVertex = this._getVertex(src);
798
805
  var paths = [];
799
806
  var distMap = new Map();
800
807
  var preMap = new Map(); // predecessor
@@ -885,9 +892,10 @@ var AbstractGraph = /** @class */ (function () {
885
892
  return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
886
893
  };
887
894
  /**
888
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
889
- * all pairs
890
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
895
+ * BellmanFord time:O(VE) space:O(V)
896
+ * one to rest pairs
897
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
898
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
891
899
  */
892
900
  /**
893
901
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
@@ -931,7 +939,11 @@ var AbstractGraph = /** @class */ (function () {
931
939
  }
932
940
  return { costs: costs, predecessor: predecessor };
933
941
  };
934
- /**--- start find cycles --- */
942
+ /**
943
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
944
+ * all pairs
945
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
946
+ */
935
947
  /**
936
948
  * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
937
949
  * Tarjan can find cycles in directed or undirected graph
@@ -1059,6 +1071,10 @@ var AbstractGraph = /** @class */ (function () {
1059
1071
  }
1060
1072
  return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
1061
1073
  };
1074
+ /**--- start find cycles --- */
1075
+ AbstractGraph.prototype._setVertices = function (value) {
1076
+ this._vertices = value;
1077
+ };
1062
1078
  return AbstractGraph;
1063
1079
  }());
1064
1080
  exports.AbstractGraph = AbstractGraph;