@limitlesspc/std 0.21.0 → 0.22.0

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.
@@ -1,6 +1,6 @@
1
1
  import { int, uint } from '../types.js';
2
- import { V as Vec } from '../vec3-S_YuL-W1.js';
3
- export { R as ReadonlyVec3Like, b as Vec3, a as Vec3Like, v as vec3 } from '../vec3-S_YuL-W1.js';
2
+ import { a as Vec } from '../vec3-a5RuSVIr.js';
3
+ export { R as ReadonlyVec3Like, V as Vec3, b as Vec3Like, v as vec3 } from '../vec3-a5RuSVIr.js';
4
4
 
5
5
  /**
6
6
  * Determines if a value is a number other than `NaN`
@@ -8,15 +8,14 @@ export { R as ReadonlyVec3Like, b as Vec3, a as Vec3Like, v as vec3 } from '../v
8
8
  */
9
9
  declare function isNumber(x: unknown): x is number;
10
10
  /**
11
- * Determines if a value is a finite number other than `NaN`
12
- * @param x
13
- */
14
- declare function isReal(x: unknown): x is number;
15
- /**
16
- * Determines if a value is an integer
17
- * @param x
11
+ * Squares a number, or multiplies it by itself
12
+ * @example
13
+ * ```ts
14
+ * sq(3) // 9
15
+ * sq(36) // 36
16
+ * ```
18
17
  */
19
- declare function isInteger(x: unknown): x is int;
18
+ declare function sq(x: number): number;
20
19
  /**
21
20
  * Rounds `x` to the nearest multiple of `n`
22
21
  * @param x the number to round
@@ -37,7 +36,7 @@ declare function smootherstep(x: number, min: number, max: number): number;
37
36
  declare function clamp(n: number, min: number, max: number): number;
38
37
  declare function overlap(min1: number, max1: number, min2: number, max2: number): number;
39
38
  /** Returns which number (a or b) is closer to x */
40
- declare function closer(x: number, a: [number, number], b: [number, number]): number;
39
+ declare function closer(x: number, a: number, b: number): number;
41
40
  declare function round(n: number, precision?: int): number;
42
41
  declare function floor(n: number, precision?: int): number;
43
42
  declare function ceil(n: number, precision?: int): number;
@@ -45,28 +44,31 @@ declare function trunc(n: number, precision?: int): number;
45
44
  declare function fract(x: number): number;
46
45
  declare function closeTo(n: number, target: number, precision?: int): boolean;
47
46
  declare function factorial(n: uint): number;
47
+ /**
48
+ * Logarithm using any base
49
+ * @param base the logarithm's base
50
+ * @param x the number to take the logarithm of
51
+ * @returns the exponent which the base is raised to, to equal x
52
+ */
48
53
  declare function log(base: number, x: number): number;
54
+ /**
55
+ * Natural logarithm, or log base e
56
+ * Simply an alias for `Math.log`
57
+ */
49
58
  declare const ln: (x: number) => number;
50
59
  /**
51
- * Calculates the greatest common factor between the numbers
60
+ * Calculates the greatest common factor between two numbers
52
61
  * a and b using the [Euclidean algorithm](https://www.wikiwand.com/en/Euclidean_algorithm)
53
62
  * @param a a number
54
63
  * @param b a number
55
64
  */
56
- declare function gcd(a: uint, b: uint): number;
65
+ declare function gcd(a: uint, b: uint): uint;
66
+ declare function gcd(a: bigint, b: bigint): bigint;
57
67
  declare function fibonacci(n: uint): number;
58
68
  /** Convert farhenheit to celsius */
59
69
  declare const celsius: (fahrenheit: number) => number;
60
70
  /** Convert celsius to farhenheit */
61
71
  declare const fahrenheit: (celsius: number) => number;
62
- /**
63
- * @param points a list of (x,y) points
64
- * @returns the line of best fit in terms of m and b in the form y = mx + b
65
- */
66
- declare function lineOfBestFit(points: Array<{
67
- x: number;
68
- y: number;
69
- }>): [m: number, b: number];
70
72
  /**
71
73
  * Calculates the number of ways to choose `k` items from `n` items without repeating and with ordering
72
74
  * @param n the number of items
@@ -79,7 +81,6 @@ declare function permutations(n: uint, k: uint): number;
79
81
  * @param k the number of choices being made
80
82
  */
81
83
  declare function combinations(n: uint, k: uint): number;
82
- declare function dot(a: Iterable<number>, b: Iterable<number>): number;
83
84
 
84
85
  /** @unstable */
85
86
  declare class Mat extends Float32Array {
@@ -268,9 +269,9 @@ declare function product(iter: Iterable<number>): number;
268
269
  * @returns The average
269
270
  * @example
270
271
  * ```ts
271
- * const numbers = [1, 2, 3, 4, 5];
272
+ * const numbers = [1, 2, 3, 4];
272
273
  * const average = avg(numbers);
273
- * console.log(average); // 3
274
+ * console.log(average); // 2.5
274
275
  * ```
275
276
  */
276
277
  declare function avg(iter: Iterable<number>): number;
@@ -307,14 +308,14 @@ declare function median(array: number[]): number;
307
308
  */
308
309
  declare function mode<T>(iter: Iterable<T>): T[];
309
310
  /**
310
- * Returns the variance of an iterable of numbers
311
+ * Returns the variance of an array of numbers
311
312
  * @param iter The iterable of numbers
312
313
  * @returns The variance
313
314
  * @example
314
315
  * ```ts
315
316
  * const numbers = [1, 2, 3, 4, 5];
316
317
  * const variance = variance(numbers);
317
- * console.log(variance); // 2.5
318
+ * console.log(variance); // 2
318
319
  * ```
319
320
  */
320
321
  declare function variance(iter: Iterable<number>): number;
@@ -326,7 +327,7 @@ declare function variance(iter: Iterable<number>): number;
326
327
  * ```ts
327
328
  * const numbers = [1, 2, 3, 4, 5];
328
329
  * const stddev = stddev(numbers);
329
- * console.log(stddev); // 1.5811388300841898
330
+ * console.log(stddev); // 1.414
330
331
  * ```
331
332
  */
332
333
  declare function stddev(iter: Iterable<number>): number;
@@ -345,10 +346,10 @@ declare function meanAbsDev(iter: Iterable<number>): number;
345
346
 
346
347
  /** The ratio to convert degrees to radians */
347
348
  declare const DEG2RAD: number;
348
- /** Converts radians to degrees */
349
- declare const degrees: (radians: number) => number;
350
349
  /** Converts degrees to radians */
351
350
  declare const radians: (degrees: number) => number;
351
+ /** Converts radians to degrees */
352
+ declare const degrees: (radians: number) => number;
352
353
 
353
354
  type Vec2Like = [x: number, y: number] | Float32Array;
354
355
  type ReadonlyVec2Like = Readonly<Vec2Like>;
@@ -373,10 +374,10 @@ declare class Vec2 extends Float32Array implements Vec {
373
374
  div(x: First$1, y?: number): this;
374
375
  static div(v1: Vec2, x: First$1, y?: number): Vec2;
375
376
  static fma(a: ReadonlyVec2Like, b: ReadonlyVec2Like, c: ReadonlyVec2Like): Vec2;
376
- lt(x: ReadonlyVec2Like): Vec2;
377
- lte(x: ReadonlyVec2Like): Vec2;
378
- gt(x: ReadonlyVec2Like): Vec2;
379
- gte(x: ReadonlyVec2Like): Vec2;
377
+ lt(v: ReadonlyVec2Like): Vec2;
378
+ lte(v: ReadonlyVec2Like): Vec2;
379
+ gt(v: ReadonlyVec2Like): Vec2;
380
+ gte(v: ReadonlyVec2Like): Vec2;
380
381
  mag(): number;
381
382
  setMag(n: number): this;
382
383
  magSq(): number;
@@ -437,10 +438,10 @@ declare class Vec4 extends Float32Array implements Vec {
437
438
  div(x: First, y?: number, z?: number, w?: number): this;
438
439
  static div(v1: Vec4, x: First, y?: number, z?: number, w?: number): Vec4;
439
440
  static fma(a: ReadonlyVec4Like, b: ReadonlyVec4Like, c: ReadonlyVec4Like): Vec4;
440
- lt(x: ReadonlyVec4Like): Vec4;
441
- lte(x: ReadonlyVec4Like): Vec4;
442
- gt(x: ReadonlyVec4Like): Vec4;
443
- gte(x: ReadonlyVec4Like): Vec4;
441
+ lt(v: ReadonlyVec4Like): Vec4;
442
+ lte(v: ReadonlyVec4Like): Vec4;
443
+ gt(v: ReadonlyVec4Like): Vec4;
444
+ gte(v: ReadonlyVec4Like): Vec4;
444
445
  limit(max: number): this;
445
446
  normalize(): this;
446
447
  static normalize(v: Vec4): Vec4;
@@ -460,4 +461,4 @@ declare class Vec4 extends Float32Array implements Vec {
460
461
  }
461
462
  declare function vec4(x?: First, y?: number, z?: number, w?: number): Vec4;
462
463
 
463
- export { DEG2RAD, Mat, Mat2, type Mat2Like, Mat3, type Mat3Like, Mat4, type Mat4Like, type ReadonlyMat2Like, type ReadonlyMat3Like, type ReadonlyMat4Like, type ReadonlyVec2Like, type ReadonlyVec4Like, Vec, Vec2, type Vec2Like, Vec4, type Vec4Like, avg, ceil, celsius, clamp, closeTo, closer, combinations, degrees, dot, factorial, fahrenheit, fibonacci, floor, fract, gcd, isInteger, isNumber, isReal, lerp, lineOfBestFit, ln, log, map, mat, mat2, mat3, mat4, max, meanAbsDev, median, min, minmax, mode, norm, overlap, permutations, product, radians, round, roundToEven, roundToMultiple, smootherstep, smoothstep, stddev, step, sum, trunc, variance, vec2, vec4 };
464
+ export { DEG2RAD, Mat, Mat2, type Mat2Like, Mat3, type Mat3Like, Mat4, type Mat4Like, type ReadonlyMat2Like, type ReadonlyMat3Like, type ReadonlyMat4Like, type ReadonlyVec2Like, type ReadonlyVec4Like, Vec, Vec2, type Vec2Like, Vec4, type Vec4Like, avg, ceil, celsius, clamp, closeTo, closer, combinations, degrees, factorial, fahrenheit, fibonacci, floor, fract, gcd, isNumber, lerp, ln, log, map, mat, mat2, mat3, mat4, max, meanAbsDev, median, min, minmax, mode, norm, overlap, permutations, product, radians, round, roundToEven, roundToMultiple, smootherstep, smoothstep, sq, stddev, step, sum, trunc, variance, vec2, vec4 };
@@ -15,18 +15,14 @@ import {
15
15
  closer,
16
16
  combinations,
17
17
  degrees,
18
- dot,
19
18
  factorial,
20
19
  fahrenheit,
21
20
  fibonacci,
22
21
  floor,
23
22
  fract,
24
23
  gcd,
25
- isInteger,
26
24
  isNumber,
27
- isReal,
28
25
  lerp,
29
- lineOfBestFit,
30
26
  ln,
31
27
  log,
32
28
  map,
@@ -50,6 +46,7 @@ import {
50
46
  roundToMultiple,
51
47
  smootherstep,
52
48
  smoothstep,
49
+ sq,
53
50
  stddev,
54
51
  step,
55
52
  sum,
@@ -58,12 +55,11 @@ import {
58
55
  vec2,
59
56
  vec3,
60
57
  vec4
61
- } from "../chunk-AZEZMYQ5.js";
62
- import "../chunk-O3YCU3KN.js";
63
- import "../chunk-65SNM7MP.js";
64
- import "../chunk-WBSY6KRH.js";
65
- import "../chunk-MG5VQSTV.js";
66
- import "../chunk-6F4PWJZI.js";
58
+ } from "../chunk-BSIDYYJX.js";
59
+ import "../chunk-SSSOLDLG.js";
60
+ import "../chunk-4POIKW4G.js";
61
+ import "../chunk-CCBSTDYA.js";
62
+ import "../chunk-NXILTE26.js";
67
63
  import "../chunk-TMLWLR46.js";
68
64
  import "../chunk-LJSF3QBT.js";
69
65
  export {
@@ -83,18 +79,14 @@ export {
83
79
  closer,
84
80
  combinations,
85
81
  degrees,
86
- dot,
87
82
  factorial,
88
83
  fahrenheit,
89
84
  fibonacci,
90
85
  floor,
91
86
  fract,
92
87
  gcd,
93
- isInteger,
94
88
  isNumber,
95
- isReal,
96
89
  lerp,
97
- lineOfBestFit,
98
90
  ln,
99
91
  log,
100
92
  map,
@@ -118,6 +110,7 @@ export {
118
110
  roundToMultiple,
119
111
  smootherstep,
120
112
  smoothstep,
113
+ sq,
121
114
  stddev,
122
115
  step,
123
116
  sum,
package/dist/random.js CHANGED
@@ -5,11 +5,10 @@ import {
5
5
  randomInt,
6
6
  sample,
7
7
  shuffle
8
- } from "./chunk-O3YCU3KN.js";
9
- import "./chunk-65SNM7MP.js";
10
- import "./chunk-WBSY6KRH.js";
11
- import "./chunk-MG5VQSTV.js";
12
- import "./chunk-6F4PWJZI.js";
8
+ } from "./chunk-SSSOLDLG.js";
9
+ import "./chunk-4POIKW4G.js";
10
+ import "./chunk-CCBSTDYA.js";
11
+ import "./chunk-NXILTE26.js";
13
12
  import "./chunk-TMLWLR46.js";
14
13
  import "./chunk-LJSF3QBT.js";
15
14
  export {
@@ -13,7 +13,7 @@ function listItems(items, conjunction = "and") {
13
13
  return "";
14
14
  }
15
15
  case 1: {
16
- return items[0] || "";
16
+ return items[0];
17
17
  }
18
18
  case 2: {
19
19
  return items.join(` ${conjunction} `);
@@ -65,14 +65,16 @@ function splitOnce(str, separator) {
65
65
  return [before, after];
66
66
  }
67
67
  function reverse(str) {
68
- return [...str].reverse().join("");
68
+ const chars = [...str];
69
+ chars.reverse();
70
+ return chars.join("");
69
71
  }
70
72
  function replace(str, replacements) {
71
73
  const regex = new RegExp(
72
74
  Object.keys(replacements).map(escapeRegex).join("|"),
73
75
  "g"
74
76
  );
75
- return str.replace(regex, (matched) => replacements[matched] || "");
77
+ return str.replace(regex, (matched) => replacements[matched]);
76
78
  }
77
79
  var escapeInRegexRegex = /[$()*+./?[\\\]^{|}-]/g;
78
80
  function escapeRegex(regexStr) {
@@ -1,29 +1,5 @@
1
- import { uint, int } from '../types.js';
2
1
  import { Compare } from '../cmp.js';
3
-
4
- interface Node$1<T> {
5
- value: T;
6
- next?: Node$1<T>;
7
- prev?: Node$1<T>;
8
- }
9
- declare class DoublyLinkedList<T> implements Iterable<T> {
10
- private head?;
11
- private tail?;
12
- private size;
13
- static from<T>(values: Iterable<T>): DoublyLinkedList<T>;
14
- get length(): uint;
15
- [Symbol.iterator](): Iterator<T>;
16
- getNode(index: uint): Node$1<T> | undefined;
17
- get(index: uint): T | undefined;
18
- set(index: uint, value: T): T | undefined;
19
- push(value: T): uint;
20
- pop(): T | undefined;
21
- unshift(value: T): uint;
22
- shift(): T | undefined;
23
- reverse(): this;
24
- remove(index: uint): T | undefined;
25
- splice(index: uint, count: uint, ...values: T[]): T[];
26
- }
2
+ import { uint, int } from '../types.js';
27
3
 
28
4
  /**
29
5
  * ## Binary Heap
@@ -64,55 +40,6 @@ declare class Heap<T> implements Iterable<T> {
64
40
  protected heapify(i?: number): void;
65
41
  }
66
42
 
67
- declare class MaxHeap<T> extends Heap<T> {
68
- constructor(data?: T[], heapify?: boolean);
69
- copy(): MaxHeap<T>;
70
- }
71
-
72
- declare class MinHeap<T> extends Heap<T> {
73
- constructor(data?: T[], heapify?: boolean);
74
- copy(): MinHeap<T>;
75
- }
76
-
77
- interface Node<T> {
78
- value: T;
79
- next?: Node<T>;
80
- }
81
- declare class LinkedList<T> implements Iterable<T> {
82
- node?: Node<T>;
83
- static from<T>(values: Iterable<T>): LinkedList<T>;
84
- get length(): uint;
85
- [Symbol.iterator](): Iterator<T>;
86
- get tail(): Node<T> | undefined;
87
- getNode(index: uint): Node<T> | undefined;
88
- get(index: uint): T | undefined;
89
- set(index: uint, value: T): T | undefined;
90
- push(value: T): void;
91
- pop(): Node<T> | undefined;
92
- unshift(value: T): void;
93
- shift(): Node<T> | undefined;
94
- }
95
-
96
- /**
97
- * ## Queue
98
- * A data structure that follows a first-in-first-out (FIFO) order
99
- *
100
- * | Method | Average Case | Worst Case |
101
- * | ----------- | ------------ | ---------- |
102
- * | enqueue() | O(1) | O(1) |
103
- * | dequeue() | O(1) | O(1) |
104
- *
105
- * @see https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
106
- */
107
- declare class Queue<T> implements Iterable<T> {
108
- protected items: T[];
109
- constructor(items?: T[]);
110
- get size(): uint;
111
- enqueue(item: T): uint;
112
- dequeue(): T | undefined;
113
- [Symbol.iterator](): Iterator<T>;
114
- }
115
-
116
43
  /**
117
44
  * ## Sorted Array
118
45
  * An array that maintains sorted order
@@ -181,4 +108,4 @@ declare class UnorderedArray<T> extends Array<T> {
181
108
  toSpliced(start: uint, deleteCount?: number, ...items: T[]): T[];
182
109
  }
183
110
 
184
- export { DoublyLinkedList, LinkedList, MaxHeap, MinHeap, Queue, SortedArray, UnorderedArray };
111
+ export { Heap, SortedArray, UnorderedArray };
@@ -1,24 +1,238 @@
1
1
  import {
2
- DoublyLinkedList,
3
- LinkedList,
4
- MaxHeap,
5
- MinHeap,
6
- Queue,
7
- SortedArray,
8
- UnorderedArray
9
- } from "../chunk-DYKZK6B5.js";
10
- import "../chunk-65SNM7MP.js";
11
- import "../chunk-WBSY6KRH.js";
12
- import "../chunk-MG5VQSTV.js";
13
- import "../chunk-6F4PWJZI.js";
14
- import "../chunk-TMLWLR46.js";
2
+ swap
3
+ } from "../chunk-4POIKW4G.js";
4
+ import "../chunk-CCBSTDYA.js";
5
+ import "../chunk-NXILTE26.js";
6
+ import {
7
+ ascend
8
+ } from "../chunk-TMLWLR46.js";
15
9
  import "../chunk-LJSF3QBT.js";
10
+
11
+ // src/structs/heap.ts
12
+ var Heap = class _Heap {
13
+ constructor(compare, data = [], heapify = true) {
14
+ this.compare = compare;
15
+ if (heapify) {
16
+ this.data = [];
17
+ this.push(...data);
18
+ } else {
19
+ this.data = data;
20
+ }
21
+ }
22
+ data;
23
+ get length() {
24
+ return this.data.length;
25
+ }
26
+ get height() {
27
+ return Math.floor(Math.log2(this.length)) + 1;
28
+ }
29
+ valueOf() {
30
+ return this.peek();
31
+ }
32
+ copy() {
33
+ return new _Heap(this.compare, [...this.data], false);
34
+ }
35
+ /**
36
+ * Returns the first value in the heap
37
+ */
38
+ peek() {
39
+ return this.data[0];
40
+ }
41
+ /**
42
+ * Removes the first value from the heap and returns it
43
+ */
44
+ pop() {
45
+ const first = this.data[0];
46
+ swap(this.data, 0, this.length - 1);
47
+ this.data.pop();
48
+ this.heapify();
49
+ return first;
50
+ }
51
+ /**
52
+ * Inserts values into the heap and makes sure the first value is the min/max
53
+ * @param values
54
+ * @returns The new length of the heap
55
+ */
56
+ push(...values) {
57
+ const { data, compare } = this;
58
+ for (const value of values) {
59
+ data.push(value);
60
+ let i = data.length - 1;
61
+ let parent = Math.floor((i - 1) / 2);
62
+ while (i > 0 && compare(data[i], data[parent]) < 0) {
63
+ swap(data, i, parent);
64
+ i = parent;
65
+ parent = Math.floor((i - 1) / 2);
66
+ }
67
+ }
68
+ return data.length;
69
+ }
70
+ *drain() {
71
+ while (this.length) {
72
+ yield this.pop();
73
+ }
74
+ }
75
+ [Symbol.iterator]() {
76
+ return this.data.values();
77
+ }
78
+ heapify(i = 0) {
79
+ const { length, compare, data } = this;
80
+ const left = 2 * i + 1;
81
+ const right = 2 * i + 2;
82
+ let largest = i;
83
+ if (left < length && compare(data[left], data[largest]) < 0) {
84
+ largest = left;
85
+ }
86
+ if (right < length && compare(data[right], data[largest]) < 0) {
87
+ largest = right;
88
+ }
89
+ if (largest !== i) {
90
+ swap(data, i, largest);
91
+ this.heapify(largest);
92
+ }
93
+ }
94
+ };
95
+
96
+ // src/structs/sorted-array.ts
97
+ var SortedArray = class _SortedArray {
98
+ constructor(data = [], compare = ascend, sort = true) {
99
+ this.data = data;
100
+ this.compare = compare;
101
+ if (sort) {
102
+ this.data.sort(compare);
103
+ }
104
+ }
105
+ valueOf() {
106
+ return this.at(0);
107
+ }
108
+ keys() {
109
+ return this.data.keys();
110
+ }
111
+ values() {
112
+ return this.data.values();
113
+ }
114
+ entries() {
115
+ return this.data.entries();
116
+ }
117
+ [Symbol.iterator]() {
118
+ return this.values();
119
+ }
120
+ length() {
121
+ return this.data.length;
122
+ }
123
+ at(index) {
124
+ return this.data[index];
125
+ }
126
+ copy() {
127
+ return new _SortedArray([...this.data], this.compare, false);
128
+ }
129
+ /**
130
+ * Returns the index of the value if it exists, otherwise -1
131
+ * @param value
132
+ */
133
+ indexOf(value) {
134
+ const { data } = this;
135
+ let low = 0;
136
+ let high = data.length - 1;
137
+ while (low <= high) {
138
+ const mid = Math.floor((low + high) / 2);
139
+ const cmp = this.compare(value, data[mid]);
140
+ if (cmp < 0) {
141
+ high = mid - 1;
142
+ } else if (cmp > 0) {
143
+ low = mid + 1;
144
+ } else {
145
+ return mid;
146
+ }
147
+ }
148
+ return -1;
149
+ }
150
+ /**
151
+ * Returns if the array has the value
152
+ * @param value
153
+ */
154
+ has(value) {
155
+ return this.indexOf(value) !== -1;
156
+ }
157
+ /**
158
+ * Binary inserts a value into the array while maintaining sorted order
159
+ * @param value
160
+ * @returns the index of where the value was inserted
161
+ */
162
+ push(value) {
163
+ const { data, compare } = this;
164
+ let low = 0;
165
+ let high = data.length - 1;
166
+ while (low <= high) {
167
+ const mid = Math.floor((low + high) / 2);
168
+ const cmp = compare(value, data[mid]);
169
+ if (cmp < 0) {
170
+ high = mid - 1;
171
+ } else if (cmp > 0) {
172
+ low = mid + 1;
173
+ } else {
174
+ data.splice(mid, 0, value);
175
+ return mid;
176
+ }
177
+ }
178
+ data.splice(low, 0, value);
179
+ return low;
180
+ }
181
+ };
182
+
183
+ // src/structs/unordered-array.ts
184
+ var UnorderedArray = class _UnorderedArray extends Array {
185
+ copy() {
186
+ return new _UnorderedArray(...this);
187
+ }
188
+ /**
189
+ * Inserts new elements at the end of an unordered array, and returns the new length of the unordered array.
190
+ * @param items Elements to insert at the end of the array.
191
+ */
192
+ unshift(...items) {
193
+ return super.push(...items);
194
+ }
195
+ /**
196
+ * Removes the last element from an array and returns it.
197
+ * If the array is empty, undefined is returned and the array is not modified.
198
+ */
199
+ shift() {
200
+ return super.pop();
201
+ }
202
+ /**
203
+ * Removes an item by index
204
+ * @param index the index of the item to remove
205
+ * @returns the removed item, if it exists
206
+ */
207
+ removeIndex(index) {
208
+ swap(this, index, this.length - 1);
209
+ return this.pop();
210
+ }
211
+ splice(start, deleteCount = this.length - start, ...items) {
212
+ const spliced = [];
213
+ for (let i = 0; i < deleteCount; i++) {
214
+ const replacement = items[i];
215
+ let removed;
216
+ if (replacement) {
217
+ removed = this[start + i];
218
+ this[start + i] = replacement;
219
+ } else {
220
+ removed = this.removeIndex(start);
221
+ }
222
+ if (removed) {
223
+ spliced.push(removed);
224
+ }
225
+ }
226
+ return spliced;
227
+ }
228
+ toSpliced(start, deleteCount = this.length - start, ...items) {
229
+ const copy = this.copy();
230
+ copy.splice(start, deleteCount, ...items);
231
+ return copy;
232
+ }
233
+ };
16
234
  export {
17
- DoublyLinkedList,
18
- LinkedList,
19
- MaxHeap,
20
- MinHeap,
21
- Queue,
235
+ Heap,
22
236
  SortedArray,
23
237
  UnorderedArray
24
238
  };
package/dist/types.js CHANGED
@@ -1 +0,0 @@
1
- import "./chunk-6F4PWJZI.js";
@@ -40,10 +40,10 @@ declare class Vec3 extends Float32Array implements Vec {
40
40
  div(x: First, y?: number, z?: number): this;
41
41
  static div(v1: Vec3, x: First, y?: number, z?: number): Vec3;
42
42
  static fma(a: ReadonlyVec3Like, b: ReadonlyVec3Like, c: ReadonlyVec3Like): Vec3;
43
- lt(x: ReadonlyVec3Like): Vec3;
44
- lte(x: ReadonlyVec3Like): Vec3;
45
- gt(x: ReadonlyVec3Like): Vec3;
46
- gte(x: ReadonlyVec3Like): Vec3;
43
+ lt(v: ReadonlyVec3Like): Vec3;
44
+ lte(v: ReadonlyVec3Like): Vec3;
45
+ gt(v: ReadonlyVec3Like): Vec3;
46
+ gte(v: ReadonlyVec3Like): Vec3;
47
47
  limit(max: number): this;
48
48
  normalize(): this;
49
49
  static normalize(v: Vec3): Vec3;
@@ -67,4 +67,4 @@ declare class Vec3 extends Float32Array implements Vec {
67
67
  }
68
68
  declare function vec3(x?: First, y?: number, z?: number): Vec3;
69
69
 
70
- export { type ReadonlyVec3Like as R, type Vec as V, type Vec3Like as a, Vec3 as b, vec3 as v };
70
+ export { type ReadonlyVec3Like as R, Vec3 as V, type Vec as a, type Vec3Like as b, vec3 as v };