data-structure-typed 0.9.16 → 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 (199) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/README.md +102 -1
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +57 -0
  5. package/dist/data-structures/binary-tree/avl-tree.js +57 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +27 -0
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.js +27 -0
  8. package/dist/data-structures/binary-tree/binary-tree.d.ts +215 -9
  9. package/dist/data-structures/binary-tree/binary-tree.js +283 -15
  10. package/dist/data-structures/binary-tree/bst.d.ts +16 -0
  11. package/dist/data-structures/binary-tree/bst.js +12 -0
  12. package/dist/data-structures/binary-tree/segment-tree.d.ts +4 -0
  13. package/dist/data-structures/binary-tree/segment-tree.js +4 -0
  14. package/dist/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.js +4 -0
  16. package/dist/data-structures/graph/abstract-graph.d.ts +163 -13
  17. package/dist/data-structures/graph/abstract-graph.js +166 -12
  18. package/dist/data-structures/graph/directed-graph.d.ts +111 -1
  19. package/dist/data-structures/graph/directed-graph.js +122 -0
  20. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  21. package/dist/data-structures/graph/undirected-graph.js +67 -0
  22. package/dist/data-structures/hash/coordinate-map.d.ts +32 -0
  23. package/dist/data-structures/hash/coordinate-map.js +32 -0
  24. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  25. package/dist/data-structures/hash/coordinate-set.js +25 -0
  26. package/dist/data-structures/heap/heap.d.ts +26 -31
  27. package/dist/data-structures/heap/heap.js +23 -32
  28. package/dist/data-structures/heap/max-heap.d.ts +6 -1
  29. package/dist/data-structures/heap/max-heap.js +6 -1
  30. package/dist/data-structures/heap/min-heap.d.ts +7 -1
  31. package/dist/data-structures/heap/min-heap.js +7 -1
  32. package/dist/data-structures/index.d.ts +0 -1
  33. package/dist/data-structures/index.js +0 -1
  34. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -6
  35. package/dist/data-structures/linked-list/doubly-linked-list.js +45 -8
  36. package/dist/data-structures/linked-list/singly-linked-list.d.ts +11 -8
  37. package/dist/data-structures/linked-list/singly-linked-list.js +4 -0
  38. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  39. package/dist/data-structures/matrix/matrix.js +11 -0
  40. package/dist/data-structures/matrix/matrix2d.d.ts +82 -2
  41. package/dist/data-structures/matrix/matrix2d.js +82 -2
  42. package/dist/data-structures/matrix/navigator.d.ts +32 -0
  43. package/dist/data-structures/matrix/navigator.js +28 -0
  44. package/dist/data-structures/matrix/vector2d.d.ts +139 -15
  45. package/dist/data-structures/matrix/vector2d.js +139 -15
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +8 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +8 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +8 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +8 -0
  50. package/dist/data-structures/priority-queue/priority-queue.d.ts +130 -0
  51. package/dist/data-structures/priority-queue/priority-queue.js +126 -0
  52. package/dist/data-structures/queue/deque.d.ts +69 -0
  53. package/dist/data-structures/queue/deque.js +69 -0
  54. package/dist/data-structures/queue/queue.d.ts +30 -32
  55. package/dist/data-structures/queue/queue.js +30 -32
  56. package/dist/data-structures/stack/stack.d.ts +26 -31
  57. package/dist/data-structures/stack/stack.js +26 -31
  58. package/dist/data-structures/trie/trie.d.ts +26 -6
  59. package/dist/data-structures/trie/trie.js +26 -7
  60. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  61. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  62. package/dist/data-structures/types/index.d.ts +1 -1
  63. package/dist/data-structures/types/index.js +1 -1
  64. package/dist/data-structures/types/singly-linked-list.d.ts +1 -5
  65. package/dist/data-structures/types/tree-multiset.d.ts +1 -1
  66. package/dist/{data-structures → utils}/trampoline.d.ts +5 -7
  67. package/dist/utils/types/index.d.ts +1 -0
  68. package/dist/utils/types/index.js +17 -0
  69. package/dist/{data-structures → utils}/types/utils.d.ts +8 -0
  70. package/dist/{data-structures → utils}/types/utils.js +1 -0
  71. package/dist/utils/utils.d.ts +1 -1
  72. package/docs/.nojekyll +1 -0
  73. package/docs/assets/highlight.css +85 -0
  74. package/docs/assets/main.js +58 -0
  75. package/docs/assets/search.js +1 -0
  76. package/docs/assets/style.css +1367 -0
  77. package/docs/classes/AVLTree.html +2046 -0
  78. package/docs/classes/AVLTreeNode.html +423 -0
  79. package/docs/classes/AaTree.html +117 -0
  80. package/docs/classes/AbstractEdge.html +198 -0
  81. package/docs/classes/AbstractGraph.html +891 -0
  82. package/docs/classes/AbstractVertex.html +164 -0
  83. package/docs/classes/ArrayDeque.html +384 -0
  84. package/docs/classes/BST.html +1893 -0
  85. package/docs/classes/BSTNode.html +425 -0
  86. package/docs/classes/BTree.html +117 -0
  87. package/docs/classes/BinaryIndexedTree.html +244 -0
  88. package/docs/classes/BinaryTree.html +1754 -0
  89. package/docs/classes/BinaryTreeNode.html +396 -0
  90. package/docs/classes/Character.html +165 -0
  91. package/docs/classes/CoordinateMap.html +394 -0
  92. package/docs/classes/CoordinateSet.html +355 -0
  93. package/docs/classes/Deque.html +617 -0
  94. package/docs/classes/DirectedEdge.html +247 -0
  95. package/docs/classes/DirectedGraph.html +1207 -0
  96. package/docs/classes/DirectedVertex.html +154 -0
  97. package/docs/classes/DoublyLinkedList.html +619 -0
  98. package/docs/classes/DoublyLinkedListNode.html +160 -0
  99. package/docs/classes/Heap.html +315 -0
  100. package/docs/classes/Matrix2D.html +447 -0
  101. package/docs/classes/MatrixNTI2D.html +181 -0
  102. package/docs/classes/MaxHeap.html +325 -0
  103. package/docs/classes/MaxPriorityQueue.html +668 -0
  104. package/docs/classes/MinHeap.html +326 -0
  105. package/docs/classes/MinPriorityQueue.html +668 -0
  106. package/docs/classes/Navigator.html +285 -0
  107. package/docs/classes/ObjectDeque.html +289 -0
  108. package/docs/classes/PriorityQueue.html +643 -0
  109. package/docs/classes/Queue.html +337 -0
  110. package/docs/classes/RBTree.html +117 -0
  111. package/docs/classes/SegmentTree.html +234 -0
  112. package/docs/classes/SegmentTreeNode.html +302 -0
  113. package/docs/classes/SinglyLinkedList.html +1035 -0
  114. package/docs/classes/SinglyLinkedListNode.html +304 -0
  115. package/docs/classes/SplayTree.html +117 -0
  116. package/docs/classes/Stack.html +313 -0
  117. package/docs/classes/TreeMultiSet.html +1897 -0
  118. package/docs/classes/Trie.html +317 -0
  119. package/docs/classes/TrieNode.html +221 -0
  120. package/docs/classes/TwoThreeTree.html +117 -0
  121. package/docs/classes/UndirectedEdge.html +220 -0
  122. package/docs/classes/UndirectedGraph.html +1006 -0
  123. package/docs/classes/UndirectedVertex.html +154 -0
  124. package/docs/classes/Vector2D.html +746 -0
  125. package/docs/enums/CP.html +126 -0
  126. package/docs/enums/FamilyPosition.html +126 -0
  127. package/docs/enums/LoopType.html +119 -0
  128. package/docs/index.html +288 -0
  129. package/docs/modules.html +146 -0
  130. package/jest.config.js +5 -0
  131. package/package.json +19 -11
  132. package/rename_clear_files.sh +29 -0
  133. package/src/assets/complexities-diff.jpg +0 -0
  134. package/src/assets/data-structure-complexities.jpg +0 -0
  135. package/src/data-structures/binary-tree/avl-tree.ts +57 -0
  136. package/src/data-structures/binary-tree/binary-indexed-tree.ts +27 -0
  137. package/src/data-structures/binary-tree/binary-tree.ts +288 -18
  138. package/src/data-structures/binary-tree/bst.ts +16 -1
  139. package/src/data-structures/binary-tree/segment-tree.ts +5 -0
  140. package/src/data-structures/binary-tree/tree-multiset.ts +4 -0
  141. package/src/data-structures/diagrams/README.md +5 -7
  142. package/src/data-structures/graph/abstract-graph.ts +167 -15
  143. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  148. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  149. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  150. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  151. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  152. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  153. package/src/data-structures/graph/directed-graph.ts +127 -5
  154. package/src/data-structures/graph/undirected-graph.ts +67 -1
  155. package/src/data-structures/hash/coordinate-map.ts +32 -0
  156. package/src/data-structures/hash/coordinate-set.ts +25 -0
  157. package/src/data-structures/heap/heap.ts +27 -32
  158. package/src/data-structures/heap/max-heap.ts +6 -1
  159. package/src/data-structures/heap/min-heap.ts +7 -1
  160. package/src/data-structures/index.ts +0 -1
  161. package/src/data-structures/linked-list/doubly-linked-list.ts +49 -8
  162. package/src/data-structures/linked-list/singly-linked-list.ts +39 -8
  163. package/src/data-structures/matrix/matrix.ts +11 -0
  164. package/src/data-structures/matrix/matrix2d.ts +82 -2
  165. package/src/data-structures/matrix/navigator.ts +32 -0
  166. package/src/data-structures/matrix/vector2d.ts +139 -15
  167. package/src/data-structures/priority-queue/max-priority-queue.ts +8 -0
  168. package/src/data-structures/priority-queue/min-priority-queue.ts +8 -0
  169. package/src/data-structures/priority-queue/priority-queue.ts +130 -0
  170. package/src/data-structures/queue/deque.ts +69 -0
  171. package/src/data-structures/queue/queue.ts +30 -32
  172. package/src/data-structures/stack/stack.ts +26 -31
  173. package/src/data-structures/trie/trie.ts +26 -7
  174. package/src/data-structures/types/avl-tree.ts +1 -1
  175. package/src/data-structures/types/binary-tree.ts +1 -1
  176. package/src/data-structures/types/bst.ts +1 -1
  177. package/src/data-structures/types/index.ts +1 -1
  178. package/src/data-structures/types/navigator.ts +1 -0
  179. package/src/data-structures/types/singly-linked-list.ts +1 -15
  180. package/src/data-structures/types/tree-multiset.ts +1 -1
  181. package/src/{data-structures → utils}/trampoline.ts +6 -6
  182. package/src/utils/types/index.ts +1 -0
  183. package/src/{data-structures → utils}/types/utils.ts +7 -0
  184. package/src/utils/utils.ts +12 -2
  185. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  186. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  187. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  188. package/tests/unit/data-structures/graph/index.ts +3 -0
  189. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  191. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  192. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  194. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  195. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  196. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  197. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  198. package/src/data-structures/graph/diagrams/mst.png +0 -0
  199. /package/dist/{data-structures → utils}/trampoline.js +0 -0
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Vector2D = void 0;
4
+ /**
5
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT
7
+ */
4
8
  var Vector2D = /** @class */ (function () {
5
9
  function Vector2D(x, y, w // needed for matrix multiplication
6
10
  ) {
@@ -13,7 +17,8 @@ var Vector2D = /** @class */ (function () {
13
17
  }
14
18
  Object.defineProperty(Vector2D.prototype, "isZero", {
15
19
  /**
16
- * Set x and y both to zero
20
+ * The function checks if the x and y values of a point are both zero.
21
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
17
22
  */
18
23
  get: function () {
19
24
  return this.x === 0 && this.y === 0;
@@ -23,7 +28,8 @@ var Vector2D = /** @class */ (function () {
23
28
  });
24
29
  Object.defineProperty(Vector2D.prototype, "length", {
25
30
  /**
26
- * The length / magnitude of the vector
31
+ * The above function calculates the length of a vector using the Pythagorean theorem.
32
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
27
33
  */
28
34
  get: function () {
29
35
  return Math.sqrt((this.x * this.x) + (this.y * this.y));
@@ -33,7 +39,8 @@ var Vector2D = /** @class */ (function () {
33
39
  });
34
40
  Object.defineProperty(Vector2D.prototype, "lengthSq", {
35
41
  /**
36
- * The squared length of the vector
42
+ * The function calculates the square of the length of a vector.
43
+ * @returns The method is returning the sum of the squares of the x and y values.
37
44
  */
38
45
  get: function () {
39
46
  return (this.x * this.x) + (this.y * this.y);
@@ -43,7 +50,9 @@ var Vector2D = /** @class */ (function () {
43
50
  });
44
51
  Object.defineProperty(Vector2D.prototype, "rounded", {
45
52
  /**
46
- * Return the vector with rounded values
53
+ * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
54
+ * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
55
+ * whole number.
47
56
  */
48
57
  get: function () {
49
58
  return new Vector2D(Math.round(this.x), Math.round(this.y));
@@ -51,24 +60,87 @@ var Vector2D = /** @class */ (function () {
51
60
  enumerable: false,
52
61
  configurable: true
53
62
  });
63
+ /**
64
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
65
+ * x and y components.
66
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
67
+ * 2-dimensional vector with an `x` and `y` component.
68
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
69
+ * an x and y component.
70
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
71
+ * vectors added together.
72
+ */
54
73
  Vector2D.add = function (vector1, vector2) {
55
74
  return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
56
75
  };
76
+ /**
77
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
78
+ * components subtracted.
79
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
80
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
81
+ * respectively.
82
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
83
+ * want to subtract from the first vector.
84
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
85
+ * vector2.
86
+ */
57
87
  Vector2D.subtract = function (vector1, vector2) {
58
88
  return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
59
89
  };
90
+ /**
91
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
92
+ * object.
93
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
94
+ * x and y components.
95
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
96
+ * of the "vector" parameter.
97
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
98
+ */
60
99
  Vector2D.subtractValue = function (vector, value) {
61
100
  return new Vector2D(vector.x - value, vector.y - value);
62
101
  };
102
+ /**
103
+ * The function multiplies a Vector2D object by a given value.
104
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
105
+ * x and y components.
106
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
107
+ * of the vector will be multiplied.
108
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
109
+ */
63
110
  Vector2D.multiply = function (vector, value) {
64
111
  return new Vector2D(vector.x * value, vector.y * value);
65
112
  };
113
+ /**
114
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
115
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
116
+ * x and y components.
117
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
118
+ * vector.
119
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
120
+ */
66
121
  Vector2D.divide = function (vector, value) {
67
122
  return new Vector2D(vector.x / value, vector.y / value);
68
123
  };
124
+ /**
125
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
126
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
127
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
128
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
129
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
130
+ */
69
131
  Vector2D.equals = function (vector1, vector2) {
70
132
  return vector1.x === vector2.x && vector1.y === vector2.y;
71
133
  };
134
+ /**
135
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
136
+ * @param {Vector2D} vector1 - The first vector to compare.
137
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
138
+ * It is used as one of the inputs for the "equalsRounded" function.
139
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
140
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
141
+ * roundingFactor, the vectors are considered equal.
142
+ * @returns a boolean value.
143
+ */
72
144
  Vector2D.equalsRounded = function (vector1, vector2, roundingFactor) {
73
145
  if (roundingFactor === void 0) { roundingFactor = 12; }
74
146
  var vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
@@ -78,7 +150,10 @@ var Vector2D = /** @class */ (function () {
78
150
  return false;
79
151
  };
80
152
  /**
81
- * Normalizes the vector if it matches a certain condition
153
+ * The normalize function takes a vector as input and returns a normalized version of the vector.Normalizes the vector if it matches a certain condition
154
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
155
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
156
+ * original vector.
82
157
  */
83
158
  Vector2D.normalize = function (vector) {
84
159
  var length = vector.length;
@@ -88,7 +163,12 @@ var Vector2D = /** @class */ (function () {
88
163
  return vector;
89
164
  };
90
165
  /**
91
- * Adjusts x and y so that the length of the vector does not exceed max
166
+ * The function truncates a vector to a maximum length if it exceeds that length.Adjusts x and y so that the length of the vector does not exceed max
167
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
168
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
169
+ * have.
170
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
171
+ * vector is greater than the maximum value specified.
92
172
  */
93
173
  Vector2D.truncate = function (vector, max) {
94
174
  if (vector.length > max) {
@@ -97,22 +177,39 @@ var Vector2D = /** @class */ (function () {
97
177
  return vector;
98
178
  };
99
179
  /**
100
- * The vector that is perpendicular to this one
180
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
181
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
182
+ * @returns A new Vector2D object is being returned.
101
183
  */
102
184
  Vector2D.perp = function (vector) {
103
185
  return new Vector2D(-vector.y, vector.x);
104
186
  };
105
187
  /**
106
- * returns the vector that is the reverse of this vector
188
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
189
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
190
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
191
+ * @returns A new Vector2D object with the negated x and y values of the input vector. Returns the vector that is the reverse of this vector
107
192
  */
108
193
  Vector2D.reverse = function (vector) {
109
194
  return new Vector2D(-vector.x, -vector.y);
110
195
  };
196
+ /**
197
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
198
+ * and y components.
199
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
200
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
201
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
202
+ * input vector.
203
+ */
111
204
  Vector2D.abs = function (vector) {
112
205
  return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
113
206
  };
114
207
  /**
115
- * The dot product of v1 and v2
208
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
209
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
210
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
211
+ * with an x and y component.
212
+ * @returns The dot product of the two input vectors.
116
213
  */
117
214
  Vector2D.dot = function (vector1, vector2) {
118
215
  return (vector1.x * vector2.x) + (vector1.y * vector2.y);
@@ -132,7 +229,14 @@ var Vector2D = /** @class */ (function () {
132
229
  // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
133
230
  // }
134
231
  /**
135
- * The distance between this and the vector
232
+ * The function calculates the distance between two points in a two-dimensional space.
233
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
234
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
235
+ * in the 2D space.
236
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
237
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
238
+ * the vector in a 2D space.
239
+ * @returns The distance between vector1 and vector2.
136
240
  */
137
241
  Vector2D.distance = function (vector1, vector2) {
138
242
  var ySeparation = vector2.y - vector1.y;
@@ -140,7 +244,12 @@ var Vector2D = /** @class */ (function () {
140
244
  return Math.sqrt((ySeparation * ySeparation) + (xSeparation * xSeparation));
141
245
  };
142
246
  /**
143
- * The distance between this and the vector squared
247
+ * The function calculates the squared distance between two 2D vectors.
248
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
249
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
250
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
251
+ * properties `x` and `y` which represent the coordinates of the vector.
252
+ * @returns the square of the distance between the two input vectors.
144
253
  */
145
254
  Vector2D.distanceSq = function (vector1, vector2) {
146
255
  var ySeparation = vector2.y - vector1.y;
@@ -148,8 +257,13 @@ var Vector2D = /** @class */ (function () {
148
257
  return (ySeparation * ySeparation) + (xSeparation * xSeparation);
149
258
  };
150
259
  /**
151
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
260
+ * The sign function determines the sign of the cross product between two 2D vectors.
152
261
  * (assuming the Y axis is pointing down, X axis to right like a Window app)
262
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
263
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
264
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
265
+ * vector2. Both vector1 and vector2 are of type Vector2D.
266
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
153
267
  */
154
268
  Vector2D.sign = function (vector1, vector2) {
155
269
  if (vector1.y * vector2.x > vector1.x * vector2.y) {
@@ -158,21 +272,31 @@ var Vector2D = /** @class */ (function () {
158
272
  return 1;
159
273
  };
160
274
  /**
161
- * Returns the angle between origin and the given vector in radians
162
- * @param vector
275
+ * The function calculates the angle between a given vector and the negative y-axis.
276
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
277
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
278
+ * respectively.
279
+ * @returns the angle between the given vector and the vector (0, -1) in radians.Returns the angle between origin and the given vector in radians
163
280
  */
164
281
  Vector2D.angle = function (vector) {
165
282
  var origin = new Vector2D(0, -1);
166
283
  var radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
167
284
  return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian;
168
285
  };
286
+ /**
287
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
288
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
289
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
290
+ * random vector.
291
+ * @returns a new instance of the Vector2D class with random x and y values.
292
+ */
169
293
  Vector2D.random = function (maxX, maxY) {
170
294
  var randX = Math.floor(Math.random() * maxX - (maxX / 2));
171
295
  var randY = Math.floor(Math.random() * maxY - (maxY / 2));
172
296
  return new Vector2D(randX, randY);
173
297
  };
174
298
  /**
175
- * Check wether both x and y are zero
299
+ * The function sets the values of x and y to zero.
176
300
  */
177
301
  Vector2D.prototype.zero = function () {
178
302
  this.x = 0;
@@ -1,5 +1,13 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import { PriorityQueue } from './priority-queue';
2
6
  import type { PriorityQueueOptions } from '../types';
3
7
  export declare class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
8
+ /**
9
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
10
+ * @param [options] - An optional object that contains the following properties:
11
+ */
4
12
  constructor(options?: PriorityQueueOptions<T>);
5
13
  }
@@ -16,9 +16,17 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MaxPriorityQueue = void 0;
19
+ /**
20
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
21
+ * @license MIT
22
+ */
19
23
  var priority_queue_1 = require("./priority-queue");
20
24
  var MaxPriorityQueue = /** @class */ (function (_super) {
21
25
  __extends(MaxPriorityQueue, _super);
26
+ /**
27
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
28
+ * @param [options] - An optional object that contains the following properties:
29
+ */
22
30
  function MaxPriorityQueue(options) {
23
31
  return _super.call(this, {
24
32
  nodes: options === null || options === void 0 ? void 0 : options.nodes, comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : function (a, b) {
@@ -1,5 +1,13 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import { PriorityQueue } from './priority-queue';
2
6
  import type { PriorityQueueOptions } from '../types';
3
7
  export declare class MinPriorityQueue<T = number> extends PriorityQueue<T> {
8
+ /**
9
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
10
+ * @param [options] - An optional object that contains the following properties:
11
+ */
4
12
  constructor(options?: PriorityQueueOptions<T>);
5
13
  }
@@ -16,9 +16,17 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MinPriorityQueue = void 0;
19
+ /**
20
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
21
+ * @license MIT
22
+ */
19
23
  var priority_queue_1 = require("./priority-queue");
20
24
  var MinPriorityQueue = /** @class */ (function (_super) {
21
25
  __extends(MinPriorityQueue, _super);
26
+ /**
27
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
28
+ * @param [options] - An optional object that contains the following properties:
29
+ */
22
30
  function MinPriorityQueue(options) {
23
31
  return _super.call(this, {
24
32
  nodes: options === null || options === void 0 ? void 0 : options.nodes, comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : function (a, b) {
@@ -1,30 +1,160 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import type { PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions } from '../types';
2
6
  export declare class PriorityQueue<T = number> {
3
7
  protected nodes: T[];
8
+ /**
9
+ * The constructor initializes a priority queue with the given options, including an array of nodes and a comparator
10
+ * function.
11
+ * @param options - The `options` parameter is an object that contains the following properties:
12
+ */
4
13
  constructor(options: PriorityQueueOptions<T>);
5
14
  get size(): number;
15
+ /**
16
+ * The `heapify` function creates a new PriorityQueue instance and fixes the heap property.
17
+ * @param options - The "options" parameter is an object that contains the configuration options for the PriorityQueue.
18
+ * It can include properties such as "comparator" which specifies the comparison function used to order the elements in
19
+ * the priority queue, and "initialValues" which is an array of initial values to be added to the priority
20
+ * @returns a new instance of the PriorityQueue class after performing the heapify operation on it.
21
+ */
6
22
  static heapify<T>(options: PriorityQueueOptions<T>): PriorityQueue<T>;
23
+ /**
24
+ * The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling
25
+ * the isValid method.
26
+ * @param options - An object containing options for creating a priority queue. The options object should have the
27
+ * following properties:
28
+ * @returns the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.
29
+ */
7
30
  static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
31
+ /**
32
+ * The "offer" function adds a node to the heap and ensures that the heap property is maintained.
33
+ * @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node
34
+ * that needs to be added to the heap.
35
+ */
8
36
  offer(node: T): void;
37
+ /**
38
+ * The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
39
+ * @returns The `peek()` function is returning the first element (`T`) of the `nodes` array if the `size` is not zero.
40
+ * Otherwise, it returns `null`.
41
+ */
9
42
  peek(): T | null;
43
+ /**
44
+ * The `poll` function removes and returns the top element from a heap data structure.
45
+ * @returns The `poll()` method returns a value of type `T` or `null`.
46
+ */
10
47
  poll(): T | null;
48
+ /**
49
+ * The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
50
+ * @returns The method `leaf()` is returning the last element (`T`) in the `nodes` array if it exists. If the array is
51
+ * empty or the last element is `null`, then it returns `null`.
52
+ */
11
53
  leaf(): T | null;
54
+ /**
55
+ * The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the
56
+ * object is empty or not.
57
+ * @returns The method `isEmpty()` is returning a boolean value indicating whether the size of the object is equal to
58
+ * 0.
59
+ */
12
60
  isEmpty(): boolean;
61
+ /**
62
+ * The clear function clears the nodes array.
63
+ */
13
64
  clear(): void;
65
+ /**
66
+ * The toArray function returns an array containing all the elements in the nodes property.
67
+ * @returns An array of type T, which is the elements of the nodes property.
68
+ */
14
69
  toArray(): T[];
70
+ /**
71
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the
72
+ * original instance.
73
+ * @returns The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and
74
+ * `comparator` properties as the original instance.
75
+ */
15
76
  clone(): PriorityQueue<T>;
77
+ /**
78
+ * The `isValid` function recursively checks if a binary tree satisfies a certain condition.
79
+ * @returns The function `isValid()` returns a boolean value.
80
+ */
16
81
  isValid(): boolean;
82
+ /**
83
+ * The function sorts the elements in a data structure and returns them in ascending order.
84
+ * @returns The `sort()` function is returning an array of type `T[]`.
85
+ */
17
86
  sort(): T[];
87
+ /**
88
+ * The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
89
+ * based on the specified traversal order.
90
+ * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
91
+ * the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
92
+ * @returns an array of type `(T | null)[]`.
93
+ */
18
94
  DFS(dfsMode: PriorityQueueDFSOrderPattern): (T | null)[];
19
95
  protected readonly _comparator: PriorityQueueComparator<T>;
96
+ /**
97
+ * The function compares two numbers using a custom comparator function.
98
+ * @param {number} a - The parameter "a" is a number that represents the index of a node in an array.
99
+ * @param {number} b - The parameter "b" is a number.
100
+ * @returns the result of the comparison between the elements at indices `a` and `b` in the `nodes` array. The
101
+ * comparison is done using the `_comparator` function, and if the result is greater than 0, `true` is returned,
102
+ * indicating that the element at index `a` is greater than the element at index `b`.
103
+ */
20
104
  protected _compare(a: number, b: number): boolean;
105
+ /**
106
+ * The function swaps two elements in an array.
107
+ * @param {number} a - The parameter "a" is a number that represents the index of an element in an array.
108
+ * @param {number} b - The parameter "b" is a number.
109
+ */
21
110
  protected _swap(a: number, b: number): void;
111
+ /**
112
+ * The function checks if a given index is valid within an array.
113
+ * @param {number} index - The parameter "index" is of type number and represents the index value that needs to be
114
+ * checked for validity.
115
+ * @returns A boolean value indicating whether the given index is valid or not.
116
+ */
22
117
  protected _isValidIndex(index: number): boolean;
118
+ /**
119
+ * The function returns the index of the parent node given the index of a child node in a binary tree.
120
+ * @param {number} child - The "child" parameter is a number representing the index of a child node in a binary tree.
121
+ * @returns the parent of the given child node.
122
+ */
23
123
  protected _getParent(child: number): number;
124
+ /**
125
+ * The function returns the index of the left child node in a binary tree given the index of its parent node.
126
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
127
+ * @returns the left child of a given parent node in a binary tree.
128
+ */
24
129
  protected _getLeft(parent: number): number;
130
+ /**
131
+ * The function returns the index of the right child node in a binary tree given the index of its parent node.
132
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
133
+ * @returns the right child of a given parent node in a binary tree.
134
+ */
25
135
  protected _getRight(parent: number): number;
136
+ /**
137
+ * The function returns the index of the smallest child node of a given parent node.
138
+ * @param {number} parent - The parent parameter is a number that represents the index of the parent node in a binary
139
+ * tree.
140
+ * @returns the minimum value between the parent node and its left and right child nodes.
141
+ */
26
142
  protected _getComparedChild(parent: number): number;
143
+ /**
144
+ * The function `_heapifyUp` is used to maintain the heap property by moving an element up the heap until it is in the
145
+ * correct position.
146
+ * @param {number} start - The start parameter is the index of the element that needs to be moved up in the heap.
147
+ */
27
148
  protected _heapifyUp(start: number): void;
149
+ /**
150
+ * The function performs a heapify operation by comparing and swapping elements in a binary heap.
151
+ * @param {number} start - The start parameter is the index of the element in the heap from where the heapifyDown
152
+ * operation should start.
153
+ */
28
154
  protected _heapifyDown(start: number): void;
155
+ /**
156
+ * The _fix function performs a heapify operation on the elements of the heap starting from the middle and moving
157
+ * towards the root.
158
+ */
29
159
  protected _fix(): void;
30
160
  }