@daneren2005/shared-memory-objects 0.0.21 → 1.1.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -167
  3. package/dist/allocated-memory.js +38 -0
  4. package/dist/allocated-memory.js.map +1 -0
  5. package/dist/cached-item-list.js +76 -0
  6. package/dist/cached-item-list.js.map +1 -0
  7. package/dist/interfaces/pow2.js +2 -0
  8. package/dist/interfaces/pow2.js.map +1 -0
  9. package/dist/interfaces/typed-array-constructor.js +2 -0
  10. package/dist/interfaces/typed-array-constructor.js.map +1 -0
  11. package/dist/interfaces/typed-array.js +2 -0
  12. package/dist/interfaces/typed-array.js.map +1 -0
  13. package/dist/local-pool.js +95 -0
  14. package/dist/local-pool.js.map +1 -0
  15. package/dist/lock/read-write-lock.js +25 -0
  16. package/dist/lock/read-write-lock.js.map +1 -0
  17. package/dist/lock/simple-lock.js +14 -0
  18. package/dist/lock/simple-lock.js.map +1 -0
  19. package/dist/memory-buffer.js +327 -0
  20. package/dist/memory-buffer.js.map +1 -0
  21. package/dist/memory-heap.js +116 -0
  22. package/dist/memory-heap.js.map +1 -0
  23. package/dist/serialize-object.js +59 -0
  24. package/dist/serialize-object.js.map +1 -0
  25. package/dist/shared-list.js +165 -0
  26. package/dist/shared-list.js.map +1 -0
  27. package/dist/shared-map.js +140 -0
  28. package/dist/shared-map.js.map +1 -0
  29. package/dist/shared-pointer-list.js +50 -0
  30. package/dist/shared-pointer-list.js.map +1 -0
  31. package/dist/shared-pool.js +165 -0
  32. package/dist/shared-pool.js.map +1 -0
  33. package/dist/shared-string.js +79 -0
  34. package/dist/shared-string.js.map +1 -0
  35. package/dist/shared-vector.js +165 -0
  36. package/dist/shared-vector.js.map +1 -0
  37. package/dist/src/memory-heap.d.ts +0 -1
  38. package/dist/src/utils/atomic-math.d.ts +4 -4
  39. package/dist/src/utils/typedarray.d.ts +278 -278
  40. package/dist/utils/16-from-32-array.js +20 -0
  41. package/dist/utils/16-from-32-array.js.map +1 -0
  42. package/dist/utils/16-from-64-array.js +12 -0
  43. package/dist/utils/16-from-64-array.js.map +1 -0
  44. package/dist/utils/atomic-math.js +36 -0
  45. package/dist/utils/atomic-math.js.map +1 -0
  46. package/dist/utils/float32-atomics.js +28 -0
  47. package/dist/utils/float32-atomics.js.map +1 -0
  48. package/dist/utils/float64-atomics.js +28 -0
  49. package/dist/utils/float64-atomics.js.map +1 -0
  50. package/dist/utils/pointer.js +44 -0
  51. package/dist/utils/pointer.js.map +1 -0
  52. package/dist/utils/typedarray.js +46 -0
  53. package/dist/utils/typedarray.js.map +1 -0
  54. package/package.json +65 -72
  55. package/dist/shared-memory-objects.js +0 -1674
  56. package/dist/shared-memory-objects.js.map +0 -1
  57. package/dist/shared-memory-objects.umd.cjs +0 -2
  58. package/dist/shared-memory-objects.umd.cjs.map +0 -1
  59. package/dist/src/main.d.ts +0 -22
@@ -1,279 +1,279 @@
1
- export type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
2
- export type NumericArray = number[] | TypedArray;
3
- export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
4
- export type BigTypedArray = BigInt64Array | BigUint64Array;
5
- export type FloatArray = Float32Array | Float64Array;
6
- export type IntArray = Int8Array | Int16Array | Int32Array;
7
- export type UIntArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
8
- export type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
9
- export type IntArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
10
- export type UIntArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
11
- export type BigIntArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
12
- export type TypedArrayConstructor = FloatArrayConstructor | IntArrayConstructor | UIntArrayConstructor;
13
- /**
14
- * Type IDs for typed array backed buffers and generally describing binary data
15
- * values.
16
- *
17
- * {@link GLType} {@link GL2TYPE} {@link TYPE2GL}
18
- */
19
- export type Type = 'u8' | 'u8c' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'f32' | 'f64';
20
- export type BigType = 'i64' | 'u64';
21
- export type UintType = 'u8' | 'u8c' | 'u16' | 'u32';
22
- export type IntType = 'i8' | 'i16' | 'i32';
23
- export type FloatType = 'f32' | 'f64';
24
- /**
25
- * WebGL numeric type constants. Use {@link GL2TYPE} to convert, if needed.
26
- *
27
- * {@link Type}
28
- * {@link GL2TYPE}
29
- * {@link TYPE2GL}
30
- */
31
- export declare enum GLType {
32
- I8 = 5120,
33
- U8 = 5121,
34
- I16 = 5122,
35
- U16 = 5123,
36
- I32 = 5124,
37
- U32 = 5125,
38
- F32 = 5126
39
- }
40
- /**
41
- * Conversion from {@link GLType} to {@link Type} enums.
42
- */
43
- export declare const GL2TYPE: Record<GLType, Type>;
44
- /**
45
- * Potentially lossy conversion from {@link Type} to {@link GLType} enums.
46
- *
47
- * Not all enums are mappable:
48
- *
49
- * - `F64` maps to `undefined`, since unsupported by WebGL
50
- * - `U8C` maps to "u8"
51
- */
52
- export declare const TYPE2GL: Record<Type, GLType | undefined>;
53
- /**
54
- * Size information (in bytes) for {@link Type} and {@link BigType}. Also see
55
- * {@link sizeOf}.
56
- */
57
- export declare const SIZEOF: {
58
- u8: number;
59
- u8c: number;
60
- i8: number;
61
- u16: number;
62
- i16: number;
63
- u32: number;
64
- i32: number;
65
- i64: number;
66
- u64: number;
67
- f32: number;
68
- f64: number;
69
- };
70
- /**
71
- * Bit shift values to convert byte addresses into array indices for all
72
- * {@link Type}s and {@link BigType}s.
73
- */
74
- export declare const BIT_SHIFTS: {
75
- i8: number;
76
- u8: number;
77
- u8c: number;
78
- i16: number;
79
- u16: number;
80
- i32: number;
81
- u32: number;
82
- i64: number;
83
- u64: number;
84
- f32: number;
85
- f64: number;
86
- };
87
- export declare const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
88
- export declare const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
89
- export declare const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
90
- export declare const BIGINT_ARRAY_CTORS: Record<BigType, BigIntArrayConstructor>;
91
- export declare const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
92
- export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
93
- u8: Uint8Array;
94
- u8c: Uint8ClampedArray;
95
- i8: Int8Array;
96
- u16: Uint16Array;
97
- i16: Int16Array;
98
- u32: Uint32Array;
99
- i32: Int32Array;
100
- f32: Float32Array;
101
- f64: Float64Array;
102
- [GLType.U8]: Uint8Array;
103
- [GLType.I8]: Int8Array;
104
- [GLType.U16]: Uint16Array;
105
- [GLType.I16]: Int16Array;
106
- [GLType.U32]: Uint32Array;
107
- [GLType.I32]: Int32Array;
108
- [GLType.F32]: Float32Array;
109
- }
110
- export interface BigTypedArrayTypeMap extends Record<BigType, BigTypedArray> {
111
- i64: BigInt64Array;
112
- u64: BigUint64Array;
113
- }
114
- /**
115
- * Returns canonical {@link Type} value of `type` by first
116
- * attempting to resolve it as {@link GLType} enum.
117
- *
118
- * @example
119
- * ```ts
120
- * asNativeType(GLType.F32) => "f32"
121
- * asNativeType("f32") => "f32"
122
- * ```
123
- *
124
- * @param type -
125
- */
126
- export declare const asNativeType: (type: GLType | Type) => Type;
127
- /**
128
- * Returns suitable {@link GLType} enum of `type`.
129
- *
130
- * @example
131
- * ```ts
132
- * asGLType("f32") => GLType.F32
133
- * asGLType(GLType.F32) => GLType.F32
134
- * ```
135
- *
136
- * @param type -
137
- */
138
- export declare const asGLType: (type: GLType | Type) => GLType;
139
- /**
140
- * Coerces given numeric args to integer values.
141
- */
142
- export declare const asInt: (...args: number[]) => number[];
143
- /**
144
- * Returns byte size for given {@link Type} ID or {@link GLType} enum.
145
- *
146
- * @param type -
147
- */
148
- export declare const sizeOf: (type: Type | BigType | GLType) => number;
149
- /**
150
- * Constructs new typed array of given {@link Type}, {@link GLType} or
151
- * {@link BigType}. Supports all arities of standard typed array ctors.
152
- *
153
- * @param type - array type enum
154
- */
155
- export declare function typedArray<T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T];
156
- export declare function typedArray<T extends Type | GLType>(type: T, src: ArrayLike<number> | ArrayBufferLike): TypedArrayTypeMap[T];
157
- export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): TypedArrayTypeMap[T];
158
- export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
159
- export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
160
- export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
161
- /**
162
- * Constructs a typed array for given `type` and populates it with given vector
163
- * values.
164
- *
165
- * @remarks
166
- * The size of the array will be `data.length * stride`, where `stride` is the
167
- * number of elements per item and defaulting to the size of the first data
168
- * item/vector given.
169
- *
170
- * @example
171
- * ```ts
172
- * // inferred stride=2 (2d vectors)
173
- * typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]);
174
- * // Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]
175
- *
176
- * // with custom stride=4
177
- * typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4);
178
- * // Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
179
- * ```
180
- *
181
- * @param type
182
- * @param data
183
- * @param stride
184
- */
185
- export declare function typedArrayOfVec<T extends Type | GLType>(type: T, data: Iterable<ArrayLike<number>>, stride?: number): TypedArrayTypeMap[T];
186
- export declare function typedArrayOfVec<T extends BigType>(type: T, data: Iterable<ArrayLike<bigint>>, stride?: number): BigTypedArrayTypeMap[T];
187
- /**
188
- * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
189
- * Standard JS arrays will default to {@link "f64"}.
190
- *
191
- * @param x -
192
- */
193
- export declare const typedArrayType: (x: NumericArray) => Type;
194
- /**
195
- * Returns the smallest possible *unsigned* int type enum for given `x`.
196
- * E.g. if `x <= 256`, the function returns `"u8"`.
197
- *
198
- * @param x - value to classify
199
- */
200
- export declare const uintTypeForSize: (x: number) => UintType;
201
- /**
202
- * Returns the smallest possible *signed* int type enum for given `x`.
203
- * E.g. if `x >= -128 && x < 128`, the function returns `"i8"`.
204
- *
205
- * @param x - value to classify
206
- */
207
- export declare const intTypeForSize: (x: number) => IntType;
208
- /**
209
- * Returns suitable {@link UintType} for given bit size (`[0,32]` range)
210
- *
211
- * @param x -
212
- */
213
- export declare const uintTypeForBits: (x: number) => UintType;
214
- /**
215
- * Returns suitable {@link IntType} for given bit size (`[0,32]` range)
216
- *
217
- * @param x -
218
- */
219
- export declare const intTypeForBits: (x: number) => IntType;
220
- /**
221
- * Returns the next smaller {@link IntType} for given type (or the same type if
222
- * already the narrowest).
223
- *
224
- * @param t
225
- */
226
- export declare const narrowInt: (t: IntType | 'i64') => 'i8' | 'i16' | 'i32';
227
- /**
228
- * Returns the next larger {@link IntType} for given type (or the same type if
229
- * already the widest).
230
- *
231
- * @param t
232
- */
233
- export declare const widenInt: (t: IntType) => 'i16' | 'i32' | 'i64';
234
- /**
235
- * Returns the next smaller {@link UintType} for given type (or the same type if
236
- * already the narrowest).
237
- *
238
- * @remarks
239
- * If type is `u8c`, returns `u8`.
240
- *
241
- * @param t
242
- */
243
- export declare const narrowUint: (t: UintType | 'u64') => 'u8' | 'u16' | 'u32';
244
- /**
245
- * Returns the next larger {@link UintType} for given type (or the same type if
246
- * already the widest).
247
- *
248
- * @param t
249
- */
250
- export declare const widenUint: (t: UintType) => 'u16' | 'u32' | 'u64';
251
- /**
252
- * Returns the next smaller {@link FloatType} for given type (or the same type
253
- * if already the narrowest).
254
- *
255
- * @param t
256
- */
257
- export declare const narrowFloat: (t: FloatType) => string;
258
- /**
259
- * Returns the next larger {@link FloatType} for given type (or the same type if
260
- * already the widest).
261
- *
262
- * @param t
263
- */
264
- export declare const widenFloat: (t: FloatType) => string;
265
- /**
266
- * Returns the next smaller type (i.e. {@link IntType}, {@link UintType} or
267
- * {@link FloatType}) for given type (or the same type if already the smallest).
268
- *
269
- * @param t
270
- */
271
- export declare const narrowType: (t: Type | BigType) => string;
272
- /**
273
- * Returns the next larger type (i.e. {@link IntType}, {@link UintType} or
274
- * {@link FloatType}) for given type (or the same type if already the widest).
275
- *
276
- * @param t
277
- */
278
- export declare const widenType: (t: Type | BigType) => string;
1
+ export type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
2
+ export type NumericArray = number[] | TypedArray;
3
+ export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
4
+ export type BigTypedArray = BigInt64Array | BigUint64Array;
5
+ export type FloatArray = Float32Array | Float64Array;
6
+ export type IntArray = Int8Array | Int16Array | Int32Array;
7
+ export type UIntArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
8
+ export type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
9
+ export type IntArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
10
+ export type UIntArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
11
+ export type BigIntArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
12
+ export type TypedArrayConstructor = FloatArrayConstructor | IntArrayConstructor | UIntArrayConstructor;
13
+ /**
14
+ * Type IDs for typed array backed buffers and generally describing binary data
15
+ * values.
16
+ *
17
+ * {@link GLType} {@link GL2TYPE} {@link TYPE2GL}
18
+ */
19
+ export type Type = 'u8' | 'u8c' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'f32' | 'f64';
20
+ export type BigType = 'i64' | 'u64';
21
+ export type UintType = 'u8' | 'u8c' | 'u16' | 'u32';
22
+ export type IntType = 'i8' | 'i16' | 'i32';
23
+ export type FloatType = 'f32' | 'f64';
24
+ /**
25
+ * WebGL numeric type constants. Use {@link GL2TYPE} to convert, if needed.
26
+ *
27
+ * {@link Type}
28
+ * {@link GL2TYPE}
29
+ * {@link TYPE2GL}
30
+ */
31
+ export declare enum GLType {
32
+ I8 = 5120,
33
+ U8 = 5121,
34
+ I16 = 5122,
35
+ U16 = 5123,
36
+ I32 = 5124,
37
+ U32 = 5125,
38
+ F32 = 5126
39
+ }
40
+ /**
41
+ * Conversion from {@link GLType} to {@link Type} enums.
42
+ */
43
+ export declare const GL2TYPE: Record<GLType, Type>;
44
+ /**
45
+ * Potentially lossy conversion from {@link Type} to {@link GLType} enums.
46
+ *
47
+ * Not all enums are mappable:
48
+ *
49
+ * - `F64` maps to `undefined`, since unsupported by WebGL
50
+ * - `U8C` maps to "u8"
51
+ */
52
+ export declare const TYPE2GL: Record<Type, GLType | undefined>;
53
+ /**
54
+ * Size information (in bytes) for {@link Type} and {@link BigType}. Also see
55
+ * {@link sizeOf}.
56
+ */
57
+ export declare const SIZEOF: {
58
+ u8: number;
59
+ u8c: number;
60
+ i8: number;
61
+ u16: number;
62
+ i16: number;
63
+ u32: number;
64
+ i32: number;
65
+ i64: number;
66
+ u64: number;
67
+ f32: number;
68
+ f64: number;
69
+ };
70
+ /**
71
+ * Bit shift values to convert byte addresses into array indices for all
72
+ * {@link Type}s and {@link BigType}s.
73
+ */
74
+ export declare const BIT_SHIFTS: {
75
+ i8: number;
76
+ u8: number;
77
+ u8c: number;
78
+ i16: number;
79
+ u16: number;
80
+ i32: number;
81
+ u32: number;
82
+ i64: number;
83
+ u64: number;
84
+ f32: number;
85
+ f64: number;
86
+ };
87
+ export declare const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
88
+ export declare const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
89
+ export declare const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
90
+ export declare const BIGINT_ARRAY_CTORS: Record<BigType, BigIntArrayConstructor>;
91
+ export declare const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
92
+ export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
93
+ u8: Uint8Array;
94
+ u8c: Uint8ClampedArray;
95
+ i8: Int8Array;
96
+ u16: Uint16Array;
97
+ i16: Int16Array;
98
+ u32: Uint32Array;
99
+ i32: Int32Array;
100
+ f32: Float32Array;
101
+ f64: Float64Array;
102
+ [GLType.U8]: Uint8Array;
103
+ [GLType.I8]: Int8Array;
104
+ [GLType.U16]: Uint16Array;
105
+ [GLType.I16]: Int16Array;
106
+ [GLType.U32]: Uint32Array;
107
+ [GLType.I32]: Int32Array;
108
+ [GLType.F32]: Float32Array;
109
+ }
110
+ export interface BigTypedArrayTypeMap extends Record<BigType, BigTypedArray> {
111
+ i64: BigInt64Array;
112
+ u64: BigUint64Array;
113
+ }
114
+ /**
115
+ * Returns canonical {@link Type} value of `type` by first
116
+ * attempting to resolve it as {@link GLType} enum.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * asNativeType(GLType.F32) => "f32"
121
+ * asNativeType("f32") => "f32"
122
+ * ```
123
+ *
124
+ * @param type -
125
+ */
126
+ export declare const asNativeType: (type: GLType | Type) => Type;
127
+ /**
128
+ * Returns suitable {@link GLType} enum of `type`.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * asGLType("f32") => GLType.F32
133
+ * asGLType(GLType.F32) => GLType.F32
134
+ * ```
135
+ *
136
+ * @param type -
137
+ */
138
+ export declare const asGLType: (type: GLType | Type) => GLType;
139
+ /**
140
+ * Coerces given numeric args to integer values.
141
+ */
142
+ export declare const asInt: (...args: number[]) => number[];
143
+ /**
144
+ * Returns byte size for given {@link Type} ID or {@link GLType} enum.
145
+ *
146
+ * @param type -
147
+ */
148
+ export declare const sizeOf: (type: Type | BigType | GLType) => number;
149
+ /**
150
+ * Constructs new typed array of given {@link Type}, {@link GLType} or
151
+ * {@link BigType}. Supports all arities of standard typed array ctors.
152
+ *
153
+ * @param type - array type enum
154
+ */
155
+ export declare function typedArray<T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T];
156
+ export declare function typedArray<T extends Type | GLType>(type: T, src: ArrayLike<number> | ArrayBufferLike): TypedArrayTypeMap[T];
157
+ export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): TypedArrayTypeMap[T];
158
+ export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
159
+ export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
160
+ export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
161
+ /**
162
+ * Constructs a typed array for given `type` and populates it with given vector
163
+ * values.
164
+ *
165
+ * @remarks
166
+ * The size of the array will be `data.length * stride`, where `stride` is the
167
+ * number of elements per item and defaulting to the size of the first data
168
+ * item/vector given.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * // inferred stride=2 (2d vectors)
173
+ * typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]);
174
+ * // Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]
175
+ *
176
+ * // with custom stride=4
177
+ * typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4);
178
+ * // Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
179
+ * ```
180
+ *
181
+ * @param type
182
+ * @param data
183
+ * @param stride
184
+ */
185
+ export declare function typedArrayOfVec<T extends Type | GLType>(type: T, data: Iterable<ArrayLike<number>>, stride?: number): TypedArrayTypeMap[T];
186
+ export declare function typedArrayOfVec<T extends BigType>(type: T, data: Iterable<ArrayLike<bigint>>, stride?: number): BigTypedArrayTypeMap[T];
187
+ /**
188
+ * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
189
+ * Standard JS arrays will default to {@link "f64"}.
190
+ *
191
+ * @param x -
192
+ */
193
+ export declare const typedArrayType: (x: NumericArray) => Type;
194
+ /**
195
+ * Returns the smallest possible *unsigned* int type enum for given `x`.
196
+ * E.g. if `x <= 256`, the function returns `"u8"`.
197
+ *
198
+ * @param x - value to classify
199
+ */
200
+ export declare const uintTypeForSize: (x: number) => UintType;
201
+ /**
202
+ * Returns the smallest possible *signed* int type enum for given `x`.
203
+ * E.g. if `x >= -128 && x < 128`, the function returns `"i8"`.
204
+ *
205
+ * @param x - value to classify
206
+ */
207
+ export declare const intTypeForSize: (x: number) => IntType;
208
+ /**
209
+ * Returns suitable {@link UintType} for given bit size (`[0,32]` range)
210
+ *
211
+ * @param x -
212
+ */
213
+ export declare const uintTypeForBits: (x: number) => UintType;
214
+ /**
215
+ * Returns suitable {@link IntType} for given bit size (`[0,32]` range)
216
+ *
217
+ * @param x -
218
+ */
219
+ export declare const intTypeForBits: (x: number) => IntType;
220
+ /**
221
+ * Returns the next smaller {@link IntType} for given type (or the same type if
222
+ * already the narrowest).
223
+ *
224
+ * @param t
225
+ */
226
+ export declare const narrowInt: (t: IntType | 'i64') => 'i8' | 'i16' | 'i32';
227
+ /**
228
+ * Returns the next larger {@link IntType} for given type (or the same type if
229
+ * already the widest).
230
+ *
231
+ * @param t
232
+ */
233
+ export declare const widenInt: (t: IntType) => 'i16' | 'i32' | 'i64';
234
+ /**
235
+ * Returns the next smaller {@link UintType} for given type (or the same type if
236
+ * already the narrowest).
237
+ *
238
+ * @remarks
239
+ * If type is `u8c`, returns `u8`.
240
+ *
241
+ * @param t
242
+ */
243
+ export declare const narrowUint: (t: UintType | 'u64') => 'u8' | 'u16' | 'u32';
244
+ /**
245
+ * Returns the next larger {@link UintType} for given type (or the same type if
246
+ * already the widest).
247
+ *
248
+ * @param t
249
+ */
250
+ export declare const widenUint: (t: UintType) => 'u16' | 'u32' | 'u64';
251
+ /**
252
+ * Returns the next smaller {@link FloatType} for given type (or the same type
253
+ * if already the narrowest).
254
+ *
255
+ * @param t
256
+ */
257
+ export declare const narrowFloat: (t: FloatType) => string;
258
+ /**
259
+ * Returns the next larger {@link FloatType} for given type (or the same type if
260
+ * already the widest).
261
+ *
262
+ * @param t
263
+ */
264
+ export declare const widenFloat: (t: FloatType) => string;
265
+ /**
266
+ * Returns the next smaller type (i.e. {@link IntType}, {@link UintType} or
267
+ * {@link FloatType}) for given type (or the same type if already the smallest).
268
+ *
269
+ * @param t
270
+ */
271
+ export declare const narrowType: (t: Type | BigType) => string;
272
+ /**
273
+ * Returns the next larger type (i.e. {@link IntType}, {@link UintType} or
274
+ * {@link FloatType}) for given type (or the same type if already the widest).
275
+ *
276
+ * @param t
277
+ */
278
+ export declare const widenType: (t: Type | BigType) => string;
279
279
  //# sourceMappingURL=typedarray.d.ts.map
@@ -0,0 +1,20 @@
1
+ const o = new ArrayBuffer(4), e = new Uint32Array(o), t = new Uint16Array(o);
2
+ function a(n, r) {
3
+ return i(Atomics.load(n, r));
4
+ }
5
+ function s(n, r, c, u) {
6
+ Atomics.store(n, r, f(c, u));
7
+ }
8
+ function i(n) {
9
+ return e[0] = n, [t[0], t[1]];
10
+ }
11
+ function f(n, r) {
12
+ return t[0] = n, t[1] = r, e[0];
13
+ }
14
+ export {
15
+ f as convert16To32,
16
+ i as convert32To16,
17
+ a as load16From32,
18
+ s as store16In32
19
+ };
20
+ //# sourceMappingURL=16-from-32-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"16-from-32-array.js","sources":["../../src/utils/16-from-32-array.ts"],"sourcesContent":["const buffer = new ArrayBuffer(4);\nconst uint32Array = new Uint32Array(buffer);\nconst uint16Array = new Uint16Array(buffer);\n\nexport function load16From32(data: Uint32Array, index: number): [number, number] {\n\treturn convert32To16(Atomics.load(data, index));\n}\n\nexport function store16In32(data: Uint32Array, index: number, value1: number, value2: number) {\n\tAtomics.store(data, index, convert16To32(value1, value2));\n}\n\nexport function convert32To16(value: number): [number, number] {\n\tuint32Array[0] = value;\n\n\treturn [uint16Array[0], uint16Array[1]];\n}\nexport function convert16To32(value1: number, value2: number): number {\n\tuint16Array[0] = value1;\n\tuint16Array[1] = value2;\n\n\treturn uint32Array[0];\n}"],"names":["buffer","uint32Array","uint16Array","load16From32","data","index","convert32To16","store16In32","value1","value2","convert16To32","value"],"mappings":"AAAA,MAAMA,IAAS,IAAI,YAAY,CAAC,GAC1BC,IAAc,IAAI,YAAYD,CAAM,GACpCE,IAAc,IAAI,YAAYF,CAAM;AAEnC,SAASG,EAAaC,GAAmBC,GAAiC;AAChF,SAAOC,EAAc,QAAQ,KAAKF,GAAMC,CAAK,CAAC;AAC/C;AAEO,SAASE,EAAYH,GAAmBC,GAAeG,GAAgBC,GAAgB;AAC7F,UAAQ,MAAML,GAAMC,GAAOK,EAAcF,GAAQC,CAAM,CAAC;AACzD;AAEO,SAASH,EAAcK,GAAiC;AAC9D,SAAAV,EAAY,CAAC,IAAIU,GAEV,CAACT,EAAY,CAAC,GAAGA,EAAY,CAAC,CAAC;AACvC;AACO,SAASQ,EAAcF,GAAgBC,GAAwB;AACrE,SAAAP,EAAY,CAAC,IAAIM,GACjBN,EAAY,CAAC,IAAIO,GAEVR,EAAY,CAAC;AACrB;"}
@@ -0,0 +1,12 @@
1
+ const o = new ArrayBuffer(8), e = new BigUint64Array(o), r = new Uint16Array(o);
2
+ function u(n, t) {
3
+ return e[0] = Atomics.load(n, t), [r[0], r[1], r[2], r[3]];
4
+ }
5
+ function A(n, t, i, a, c, s = 0) {
6
+ r[0] = i, r[1] = a, r[2] = c, r[3] = s, Atomics.store(n, t, e[0]);
7
+ }
8
+ export {
9
+ u as load16From64,
10
+ A as store16In64
11
+ };
12
+ //# sourceMappingURL=16-from-64-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"16-from-64-array.js","sources":["../../src/utils/16-from-64-array.ts"],"sourcesContent":["const buffer = new ArrayBuffer(8);\nconst uint64Array = new BigUint64Array(buffer);\nconst uint16Array = new Uint16Array(buffer);\n\nexport function load16From64(data: BigUint64Array, index: number): [number, number, number, number] {\n\tuint64Array[0] = Atomics.load(data, index);\n\t\n\treturn [uint16Array[0], uint16Array[1], uint16Array[2], uint16Array[3]];\n}\n\nexport function store16In64(data: BigUint64Array, index: number, value1: number, value2: number, value3: number, value4: number = 0) {\n\tuint16Array[0] = value1;\n\tuint16Array[1] = value2;\n\tuint16Array[2] = value3;\n\tuint16Array[3] = value4;\n\n\tAtomics.store(data, index, uint64Array[0]);\n}"],"names":["buffer","uint64Array","uint16Array","load16From64","data","index","store16In64","value1","value2","value3","value4"],"mappings":"AAAA,MAAMA,IAAS,IAAI,YAAY,CAAC,GAC1BC,IAAc,IAAI,eAAeD,CAAM,GACvCE,IAAc,IAAI,YAAYF,CAAM;AAEnC,SAASG,EAAaC,GAAsBC,GAAiD;AACnG,SAAAJ,EAAY,CAAC,IAAI,QAAQ,KAAKG,GAAMC,CAAK,GAElC,CAACH,EAAY,CAAC,GAAGA,EAAY,CAAC,GAAGA,EAAY,CAAC,GAAGA,EAAY,CAAC,CAAC;AACvE;AAEO,SAASI,EAAYF,GAAsBC,GAAeE,GAAgBC,GAAgBC,GAAgBC,IAAiB,GAAG;AACpI,EAAAR,EAAY,CAAC,IAAIK,GACjBL,EAAY,CAAC,IAAIM,GACjBN,EAAY,CAAC,IAAIO,GACjBP,EAAY,CAAC,IAAIQ,GAEjB,QAAQ,MAAMN,GAAMC,GAAOJ,EAAY,CAAC,CAAC;AAC1C;"}
@@ -0,0 +1,36 @@
1
+ import { compareExchangeFloat32 as n, loadFloat32 as u } from "./float32-atomics.js";
2
+ function i(e, l, a, c) {
3
+ let t, o;
4
+ do
5
+ t = Atomics.load(e, l), o = Math.min(t + a, c);
6
+ while (Atomics.compareExchange(e, l, t, o) !== t);
7
+ return o;
8
+ }
9
+ function d(e, l, a, c) {
10
+ let t, o;
11
+ do
12
+ t = Atomics.load(e, l), o = Math.max(t - a, c);
13
+ while (Atomics.compareExchange(e, l, t, o) !== t);
14
+ return o;
15
+ }
16
+ function h(e, l, a, c) {
17
+ let t, o;
18
+ do
19
+ t = u(e, l), o = Math.min(t + a, c);
20
+ while (n(e, l, t, o) !== t);
21
+ return o;
22
+ }
23
+ function r(e, l, a, c) {
24
+ let t, o;
25
+ do
26
+ t = u(e, l), o = Math.max(t - a, c);
27
+ while (n(e, l, t, o) !== t);
28
+ return o;
29
+ }
30
+ export {
31
+ h as addAtomicFloat32,
32
+ i as addAtomicInt,
33
+ r as subtractAtomicFloat,
34
+ d as subtractAtomicInt
35
+ };
36
+ //# sourceMappingURL=atomic-math.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic-math.js","sources":["../../src/utils/atomic-math.ts"],"sourcesContent":["import { compareExchangeFloat32, loadFloat32 } from './float32-atomics';\n\nexport function addAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, max: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = Atomics.load(array, index);\n\t\tnewValue = Math.min(oldValue + amount, max);\n\t} while(Atomics.compareExchange(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}\n\nexport function subtractAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, min: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = Atomics.load(array, index);\n\t\tnewValue = Math.max(oldValue - amount, min);\n\t} while(Atomics.compareExchange(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}\n\nexport function addAtomicFloat32(array: Float32Array, index: number, amount: number, max: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = loadFloat32(array, index);\n\t\tnewValue = Math.min(oldValue + amount, max);\n\t} while(compareExchangeFloat32(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}\n\nexport function subtractAtomicFloat(array: Float32Array, index: number, amount: number, min: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = loadFloat32(array, index);\n\t\tnewValue = Math.max(oldValue - amount, min);\n\t} while(compareExchangeFloat32(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}"],"names":["addAtomicInt","array","index","amount","max","oldValue","newValue","subtractAtomicInt","min","addAtomicFloat32","loadFloat32","compareExchangeFloat32","subtractAtomicFloat"],"mappings":";AAEO,SAASA,EAAaC,GAAiCC,GAAeC,GAAgBC,GAAa;AACzG,MAAIC,GACAC;AACJ;AACC,IAAAD,IAAW,QAAQ,KAAKJ,GAAOC,CAAK,GACpCI,IAAW,KAAK,IAAID,IAAWF,GAAQC,CAAG;AAAA,SACnC,QAAQ,gBAAgBH,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAEtE,SAAOC;AACR;AAEO,SAASC,EAAkBN,GAAiCC,GAAeC,GAAgBK,GAAa;AAC9G,MAAIH,GACAC;AACJ;AACC,IAAAD,IAAW,QAAQ,KAAKJ,GAAOC,CAAK,GACpCI,IAAW,KAAK,IAAID,IAAWF,GAAQK,CAAG;AAAA,SACnC,QAAQ,gBAAgBP,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAEtE,SAAOC;AACR;AAEO,SAASG,EAAiBR,GAAqBC,GAAeC,GAAgBC,GAAa;AACjG,MAAIC,GACAC;AACJ;AACC,IAAAD,IAAWK,EAAYT,GAAOC,CAAK,GACnCI,IAAW,KAAK,IAAID,IAAWF,GAAQC,CAAG;AAAA,SACnCO,EAAuBV,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAErE,SAAOC;AACR;AAEO,SAASM,EAAoBX,GAAqBC,GAAeC,GAAgBK,GAAa;AACpG,MAAIH,GACAC;AACJ;AACC,IAAAD,IAAWK,EAAYT,GAAOC,CAAK,GACnCI,IAAW,KAAK,IAAID,IAAWF,GAAQK,CAAG;AAAA,SACnCG,EAAuBV,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAErE,SAAOC;AACR;"}