data-structure-typed 0.8.18 → 1.12.9

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 (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
@@ -3,95 +3,90 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stack = void 0;
4
4
  /**
5
5
  * @license MIT
6
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
7
- *
6
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
8
7
  * @class
9
8
  */
10
- class Stack {
9
+ var Stack = /** @class */ (function () {
11
10
  /**
12
- * Creates a stack.
13
- * @param {array} [elements]
11
+ * The constructor initializes an array of elements, which can be provided as an optional parameter.
12
+ * @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
13
+ * of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
14
+ * is provided and is an array, it is assigned to the `_elements
14
15
  */
15
- constructor(elements) {
16
+ function Stack(elements) {
16
17
  this._elements = Array.isArray(elements) ? elements : [];
17
18
  }
18
19
  /**
19
- * Checks if the stack is empty.
20
- * @public
21
- * @returns {boolean}
20
+ * The function "fromArray" creates a new Stack object from an array of elements.
21
+ * @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
22
+ * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
23
+ * array.
22
24
  */
23
- isEmpty() {
25
+ Stack.fromArray = function (elements) {
26
+ return new Stack(elements);
27
+ };
28
+ /**
29
+ * The function checks if an array is empty and returns a boolean value.
30
+ * @returns A boolean value indicating whether the `_elements` array is empty or not.
31
+ */
32
+ Stack.prototype.isEmpty = function () {
24
33
  return this._elements.length === 0;
25
- }
34
+ };
26
35
  /**
27
- * Returns the number of elements in the stack.
28
- * @public
29
- * @returns {number}
36
+ * The size() function returns the number of elements in an array.
37
+ * @returns The size of the elements array.
30
38
  */
31
- size() {
39
+ Stack.prototype.size = function () {
32
40
  return this._elements.length;
33
- }
41
+ };
34
42
  /**
35
- * Returns the top element in the stack.
36
- * @public
37
- * @returns {object}
43
+ * The `peek` function returns the last element of an array, or null if the array is empty.
44
+ * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
38
45
  */
39
- peek() {
46
+ Stack.prototype.peek = function () {
40
47
  if (this.isEmpty())
41
48
  return null;
42
49
  return this._elements[this._elements.length - 1];
43
- }
50
+ };
44
51
  /**
45
- * Adds an element to the top of the stack.
46
- * @public
47
- * @param {object} element
52
+ * The push function adds an element to the stack and returns the updated stack.
53
+ * @param {T} element - The parameter "element" is of type T, which means it can be any data type.
54
+ * @returns The `push` method is returning the updated `Stack<T>` object.
48
55
  */
49
- push(element) {
56
+ Stack.prototype.push = function (element) {
50
57
  this._elements.push(element);
51
58
  return this;
52
- }
59
+ };
53
60
  /**
54
- * Removes and returns the top element in the stack.
55
- * @public
56
- * @returns {object}
61
+ * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
62
+ * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
63
+ * array is empty, it returns `null`.
57
64
  */
58
- pop() {
65
+ Stack.prototype.pop = function () {
59
66
  if (this.isEmpty())
60
67
  return null;
61
68
  return this._elements.pop() || null;
62
- }
69
+ };
63
70
  /**
64
- * Returns the remaining elements as an array.
65
- * @public
66
- * @returns {array}
71
+ * The toArray function returns a copy of the elements in an array.
72
+ * @returns An array of type T.
67
73
  */
68
- toArray() {
74
+ Stack.prototype.toArray = function () {
69
75
  return this._elements.slice();
70
- }
76
+ };
71
77
  /**
72
- * Clears all elements from the stack.
73
- * @public
78
+ * The clear function clears the elements array.
74
79
  */
75
- clear() {
80
+ Stack.prototype.clear = function () {
76
81
  this._elements = [];
77
- }
82
+ };
78
83
  /**
79
- * Creates a shallow copy from the stack.
80
- * @public
81
- * @return {Stack}
84
+ * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
85
+ * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
82
86
  */
83
- clone() {
87
+ Stack.prototype.clone = function () {
84
88
  return new Stack(this._elements.slice());
85
- }
86
- /**
87
- * Creates a stack from an existing array
88
- * @public
89
- * @static
90
- * @param {array} [elements]
91
- * @return {Stack}
92
- */
93
- static fromArray(elements) {
94
- return new Stack(elements);
95
- }
96
- }
89
+ };
90
+ return Stack;
91
+ }());
97
92
  exports.Stack = Stack;
@@ -1,28 +1,58 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  export declare class TrieNode {
6
+ protected _value: string;
7
+ constructor(v: string);
2
8
  protected _children: Map<string, TrieNode>;
3
9
  get children(): Map<string, TrieNode>;
4
10
  set children(v: Map<string, TrieNode>);
5
11
  protected _isEnd: boolean;
6
12
  get isEnd(): boolean;
7
13
  set isEnd(v: boolean);
14
+ get val(): string;
15
+ set val(v: string);
8
16
  }
9
17
  export declare class Trie {
18
+ constructor(words?: string[]);
10
19
  protected _root: TrieNode;
11
20
  get root(): TrieNode;
12
21
  set root(v: TrieNode);
13
- constructor();
14
- put(input: string): boolean;
22
+ put(word: string): boolean;
15
23
  has(input: string): boolean;
16
24
  remove(word: string): boolean;
17
25
  /**
18
- * Only can present as a prefix, not a word
19
- * @param input
26
+ * The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
27
+ * @param {string} input - The input parameter is a string that represents the input value for the function.
28
+ * @returns a boolean value.
20
29
  */
21
30
  isAbsPrefix(input: string): boolean;
22
31
  /**
23
- * Can present as a prefix or word
24
- * @param input
32
+ * The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
33
+ * @param {string} input - The input parameter is a string that represents the prefix we want to check.
34
+ * @returns a boolean value.
25
35
  */
26
36
  isPrefix(input: string): boolean;
37
+ /**
38
+ * The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
39
+ * @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
40
+ * in the Trie data structure.
41
+ * @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
42
+ */
43
+ isCommonPrefix(input: string): boolean;
44
+ /**
45
+ * The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
46
+ * structure.
47
+ * @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
48
+ * Trie.
49
+ */
50
+ getLongestCommonPrefix(): string;
51
+ /**
52
+ * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
53
+ * @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
54
+ * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
55
+ * @returns an array of strings.
56
+ */
27
57
  getAll(prefix?: string): string[];
28
58
  }
@@ -1,63 +1,140 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.Trie = exports.TrieNode = void 0;
4
- class TrieNode {
5
- constructor() {
6
- this._children = new Map();
15
+ /**
16
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
17
+ * @license MIT
18
+ */
19
+ var TrieNode = /** @class */ (function () {
20
+ function TrieNode(v) {
21
+ this._value = v;
7
22
  this._isEnd = false;
23
+ this._children = new Map();
8
24
  }
9
- get children() {
10
- return this._children;
11
- }
12
- set children(v) {
13
- this._children = v;
14
- }
15
- get isEnd() {
16
- return this._isEnd;
17
- }
18
- set isEnd(v) {
19
- this._isEnd = v;
20
- }
21
- }
25
+ Object.defineProperty(TrieNode.prototype, "children", {
26
+ get: function () {
27
+ return this._children;
28
+ },
29
+ set: function (v) {
30
+ this._children = v;
31
+ },
32
+ enumerable: false,
33
+ configurable: true
34
+ });
35
+ Object.defineProperty(TrieNode.prototype, "isEnd", {
36
+ get: function () {
37
+ return this._isEnd;
38
+ },
39
+ set: function (v) {
40
+ this._isEnd = v;
41
+ },
42
+ enumerable: false,
43
+ configurable: true
44
+ });
45
+ Object.defineProperty(TrieNode.prototype, "val", {
46
+ get: function () {
47
+ return this._value;
48
+ },
49
+ set: function (v) {
50
+ this._value = v;
51
+ },
52
+ enumerable: false,
53
+ configurable: true
54
+ });
55
+ return TrieNode;
56
+ }());
22
57
  exports.TrieNode = TrieNode;
23
- class Trie {
24
- get root() {
25
- return this._root;
26
- }
27
- set root(v) {
28
- this._root = v;
29
- }
30
- constructor() {
31
- this._root = new TrieNode();
58
+ var Trie = /** @class */ (function () {
59
+ function Trie(words) {
60
+ var e_1, _a;
61
+ this._root = new TrieNode('');
62
+ if (words) {
63
+ try {
64
+ for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
65
+ var i = words_1_1.value;
66
+ this.put(i);
67
+ }
68
+ }
69
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
70
+ finally {
71
+ try {
72
+ if (words_1_1 && !words_1_1.done && (_a = words_1.return)) _a.call(words_1);
73
+ }
74
+ finally { if (e_1) throw e_1.error; }
75
+ }
76
+ }
32
77
  }
33
- put(input) {
34
- let cur = this._root;
35
- for (const c of input) {
36
- let nodeC = cur.children.get(c);
37
- if (!nodeC) {
38
- nodeC = new TrieNode();
39
- cur.children.set(c, nodeC);
40
- }
41
- cur = nodeC;
78
+ Object.defineProperty(Trie.prototype, "root", {
79
+ get: function () {
80
+ return this._root;
81
+ },
82
+ set: function (v) {
83
+ this._root = v;
84
+ },
85
+ enumerable: false,
86
+ configurable: true
87
+ });
88
+ Trie.prototype.put = function (word) {
89
+ var e_2, _a;
90
+ var cur = this._root;
91
+ try {
92
+ for (var word_1 = __values(word), word_1_1 = word_1.next(); !word_1_1.done; word_1_1 = word_1.next()) {
93
+ var c = word_1_1.value;
94
+ var nodeC = cur.children.get(c);
95
+ if (!nodeC) {
96
+ nodeC = new TrieNode(c);
97
+ cur.children.set(c, nodeC);
98
+ }
99
+ cur = nodeC;
100
+ }
101
+ }
102
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
103
+ finally {
104
+ try {
105
+ if (word_1_1 && !word_1_1.done && (_a = word_1.return)) _a.call(word_1);
106
+ }
107
+ finally { if (e_2) throw e_2.error; }
42
108
  }
43
109
  cur.isEnd = true;
44
110
  return true;
45
- }
46
- has(input) {
47
- let cur = this._root;
48
- for (const c of input) {
49
- const nodeC = cur.children.get(c);
50
- if (!nodeC)
51
- return false;
52
- cur = nodeC;
111
+ };
112
+ Trie.prototype.has = function (input) {
113
+ var e_3, _a;
114
+ var cur = this._root;
115
+ try {
116
+ for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
117
+ var c = input_1_1.value;
118
+ var nodeC = cur.children.get(c);
119
+ if (!nodeC)
120
+ return false;
121
+ cur = nodeC;
122
+ }
123
+ }
124
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
125
+ finally {
126
+ try {
127
+ if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
128
+ }
129
+ finally { if (e_3) throw e_3.error; }
53
130
  }
54
131
  return cur.isEnd;
55
- }
56
- remove(word) {
57
- let isDeleted = false;
58
- const dfs = (cur, i) => {
59
- const char = word[i];
60
- const child = cur.children.get(char);
132
+ };
133
+ Trie.prototype.remove = function (word) {
134
+ var isDeleted = false;
135
+ var dfs = function (cur, i) {
136
+ var char = word[i];
137
+ var child = cur.children.get(char);
61
138
  if (child) {
62
139
  if (i === word.length - 1) {
63
140
  if (child.isEnd) {
@@ -72,7 +149,7 @@ class Trie {
72
149
  }
73
150
  return false;
74
151
  }
75
- const res = dfs(child, i + 1);
152
+ var res = dfs(child, i + 1);
76
153
  if (res && !cur.isEnd && child.children.size === 0) {
77
154
  cur.children.delete(char);
78
155
  return true;
@@ -83,59 +160,155 @@ class Trie {
83
160
  };
84
161
  dfs(this.root, 0);
85
162
  return isDeleted;
86
- }
163
+ };
87
164
  // --- start additional methods ---
88
165
  /**
89
- * Only can present as a prefix, not a word
90
- * @param input
166
+ * The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
167
+ * @param {string} input - The input parameter is a string that represents the input value for the function.
168
+ * @returns a boolean value.
91
169
  */
92
- isAbsPrefix(input) {
93
- let cur = this._root;
94
- for (const c of input) {
95
- const nodeC = cur.children.get(c);
96
- if (!nodeC)
97
- return false;
98
- cur = nodeC;
170
+ Trie.prototype.isAbsPrefix = function (input) {
171
+ var e_4, _a;
172
+ var cur = this._root;
173
+ try {
174
+ for (var input_2 = __values(input), input_2_1 = input_2.next(); !input_2_1.done; input_2_1 = input_2.next()) {
175
+ var c = input_2_1.value;
176
+ var nodeC = cur.children.get(c);
177
+ if (!nodeC)
178
+ return false;
179
+ cur = nodeC;
180
+ }
181
+ }
182
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
183
+ finally {
184
+ try {
185
+ if (input_2_1 && !input_2_1.done && (_a = input_2.return)) _a.call(input_2);
186
+ }
187
+ finally { if (e_4) throw e_4.error; }
99
188
  }
100
189
  return !cur.isEnd;
101
- }
190
+ };
102
191
  /**
103
- * Can present as a prefix or word
104
- * @param input
192
+ * The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
193
+ * @param {string} input - The input parameter is a string that represents the prefix we want to check.
194
+ * @returns a boolean value.
105
195
  */
106
- isPrefix(input) {
107
- let cur = this._root;
108
- for (const c of input) {
109
- const nodeC = cur.children.get(c);
110
- if (!nodeC)
111
- return false;
112
- cur = nodeC;
196
+ Trie.prototype.isPrefix = function (input) {
197
+ var e_5, _a;
198
+ var cur = this._root;
199
+ try {
200
+ for (var input_3 = __values(input), input_3_1 = input_3.next(); !input_3_1.done; input_3_1 = input_3.next()) {
201
+ var c = input_3_1.value;
202
+ var nodeC = cur.children.get(c);
203
+ if (!nodeC)
204
+ return false;
205
+ cur = nodeC;
206
+ }
207
+ }
208
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
209
+ finally {
210
+ try {
211
+ if (input_3_1 && !input_3_1.done && (_a = input_3.return)) _a.call(input_3);
212
+ }
213
+ finally { if (e_5) throw e_5.error; }
113
214
  }
114
215
  return true;
115
- }
116
- getAll(prefix = '') {
117
- const words = [];
216
+ };
217
+ /**
218
+ * The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
219
+ * @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
220
+ * in the Trie data structure.
221
+ * @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
222
+ */
223
+ Trie.prototype.isCommonPrefix = function (input) {
224
+ var commonPre = '';
225
+ var dfs = function (cur) {
226
+ commonPre += cur.val;
227
+ if (commonPre === input)
228
+ return;
229
+ if (cur.isEnd)
230
+ return;
231
+ if (cur && cur.children && cur.children.size === 1)
232
+ dfs(Array.from(cur.children.values())[0]);
233
+ else
234
+ return;
235
+ };
236
+ dfs(this._root);
237
+ return commonPre === input;
238
+ };
239
+ /**
240
+ * The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
241
+ * structure.
242
+ * @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
243
+ * Trie.
244
+ */
245
+ Trie.prototype.getLongestCommonPrefix = function () {
246
+ var commonPre = '';
247
+ var dfs = function (cur) {
248
+ commonPre += cur.val;
249
+ if (cur.isEnd)
250
+ return;
251
+ if (cur && cur.children && cur.children.size === 1)
252
+ dfs(Array.from(cur.children.values())[0]);
253
+ else
254
+ return;
255
+ };
256
+ dfs(this._root);
257
+ return commonPre;
258
+ };
259
+ /**
260
+ * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
261
+ * @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
262
+ * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
263
+ * @returns an array of strings.
264
+ */
265
+ Trie.prototype.getAll = function (prefix) {
266
+ var e_6, _a;
267
+ if (prefix === void 0) { prefix = ''; }
268
+ var words = [];
118
269
  function dfs(node, word) {
119
- for (const char of node.children.keys()) {
120
- const charNode = node.children.get(char);
121
- if (charNode !== undefined) {
122
- dfs(charNode, word.concat(char));
270
+ var e_7, _a;
271
+ try {
272
+ for (var _b = __values(node.children.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
273
+ var char = _c.value;
274
+ var charNode = node.children.get(char);
275
+ if (charNode !== undefined) {
276
+ dfs(charNode, word.concat(char));
277
+ }
123
278
  }
124
279
  }
280
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
281
+ finally {
282
+ try {
283
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
284
+ }
285
+ finally { if (e_7) throw e_7.error; }
286
+ }
125
287
  if (node.isEnd) {
126
288
  words.push(word);
127
289
  }
128
290
  }
129
- let startNode = this._root;
291
+ var startNode = this._root;
130
292
  if (prefix) {
131
- for (const c of prefix) {
132
- const nodeC = startNode.children.get(c);
133
- if (nodeC)
134
- startNode = nodeC;
293
+ try {
294
+ for (var prefix_1 = __values(prefix), prefix_1_1 = prefix_1.next(); !prefix_1_1.done; prefix_1_1 = prefix_1.next()) {
295
+ var c = prefix_1_1.value;
296
+ var nodeC = startNode.children.get(c);
297
+ if (nodeC)
298
+ startNode = nodeC;
299
+ }
300
+ }
301
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
302
+ finally {
303
+ try {
304
+ if (prefix_1_1 && !prefix_1_1.done && (_a = prefix_1.return)) _a.call(prefix_1);
305
+ }
306
+ finally { if (e_6) throw e_6.error; }
135
307
  }
136
308
  }
137
309
  dfs(startNode, prefix);
138
310
  return words;
139
- }
140
- }
311
+ };
312
+ return Trie;
313
+ }());
141
314
  exports.Trie = Trie;
@@ -0,0 +1,29 @@
1
+ export type VertexId = string | number;
2
+ export type DijkstraResult<V> = {
3
+ distMap: Map<V, number>;
4
+ preMap: Map<V, V | null>;
5
+ seen: Set<V>;
6
+ paths: V[][];
7
+ minDist: number;
8
+ minPath: V[];
9
+ } | null;
10
+ export interface IGraph<V, E> {
11
+ containsVertex(vertexOrId: V | VertexId): boolean;
12
+ getVertex(vertexOrId: VertexId | V): V | null;
13
+ getVertexId(vertexOrId: V | VertexId): VertexId;
14
+ vertexSet(): Map<VertexId, V>;
15
+ addVertex(v: V): boolean;
16
+ removeVertex(vertexOrId: V | VertexId): boolean;
17
+ removeAllVertices(vertices: V[] | VertexId[]): boolean;
18
+ degreeOf(vertexOrId: V | VertexId): number;
19
+ edgesOf(vertexOrId: V | VertexId): E[];
20
+ containsEdge(src: V | VertexId, dest: V | VertexId): boolean;
21
+ getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
22
+ edgeSet(): E[];
23
+ addEdge(edge: E): boolean;
24
+ removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
25
+ removeEdge(edge: E): E | null;
26
+ setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
27
+ getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
28
+ getNeighbors(vertexOrId: V | VertexId): V[];
29
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { AVLTreeNode } from '../binary-tree';
2
+ export interface AVLTreeDeleted<T> {
3
+ deleted: AVLTreeNode<T> | null;
4
+ needBalanced: AVLTreeNode<T> | null;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { BinaryTreeNode } from '../binary-tree';
2
+ export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
3
+ export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
4
+ export type DFSOrderPattern = 'in' | 'pre' | 'post';
5
+ export type BinaryTreeNodeId = number;
6
+ export type BinaryTreeDeleted<T> = {
7
+ deleted: BinaryTreeNode<T> | null | undefined;
8
+ needBalanced: BinaryTreeNode<T> | null;
9
+ };
10
+ export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
11
+ export type ResultsByProperty<T> = ResultByProperty<T>[];
12
+ export interface BinaryTreeNodeObj<T> {
13
+ id: BinaryTreeNodeId;
14
+ val: T;
15
+ count?: number;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });