data-structure-typed 1.35.0 → 1.40.0-rc

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 (173) hide show
  1. package/.github/workflows/ci.yml +3 -0
  2. package/CHANGELOG.md +3 -1
  3. package/CONTRIBUTING.md +18 -0
  4. package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
  9. package/dist/data-structures/binary-tree/avl-tree.js +90 -3
  10. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
  13. package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  15. package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
  16. package/dist/data-structures/binary-tree/binary-tree.js +21 -0
  17. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  18. package/dist/data-structures/binary-tree/bst.d.ts +133 -0
  19. package/dist/data-structures/binary-tree/bst.js +114 -0
  20. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  21. package/dist/data-structures/binary-tree/index.d.ts +12 -0
  22. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  23. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  24. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  25. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  26. package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
  27. package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
  28. package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
  29. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  30. package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
  31. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  32. package/dist/data-structures/graph/abstract-graph.js +269 -4
  33. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  34. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  35. package/dist/data-structures/graph/directed-graph.js +167 -0
  36. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  37. package/dist/data-structures/graph/index.d.ts +4 -0
  38. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  39. package/dist/data-structures/graph/map-graph.js +54 -0
  40. package/dist/data-structures/graph/map-graph.js.map +1 -1
  41. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  42. package/dist/data-structures/graph/undirected-graph.js +105 -0
  43. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  44. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  45. package/dist/data-structures/hash/coordinate-map.js +35 -0
  46. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  47. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  48. package/dist/data-structures/hash/coordinate-set.js +28 -0
  49. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  50. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  51. package/dist/data-structures/hash/hash-map.js +29 -1
  52. package/dist/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  54. package/dist/data-structures/hash/hash-table.js +88 -6
  55. package/dist/data-structures/hash/hash-table.js.map +1 -1
  56. package/dist/data-structures/hash/index.d.ts +7 -0
  57. package/dist/data-structures/hash/pair.d.ts +2 -0
  58. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  59. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  60. package/dist/data-structures/heap/heap.d.ts +83 -0
  61. package/dist/data-structures/heap/heap.js +62 -0
  62. package/dist/data-structures/heap/heap.js.map +1 -1
  63. package/dist/data-structures/heap/index.d.ts +3 -0
  64. package/dist/data-structures/heap/max-heap.d.ts +23 -0
  65. package/dist/data-structures/heap/max-heap.js +16 -0
  66. package/dist/data-structures/heap/max-heap.js.map +1 -1
  67. package/dist/data-structures/heap/min-heap.d.ts +24 -0
  68. package/dist/data-structures/heap/min-heap.js +17 -0
  69. package/dist/data-structures/heap/min-heap.js.map +1 -1
  70. package/dist/data-structures/index.d.ts +11 -0
  71. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  72. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
  73. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  74. package/dist/data-structures/linked-list/index.d.ts +3 -0
  75. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  76. package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
  77. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  78. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  79. package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
  80. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  81. package/dist/data-structures/matrix/index.d.ts +4 -0
  82. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  83. package/dist/data-structures/matrix/matrix.js +15 -0
  84. package/dist/data-structures/matrix/matrix.js.map +1 -1
  85. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  86. package/dist/data-structures/matrix/matrix2d.js +91 -2
  87. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  88. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  89. package/dist/data-structures/matrix/navigator.js +28 -0
  90. package/dist/data-structures/matrix/navigator.js.map +1 -1
  91. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  92. package/dist/data-structures/matrix/vector2d.js +188 -1
  93. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  94. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  95. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  96. package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
  97. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  98. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  99. package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
  100. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  101. package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
  102. package/dist/data-structures/priority-queue/priority-queue.js +141 -0
  103. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  104. package/dist/data-structures/queue/deque.d.ts +165 -0
  105. package/dist/data-structures/queue/deque.js +124 -0
  106. package/dist/data-structures/queue/deque.js.map +1 -1
  107. package/dist/data-structures/queue/index.d.ts +2 -0
  108. package/dist/data-structures/queue/queue.d.ts +107 -0
  109. package/dist/data-structures/queue/queue.js +80 -0
  110. package/dist/data-structures/queue/queue.js.map +1 -1
  111. package/dist/data-structures/stack/index.d.ts +1 -0
  112. package/dist/data-structures/stack/stack.d.ts +63 -0
  113. package/dist/data-structures/stack/stack.js +50 -0
  114. package/dist/data-structures/stack/stack.js.map +1 -1
  115. package/dist/data-structures/tree/index.d.ts +1 -0
  116. package/dist/data-structures/tree/tree.d.ts +14 -0
  117. package/dist/data-structures/tree/tree.js +1 -0
  118. package/dist/data-structures/tree/tree.js.map +1 -1
  119. package/dist/data-structures/trie/index.d.ts +1 -0
  120. package/dist/data-structures/trie/trie.d.ts +61 -0
  121. package/dist/data-structures/trie/trie.js +36 -0
  122. package/dist/data-structures/trie/trie.js.map +1 -1
  123. package/dist/index.d.ts +4 -0
  124. package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
  125. package/dist/interfaces/abstract-graph.d.ts +5 -0
  126. package/dist/interfaces/avl-tree.d.ts +7 -0
  127. package/dist/interfaces/binary-tree.d.ts +6 -0
  128. package/dist/interfaces/bst.d.ts +6 -0
  129. package/dist/interfaces/directed-graph.d.ts +3 -0
  130. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  131. package/dist/interfaces/heap.d.ts +1 -0
  132. package/dist/interfaces/index.d.ts +15 -0
  133. package/dist/interfaces/navigator.d.ts +1 -0
  134. package/dist/interfaces/priority-queue.d.ts +1 -0
  135. package/dist/interfaces/rb-tree.d.ts +6 -0
  136. package/dist/interfaces/segment-tree.d.ts +1 -0
  137. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  138. package/dist/interfaces/tree-multiset.d.ts +6 -0
  139. package/dist/interfaces/undirected-graph.d.ts +3 -0
  140. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  141. package/dist/types/data-structures/abstract-binary-tree.js +6 -0
  142. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  143. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  144. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  145. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  146. package/dist/types/data-structures/bst.d.ts +13 -0
  147. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  148. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  149. package/dist/types/data-structures/hash.d.ts +1 -0
  150. package/dist/types/data-structures/heap.d.ts +3 -0
  151. package/dist/types/data-structures/index.d.ts +16 -0
  152. package/dist/types/data-structures/map-graph.d.ts +1 -0
  153. package/dist/types/data-structures/navigator.d.ts +14 -0
  154. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  155. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  156. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  157. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  158. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  159. package/dist/types/helpers.d.ts +1 -0
  160. package/dist/types/index.d.ts +3 -0
  161. package/dist/types/utils/index.d.ts +2 -0
  162. package/dist/types/utils/utils.d.ts +7 -0
  163. package/dist/types/utils/validate-type.d.ts +19 -0
  164. package/dist/utils/index.d.ts +1 -0
  165. package/dist/utils/utils.d.ts +19 -0
  166. package/package.json +11 -7
  167. package/test/integration/avl-tree.test.ts +4 -4
  168. package/test/integration/bst.test.ts +8 -8
  169. package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
  170. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  171. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
  172. package/test/unit/data-structures/graph/index.ts +0 -2
  173. package/test/unit/data-structures/linked-list/index.ts +0 -4
@@ -1,42 +1,130 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Vector2D = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  class Vector2D {
5
- constructor(x = 0, y = 0, w = 1) {
12
+ constructor(x = 0, y = 0, w = 1 // needed for matrix multiplication
13
+ ) {
6
14
  this.x = x;
7
15
  this.y = y;
8
16
  this.w = w;
9
17
  }
18
+ /**
19
+ * The function checks if the x and y values of a point are both zero.
20
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
21
+ */
10
22
  get isZero() {
11
23
  return this.x === 0 && this.y === 0;
12
24
  }
25
+ /**
26
+ * The above function calculates the length of a vector using the Pythagorean theorem.
27
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
28
+ */
13
29
  get length() {
14
30
  return Math.sqrt(this.x * this.x + this.y * this.y);
15
31
  }
32
+ /**
33
+ * The function calculates the square of the length of a vector.
34
+ * @returns The method is returning the sum of the squares of the x and y values.
35
+ */
16
36
  get lengthSq() {
17
37
  return this.x * this.x + this.y * this.y;
18
38
  }
39
+ /**
40
+ * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
41
+ * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
42
+ * whole number.
43
+ */
19
44
  get rounded() {
20
45
  return new Vector2D(Math.round(this.x), Math.round(this.y));
21
46
  }
47
+ /**
48
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
49
+ * x and y components.
50
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
51
+ * 2-dimensional vector with an `x` and `y` component.
52
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
53
+ * an x and y component.
54
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
55
+ * vectors added together.
56
+ */
22
57
  static add(vector1, vector2) {
23
58
  return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
24
59
  }
60
+ /**
61
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
62
+ * components subtracted.
63
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
64
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
65
+ * respectively.
66
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
67
+ * want to subtract from the first vector.
68
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
69
+ * vector2.
70
+ */
25
71
  static subtract(vector1, vector2) {
26
72
  return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
27
73
  }
74
+ /**
75
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
76
+ * object.
77
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
78
+ * x and y components.
79
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
80
+ * of the "vector" parameter.
81
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
82
+ */
28
83
  static subtractValue(vector, value) {
29
84
  return new Vector2D(vector.x - value, vector.y - value);
30
85
  }
86
+ /**
87
+ * The function multiplies a Vector2D object by a given value.
88
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
89
+ * x and y components.
90
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
91
+ * of the vector will be multiplied.
92
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
93
+ */
31
94
  static multiply(vector, value) {
32
95
  return new Vector2D(vector.x * value, vector.y * value);
33
96
  }
97
+ /**
98
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
99
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
100
+ * x and y components.
101
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
102
+ * vector.
103
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
104
+ */
34
105
  static divide(vector, value) {
35
106
  return new Vector2D(vector.x / value, vector.y / value);
36
107
  }
108
+ /**
109
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
110
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
111
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
112
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
113
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
114
+ */
37
115
  static equals(vector1, vector2) {
38
116
  return vector1.x === vector2.x && vector1.y === vector2.y;
39
117
  }
118
+ /**
119
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
120
+ * @param {Vector2D} vector1 - The first vector to compare.
121
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
122
+ * It is used as one of the inputs for the "equalsRounded" function.
123
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
124
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
125
+ * roundingFactor, the vectors are considered equal.
126
+ * @returns a boolean value.
127
+ */
40
128
  static equalsRounded(vector1, vector2, roundingFactor = 12) {
41
129
  const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
42
130
  if (vector.x < roundingFactor && vector.y < roundingFactor) {
@@ -44,57 +132,156 @@ class Vector2D {
44
132
  }
45
133
  return false;
46
134
  }
135
+ /**
136
+ * 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
137
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
138
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
139
+ * original vector.
140
+ */
47
141
  static normalize(vector) {
48
142
  const length = vector.length;
49
143
  if (length > 2.220446049250313e-16) {
144
+ // Epsilon
50
145
  return Vector2D.divide(vector, length);
51
146
  }
52
147
  return vector;
53
148
  }
149
+ /**
150
+ * 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
151
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
152
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
153
+ * have.
154
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
155
+ * vector is greater than the maximum value specified.
156
+ */
54
157
  static truncate(vector, max) {
55
158
  if (vector.length > max) {
56
159
  return Vector2D.multiply(Vector2D.normalize(vector), max);
57
160
  }
58
161
  return vector;
59
162
  }
163
+ /**
164
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
165
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
166
+ * @returns A new Vector2D object is being returned.
167
+ */
60
168
  static perp(vector) {
61
169
  return new Vector2D(-vector.y, vector.x);
62
170
  }
171
+ /**
172
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
173
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
174
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
175
+ * @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
176
+ */
63
177
  static reverse(vector) {
64
178
  return new Vector2D(-vector.x, -vector.y);
65
179
  }
180
+ /**
181
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
182
+ * and y components.
183
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
184
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
185
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
186
+ * input vector.
187
+ */
66
188
  static abs(vector) {
67
189
  return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
68
190
  }
191
+ /**
192
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
193
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
194
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
195
+ * with an x and y component.
196
+ * @returns The dot product of the two input vectors.
197
+ */
69
198
  static dot(vector1, vector2) {
70
199
  return vector1.x * vector2.x + vector1.y * vector2.y;
71
200
  }
201
+ // /**
202
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
203
+ // * @param vectors The vectors to transform
204
+ // */
205
+ // static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
206
+ // return Matrix2D.multiplyByVector(transformation, vector)
207
+ // }
208
+ // /**
209
+ // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
210
+ // * @param vectors The vectors to transform
211
+ // */
212
+ // static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
213
+ // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
214
+ // }
215
+ /**
216
+ * The function calculates the distance between two points in a two-dimensional space.
217
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
218
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
219
+ * in the 2D space.
220
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
221
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
222
+ * the vector in a 2D space.
223
+ * @returns The distance between vector1 and vector2.
224
+ */
72
225
  static distance(vector1, vector2) {
73
226
  const ySeparation = vector2.y - vector1.y;
74
227
  const xSeparation = vector2.x - vector1.x;
75
228
  return Math.sqrt(ySeparation * ySeparation + xSeparation * xSeparation);
76
229
  }
230
+ /**
231
+ * The function calculates the squared distance between two 2D vectors.
232
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
233
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
234
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
235
+ * properties `x` and `y` which represent the coordinates of the vector.
236
+ * @returns the square of the distance between the two input vectors.
237
+ */
77
238
  static distanceSq(vector1, vector2) {
78
239
  const ySeparation = vector2.y - vector1.y;
79
240
  const xSeparation = vector2.x - vector1.x;
80
241
  return ySeparation * ySeparation + xSeparation * xSeparation;
81
242
  }
243
+ /**
244
+ * The sign function determines the sign of the cross product between two 2D vectors.
245
+ * (assuming the Y axis is pointing down, X axis to right like a Window app)
246
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
247
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
248
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
249
+ * vector2. Both vector1 and vector2 are of type Vector2D.
250
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
251
+ */
82
252
  static sign(vector1, vector2) {
83
253
  if (vector1.y * vector2.x > vector1.x * vector2.y) {
84
254
  return -1;
85
255
  }
86
256
  return 1;
87
257
  }
258
+ /**
259
+ * The function calculates the angle between a given vector and the negative y-axis.
260
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
261
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
262
+ * respectively.
263
+ * @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
264
+ */
88
265
  static angle(vector) {
89
266
  const origin = new Vector2D(0, -1);
90
267
  const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
91
268
  return Vector2D.sign(vector, origin) === 1 ? Math.PI * 2 - radian : radian;
92
269
  }
270
+ /**
271
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
272
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
273
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
274
+ * random vector.
275
+ * @returns a new instance of the Vector2D class with random x and y values.
276
+ */
93
277
  static random(maxX, maxY) {
94
278
  const randX = Math.floor(Math.random() * maxX - maxX / 2);
95
279
  const randY = Math.floor(Math.random() * maxY - maxY / 2);
96
280
  return new Vector2D(randX, randY);
97
281
  }
282
+ /**
283
+ * The function sets the values of x and y to zero.
284
+ */
98
285
  zero() {
99
286
  this.x = 0;
100
287
  this.y = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"vector2d.js","sourceRoot":"","sources":["../../../src/data-structures/matrix/vector2d.ts"],"names":[],"mappings":";;;AAOA,MAAa,QAAQ;IACnB,YACS,IAAY,CAAC,EACb,IAAY,CAAC,EACb,IAAY,CAAC;QAFb,MAAC,GAAD,CAAC,CAAY;QACb,MAAC,GAAD,CAAC,CAAY;QACb,MAAC,GAAD,CAAC,CAAY;IACnB,CAAC;IAMJ,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAMD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAMD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;IAOD,IAAI,OAAO;QACT,OAA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CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;QAC1D,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,IAAI;QACF,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF;AAlTD,4BAkTC;AAED,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './priority-queue';
2
+ export * from './min-priority-queue';
3
+ export * from './max-priority-queue';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { PriorityQueue } from './priority-queue';
9
+ import type { PriorityQueueOptions } from '../../types';
10
+ export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
12
+ constructor(options: PriorityQueueOptions<E>);
13
+ static heapify<E extends number>(options?: Omit<PriorityQueueOptions<E>, 'comparator'>): MaxPriorityQueue<E>;
14
+ static heapify<E>(options: PriorityQueueOptions<E>): MaxPriorityQueue<E>;
15
+ }
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MaxPriorityQueue = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const priority_queue_1 = require("./priority-queue");
5
12
  class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
13
+ /**
14
+ * The constructor initializes a priority queue with an optional comparator function.
15
+ * @param [options] - The `options` parameter is an optional object that can contain various properties to configure
16
+ * the priority queue.
17
+ */
6
18
  constructor(options) {
7
19
  super(Object.assign(Object.assign({}, options), { comparator: (options === null || options === void 0 ? void 0 : options.comparator)
8
20
  ? options.comparator
@@ -11,6 +23,12 @@ class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
11
23
  return bKey - aKey;
12
24
  } }));
13
25
  }
26
+ /**
27
+ * The function `heapify` creates a max priority queue from the given options and returns it.
28
+ * @param options - The `options` parameter is an object that contains configuration options for creating a priority
29
+ * queue. It can have the following properties:
30
+ * @returns a MaxPriorityQueue object.
31
+ */
14
32
  static heapify(options) {
15
33
  const maxPQ = new MaxPriorityQueue(Object.assign(Object.assign({}, options), { comparator: (options === null || options === void 0 ? void 0 : options.comparator)
16
34
  ? options.comparator
@@ -1 +1 @@
1
- {"version":3,"file":"max-priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/max-priority-queue.ts"],"names":[],"mappings":";;;AAOA,qDAA+C;AAG/C,MAAa,gBAA0B,SAAQ,8BAAgB;IAS7D,YAAY,OAAgE;QAC1E,KAAK,iCACA,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;IACL,CAAC;IAWD,MAAM,CAAU,OAAO,CAAI,OAAgC;QACzD,MAAM,KAAK,GAAG,IAAI,gBAAgB,iCAC7B,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;QACH,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA7CD,4CA6CC"}
1
+ {"version":3,"file":"max-priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/max-priority-queue.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,qDAA+C;AAG/C,MAAa,gBAA0B,SAAQ,8BAAgB;IAI7D;;;;OAIG;IACH,YAAY,OAAgE;QAC1E,KAAK,iCACA,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;IACL,CAAC;IAKD;;;;;OAKG;IACH,MAAM,CAAU,OAAO,CAAI,OAAgC;QACzD,MAAM,KAAK,GAAG,IAAI,gBAAgB,iCAC7B,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;QACH,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA7CD,4CA6CC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { PriorityQueue } from './priority-queue';
9
+ import type { PriorityQueueOptions } from '../../types';
10
+ export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
12
+ constructor(options: PriorityQueueOptions<E>);
13
+ static heapify<E extends number>(options?: Omit<PriorityQueueOptions<E>, 'comparator'>): MinPriorityQueue<E>;
14
+ static heapify<E>(options: PriorityQueueOptions<E>): MinPriorityQueue<E>;
15
+ }
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MinPriorityQueue = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const priority_queue_1 = require("./priority-queue");
5
12
  class MinPriorityQueue extends priority_queue_1.PriorityQueue {
13
+ /**
14
+ * The constructor initializes a priority queue with an optional comparator function.
15
+ * @param [options] - The `options` parameter is an optional object that can contain various configuration options for
16
+ * the `PriorityQueue` constructor.
17
+ */
6
18
  constructor(options) {
7
19
  super(Object.assign(Object.assign({}, options), { comparator: (options === null || options === void 0 ? void 0 : options.comparator)
8
20
  ? options.comparator
@@ -11,6 +23,13 @@ class MinPriorityQueue extends priority_queue_1.PriorityQueue {
11
23
  return aKey - bKey;
12
24
  } }));
13
25
  }
26
+ /**
27
+ * The function `heapify` creates a new MinPriorityQueue instance and sets the comparator function based on the options
28
+ * provided, and then fixes the heap structure of the queue.
29
+ * @param options - The `options` parameter is an object that contains configuration options for creating a priority
30
+ * queue. It can have the following properties:
31
+ * @returns a MinPriorityQueue object.
32
+ */
14
33
  static heapify(options) {
15
34
  const minPQ = new MinPriorityQueue(Object.assign(Object.assign({}, options), { comparator: (options === null || options === void 0 ? void 0 : options.comparator)
16
35
  ? options.comparator
@@ -1 +1 @@
1
- {"version":3,"file":"min-priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/min-priority-queue.ts"],"names":[],"mappings":";;;AAOA,qDAA+C;AAG/C,MAAa,gBAA0B,SAAQ,8BAAgB;IAS7D,YAAY,OAAgE;QAC1E,KAAK,iCACA,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;IACL,CAAC;IAYD,MAAM,CAAU,OAAO,CAAI,OAAgC;QACzD,MAAM,KAAK,GAAG,IAAI,gBAAgB,iCAC7B,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;QACH,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA9CD,4CA8CC"}
1
+ {"version":3,"file":"min-priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/min-priority-queue.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,qDAA+C;AAG/C,MAAa,gBAA0B,SAAQ,8BAAgB;IAI7D;;;;OAIG;IACH,YAAY,OAAgE;QAC1E,KAAK,iCACA,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;IACL,CAAC;IAKD;;;;;;OAMG;IACH,MAAM,CAAU,OAAO,CAAI,OAAgC;QACzD,MAAM,KAAK,GAAG,IAAI,gBAAgB,iCAC7B,OAAO,KACV,UAAU,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;gBAC7B,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;oBACb,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;oBAChC,OAAO,IAAI,GAAG,IAAI,CAAC;gBACrB,CAAC,IACL,CAAC;QACH,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA9CD,4CA8CC"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions } from '../../types';
9
+ export declare class PriorityQueue<E = any> {
10
+ /**
11
+ * The constructor initializes a priority queue with the given options, including an array of nodes and a comparator
12
+ * function.
13
+ * @param options - The `options` parameter is an object that contains the following properties:
14
+ */
15
+ constructor(options: PriorityQueueOptions<E>);
16
+ protected _nodes: E[];
17
+ get nodes(): E[];
18
+ get size(): number;
19
+ /**
20
+ * The `heapify` function creates a new PriorityQueue instance and fixes the heap property.
21
+ * @param options - The "options" parameter is an object that contains the configuration options for the PriorityQueue.
22
+ * It can include properties such as "comparator" which specifies the comparison function used to order the elements in
23
+ * the priority queue, and "initialValues" which is an array of initial values to be added to the priority
24
+ * @returns a new instance of the PriorityQueue class after performing the heapify operation on it.
25
+ */
26
+ static heapify<E>(options: PriorityQueueOptions<E>): PriorityQueue<E>;
27
+ /**
28
+ * The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling
29
+ * the isValid method.
30
+ * @param options - An object containing options for creating a priority queue. The options object should have the
31
+ * following properties:
32
+ * @returns the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.
33
+ */
34
+ static isPriorityQueueified<E>(options: Omit<PriorityQueueOptions<E>, 'isFix'>): boolean;
35
+ /**
36
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
37
+ */
38
+ getNodes(): E[];
39
+ /**
40
+ * The "add" function adds a node to the heap and ensures that the heap property is maintained.
41
+ * @param {E} node - The parameter "node" is of type E, which means it can be any data type. It represents the node
42
+ * that needs to be added to the heap.
43
+ */
44
+ add(node: E): void;
45
+ /**
46
+ * The "has" function checks if a given node is present in the list of nodes.
47
+ * @param {E} node - The parameter `node` is of type `E`, which means it can be any type. It represents the node that
48
+ * we want to check if it exists in the `nodes` array.
49
+ * @returns a boolean value indicating whether the given node is included in the array of nodes.
50
+ */
51
+ has(node: E): boolean;
52
+ /**
53
+ * The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
54
+ * @returns The `peek()` function is returning the first element (`E`) of the `nodes` array if the `size` is not zero.
55
+ * Otherwise, it returns `null`.
56
+ */
57
+ peek(): E | null;
58
+ /**
59
+ * The `poll` function removes and returns the top element from a heap data structure.
60
+ * @returns The `poll()` method returns a value of type `E` or `null`.
61
+ */
62
+ poll(): E | null;
63
+ /**
64
+ * The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
65
+ * @returns The method `leaf()` is returning the last element (`E`) in the `nodes` array if it exists. If the array is
66
+ * empty or the last element is `null`, then it returns `null`.
67
+ */
68
+ leaf(): E | null;
69
+ /**
70
+ * The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the
71
+ * object is empty or not.
72
+ * @returns The method `isEmpty()` is returning a boolean value indicating whether the size of the object is equal to
73
+ * 0.
74
+ */
75
+ isEmpty(): boolean;
76
+ /**
77
+ * The clear function clears the nodes array.
78
+ */
79
+ clear(): void;
80
+ /**
81
+ * The toArray function returns an array containing all the elements in the nodes property.
82
+ * @returns An array of type E, which is the elements of the nodes property.
83
+ */
84
+ toArray(): E[];
85
+ /**
86
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the
87
+ * original instance.
88
+ * @returns The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and
89
+ * `comparator` properties as the original instance.
90
+ */
91
+ clone(): PriorityQueue<E>;
92
+ /**
93
+ * The `isValid` function recursively checks if a binary tree satisfies a certain condition.
94
+ * @returns The function `isValid()` returns a boolean value.
95
+ */
96
+ isValid(): boolean;
97
+ /**
98
+ * O(n log n), In scenarios with smaller data sizes, heap sort is generally expected to be slower than QuickSort or MergeSort.
99
+ */
100
+ /**
101
+ * The function sorts the elements in a data structure and returns them in an array.
102
+ * Plan to support sorting of duplicate elements.
103
+ * @returns The `sort()` method is returning an array of type `E[]`.
104
+ */
105
+ sort(): E[];
106
+ /**
107
+ * The dfs function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
108
+ * based on the specified traversal order.
109
+ * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
110
+ * the nodes should be visited during the Depth-First Search (dfs) traversal. It can have one of the following values:
111
+ * @returns an array of type `(E | null)[]`.
112
+ */
113
+ dfs(dfsMode: PriorityQueueDFSOrderPattern): (E | null)[];
114
+ protected _setNodes(value: E[]): void;
115
+ protected readonly _comparator: PriorityQueueComparator<E>;
116
+ /**
117
+ * The function compares two numbers using a custom comparator function.
118
+ * @param {number} a - The parameter "a" is a number that represents the index of a node in an array.
119
+ * @param {number} b - The parameter "b" is a number.
120
+ * @returns the result of the comparison between the elements at indices `a` and `b` in the `nodes` array. The
121
+ * comparison is done using the `_comparator` function, and if the result is greater than 0, `true` is returned,
122
+ * indicating that the element at index `a` is greater than the element at index `b`.
123
+ */
124
+ protected _compare(a: number, b: number): boolean;
125
+ /**
126
+ * The function swaps two elements in an array.
127
+ * @param {number} a - The parameter "a" is a number that represents the index of an element in an array.
128
+ * @param {number} b - The parameter "b" is a number.
129
+ */
130
+ protected _swap(a: number, b: number): void;
131
+ /**
132
+ * The function checks if a given index is valid within an array.
133
+ * @param {number} index - The parameter "index" is of type number and represents the index value that needs to be
134
+ * checked for validity.
135
+ * @returns A boolean value indicating whether the given index is valid or not.
136
+ */
137
+ protected _isValidIndex(index: number): boolean;
138
+ /**
139
+ * The function returns the index of the parent node given the index of a child node in a binary tree.
140
+ * @param {number} child - The "child" parameter is a number representing the index of a child node in a binary tree.
141
+ * @returns the parent of the given child node.
142
+ */
143
+ protected _getParent(child: number): number;
144
+ /**
145
+ * The function returns the index of the left child node in a binary tree given the index of its parent node.
146
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
147
+ * @returns the left child of a given parent node in a binary tree.
148
+ */
149
+ protected _getLeft(parent: number): number;
150
+ /**
151
+ * The function returns the index of the right child node in a binary tree given the index of its parent node.
152
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
153
+ * @returns the right child of a given parent node in a binary tree.
154
+ */
155
+ protected _getRight(parent: number): number;
156
+ /**
157
+ * The function returns the index of the smallest child node of a given parent node.
158
+ * @param {number} parent - The parent parameter is a number that represents the index of the parent node in a binary
159
+ * tree.
160
+ * @returns the minimum value between the parent node and its left and right child nodes.
161
+ */
162
+ protected _getComparedChild(parent: number): number;
163
+ /**
164
+ * The function `_heapifyUp` is used to maintain the heap property by moving an element up the heap until it is in the
165
+ * correct position.
166
+ * @param {number} start - The start parameter is the index of the element that needs to be moved up in the heap.
167
+ */
168
+ protected _heapifyUp(start: number): void;
169
+ /**
170
+ * The function performs a heapify operation by comparing and swapping elements in a binary heap.
171
+ * @param {number} start - The start parameter is the index of the element in the heap from where the heapifyDown
172
+ * operation should start.
173
+ */
174
+ protected _heapifyDown(start: number): void;
175
+ /**
176
+ * The _fix function performs a heapify operation on the elements of the heap starting from the middle and moving
177
+ * towards the root.
178
+ */
179
+ protected _fix(): void;
180
+ }