queue-typed 1.49.3 → 1.49.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +1 -1
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +2 -14
  3. package/dist/data-structures/binary-tree/binary-tree.js +19 -49
  4. package/dist/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  5. package/dist/data-structures/binary-tree/tree-multimap.js +1 -43
  6. package/dist/data-structures/graph/abstract-graph.d.ts +2 -11
  7. package/dist/data-structures/graph/abstract-graph.js +3 -19
  8. package/dist/data-structures/graph/directed-graph.js +4 -0
  9. package/dist/data-structures/hash/hash-map.d.ts +1 -1
  10. package/dist/data-structures/hash/hash-map.js +2 -2
  11. package/dist/data-structures/heap/heap.js +2 -3
  12. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  13. package/dist/data-structures/matrix/index.d.ts +0 -2
  14. package/dist/data-structures/matrix/index.js +0 -2
  15. package/dist/data-structures/matrix/matrix.d.ts +128 -10
  16. package/dist/data-structures/matrix/matrix.js +400 -15
  17. package/dist/data-structures/queue/deque.d.ts +2 -2
  18. package/dist/data-structures/queue/deque.js +5 -7
  19. package/dist/data-structures/queue/queue.d.ts +1 -1
  20. package/dist/types/data-structures/base/base.d.ts +1 -1
  21. package/dist/types/data-structures/heap/heap.d.ts +1 -1
  22. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  23. package/dist/utils/utils.d.ts +1 -0
  24. package/dist/utils/utils.js +6 -1
  25. package/package.json +2 -2
  26. package/src/data-structures/base/index.ts +1 -1
  27. package/src/data-structures/base/iterable-base.ts +7 -10
  28. package/src/data-structures/binary-tree/avl-tree.ts +15 -8
  29. package/src/data-structures/binary-tree/binary-tree.ts +57 -74
  30. package/src/data-structures/binary-tree/bst.ts +16 -13
  31. package/src/data-structures/binary-tree/rb-tree.ts +16 -10
  32. package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
  33. package/src/data-structures/graph/abstract-graph.ts +14 -24
  34. package/src/data-structures/graph/directed-graph.ts +8 -6
  35. package/src/data-structures/graph/map-graph.ts +6 -1
  36. package/src/data-structures/graph/undirected-graph.ts +4 -7
  37. package/src/data-structures/hash/hash-map.ts +18 -16
  38. package/src/data-structures/heap/heap.ts +7 -10
  39. package/src/data-structures/heap/max-heap.ts +2 -1
  40. package/src/data-structures/heap/min-heap.ts +2 -1
  41. package/src/data-structures/linked-list/singly-linked-list.ts +3 -5
  42. package/src/data-structures/matrix/index.ts +0 -2
  43. package/src/data-structures/matrix/matrix.ts +442 -13
  44. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  45. package/src/data-structures/queue/deque.ts +18 -39
  46. package/src/data-structures/queue/queue.ts +1 -1
  47. package/src/interfaces/binary-tree.ts +7 -2
  48. package/src/types/common.ts +4 -4
  49. package/src/types/data-structures/base/base.ts +14 -3
  50. package/src/types/data-structures/base/index.ts +1 -1
  51. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  52. package/src/types/data-structures/hash/hash-map.ts +3 -3
  53. package/src/types/data-structures/heap/heap.ts +2 -2
  54. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  55. package/src/utils/utils.ts +7 -1
  56. package/dist/data-structures/matrix/matrix2d.d.ts +0 -107
  57. package/dist/data-structures/matrix/matrix2d.js +0 -199
  58. package/dist/data-structures/matrix/vector2d.d.ts +0 -200
  59. package/dist/data-structures/matrix/vector2d.js +0 -290
  60. package/src/data-structures/matrix/matrix2d.ts +0 -211
  61. package/src/data-structures/matrix/vector2d.ts +0 -315
@@ -1,315 +0,0 @@
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
- export class Vector2D {
9
- constructor(
10
- public x: number = 0,
11
- public y: number = 0,
12
- public w: number = 1 // needed for matrix multiplication
13
- ) {
14
- }
15
-
16
- /**
17
- * The function checks if the x and y values of a point are both zero.
18
- * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
19
- */
20
- get isZero(): boolean {
21
- return this.x === 0 && this.y === 0;
22
- }
23
-
24
- /**
25
- * The above function calculates the length of a vector using the Pythagorean theorem.
26
- * @returns The length of a vector, calculated using the Pythagorean theorem.
27
- */
28
- get length(): number {
29
- return Math.sqrt(this.x * this.x + this.y * this.y);
30
- }
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
- */
36
- get lengthSq(): number {
37
- return this.x * this.x + this.y * this.y;
38
- }
39
-
40
- /**
41
- * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
42
- * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
43
- * whole number.
44
- */
45
- get rounded(): Vector2D {
46
- return new Vector2D(Math.round(this.x), Math.round(this.y));
47
- }
48
-
49
- /**
50
- * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
51
- * x and y components.
52
- * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
53
- * 2-dimensional vector with an `x` and `y` component.
54
- * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
55
- * an x and y component.
56
- * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
57
- * vectors added together.
58
- */
59
- static add(vector1: Vector2D, vector2: Vector2D): Vector2D {
60
- return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y);
61
- }
62
-
63
- /**
64
- * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
65
- * components subtracted.
66
- * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
67
- * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
68
- * respectively.
69
- * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
70
- * want to subtract from the first vector.
71
- * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
72
- * vector2.
73
- */
74
- static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D {
75
- return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y);
76
- }
77
-
78
- /**
79
- * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
80
- * object.
81
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
82
- * x and y components.
83
- * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
84
- * of the "vector" parameter.
85
- * @returns A new Vector2D object with the x and y values subtracted by the given value.
86
- */
87
- static subtractValue(vector: Vector2D, value: number): Vector2D {
88
- return new Vector2D(vector.x - value, vector.y - value);
89
- }
90
-
91
- /**
92
- * The function multiplies a Vector2D object by a given value.
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 represents the value by which the x and y components
96
- * of the vector will be multiplied.
97
- * @returns A new Vector2D object with the x and y values multiplied by the given value.
98
- */
99
- static multiply(vector: Vector2D, value: number): Vector2D {
100
- return new Vector2D(vector.x * value, vector.y * value);
101
- }
102
-
103
- /**
104
- * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
105
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
106
- * x and y components.
107
- * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
108
- * vector.
109
- * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
110
- */
111
- static divide(vector: Vector2D, value: number): Vector2D {
112
- return new Vector2D(vector.x / value, vector.y / value);
113
- }
114
-
115
- /**
116
- * The function checks if two Vector2D objects are equal by comparing their x and y values.
117
- * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
118
- * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
119
- * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
120
- * @returns a boolean value, which indicates whether the two input vectors are equal or not.
121
- */
122
- static equals(vector1: Vector2D, vector2: Vector2D): boolean {
123
- return vector1.x === vector2.x && vector1.y === vector2.y;
124
- }
125
-
126
- /**
127
- * The function checks if two Vector2D objects are equal within a specified rounding factor.
128
- * @param {Vector2D} vector1 - The first vector to compare.
129
- * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
130
- * It is used as one of the inputs for the "equalsRounded" function.
131
- * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
132
- * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
133
- * roundingFactor, the vectors are considered equal.
134
- * @returns a boolean value.
135
- */
136
- static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor = 12): boolean {
137
- const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2));
138
- if (vector.x < roundingFactor && vector.y < roundingFactor) {
139
- return true;
140
- }
141
-
142
- return false;
143
- }
144
-
145
- /**
146
- * 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
147
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
148
- * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
149
- * original vector.
150
- */
151
- static normalize(vector: Vector2D): Vector2D {
152
- const length = vector.length;
153
- if (length > 2.220446049250313e-16) {
154
- // Epsilon
155
- return Vector2D.divide(vector, length);
156
- }
157
-
158
- return vector;
159
- }
160
-
161
- /**
162
- * 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
163
- * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
164
- * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
165
- * have.
166
- * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
167
- * vector is greater than the maximum value specified.
168
- */
169
- static truncate(vector: Vector2D, max: number): Vector2D {
170
- if (vector.length > max) {
171
- return Vector2D.multiply(Vector2D.normalize(vector), max);
172
- }
173
-
174
- return vector;
175
- }
176
-
177
- /**
178
- * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
179
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
180
- * @returns A new Vector2D object is being returned.
181
- */
182
- static perp(vector: Vector2D): Vector2D {
183
- return new Vector2D(-vector.y, vector.x);
184
- }
185
-
186
- /**
187
- * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
188
- * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
189
- * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
190
- * @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
191
- */
192
- static reverse(vector: Vector2D): Vector2D {
193
- return new Vector2D(-vector.x, -vector.y);
194
- }
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
- */
204
- static abs(vector: Vector2D): Vector2D {
205
- return new Vector2D(Math.abs(vector.x), Math.abs(vector.y));
206
- }
207
-
208
- /**
209
- * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
210
- * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
211
- * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
212
- * with an x and y component.
213
- * @returns The dot product of the two input vectors.
214
- */
215
- static dot(vector1: Vector2D, vector2: Vector2D): number {
216
- return vector1.x * vector2.x + vector1.y * vector2.y;
217
- }
218
-
219
- // /**
220
- // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
221
- // * @param vectors The vectors to transform
222
- // */
223
- // static transform(vector: Vector2D, transformation: Matrix2D): Vector2D {
224
- // return Matrix2D.multiplyByVector(transformation, vector)
225
- // }
226
-
227
- // /**
228
- // * Transform vectors based on the current tranformation matrices: translation, rotation and scale
229
- // * @param vectors The vectors to transform
230
- // */
231
- // static transformList(vectors: Vector2D[], transformation: Matrix2D): Vector2D[] {
232
- // return vectors.map(vector => Matrix2D.multiplyByVector(transformation, vector))
233
- // }
234
-
235
- /**
236
- * The function calculates the distance between two points in a two-dimensional space.
237
- * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
238
- * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
239
- * in the 2D space.
240
- * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
241
- * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
242
- * the vector in a 2D space.
243
- * @returns The distance between vector1 and vector2.
244
- */
245
- static distance(vector1: Vector2D, vector2: Vector2D): number {
246
- const ySeparation = vector2.y - vector1.y;
247
- const xSeparation = vector2.x - vector1.x;
248
- return Math.sqrt(ySeparation * ySeparation + xSeparation * xSeparation);
249
- }
250
-
251
- /**
252
- * The function calculates the squared distance between two 2D vectors.
253
- * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
254
- * `Vector2D` class. It contains the x and y coordinates of the vector.
255
- * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
256
- * properties `x` and `y` which represent the coordinates of the vector.
257
- * @returns the square of the distance between the two input vectors.
258
- */
259
- static distanceSq(vector1: Vector2D, vector2: Vector2D): number {
260
- const ySeparation = vector2.y - vector1.y;
261
- const xSeparation = vector2.x - vector1.x;
262
- return ySeparation * ySeparation + xSeparation * xSeparation;
263
- }
264
-
265
- /**
266
- * The sign function determines the sign of the cross product between two 2D vectors.
267
- * (assuming the Y axis is pointing down, X axis to right like a Window app)
268
- * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
269
- * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
270
- * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
271
- * vector2. Both vector1 and vector2 are of type Vector2D.
272
- * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
273
- */
274
- static sign(vector1: Vector2D, vector2: Vector2D): number {
275
- if (vector1.y * vector2.x > vector1.x * vector2.y) {
276
- return -1;
277
- }
278
-
279
- return 1;
280
- }
281
-
282
- /**
283
- * The function calculates the angle between a given vector and the negative y-axis.
284
- * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
285
- * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
286
- * respectively.
287
- * @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
288
- */
289
- static angle(vector: Vector2D): number {
290
- const origin = new Vector2D(0, -1);
291
- const radian = Math.acos(Vector2D.dot(vector, origin) / (vector.length * origin.length));
292
- return Vector2D.sign(vector, origin) === 1 ? Math.PI * 2 - radian : radian;
293
- }
294
-
295
- /**
296
- * The function "random" generates a random Vector2D object with x and y values within the specified range.
297
- * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
298
- * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
299
- * random vector.
300
- * @returns a new instance of the Vector2D class with random x and y values.
301
- */
302
- static random(maxX: number, maxY: number): Vector2D {
303
- const randX = Math.floor(Math.random() * maxX - maxX / 2);
304
- const randY = Math.floor(Math.random() * maxY - maxY / 2);
305
- return new Vector2D(randX, randY);
306
- }
307
-
308
- /**
309
- * The function sets the values of x and y to zero.
310
- */
311
- zero(): void {
312
- this.x = 0;
313
- this.y = 0;
314
- }
315
- }