@daneren2005/shared-memory-objects 0.0.12 → 0.0.14
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.
- package/README.md +25 -25
- package/dist/shared-memory-objects.js +452 -274
- package/dist/shared-memory-objects.js.map +1 -1
- package/dist/shared-memory-objects.umd.cjs +1 -1
- package/dist/shared-memory-objects.umd.cjs.map +1 -1
- package/dist/src/main.d.ts +3 -1
- package/dist/src/shared-pool.d.ts +1 -0
- package/dist/src/utils/atomic-math.d.ts +4 -0
- package/dist/src/utils/float32-atomics.d.ts +4 -3
- package/package.json +1 -1
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
const oe = 20, ae = 12, tt = Math.pow(2, 20), et = Math.pow(2, 12);
|
|
2
|
+
function c(i, t = 0) {
|
|
3
|
+
return k(Atomics.load(i, t));
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function O(i, t = 0) {
|
|
6
6
|
return Atomics.load(i, t);
|
|
7
7
|
}
|
|
8
8
|
function m(i, t = 0, e, r) {
|
|
9
|
-
Atomics.store(i, t,
|
|
9
|
+
Atomics.store(i, t, T(e, r));
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function v(i, t = 0, e) {
|
|
12
12
|
Atomics.store(i, t, e);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
let a =
|
|
16
|
-
return Atomics.compareExchange(i, t, a,
|
|
14
|
+
function ne(i, t, e, r, s, o) {
|
|
15
|
+
let a = T(s, o);
|
|
16
|
+
return Atomics.compareExchange(i, t, a, T(e, r)) === a;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function Y(i, t, e, r) {
|
|
19
19
|
return Atomics.compareExchange(i, t, r, e) === r;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function k(i) {
|
|
22
22
|
return {
|
|
23
23
|
bufferPosition: i & 4095,
|
|
24
24
|
bufferByteOffset: i >>> 12
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function T(i, t) {
|
|
28
28
|
return i + (t << 12);
|
|
29
29
|
}
|
|
30
|
-
class
|
|
30
|
+
class h {
|
|
31
31
|
memory;
|
|
32
32
|
bufferPosition;
|
|
33
33
|
get bufferByteOffset() {
|
|
34
34
|
return this.data.byteOffset;
|
|
35
35
|
}
|
|
36
36
|
get pointer() {
|
|
37
|
-
return
|
|
37
|
+
return T(this.bufferPosition, this.bufferByteOffset);
|
|
38
38
|
}
|
|
39
39
|
buffer;
|
|
40
40
|
data;
|
|
@@ -60,15 +60,15 @@ class c {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const
|
|
64
|
-
function
|
|
65
|
-
for (; Atomics.compareExchange(i, t,
|
|
66
|
-
"WorkerGlobalScope" in self && Atomics.wait(i, t,
|
|
63
|
+
const j = 0, F = 1;
|
|
64
|
+
function x(i, t = 0) {
|
|
65
|
+
for (; Atomics.compareExchange(i, t, j, F) !== j; )
|
|
66
|
+
"WorkerGlobalScope" in self && Atomics.wait(i, t, F);
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
Atomics.compareExchange(i, t,
|
|
68
|
+
function A(i, t = 0) {
|
|
69
|
+
Atomics.compareExchange(i, t, F, j) !== F && console.warn("We are unlocking when it was not locked!"), Atomics.notify(i, t);
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const fe = 1, Rt = {
|
|
72
72
|
5120: "i8",
|
|
73
73
|
5121: "u8",
|
|
74
74
|
5122: "i16",
|
|
@@ -76,35 +76,35 @@ const te = 1, Pt = {
|
|
|
76
76
|
5124: "i32",
|
|
77
77
|
5125: "u32",
|
|
78
78
|
5126: "f32"
|
|
79
|
-
},
|
|
79
|
+
}, $t = {
|
|
80
80
|
f32: Float32Array,
|
|
81
81
|
f64: Float64Array
|
|
82
|
-
},
|
|
82
|
+
}, zt = {
|
|
83
83
|
i8: Int8Array,
|
|
84
84
|
i16: Int16Array,
|
|
85
85
|
i32: Int32Array
|
|
86
|
-
},
|
|
86
|
+
}, Yt = {
|
|
87
87
|
u8: Uint8Array,
|
|
88
88
|
u8c: Uint8ClampedArray,
|
|
89
89
|
u16: Uint16Array,
|
|
90
90
|
u32: Uint32Array
|
|
91
|
-
},
|
|
91
|
+
}, Ht = {
|
|
92
92
|
i64: BigInt64Array,
|
|
93
93
|
u64: BigUint64Array
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
...
|
|
97
|
-
...
|
|
98
|
-
},
|
|
99
|
-
const t =
|
|
94
|
+
}, Vt = {
|
|
95
|
+
...$t,
|
|
96
|
+
...zt,
|
|
97
|
+
...Yt
|
|
98
|
+
}, Kt = (i) => {
|
|
99
|
+
const t = Rt[i];
|
|
100
100
|
return t !== void 0 ? t : i;
|
|
101
101
|
};
|
|
102
|
-
function
|
|
103
|
-
const e =
|
|
104
|
-
return new (e ||
|
|
102
|
+
function Gt(i, ...t) {
|
|
103
|
+
const e = Ht[i];
|
|
104
|
+
return new (e || Vt[Kt(i)])(...t);
|
|
105
105
|
}
|
|
106
|
-
const
|
|
107
|
-
class
|
|
106
|
+
const rt = 0, it = 1, st = 2, ot = 3, at = 4, g = 5, nt = 6, H = 1, V = 2, ft = 32, K = 0, G = 1, d = 8;
|
|
107
|
+
class X {
|
|
108
108
|
buf;
|
|
109
109
|
start;
|
|
110
110
|
u8;
|
|
@@ -112,7 +112,7 @@ class K {
|
|
|
112
112
|
state;
|
|
113
113
|
lock;
|
|
114
114
|
constructor(t = {}) {
|
|
115
|
-
if (this.buf = t.buf ? t.buf : new ArrayBuffer(t.size || 4096), this.start = t.start != null ?
|
|
115
|
+
if (this.buf = t.buf ? t.buf : new ArrayBuffer(t.size || 4096), this.start = t.start != null ? N(Math.max(t.start, 0), 4) : 0, this.u8 = new Uint8Array(this.buf), this.u32 = new Uint32Array(this.buf), this.state = new Uint32Array(this.buf, this.start, ft / 4), this.lock = new Int32Array(this.buf, this.start + this.state.byteLength - 4, 1), !t.skipInitialization) {
|
|
116
116
|
const e = t.align || 8;
|
|
117
117
|
if (e < 8)
|
|
118
118
|
throw new Error(`invalid alignment: ${e}, must be a pow2 and >= 8`);
|
|
@@ -149,8 +149,8 @@ class K {
|
|
|
149
149
|
return s && s.fill(r), s;
|
|
150
150
|
}
|
|
151
151
|
mallocAs(t, e) {
|
|
152
|
-
const r = this.malloc(e *
|
|
153
|
-
return r ?
|
|
152
|
+
const r = this.malloc(e * Xt[t]);
|
|
153
|
+
return r ? Gt(t, this.buf, r, e) : void 0;
|
|
154
154
|
}
|
|
155
155
|
calloc(t, e = 0) {
|
|
156
156
|
const r = this.malloc(t);
|
|
@@ -159,8 +159,8 @@ class K {
|
|
|
159
159
|
malloc(t) {
|
|
160
160
|
if (t <= 0)
|
|
161
161
|
return 0;
|
|
162
|
-
|
|
163
|
-
const e =
|
|
162
|
+
x(this.lock);
|
|
163
|
+
const e = N(t + d, this.align), r = this.end;
|
|
164
164
|
let s = this.top, o = this._free, a = 0;
|
|
165
165
|
for (; o; ) {
|
|
166
166
|
const f = this.blockSize(o), n = o + f >= s;
|
|
@@ -172,16 +172,16 @@ class K {
|
|
|
172
172
|
e,
|
|
173
173
|
n
|
|
174
174
|
);
|
|
175
|
-
return
|
|
175
|
+
return A(this.lock), l;
|
|
176
176
|
}
|
|
177
177
|
a = o, o = this.blockNext(o);
|
|
178
178
|
}
|
|
179
179
|
if (o = s, s = o + e, s <= r) {
|
|
180
180
|
this.initBlock(o, e, this._used), this._used = o, this.top = s;
|
|
181
181
|
let f = _(o);
|
|
182
|
-
return
|
|
182
|
+
return A(this.lock), f;
|
|
183
183
|
}
|
|
184
|
-
return
|
|
184
|
+
return A(this.lock), 0;
|
|
185
185
|
}
|
|
186
186
|
mallocTop(t, e, r, s, o) {
|
|
187
187
|
if (o && t + s > this.end) return 0;
|
|
@@ -196,7 +196,7 @@ class K {
|
|
|
196
196
|
realloc(t, e) {
|
|
197
197
|
if (e <= 0)
|
|
198
198
|
return 0;
|
|
199
|
-
const r =
|
|
199
|
+
const r = P(t);
|
|
200
200
|
let s = 0, o = this._used, a = 0;
|
|
201
201
|
for (; o; ) {
|
|
202
202
|
if (o === r) {
|
|
@@ -212,7 +212,7 @@ class K {
|
|
|
212
212
|
), _(s);
|
|
213
213
|
}
|
|
214
214
|
reallocBlock(t, e) {
|
|
215
|
-
const r = this.blockSize(t), s = t + r, o = s >= this.top, a =
|
|
215
|
+
const r = this.blockSize(t), s = t + r, o = s >= this.top, a = N(e + d, this.align);
|
|
216
216
|
if (a <= r) {
|
|
217
217
|
if (this.doSplit) {
|
|
218
218
|
const f = r - a;
|
|
@@ -220,7 +220,7 @@ class K {
|
|
|
220
220
|
} else o && (this.top = t + a);
|
|
221
221
|
return [t, s];
|
|
222
222
|
}
|
|
223
|
-
return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, s]) : (this.free(t), [
|
|
223
|
+
return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, s]) : (this.free(t), [P(this.malloc(e)), s]);
|
|
224
224
|
}
|
|
225
225
|
reallocArray(t, e) {
|
|
226
226
|
if (t.buffer !== this.buf)
|
|
@@ -239,7 +239,7 @@ class K {
|
|
|
239
239
|
e = t.byteOffset;
|
|
240
240
|
} else
|
|
241
241
|
e = t;
|
|
242
|
-
e =
|
|
242
|
+
e = P(e);
|
|
243
243
|
let r = this._used;
|
|
244
244
|
for (; r; ) {
|
|
245
245
|
if (r === e)
|
|
@@ -260,14 +260,14 @@ class K {
|
|
|
260
260
|
e = t.byteOffset;
|
|
261
261
|
} else
|
|
262
262
|
e = t;
|
|
263
|
-
|
|
263
|
+
x(this.lock), e = P(e);
|
|
264
264
|
let r = this._used, s = 0;
|
|
265
265
|
for (; r; ) {
|
|
266
266
|
if (r === e)
|
|
267
|
-
return s ? this.unlinkBlock(s, r) : this._used = this.blockNext(r), this.insert(r), this.doCompact && this.compact(),
|
|
267
|
+
return s ? this.unlinkBlock(s, r) : this._used = this.blockNext(r), this.insert(r), this.doCompact && this.compact(), A(this.lock), !0;
|
|
268
268
|
s = r, r = this.blockNext(r);
|
|
269
269
|
}
|
|
270
|
-
return
|
|
270
|
+
return A(this.lock), !1;
|
|
271
271
|
}
|
|
272
272
|
freeAll() {
|
|
273
273
|
this._free = 0, this._used = 0, this.top = this.initialTop();
|
|
@@ -276,57 +276,57 @@ class K {
|
|
|
276
276
|
return delete this.u8, delete this.u32, delete this.state, delete this.buf, !0;
|
|
277
277
|
}
|
|
278
278
|
get align() {
|
|
279
|
-
return this.state[
|
|
279
|
+
return this.state[at];
|
|
280
280
|
}
|
|
281
281
|
set align(t) {
|
|
282
|
-
this.state[
|
|
282
|
+
this.state[at] = t;
|
|
283
283
|
}
|
|
284
284
|
get end() {
|
|
285
|
-
return this.state[
|
|
285
|
+
return this.state[ot];
|
|
286
286
|
}
|
|
287
287
|
set end(t) {
|
|
288
|
-
this.state[
|
|
288
|
+
this.state[ot] = t;
|
|
289
289
|
}
|
|
290
290
|
get top() {
|
|
291
|
-
return Atomics.load(this.state,
|
|
291
|
+
return Atomics.load(this.state, st);
|
|
292
292
|
}
|
|
293
293
|
set top(t) {
|
|
294
|
-
Atomics.store(this.state,
|
|
294
|
+
Atomics.store(this.state, st, t);
|
|
295
295
|
}
|
|
296
296
|
get _free() {
|
|
297
|
-
return Atomics.load(this.state,
|
|
297
|
+
return Atomics.load(this.state, rt);
|
|
298
298
|
}
|
|
299
299
|
set _free(t) {
|
|
300
|
-
Atomics.store(this.state,
|
|
300
|
+
Atomics.store(this.state, rt, t);
|
|
301
301
|
}
|
|
302
302
|
get _used() {
|
|
303
|
-
return Atomics.load(this.state,
|
|
303
|
+
return Atomics.load(this.state, it);
|
|
304
304
|
}
|
|
305
305
|
set _used(t) {
|
|
306
|
-
Atomics.store(this.state,
|
|
306
|
+
Atomics.store(this.state, it, t);
|
|
307
307
|
}
|
|
308
308
|
get doCompact() {
|
|
309
|
-
return !!(this.state[
|
|
309
|
+
return !!(this.state[g] & H);
|
|
310
310
|
}
|
|
311
311
|
set doCompact(t) {
|
|
312
|
-
t ? this.state[
|
|
312
|
+
t ? this.state[g] |= 1 << H - 1 : this.state[g] &= ~H;
|
|
313
313
|
}
|
|
314
314
|
get doSplit() {
|
|
315
|
-
return !!(this.state[
|
|
315
|
+
return !!(this.state[g] & V);
|
|
316
316
|
}
|
|
317
317
|
set doSplit(t) {
|
|
318
|
-
t ? this.state[
|
|
318
|
+
t ? this.state[g] |= 1 << V - 1 : this.state[g] &= ~V;
|
|
319
319
|
}
|
|
320
320
|
get minSplit() {
|
|
321
|
-
return this.state[
|
|
321
|
+
return this.state[nt];
|
|
322
322
|
}
|
|
323
323
|
set minSplit(t) {
|
|
324
324
|
if (t <= d)
|
|
325
325
|
throw new Error(`illegal min split threshold: ${t}, require at least ${d + 1}`);
|
|
326
|
-
this.state[
|
|
326
|
+
this.state[nt] = t;
|
|
327
327
|
}
|
|
328
328
|
blockSize(t) {
|
|
329
|
-
return Atomics.load(this.u32, (t >> 2) +
|
|
329
|
+
return Atomics.load(this.u32, (t >> 2) + K);
|
|
330
330
|
}
|
|
331
331
|
/**
|
|
332
332
|
* Sets & returns given block size.
|
|
@@ -335,10 +335,10 @@ class K {
|
|
|
335
335
|
* @param size -
|
|
336
336
|
*/
|
|
337
337
|
setBlockSize(t, e) {
|
|
338
|
-
return Atomics.store(this.u32, (t >> 2) +
|
|
338
|
+
return Atomics.store(this.u32, (t >> 2) + K, e), e;
|
|
339
339
|
}
|
|
340
340
|
blockNext(t) {
|
|
341
|
-
return Atomics.load(this.u32, (t >> 2) +
|
|
341
|
+
return Atomics.load(this.u32, (t >> 2) + G);
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
344
344
|
* Sets block next pointer to `next`. Use zero to indicate list end.
|
|
@@ -346,7 +346,7 @@ class K {
|
|
|
346
346
|
* @param block -
|
|
347
347
|
*/
|
|
348
348
|
setBlockNext(t, e) {
|
|
349
|
-
Atomics.store(this.u32, (t >> 2) +
|
|
349
|
+
Atomics.store(this.u32, (t >> 2) + G, e);
|
|
350
350
|
}
|
|
351
351
|
/**
|
|
352
352
|
* Initializes block header with given `size` and `next` pointer. Returns `block`.
|
|
@@ -357,7 +357,7 @@ class K {
|
|
|
357
357
|
*/
|
|
358
358
|
initBlock(t, e, r) {
|
|
359
359
|
const s = t >>> 2;
|
|
360
|
-
return Atomics.store(this.u32, s +
|
|
360
|
+
return Atomics.store(this.u32, s + K, e), Atomics.store(this.u32, s + G, r), t;
|
|
361
361
|
}
|
|
362
362
|
unlinkBlock(t, e) {
|
|
363
363
|
this.setBlockNext(t, this.blockNext(e));
|
|
@@ -372,7 +372,7 @@ class K {
|
|
|
372
372
|
), this.doCompact && this.compact();
|
|
373
373
|
}
|
|
374
374
|
initialTop(t = this.align) {
|
|
375
|
-
return
|
|
375
|
+
return N(this.start + ft + d, t) - d;
|
|
376
376
|
}
|
|
377
377
|
/**
|
|
378
378
|
* Traverses free list and attempts to recursively merge blocks
|
|
@@ -411,7 +411,7 @@ class K {
|
|
|
411
411
|
r ? this.setBlockNext(r, t) : this._free = t, this.setBlockNext(t, e);
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
|
-
const _ = (i) => i > 0 ? i + d : 0,
|
|
414
|
+
const _ = (i) => i > 0 ? i + d : 0, P = (i) => i > 0 ? i - d : 0, N = (i, t) => (t--, i + t & ~t), Xt = {
|
|
415
415
|
u8: 1,
|
|
416
416
|
u8c: 1,
|
|
417
417
|
i8: 1,
|
|
@@ -423,7 +423,7 @@ const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) =>
|
|
|
423
423
|
u64: 8,
|
|
424
424
|
f32: 4,
|
|
425
425
|
f64: 8
|
|
426
|
-
},
|
|
426
|
+
}, Zt = [
|
|
427
427
|
"B",
|
|
428
428
|
"kB",
|
|
429
429
|
"MB",
|
|
@@ -433,7 +433,7 @@ const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) =>
|
|
|
433
433
|
"EB",
|
|
434
434
|
"ZB",
|
|
435
435
|
"YB"
|
|
436
|
-
],
|
|
436
|
+
], Wt = [
|
|
437
437
|
"B",
|
|
438
438
|
"KiB",
|
|
439
439
|
"MiB",
|
|
@@ -443,7 +443,7 @@ const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) =>
|
|
|
443
443
|
"EiB",
|
|
444
444
|
"ZiB",
|
|
445
445
|
"YiB"
|
|
446
|
-
],
|
|
446
|
+
], vt = [
|
|
447
447
|
"b",
|
|
448
448
|
"kbit",
|
|
449
449
|
"Mbit",
|
|
@@ -453,7 +453,7 @@ const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) =>
|
|
|
453
453
|
"Ebit",
|
|
454
454
|
"Zbit",
|
|
455
455
|
"Ybit"
|
|
456
|
-
],
|
|
456
|
+
], jt = [
|
|
457
457
|
"b",
|
|
458
458
|
"kibit",
|
|
459
459
|
"Mibit",
|
|
@@ -463,26 +463,26 @@ const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) =>
|
|
|
463
463
|
"Eibit",
|
|
464
464
|
"Zibit",
|
|
465
465
|
"Yibit"
|
|
466
|
-
],
|
|
466
|
+
], lt = (i, t, e) => {
|
|
467
467
|
let r = i;
|
|
468
468
|
return typeof t == "string" || Array.isArray(t) ? r = i.toLocaleString(t, e) : (t === !0 || e !== void 0) && (r = i.toLocaleString(void 0, e)), r;
|
|
469
|
-
},
|
|
469
|
+
}, Lt = (i) => {
|
|
470
470
|
if (typeof i == "number")
|
|
471
471
|
return Math.log10(i);
|
|
472
472
|
const t = i.toString(10);
|
|
473
473
|
return t.length + Math.log10(`0.${t.slice(0, 15)}`);
|
|
474
|
-
},
|
|
474
|
+
}, qt = (i) => typeof i == "number" ? Math.log(i) : Lt(i) * Math.log(10), Jt = (i, t) => {
|
|
475
475
|
if (typeof i == "number")
|
|
476
476
|
return i / t;
|
|
477
477
|
const e = i / BigInt(t), r = i % BigInt(t);
|
|
478
478
|
return Number(e) + Number(r) / t;
|
|
479
|
-
},
|
|
479
|
+
}, ht = (i, t) => {
|
|
480
480
|
if (t === void 0)
|
|
481
481
|
return i;
|
|
482
482
|
if (typeof t != "number" || !Number.isSafeInteger(t) || t < 0)
|
|
483
483
|
throw new TypeError(`Expected fixedWidth to be a non-negative integer, got ${typeof t}: ${t}`);
|
|
484
484
|
return t === 0 ? i : i.length < t ? i.padStart(t, " ") : i;
|
|
485
|
-
},
|
|
485
|
+
}, Qt = (i) => {
|
|
486
486
|
const { minimumFractionDigits: t, maximumFractionDigits: e } = i;
|
|
487
487
|
if (!(t === void 0 && e === void 0))
|
|
488
488
|
return {
|
|
@@ -491,7 +491,7 @@ const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) =>
|
|
|
491
491
|
roundingMode: "trunc"
|
|
492
492
|
};
|
|
493
493
|
};
|
|
494
|
-
function
|
|
494
|
+
function te(i, t) {
|
|
495
495
|
if (typeof i != "bigint" && !Number.isFinite(i))
|
|
496
496
|
throw new TypeError(`Expected a finite number, got ${typeof i}: ${i}`);
|
|
497
497
|
t = {
|
|
@@ -501,78 +501,78 @@ function Zt(i, t) {
|
|
|
501
501
|
nonBreakingSpace: !1,
|
|
502
502
|
...t
|
|
503
503
|
};
|
|
504
|
-
const e = t.bits ? t.binary ?
|
|
504
|
+
const e = t.bits ? t.binary ? jt : vt : t.binary ? Wt : Zt, r = t.space ? t.nonBreakingSpace ? " " : " " : "", s = typeof i == "number" ? i === 0 : i === 0n;
|
|
505
505
|
if (t.signed && s) {
|
|
506
506
|
const l = ` 0${r}${e[0]}`;
|
|
507
|
-
return
|
|
507
|
+
return ht(l, t.fixedWidth);
|
|
508
508
|
}
|
|
509
509
|
const o = i < 0, a = o ? "-" : t.signed ? "+" : "";
|
|
510
510
|
o && (i = -i);
|
|
511
|
-
const f =
|
|
511
|
+
const f = Qt(t);
|
|
512
512
|
let n;
|
|
513
513
|
if (i < 1) {
|
|
514
|
-
const l =
|
|
514
|
+
const l = lt(i, t.locale, f);
|
|
515
515
|
n = a + l + r + e[0];
|
|
516
516
|
} else {
|
|
517
|
-
const l = Math.min(Math.floor(t.binary ?
|
|
518
|
-
if (i =
|
|
519
|
-
const
|
|
520
|
-
i = i.toPrecision(
|
|
517
|
+
const l = Math.min(Math.floor(t.binary ? qt(i) / Math.log(1024) : Lt(i) / 3), e.length - 1);
|
|
518
|
+
if (i = Jt(i, (t.binary ? 1024 : 1e3) ** l), !f) {
|
|
519
|
+
const M = Math.max(3, Math.floor(i).toString().length);
|
|
520
|
+
i = i.toPrecision(M);
|
|
521
521
|
}
|
|
522
|
-
const
|
|
523
|
-
n = a +
|
|
522
|
+
const S = lt(Number(i), t.locale, f), z = e[l];
|
|
523
|
+
n = a + S + r + z;
|
|
524
524
|
}
|
|
525
|
-
return
|
|
525
|
+
return ht(n, t.fixedWidth);
|
|
526
526
|
}
|
|
527
|
-
const
|
|
528
|
-
class
|
|
527
|
+
const ee = 8192, ct = 0, Z = 1, I = 2;
|
|
528
|
+
class le {
|
|
529
529
|
buffers;
|
|
530
530
|
onGrowBufferHandlers = [];
|
|
531
531
|
isClone;
|
|
532
532
|
memory;
|
|
533
533
|
get bufferSize() {
|
|
534
|
-
return this.memory.data[
|
|
534
|
+
return this.memory.data[ct];
|
|
535
535
|
}
|
|
536
536
|
constructor(t) {
|
|
537
537
|
if (t && "buffers" in t)
|
|
538
|
-
this.buffers = t.buffers.map((e) => new
|
|
538
|
+
this.buffers = t.buffers.map((e) => new X({
|
|
539
539
|
buf: e,
|
|
540
540
|
skipInitialization: !0
|
|
541
|
-
})), this.memory = new
|
|
541
|
+
})), this.memory = new h(this, {
|
|
542
542
|
bufferPosition: 0,
|
|
543
543
|
bufferByteOffset: 40
|
|
544
544
|
}), this.isClone = !0;
|
|
545
545
|
else {
|
|
546
546
|
"SharedArrayBuffer" in globalThis || console.warn("SharedArrayBuffer is not working: falling back to ArrayBuffer");
|
|
547
|
-
const e = t?.bufferSize ??
|
|
548
|
-
if (e >
|
|
549
|
-
throw new Error(`Buffer size ${e} is greater than max ${
|
|
547
|
+
const e = t?.bufferSize ?? ee;
|
|
548
|
+
if (e > tt)
|
|
549
|
+
throw new Error(`Buffer size ${e} is greater than max ${tt} that we can reference with pointers`);
|
|
550
550
|
let r = this.createBuffer(e);
|
|
551
551
|
this.buffers = [
|
|
552
552
|
r
|
|
553
553
|
];
|
|
554
554
|
const s = r.callocAs("u32", 3);
|
|
555
555
|
if (s)
|
|
556
|
-
this.memory = new
|
|
556
|
+
this.memory = new h(this, {
|
|
557
557
|
bufferPosition: 0,
|
|
558
558
|
bufferByteOffset: s.byteOffset
|
|
559
559
|
});
|
|
560
560
|
else
|
|
561
561
|
throw new Error("Failed to initialize first byte from buffer");
|
|
562
|
-
this.memory.data[
|
|
562
|
+
this.memory.data[ct] = e, this.memory.data[Z] = 1, this.memory.data[I] = t?.autoGrowSize ?? 100, this.isClone = !1;
|
|
563
563
|
for (let o = 1; o < (t?.initialBuffers ?? 1); o++)
|
|
564
564
|
this.buffers.push(this.createBuffer(e));
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
addSharedBuffer(t) {
|
|
568
|
-
this.buffers[t.bufferPosition] = new
|
|
568
|
+
this.buffers[t.bufferPosition] = new X({
|
|
569
569
|
buf: t.buffer,
|
|
570
570
|
skipInitialization: !0
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
573
|
growBuffer() {
|
|
574
574
|
const t = this.createBuffer();
|
|
575
|
-
let e = Atomics.add(this.memory.data,
|
|
575
|
+
let e = Atomics.add(this.memory.data, Z, 1);
|
|
576
576
|
return this.buffers[e] = t, this.onGrowBufferHandlers.forEach((r) => r({
|
|
577
577
|
bufferPosition: e,
|
|
578
578
|
buffer: t.buf
|
|
@@ -581,7 +581,7 @@ class ee {
|
|
|
581
581
|
createBuffer(t) {
|
|
582
582
|
const e = t ?? this.bufferSize;
|
|
583
583
|
let r;
|
|
584
|
-
return "SharedArrayBuffer" in globalThis ? r = new SharedArrayBuffer(e) : r = new ArrayBuffer(e), new
|
|
584
|
+
return "SharedArrayBuffer" in globalThis ? r = new SharedArrayBuffer(e) : r = new ArrayBuffer(e), new X({
|
|
585
585
|
buf: r,
|
|
586
586
|
// We can't use this unless we can 100% guarantee that every thread will stop using memory the instant it is freed
|
|
587
587
|
// ex: Allocate 16 bytes. Thread A frees that allocation and then allocates 12 bytes and 4 bytes, but Thread B is mid-execution on the old allocation can changes the internal state of the 4-byte allocation breaking everything
|
|
@@ -601,17 +601,17 @@ class ee {
|
|
|
601
601
|
continue;
|
|
602
602
|
const a = o.callocAs("u32", t);
|
|
603
603
|
if (a)
|
|
604
|
-
return s === this.buffers.length - 1 && Atomics.load(this.memory.data,
|
|
604
|
+
return s === this.buffers.length - 1 && Atomics.load(this.memory.data, Z) === this.buffers.length && this.memory.data[I] < 100 && this.memory.data[I] > 0 && o.top / o.end > this.memory.data[I] / 100 && this.growBuffer(), new h(this, {
|
|
605
605
|
data: a,
|
|
606
606
|
buffer: o
|
|
607
607
|
});
|
|
608
608
|
}
|
|
609
|
-
if (this.buffers.length >=
|
|
610
|
-
throw new Error(`Can't initialize a new buffer since it would have a position greater than the max of ${
|
|
609
|
+
if (this.buffers.length >= et)
|
|
610
|
+
throw new Error(`Can't initialize a new buffer since it would have a position greater than the max of ${et}`);
|
|
611
611
|
let e = this.growBuffer();
|
|
612
612
|
const r = e.callocAs("u32", t);
|
|
613
613
|
if (r)
|
|
614
|
-
return new
|
|
614
|
+
return new h(this, {
|
|
615
615
|
data: r,
|
|
616
616
|
buffer: e
|
|
617
617
|
});
|
|
@@ -619,7 +619,7 @@ class ee {
|
|
|
619
619
|
}
|
|
620
620
|
getSharedAlloc(t) {
|
|
621
621
|
if (this.buffers[t.bufferPosition] !== void 0)
|
|
622
|
-
return new
|
|
622
|
+
return new h(this, t);
|
|
623
623
|
}
|
|
624
624
|
get currentUsed() {
|
|
625
625
|
return this.totalAllocated - this.buffers.reduce((t, e) => t + e.stats().available, 0);
|
|
@@ -628,7 +628,7 @@ class ee {
|
|
|
628
628
|
return this.buffers[0].buf.byteLength * this.buffers.length;
|
|
629
629
|
}
|
|
630
630
|
prettyMemory() {
|
|
631
|
-
return `${
|
|
631
|
+
return `${ut(this.currentUsed)} / ${ut(this.totalAllocated)}`;
|
|
632
632
|
}
|
|
633
633
|
getSharedMemory() {
|
|
634
634
|
return {
|
|
@@ -636,16 +636,16 @@ class ee {
|
|
|
636
636
|
};
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
|
-
function
|
|
640
|
-
return
|
|
639
|
+
function ut(i) {
|
|
640
|
+
return te(i, {
|
|
641
641
|
binary: !0,
|
|
642
642
|
minimumFractionDigits: 1,
|
|
643
643
|
maximumFractionDigits: 1
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
|
-
const
|
|
646
|
+
const dt = 4, yt = 1, E = 2;
|
|
647
647
|
class u {
|
|
648
|
-
static ALLOCATE_COUNT =
|
|
648
|
+
static ALLOCATE_COUNT = dt;
|
|
649
649
|
memory;
|
|
650
650
|
/* First block
|
|
651
651
|
32 index 0
|
|
@@ -670,7 +670,7 @@ class u {
|
|
|
670
670
|
uint16Array;
|
|
671
671
|
onDelete;
|
|
672
672
|
get length() {
|
|
673
|
-
return Atomics.load(this.firstBlock.data,
|
|
673
|
+
return Atomics.load(this.firstBlock.data, E);
|
|
674
674
|
}
|
|
675
675
|
get type() {
|
|
676
676
|
return Atomics.load(this.uint16Array, 0);
|
|
@@ -686,9 +686,9 @@ class u {
|
|
|
686
686
|
}
|
|
687
687
|
constructor(t, e) {
|
|
688
688
|
if (this.memory = t, e && "firstBlock" in e)
|
|
689
|
-
this.firstBlock = new
|
|
689
|
+
this.firstBlock = new h(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (E + 1) * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
690
690
|
else {
|
|
691
|
-
e && e.initWithBlock ? this.firstBlock = new
|
|
691
|
+
e && e.initWithBlock ? this.firstBlock = new h(t, e.initWithBlock) : this.firstBlock = t.allocUI32(dt), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (E + 1) * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
692
692
|
const r = e?.type ?? Uint32Array;
|
|
693
693
|
r === Uint32Array ? this.type = 0 : r === Int32Array ? this.type = 1 : r === Float32Array && (this.type = 2), this.dataLength = e?.dataLength ?? 1;
|
|
694
694
|
}
|
|
@@ -698,18 +698,18 @@ class u {
|
|
|
698
698
|
let e = this.dataLength;
|
|
699
699
|
if (t.length > e)
|
|
700
700
|
throw new Error(`Can't insert ${t.length} array into shared list of ${e} dataLength`);
|
|
701
|
-
let r = this.memory.allocUI32(
|
|
701
|
+
let r = this.memory.allocUI32(yt + e), s = this.getDataBlock(r.data), o = r.pointer;
|
|
702
702
|
for (let n = 0; n < t.length; n++)
|
|
703
703
|
s instanceof Int32Array || s instanceof Uint32Array ? Atomics.store(s, n, t[n]) : s[n] = t[n];
|
|
704
704
|
let a, f = !1;
|
|
705
705
|
for (; !f; )
|
|
706
|
-
a =
|
|
706
|
+
a = O(this.firstBlock.data, 1), f = Y(this.firstBlock.data, 1, o, a);
|
|
707
707
|
if (a) {
|
|
708
|
-
let { bufferPosition: n, bufferByteOffset: l } =
|
|
709
|
-
|
|
708
|
+
let { bufferPosition: n, bufferByteOffset: l } = k(a), S = new Uint32Array(this.memory.buffers[n].buf, l, 1);
|
|
709
|
+
v(S, 0, o);
|
|
710
710
|
} else
|
|
711
|
-
|
|
712
|
-
Atomics.add(this.firstBlock.data,
|
|
711
|
+
v(this.firstBlock.data, 0, o);
|
|
712
|
+
Atomics.add(this.firstBlock.data, E, 1);
|
|
713
713
|
}
|
|
714
714
|
deleteMatch(t) {
|
|
715
715
|
for (let { data: e, index: r, deleteCurrent: s } of this)
|
|
@@ -733,39 +733,39 @@ class u {
|
|
|
733
733
|
clear() {
|
|
734
734
|
let t, e, r = !1;
|
|
735
735
|
for (; !r; ) {
|
|
736
|
-
if (t =
|
|
736
|
+
if (t = O(this.firstBlock.data, 0), e = O(this.firstBlock.data, 1), !e)
|
|
737
737
|
return;
|
|
738
|
-
r =
|
|
738
|
+
r = Y(this.firstBlock.data, 1, 0, e);
|
|
739
739
|
}
|
|
740
740
|
if (!t)
|
|
741
741
|
return;
|
|
742
|
-
|
|
742
|
+
Y(this.firstBlock.data, 0, 0, t);
|
|
743
743
|
let s = 0, o = t;
|
|
744
744
|
for (; o; ) {
|
|
745
|
-
let { bufferPosition: a, bufferByteOffset: f } =
|
|
745
|
+
let { bufferPosition: a, bufferByteOffset: f } = k(o), n = this.memory.buffers[a];
|
|
746
746
|
if (!n)
|
|
747
747
|
break;
|
|
748
748
|
let l = new Uint32Array(n.buf, f, 2);
|
|
749
|
-
o =
|
|
749
|
+
o = O(l, 0), s++, this.onDelete && this.onDelete(this.getDataBlock(l)), n.free(l.byteOffset);
|
|
750
750
|
}
|
|
751
|
-
Atomics.sub(this.firstBlock.data,
|
|
751
|
+
Atomics.sub(this.firstBlock.data, E, s);
|
|
752
752
|
}
|
|
753
753
|
*[Symbol.iterator]() {
|
|
754
|
-
let t = 0, { bufferPosition: e, bufferByteOffset: r } =
|
|
754
|
+
let t = 0, { bufferPosition: e, bufferByteOffset: r } = c(this.firstBlock.data, 0), s = this.firstBlock.data, o = 0, a = 0;
|
|
755
755
|
for (; r; ) {
|
|
756
756
|
let f = this.memory.buffers[e];
|
|
757
757
|
if (!f)
|
|
758
758
|
return;
|
|
759
|
-
let n = new Uint32Array(f.buf, r, 2), l = this.getDataBlock(n),
|
|
760
|
-
({ bufferPosition: e, bufferByteOffset: r } =
|
|
761
|
-
let
|
|
759
|
+
let n = new Uint32Array(f.buf, r, 2), l = this.getDataBlock(n), S = e, z = r;
|
|
760
|
+
({ bufferPosition: e, bufferByteOffset: r } = c(n, 0));
|
|
761
|
+
let M = !0;
|
|
762
762
|
yield {
|
|
763
763
|
data: l,
|
|
764
764
|
index: t,
|
|
765
765
|
deleteCurrent: () => {
|
|
766
|
-
m(s, 0, e, r), r || m(this.firstBlock.data, 1, o, a), this.onDelete && this.onDelete(this.getDataBlock(n)), f.free(n.byteOffset), Atomics.sub(this.firstBlock.data,
|
|
766
|
+
m(s, 0, e, r), r || m(this.firstBlock.data, 1, o, a), this.onDelete && this.onDelete(this.getDataBlock(n)), f.free(n.byteOffset), Atomics.sub(this.firstBlock.data, E, 1), M = !1;
|
|
767
767
|
}
|
|
768
|
-
},
|
|
768
|
+
}, M && (s = n, o = S, a = z, t++);
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
forEach(t) {
|
|
@@ -778,7 +778,7 @@ class u {
|
|
|
778
778
|
};
|
|
779
779
|
}
|
|
780
780
|
getDataBlock(t) {
|
|
781
|
-
const e = t.byteOffset +
|
|
781
|
+
const e = t.byteOffset + yt * t.BYTES_PER_ELEMENT;
|
|
782
782
|
switch (this.type) {
|
|
783
783
|
case 1:
|
|
784
784
|
return new Int32Array(t.buffer, e, this.dataLength);
|
|
@@ -791,26 +791,26 @@ class u {
|
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
free() {
|
|
794
|
-
let { bufferPosition: t, bufferByteOffset: e } =
|
|
794
|
+
let { bufferPosition: t, bufferByteOffset: e } = c(this.firstBlock.data, 0);
|
|
795
795
|
for (; e; ) {
|
|
796
|
-
let r = new
|
|
796
|
+
let r = new h(this.memory, {
|
|
797
797
|
bufferPosition: t,
|
|
798
798
|
bufferByteOffset: e
|
|
799
799
|
});
|
|
800
|
-
({ bufferPosition: t, bufferByteOffset: e } =
|
|
800
|
+
({ bufferPosition: t, bufferByteOffset: e } = c(r.data, 0)), this.onDelete && this.onDelete(this.getDataBlock(r.data)), r.free();
|
|
801
801
|
}
|
|
802
802
|
this.firstBlock.free();
|
|
803
803
|
}
|
|
804
804
|
}
|
|
805
|
-
const
|
|
806
|
-
class
|
|
805
|
+
const Bt = 10;
|
|
806
|
+
class St {
|
|
807
807
|
static ALLOCATE_COUNT = 4;
|
|
808
808
|
memory;
|
|
809
809
|
// Memory order: Pointer, Lock, Length, MaxHash
|
|
810
810
|
pointerMemory;
|
|
811
811
|
lock;
|
|
812
812
|
get hashMemory() {
|
|
813
|
-
return new
|
|
813
|
+
return new h(this.memory, c(this.pointerMemory.data, 0));
|
|
814
814
|
}
|
|
815
815
|
get length() {
|
|
816
816
|
return Atomics.load(this.pointerMemory.data, 2);
|
|
@@ -820,21 +820,21 @@ class At {
|
|
|
820
820
|
}
|
|
821
821
|
constructor(t, e) {
|
|
822
822
|
if (this.memory = t, e)
|
|
823
|
-
this.pointerMemory = new
|
|
823
|
+
this.pointerMemory = new h(t, e.firstBlock);
|
|
824
824
|
else {
|
|
825
|
-
this.pointerMemory = t.allocUI32(
|
|
826
|
-
let r = t.allocUI32(
|
|
827
|
-
m(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3,
|
|
825
|
+
this.pointerMemory = t.allocUI32(St.ALLOCATE_COUNT);
|
|
826
|
+
let r = t.allocUI32(Bt);
|
|
827
|
+
m(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3, Bt);
|
|
828
828
|
}
|
|
829
829
|
this.lock = new Int32Array(this.pointerMemory.data.buffer, this.pointerMemory.bufferByteOffset + Uint32Array.BYTES_PER_ELEMENT, 1);
|
|
830
830
|
}
|
|
831
831
|
set(t, e) {
|
|
832
832
|
this.length >= this.maxHash * 2 && this.growHashTable();
|
|
833
|
-
let r =
|
|
833
|
+
let r = U(t);
|
|
834
834
|
this.setHashKey(this.hashMemory, this.maxHash, r, e) && Atomics.add(this.pointerMemory.data, 2, 1);
|
|
835
835
|
}
|
|
836
836
|
setHashKey(t, e, r, s) {
|
|
837
|
-
let o = this.hash(r, e), a, f =
|
|
837
|
+
let o = this.hash(r, e), a, f = c(t.data, o);
|
|
838
838
|
if (f.bufferByteOffset === 0) {
|
|
839
839
|
a = new u(this.memory, {
|
|
840
840
|
dataLength: 2
|
|
@@ -849,7 +849,7 @@ class At {
|
|
|
849
849
|
return a.deleteValue(r) && (n = !1), a.insert([r, s]), n;
|
|
850
850
|
}
|
|
851
851
|
get(t) {
|
|
852
|
-
let e =
|
|
852
|
+
let e = U(t), r = this.hash(e, this.maxHash), s = c(this.hashMemory.data, r);
|
|
853
853
|
if (s.bufferByteOffset === 0)
|
|
854
854
|
return;
|
|
855
855
|
let o = new u(this.memory, {
|
|
@@ -860,7 +860,7 @@ class At {
|
|
|
860
860
|
return a[1];
|
|
861
861
|
}
|
|
862
862
|
has(t) {
|
|
863
|
-
let e =
|
|
863
|
+
let e = U(t), r = this.hash(e, this.maxHash), s = c(this.hashMemory.data, r);
|
|
864
864
|
if (s.bufferByteOffset === 0)
|
|
865
865
|
return !1;
|
|
866
866
|
let o = new u(this.memory, {
|
|
@@ -872,7 +872,7 @@ class At {
|
|
|
872
872
|
return !1;
|
|
873
873
|
}
|
|
874
874
|
delete(t) {
|
|
875
|
-
let e =
|
|
875
|
+
let e = U(t), r = this.hash(e, this.maxHash), s = c(this.hashMemory.data, r);
|
|
876
876
|
if (s.bufferByteOffset === 0)
|
|
877
877
|
return !1;
|
|
878
878
|
let o = new u(this.memory, {
|
|
@@ -886,7 +886,7 @@ class At {
|
|
|
886
886
|
growHashTable() {
|
|
887
887
|
let t = this.maxHash, e = t * 2, r = this.memory.allocUI32(e), s = this.hashMemory;
|
|
888
888
|
for (let o = 0; o < t; o++) {
|
|
889
|
-
let a =
|
|
889
|
+
let a = c(s.data, o);
|
|
890
890
|
if (a.bufferByteOffset === 0)
|
|
891
891
|
continue;
|
|
892
892
|
let f = new u(this.memory, {
|
|
@@ -902,7 +902,7 @@ class At {
|
|
|
902
902
|
}
|
|
903
903
|
free() {
|
|
904
904
|
for (let t = 0; t < this.maxHash; t++) {
|
|
905
|
-
let e =
|
|
905
|
+
let e = c(this.hashMemory.data, t);
|
|
906
906
|
if (e.bufferByteOffset === 0)
|
|
907
907
|
continue;
|
|
908
908
|
new u(this.memory, {
|
|
@@ -917,10 +917,10 @@ class At {
|
|
|
917
917
|
};
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
|
-
function
|
|
921
|
-
return typeof i == "number" ? i : typeof i == "string" ?
|
|
920
|
+
function U(i) {
|
|
921
|
+
return typeof i == "number" ? i : typeof i == "string" ? re(i) : i;
|
|
922
922
|
}
|
|
923
|
-
function
|
|
923
|
+
function re(i) {
|
|
924
924
|
let t = i.length, e = 17 ^ t, r = 0, s;
|
|
925
925
|
for (; t >= 4; )
|
|
926
926
|
s = i.charCodeAt(r) & 255 | (i.charCodeAt(++r) & 255) << 8 | (i.charCodeAt(++r) & 255) << 16 | (i.charCodeAt(++r) & 255) << 14, s = (s & 65535) * 1540483477 + (((s >>> 16) * 1540483477 & 65535) << 16), s ^= s >>> 14, s = (s & 65535) * 1540483477 + (((s >>> 16) * 1540483477 & 65535) << 16), e = (e & 65535) * 1540483477 + (((e >>> 16) * 1540483477 & 65535) << 16) ^ s, t -= 4, ++r;
|
|
@@ -934,7 +934,7 @@ function vt(i) {
|
|
|
934
934
|
}
|
|
935
935
|
return e ^= e >>> 13, e = (e & 65535) * 1540483477 + (((e >>> 16) * 1540483477 & 65535) << 16), e ^= e >>> 15, e = e >>> 0, e;
|
|
936
936
|
}
|
|
937
|
-
class
|
|
937
|
+
class he {
|
|
938
938
|
memory;
|
|
939
939
|
list;
|
|
940
940
|
constructor(t, e) {
|
|
@@ -944,15 +944,15 @@ class re {
|
|
|
944
944
|
return this.list.length;
|
|
945
945
|
}
|
|
946
946
|
insert(t) {
|
|
947
|
-
this.list.insert(
|
|
947
|
+
this.list.insert(T(t.memory.bufferPosition, t.memory.bufferByteOffset));
|
|
948
948
|
}
|
|
949
949
|
delete(t) {
|
|
950
|
-
return this.list.deleteValue(
|
|
950
|
+
return this.list.deleteValue(T(t.memory.bufferPosition, t.memory.bufferByteOffset));
|
|
951
951
|
}
|
|
952
952
|
*[Symbol.iterator]() {
|
|
953
953
|
let t = this.list[Symbol.iterator]();
|
|
954
954
|
for (let { data: e } of t) {
|
|
955
|
-
let { bufferPosition: r, bufferByteOffset: s } =
|
|
955
|
+
let { bufferPosition: r, bufferByteOffset: s } = c(e, 0), o = new h(this.memory, {
|
|
956
956
|
bufferPosition: r,
|
|
957
957
|
bufferByteOffset: s
|
|
958
958
|
});
|
|
@@ -977,11 +977,11 @@ class re {
|
|
|
977
977
|
this.list.free();
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
|
-
const
|
|
980
|
+
const mt = {
|
|
981
981
|
1: Uint8Array,
|
|
982
982
|
2: Uint16Array
|
|
983
|
-
},
|
|
984
|
-
class
|
|
983
|
+
}, C = 0, bt = 1, At = 2, kt = 3;
|
|
984
|
+
class _t {
|
|
985
985
|
static ALLOCATE_COUNT = 4;
|
|
986
986
|
memory;
|
|
987
987
|
allocatedMemory;
|
|
@@ -989,11 +989,11 @@ class gt {
|
|
|
989
989
|
cachedPointer;
|
|
990
990
|
cachedString;
|
|
991
991
|
constructor(t, e) {
|
|
992
|
-
this.memory = t, typeof e == "string" ? (this.allocatedMemory = this.memory.allocUI32(
|
|
992
|
+
this.memory = t, typeof e == "string" ? (this.allocatedMemory = this.memory.allocUI32(_t.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + kt * this.allocatedMemory.data.BYTES_PER_ELEMENT), this.updateString(e)) : (this.allocatedMemory = new h(t, e), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + kt * this.allocatedMemory.data.BYTES_PER_ELEMENT), "value" in e && this.updateString(e.value));
|
|
993
993
|
}
|
|
994
994
|
updateString(t) {
|
|
995
995
|
let e = this.createString(t);
|
|
996
|
-
|
|
996
|
+
x(this.lock), v(this.allocatedMemory.data, C, e.pointer), Atomics.store(this.allocatedMemory.data, bt, t.length), Atomics.store(this.allocatedMemory.data, At, e.charType), A(this.lock), this.cachedPointer = e.pointer, this.cachedString = t;
|
|
997
997
|
}
|
|
998
998
|
createString(t) {
|
|
999
999
|
if (t === "")
|
|
@@ -1005,7 +1005,7 @@ class gt {
|
|
|
1005
1005
|
let e = [];
|
|
1006
1006
|
for (let n = 0; n < t.length; n++)
|
|
1007
1007
|
e.push(t.charCodeAt(n));
|
|
1008
|
-
let s = Math.max(...e) > 255 ? 2 : 1, o =
|
|
1008
|
+
let s = Math.max(...e) > 255 ? 2 : 1, o = mt[s], a = this.memory.allocUI32(Math.ceil(t.length / (4 / o.BYTES_PER_ELEMENT))), f = new o(a.data.buffer, a.data.byteOffset, t.length);
|
|
1009
1009
|
for (let n = 0; n < t.length; n++)
|
|
1010
1010
|
f[n] = t.charCodeAt(n);
|
|
1011
1011
|
return {
|
|
@@ -1014,18 +1014,18 @@ class gt {
|
|
|
1014
1014
|
};
|
|
1015
1015
|
}
|
|
1016
1016
|
get value() {
|
|
1017
|
-
let t =
|
|
1017
|
+
let t = O(this.allocatedMemory.data, C);
|
|
1018
1018
|
if (this.cachedPointer === t && this.cachedString !== void 0)
|
|
1019
1019
|
return this.cachedString;
|
|
1020
1020
|
if (t === 0)
|
|
1021
1021
|
return "";
|
|
1022
|
-
let { bufferPosition: e, bufferByteOffset: r } =
|
|
1023
|
-
|
|
1024
|
-
let s = Atomics.load(this.allocatedMemory.data,
|
|
1025
|
-
return
|
|
1022
|
+
let { bufferPosition: e, bufferByteOffset: r } = k(t);
|
|
1023
|
+
x(this.lock);
|
|
1024
|
+
let s = Atomics.load(this.allocatedMemory.data, At), o = mt[s], a = Atomics.load(this.allocatedMemory.data, bt), f = new o(this.memory.buffers[e].buf, r, a), n = String.fromCharCode.apply(null, f);
|
|
1025
|
+
return A(this.lock), this.cachedPointer = t, this.cachedString = n, n;
|
|
1026
1026
|
}
|
|
1027
1027
|
set value(t) {
|
|
1028
|
-
let { bufferPosition: e, bufferByteOffset: r } =
|
|
1028
|
+
let { bufferPosition: e, bufferByteOffset: r } = c(this.allocatedMemory.data, C);
|
|
1029
1029
|
this.updateString(t), r && this.memory.buffers[e].free(r);
|
|
1030
1030
|
}
|
|
1031
1031
|
getSharedMemory() {
|
|
@@ -1035,19 +1035,19 @@ class gt {
|
|
|
1035
1035
|
return this.allocatedMemory.pointer;
|
|
1036
1036
|
}
|
|
1037
1037
|
free() {
|
|
1038
|
-
let { bufferPosition: t, bufferByteOffset: e } =
|
|
1038
|
+
let { bufferPosition: t, bufferByteOffset: e } = c(this.allocatedMemory.data, C);
|
|
1039
1039
|
e && this.memory.buffers[t].free(e), this.allocatedMemory.free();
|
|
1040
1040
|
}
|
|
1041
1041
|
}
|
|
1042
|
-
const
|
|
1043
|
-
class
|
|
1042
|
+
const w = 0, b = 1, gt = 2, Et = 3, W = 4;
|
|
1043
|
+
class y {
|
|
1044
1044
|
static ALLOCATE_COUNT = 4;
|
|
1045
1045
|
memory;
|
|
1046
1046
|
// Pointer, List Length, Buffer Length, Type/DataLength
|
|
1047
1047
|
firstBlock;
|
|
1048
1048
|
uint16Array;
|
|
1049
1049
|
get length() {
|
|
1050
|
-
return Atomics.load(this.firstBlock.data,
|
|
1050
|
+
return Atomics.load(this.firstBlock.data, b);
|
|
1051
1051
|
}
|
|
1052
1052
|
get type() {
|
|
1053
1053
|
return this.uint16Array[0];
|
|
@@ -1062,10 +1062,10 @@ class kt {
|
|
|
1062
1062
|
Atomics.store(this.uint16Array, 1, t);
|
|
1063
1063
|
}
|
|
1064
1064
|
get bufferLength() {
|
|
1065
|
-
return Atomics.load(this.firstBlock.data,
|
|
1065
|
+
return Atomics.load(this.firstBlock.data, gt);
|
|
1066
1066
|
}
|
|
1067
1067
|
set bufferLength(t) {
|
|
1068
|
-
Atomics.store(this.firstBlock.data,
|
|
1068
|
+
Atomics.store(this.firstBlock.data, gt, t);
|
|
1069
1069
|
}
|
|
1070
1070
|
get pointer() {
|
|
1071
1071
|
return this.firstBlock.pointer;
|
|
@@ -1074,18 +1074,18 @@ class kt {
|
|
|
1074
1074
|
cachedPointer;
|
|
1075
1075
|
constructor(t, e) {
|
|
1076
1076
|
if (this.memory = t, e && "firstBlock" in e) {
|
|
1077
|
-
if (this.firstBlock = new
|
|
1078
|
-
let r = t.allocUI32(
|
|
1079
|
-
m(this.firstBlock.data,
|
|
1077
|
+
if (this.firstBlock = new h(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + Et * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in e || "dataLength" in e) {
|
|
1078
|
+
let r = t.allocUI32(W * (e.dataLength ?? 1));
|
|
1079
|
+
m(this.firstBlock.data, w, r.bufferPosition, r.bufferByteOffset), this.bufferLength = W, this.dataLength = e.dataLength ?? 1;
|
|
1080
1080
|
}
|
|
1081
1081
|
if ("type" in e) {
|
|
1082
1082
|
const r = e?.type ?? Uint32Array;
|
|
1083
1083
|
r === Uint32Array ? this.type = 0 : r === Int32Array ? this.type = 1 : r === Float32Array && (this.type = 2);
|
|
1084
1084
|
}
|
|
1085
1085
|
} else {
|
|
1086
|
-
this.firstBlock = t.allocUI32(
|
|
1087
|
-
let r = e?.dataLength ?? 1, s = e?.bufferLength ??
|
|
1088
|
-
m(this.firstBlock.data,
|
|
1086
|
+
this.firstBlock = t.allocUI32(y.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + Et * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
1087
|
+
let r = e?.dataLength ?? 1, s = e?.bufferLength ?? W, o = t.allocUI32(s * r);
|
|
1088
|
+
m(this.firstBlock.data, w, o.bufferPosition, o.bufferByteOffset), this.bufferLength = s;
|
|
1089
1089
|
const a = e?.type ?? Uint32Array;
|
|
1090
1090
|
a === Uint32Array ? this.type = 0 : a === Int32Array ? this.type = 1 : a === Float32Array && (this.type = 2), this.dataLength = r;
|
|
1091
1091
|
}
|
|
@@ -1111,10 +1111,10 @@ class kt {
|
|
|
1111
1111
|
if (t.length > e)
|
|
1112
1112
|
throw new Error(`Can't insert ${t.length} array into shared list of ${e} dataLength`);
|
|
1113
1113
|
let r = this.getFullDataBlock(), s = this.length;
|
|
1114
|
-
return r.set(t, e * s), Atomics.add(this.firstBlock.data,
|
|
1114
|
+
return r.set(t, e * s), Atomics.add(this.firstBlock.data, b, 1) + 1 >= this.bufferLength && this.growBuffer(), s;
|
|
1115
1115
|
}
|
|
1116
1116
|
pop() {
|
|
1117
|
-
let t = Atomics.sub(this.firstBlock.data,
|
|
1117
|
+
let t = Atomics.sub(this.firstBlock.data, b, b), e = this.getFullDataBlock();
|
|
1118
1118
|
return this.getDataBlock(e, t - 1);
|
|
1119
1119
|
}
|
|
1120
1120
|
deleteIndex(t) {
|
|
@@ -1125,10 +1125,10 @@ class kt {
|
|
|
1125
1125
|
for (let o = t; o < e; o++)
|
|
1126
1126
|
for (let a = 0; a < r; a++)
|
|
1127
1127
|
s[o * r + a] = s[(o + 1) * r + a];
|
|
1128
|
-
Atomics.sub(this.firstBlock.data,
|
|
1128
|
+
Atomics.sub(this.firstBlock.data, b, b);
|
|
1129
1129
|
}
|
|
1130
1130
|
clear() {
|
|
1131
|
-
this.firstBlock.data[
|
|
1131
|
+
this.firstBlock.data[b] = 0;
|
|
1132
1132
|
}
|
|
1133
1133
|
*[Symbol.iterator]() {
|
|
1134
1134
|
let t = this.getFullDataBlock();
|
|
@@ -1136,10 +1136,10 @@ class kt {
|
|
|
1136
1136
|
yield this.getDataBlock(t, e);
|
|
1137
1137
|
}
|
|
1138
1138
|
getFullDataBlock() {
|
|
1139
|
-
let t = Atomics.load(this.firstBlock.data,
|
|
1139
|
+
let t = Atomics.load(this.firstBlock.data, w);
|
|
1140
1140
|
if (this.cachedPointer === t && this.cachedFullDataBlock)
|
|
1141
1141
|
return this.cachedFullDataBlock;
|
|
1142
|
-
let e =
|
|
1142
|
+
let e = k(t), r = new h(this.memory, e), s;
|
|
1143
1143
|
switch (this.type) {
|
|
1144
1144
|
case 1:
|
|
1145
1145
|
s = new Int32Array(r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
|
|
@@ -1160,7 +1160,7 @@ class kt {
|
|
|
1160
1160
|
return t.subarray(r, r + this.dataLength);
|
|
1161
1161
|
}
|
|
1162
1162
|
growBuffer() {
|
|
1163
|
-
let e = this.bufferLength * 2, r = this.dataLength, s =
|
|
1163
|
+
let e = this.bufferLength * 2, r = this.dataLength, s = c(this.firstBlock.data, w), o = new h(this.memory, s), a = this.getFullDataBlock(), f = this.memory.allocUI32(e * r), n;
|
|
1164
1164
|
switch (this.type) {
|
|
1165
1165
|
case 1:
|
|
1166
1166
|
n = new Int32Array(f.data.buffer, f.bufferByteOffset, r * this.bufferLength);
|
|
@@ -1174,11 +1174,11 @@ class kt {
|
|
|
1174
1174
|
default:
|
|
1175
1175
|
throw new Error(`Unknown data block type ${this.type}`);
|
|
1176
1176
|
}
|
|
1177
|
-
n.set(a), m(this.firstBlock.data,
|
|
1177
|
+
n.set(a), m(this.firstBlock.data, w, f.bufferPosition, f.bufferByteOffset), this.bufferLength = e, o.free();
|
|
1178
1178
|
}
|
|
1179
1179
|
free() {
|
|
1180
|
-
let t =
|
|
1181
|
-
new
|
|
1180
|
+
let t = c(this.firstBlock.data, w);
|
|
1181
|
+
new h(this.memory, t).free(), this.firstBlock.free();
|
|
1182
1182
|
}
|
|
1183
1183
|
getSharedMemory() {
|
|
1184
1184
|
return {
|
|
@@ -1186,7 +1186,7 @@ class kt {
|
|
|
1186
1186
|
};
|
|
1187
1187
|
}
|
|
1188
1188
|
}
|
|
1189
|
-
class
|
|
1189
|
+
class ce {
|
|
1190
1190
|
static ALLOCATE_COUNT = u.ALLOCATE_COUNT;
|
|
1191
1191
|
heap;
|
|
1192
1192
|
list;
|
|
@@ -1257,100 +1257,278 @@ class ie {
|
|
|
1257
1257
|
this.list.free(), this.cache.clear();
|
|
1258
1258
|
}
|
|
1259
1259
|
}
|
|
1260
|
-
const
|
|
1260
|
+
const D = 0, wt = 1, pt = 2, q = 3, Tt = q + y.ALLOCATE_COUNT;
|
|
1261
|
+
class Ot {
|
|
1262
|
+
static ALLOCATE_COUNT = 3 + y.ALLOCATE_COUNT * 2;
|
|
1263
|
+
memory;
|
|
1264
|
+
// Current Length, Type/DataLength, MaxChunkLength, Pointer vector, Recycle vector
|
|
1265
|
+
firstBlock;
|
|
1266
|
+
uint16Array;
|
|
1267
|
+
pointerVector;
|
|
1268
|
+
recycleVector;
|
|
1269
|
+
cachedFullDataBlock = {};
|
|
1270
|
+
get length() {
|
|
1271
|
+
return Atomics.load(this.firstBlock.data, D) - this.recycleVector.length;
|
|
1272
|
+
}
|
|
1273
|
+
get maxChunkSize() {
|
|
1274
|
+
return this.firstBlock.data[pt];
|
|
1275
|
+
}
|
|
1276
|
+
set maxChunkSize(t) {
|
|
1277
|
+
Atomics.store(this.firstBlock.data, pt, t);
|
|
1278
|
+
}
|
|
1279
|
+
get type() {
|
|
1280
|
+
return this.uint16Array[0];
|
|
1281
|
+
}
|
|
1282
|
+
set type(t) {
|
|
1283
|
+
Atomics.store(this.uint16Array, 0, t);
|
|
1284
|
+
}
|
|
1285
|
+
get dataLength() {
|
|
1286
|
+
return Math.max(1, this.uint16Array[1]);
|
|
1287
|
+
}
|
|
1288
|
+
set dataLength(t) {
|
|
1289
|
+
Atomics.store(this.uint16Array, 1, t);
|
|
1290
|
+
}
|
|
1291
|
+
get bufferLength() {
|
|
1292
|
+
return this.maxChunkSize * this.pointerVector.length;
|
|
1293
|
+
}
|
|
1294
|
+
constructor(t, e) {
|
|
1295
|
+
if (this.memory = t, e && "firstBlock" in e)
|
|
1296
|
+
this.firstBlock = new h(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + wt * Uint32Array.BYTES_PER_ELEMENT, 2), this.pointerVector = new y(t, {
|
|
1297
|
+
firstBlock: {
|
|
1298
|
+
bufferPosition: this.firstBlock.bufferPosition,
|
|
1299
|
+
bufferByteOffset: this.firstBlock.bufferByteOffset + q * Uint32Array.BYTES_PER_ELEMENT
|
|
1300
|
+
}
|
|
1301
|
+
}), this.recycleVector = new y(t, {
|
|
1302
|
+
firstBlock: {
|
|
1303
|
+
bufferPosition: this.firstBlock.bufferPosition,
|
|
1304
|
+
bufferByteOffset: this.firstBlock.bufferByteOffset + Tt * Uint32Array.BYTES_PER_ELEMENT
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
else {
|
|
1308
|
+
this.firstBlock = t.allocUI32(Ot.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + wt * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
1309
|
+
let r = e?.dataLength ?? 1, s = e?.maxChunkSize ?? 100;
|
|
1310
|
+
this.pointerVector = new y(t, {
|
|
1311
|
+
type: Uint32Array,
|
|
1312
|
+
firstBlock: {
|
|
1313
|
+
bufferPosition: this.firstBlock.bufferPosition,
|
|
1314
|
+
bufferByteOffset: this.firstBlock.bufferByteOffset + q * Uint32Array.BYTES_PER_ELEMENT
|
|
1315
|
+
}
|
|
1316
|
+
}), this.recycleVector = new y(t, {
|
|
1317
|
+
type: Uint32Array,
|
|
1318
|
+
firstBlock: {
|
|
1319
|
+
bufferPosition: this.firstBlock.bufferPosition,
|
|
1320
|
+
bufferByteOffset: this.firstBlock.bufferByteOffset + Tt * Uint32Array.BYTES_PER_ELEMENT
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
let o = t.allocUI32(s * r);
|
|
1324
|
+
this.pointerVector.push(o.pointer);
|
|
1325
|
+
const a = e?.type ?? Uint32Array;
|
|
1326
|
+
a === Uint32Array ? this.type = 0 : a === Int32Array ? this.type = 1 : a === Float32Array && (this.type = 2), this.dataLength = r, this.maxChunkSize = s;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
at(t) {
|
|
1330
|
+
let e = this.getFullDataBlock(t);
|
|
1331
|
+
return this.getDataBlock(e, t % this.maxChunkSize);
|
|
1332
|
+
}
|
|
1333
|
+
get(t, e = 0) {
|
|
1334
|
+
const r = this.dataLength;
|
|
1335
|
+
if (e >= r)
|
|
1336
|
+
throw new Error(`${e} is out of dataLength bounds ${r}`);
|
|
1337
|
+
return this.getFullDataBlock(t)[t % this.maxChunkSize * r + e];
|
|
1338
|
+
}
|
|
1339
|
+
push(t) {
|
|
1340
|
+
typeof t == "number" && (t = [t]);
|
|
1341
|
+
let e = this.dataLength;
|
|
1342
|
+
if (t.length > e)
|
|
1343
|
+
throw new Error(`Can't insert ${t.length} array into shared list of ${e} dataLength`);
|
|
1344
|
+
let r;
|
|
1345
|
+
this.recycleVector.length ? r = this.recycleVector.pop()[0] : r = Atomics.add(this.firstBlock.data, D, 1);
|
|
1346
|
+
let s = this.getFullDataBlock(r), o = r % this.maxChunkSize;
|
|
1347
|
+
return s.set(t, e * o), r;
|
|
1348
|
+
}
|
|
1349
|
+
deleteIndex(t) {
|
|
1350
|
+
this.recycleVector.push(t);
|
|
1351
|
+
}
|
|
1352
|
+
clear() {
|
|
1353
|
+
this.firstBlock.data[D] = 0;
|
|
1354
|
+
}
|
|
1355
|
+
*[Symbol.iterator]() {
|
|
1356
|
+
let t = [...this.recycleVector].reduce((s, o) => (s.push(...o), s), []), e = this.getFullDataBlock(0), r = 0;
|
|
1357
|
+
for (let s = 0; s < Atomics.load(this.firstBlock.data, D); s++)
|
|
1358
|
+
if (!t.includes(s)) {
|
|
1359
|
+
let o = Math.floor(s / this.maxChunkSize);
|
|
1360
|
+
o !== r && (e = this.getFullDataBlock(s), r = o), yield this.getDataBlock(e, s % this.maxChunkSize);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
getFullDataBlock(t) {
|
|
1364
|
+
let e = Math.floor(t / this.maxChunkSize), r = this.cachedFullDataBlock[e];
|
|
1365
|
+
if (r)
|
|
1366
|
+
return r;
|
|
1367
|
+
if (e >= this.pointerVector.length) {
|
|
1368
|
+
let a = this.memory.allocUI32(this.maxChunkSize * this.dataLength);
|
|
1369
|
+
this.pointerVector.push(a.pointer);
|
|
1370
|
+
}
|
|
1371
|
+
let s = new h(this.memory, k(this.pointerVector.get(e))), o;
|
|
1372
|
+
switch (this.type) {
|
|
1373
|
+
case 1:
|
|
1374
|
+
o = new Int32Array(s.data.buffer, s.bufferByteOffset, this.dataLength * this.maxChunkSize);
|
|
1375
|
+
break;
|
|
1376
|
+
case 0:
|
|
1377
|
+
o = new Uint32Array(s.data.buffer, s.bufferByteOffset, this.dataLength * this.maxChunkSize);
|
|
1378
|
+
break;
|
|
1379
|
+
case 2:
|
|
1380
|
+
o = new Float32Array(s.data.buffer, s.bufferByteOffset, this.dataLength * this.maxChunkSize);
|
|
1381
|
+
break;
|
|
1382
|
+
default:
|
|
1383
|
+
throw new Error(`Unknown data block type ${this.type}`);
|
|
1384
|
+
}
|
|
1385
|
+
return this.cachedFullDataBlock[e] = o, o;
|
|
1386
|
+
}
|
|
1387
|
+
getDataBlock(t, e) {
|
|
1388
|
+
const r = e * this.dataLength;
|
|
1389
|
+
return t.subarray(r, r + this.dataLength);
|
|
1390
|
+
}
|
|
1391
|
+
free() {
|
|
1392
|
+
this.recycleVector.free();
|
|
1393
|
+
for (let t of this.pointerVector) {
|
|
1394
|
+
let e = t[0];
|
|
1395
|
+
new h(this.memory, k(e)).free();
|
|
1396
|
+
}
|
|
1397
|
+
this.pointerVector.free(), this.firstBlock.free();
|
|
1398
|
+
}
|
|
1399
|
+
getSharedMemory() {
|
|
1400
|
+
return {
|
|
1401
|
+
firstBlock: this.firstBlock.getSharedMemory()
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
const Mt = new ArrayBuffer(4), Pt = new Uint32Array(Mt), R = new Uint16Array(Mt);
|
|
1406
|
+
function ue(i, t) {
|
|
1407
|
+
return ie(Atomics.load(i, t));
|
|
1408
|
+
}
|
|
1409
|
+
function de(i, t, e, r) {
|
|
1410
|
+
Atomics.store(i, t, se(e, r));
|
|
1411
|
+
}
|
|
1412
|
+
function ie(i) {
|
|
1413
|
+
return Pt[0] = i, [R[0], R[1]];
|
|
1414
|
+
}
|
|
1261
1415
|
function se(i, t) {
|
|
1262
|
-
return
|
|
1416
|
+
return R[0] = i, R[1] = t, Pt[0];
|
|
1417
|
+
}
|
|
1418
|
+
const Nt = new ArrayBuffer(8), It = new BigUint64Array(Nt), B = new Uint16Array(Nt);
|
|
1419
|
+
function ye(i, t) {
|
|
1420
|
+
return It[0] = Atomics.load(i, t), [B[0], B[1], B[2], B[3]];
|
|
1421
|
+
}
|
|
1422
|
+
function Be(i, t, e, r, s, o = 0) {
|
|
1423
|
+
B[0] = e, B[1] = r, B[2] = s, B[3] = o, Atomics.store(i, t, It[0]);
|
|
1263
1424
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1425
|
+
const Ut = new ArrayBuffer(4), Ct = new Float32Array(Ut), Dt = new Int32Array(Ut);
|
|
1426
|
+
function Ft(i, t) {
|
|
1427
|
+
return i instanceof Float32Array && (i = new Int32Array(i.buffer, i.byteOffset, i.length)), Q(Atomics.load(i, t));
|
|
1266
1428
|
}
|
|
1267
|
-
function
|
|
1268
|
-
|
|
1429
|
+
function me(i, t, e) {
|
|
1430
|
+
i instanceof Float32Array && (i = new Int32Array(i.buffer, i.byteOffset, i.length)), Atomics.store(i, t, $(e));
|
|
1269
1431
|
}
|
|
1270
|
-
function
|
|
1271
|
-
return
|
|
1432
|
+
function Q(i) {
|
|
1433
|
+
return Dt[0] = i, Ct[0];
|
|
1272
1434
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
return Tt[0] = Atomics.load(i, t), [y[0], y[1], y[2], y[3]];
|
|
1435
|
+
function $(i) {
|
|
1436
|
+
return Ct[0] = i, Dt[0];
|
|
1276
1437
|
}
|
|
1277
|
-
function
|
|
1278
|
-
|
|
1438
|
+
function be(i, t, e) {
|
|
1439
|
+
return i instanceof Float32Array && (i = new Int32Array(i.buffer, i.byteOffset, i.length)), Q(Atomics.exchange(i, t, $(e)));
|
|
1279
1440
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
return Ot(Atomics.load(i, t));
|
|
1441
|
+
function xt(i, t, e, r) {
|
|
1442
|
+
return i instanceof Float32Array && (i = new Int32Array(i.buffer, i.byteOffset, i.length)), Q(Atomics.compareExchange(i, t, $(e), $(r)));
|
|
1283
1443
|
}
|
|
1284
|
-
function
|
|
1285
|
-
|
|
1444
|
+
function Ae(i, t, e, r) {
|
|
1445
|
+
let s, o;
|
|
1446
|
+
do
|
|
1447
|
+
s = Atomics.load(i, t), o = Math.min(s + e, r);
|
|
1448
|
+
while (Atomics.compareExchange(i, t, s, o) !== s);
|
|
1286
1449
|
}
|
|
1287
|
-
function
|
|
1288
|
-
|
|
1450
|
+
function ke(i, t, e, r) {
|
|
1451
|
+
let s, o;
|
|
1452
|
+
do
|
|
1453
|
+
s = Atomics.load(i, t), o = Math.max(s - e, r);
|
|
1454
|
+
while (Atomics.compareExchange(i, t, s, o) !== s);
|
|
1289
1455
|
}
|
|
1290
|
-
function
|
|
1291
|
-
|
|
1456
|
+
function ge(i, t, e, r) {
|
|
1457
|
+
let s, o;
|
|
1458
|
+
do
|
|
1459
|
+
s = Ft(i, t), o = Math.min(s + e, r);
|
|
1460
|
+
while (xt(i, t, s, o) !== s);
|
|
1292
1461
|
}
|
|
1293
|
-
function
|
|
1294
|
-
|
|
1462
|
+
function Ee(i, t, e, r) {
|
|
1463
|
+
let s, o;
|
|
1464
|
+
do
|
|
1465
|
+
s = Ft(i, t), o = Math.max(s - e, r);
|
|
1466
|
+
while (xt(i, t, s, o) !== s);
|
|
1295
1467
|
}
|
|
1296
|
-
const
|
|
1297
|
-
function
|
|
1298
|
-
for (; Atomics.compareExchange(i, t,
|
|
1299
|
-
Atomics.wait(i, t,
|
|
1468
|
+
const p = 0, J = 1, L = 2;
|
|
1469
|
+
function we(i, t = 0) {
|
|
1470
|
+
for (; Atomics.compareExchange(i, t, p, J) === L; )
|
|
1471
|
+
Atomics.wait(i, t, L);
|
|
1300
1472
|
Atomics.add(i, t + 1, 1);
|
|
1301
1473
|
}
|
|
1302
|
-
function
|
|
1303
|
-
let e = Atomics.compareExchange(i, t,
|
|
1304
|
-
for (; e !==
|
|
1305
|
-
Atomics.wait(i, t, e), e = Atomics.compareExchange(i, t,
|
|
1474
|
+
function pe(i, t = 0) {
|
|
1475
|
+
let e = Atomics.compareExchange(i, t, p, L);
|
|
1476
|
+
for (; e !== p; )
|
|
1477
|
+
Atomics.wait(i, t, e), e = Atomics.compareExchange(i, t, p, L);
|
|
1306
1478
|
}
|
|
1307
|
-
function
|
|
1308
|
-
Atomics.sub(i, t + 1, 1) - 1 <= 0 && (Atomics.compareExchange(i, t,
|
|
1479
|
+
function Te(i, t = 0) {
|
|
1480
|
+
Atomics.sub(i, t + 1, 1) - 1 <= 0 && (Atomics.compareExchange(i, t, J, p) !== J && console.warn("We are unlocking when it was not read locked!"), Atomics.notify(i, t));
|
|
1309
1481
|
}
|
|
1310
|
-
function
|
|
1311
|
-
Atomics.compareExchange(i, t,
|
|
1482
|
+
function Le(i, t = 0) {
|
|
1483
|
+
Atomics.compareExchange(i, t, L, p) !== L && console.warn("We are unlocking when it was not write locked!"), Atomics.notify(i, t);
|
|
1312
1484
|
}
|
|
1313
|
-
const
|
|
1485
|
+
const Se = 2;
|
|
1314
1486
|
export {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1487
|
+
h as AllocatedMemory,
|
|
1488
|
+
oe as BYTE_OFFSET_BIT_COUNT,
|
|
1489
|
+
ce as CachedItemList,
|
|
1490
|
+
tt as MAX_BYTE_OFFSET_LENGTH,
|
|
1491
|
+
et as MAX_POSITION_LENGTH,
|
|
1492
|
+
X as MemoryBuffer,
|
|
1493
|
+
le as MemoryHeap,
|
|
1494
|
+
ae as POSITION_BIT_COUNT,
|
|
1495
|
+
Se as READ_WRITE_LOCK_ALLOCATE_COUNT,
|
|
1496
|
+
fe as SIMPLE_LOCK_ALLOCATE_COUNT,
|
|
1325
1497
|
u as SharedList,
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1498
|
+
St as SharedMap,
|
|
1499
|
+
he as SharedPointerList,
|
|
1500
|
+
Ot as SharedPool,
|
|
1501
|
+
_t as SharedString,
|
|
1502
|
+
y as SharedVector,
|
|
1503
|
+
ge as addAtomicFloat32,
|
|
1504
|
+
Ae as addAtomicInt,
|
|
1505
|
+
xt as compareExchangeFloat32,
|
|
1506
|
+
se as convert16To32,
|
|
1507
|
+
ie as convert32To16,
|
|
1508
|
+
$ as convertFloat32ToInt32,
|
|
1509
|
+
Q as convertInt32ToFloat32,
|
|
1510
|
+
T as createPointer,
|
|
1511
|
+
be as exchangeFloat32,
|
|
1512
|
+
k as getPointer,
|
|
1513
|
+
ue as load16From32,
|
|
1514
|
+
ye as load16From64,
|
|
1515
|
+
Ft as loadFloat32,
|
|
1516
|
+
c as loadPointer,
|
|
1517
|
+
O as loadRawPointer,
|
|
1518
|
+
x as lock,
|
|
1519
|
+
we as readLock,
|
|
1520
|
+
Te as readUnlock,
|
|
1521
|
+
ne as replacePointer,
|
|
1522
|
+
Y as replaceRawPointer,
|
|
1523
|
+
de as store16In32,
|
|
1524
|
+
Be as store16In64,
|
|
1525
|
+
me as storeFloat32,
|
|
1350
1526
|
m as storePointer,
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1527
|
+
v as storeRawPointer,
|
|
1528
|
+
Ee as subtractAtomicFloat,
|
|
1529
|
+
ke as subtractAtomicInt,
|
|
1530
|
+
A as unlock,
|
|
1531
|
+
pe as writeLock,
|
|
1532
|
+
Le as writeUnlock
|
|
1355
1533
|
};
|
|
1356
1534
|
//# sourceMappingURL=shared-memory-objects.js.map
|