@daneren2005/shared-memory-objects 0.0.11 → 0.0.13

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,48 +1,45 @@
1
- var Pt = Object.defineProperty;
2
- var Nt = (s, t, e) => t in s ? Pt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var l = (s, t, e) => (Nt(s, typeof t != "symbol" ? t + "" : t, e), e);
4
- const Vt = 20, te = 12, q = Math.pow(2, 20), J = Math.pow(2, 12);
5
- function h(s, t = 0) {
6
- return S(Atomics.load(s, t));
1
+ const ie = 20, se = 12, J = Math.pow(2, 20), Q = Math.pow(2, 12);
2
+ function c(s, t = 0) {
3
+ return A(Atomics.load(s, t));
7
4
  }
8
5
  function O(s, t = 0) {
9
6
  return Atomics.load(s, t);
10
7
  }
11
- function A(s, t = 0, e, r) {
12
- Atomics.store(s, t, w(e, r));
8
+ function m(s, t = 0, e, r) {
9
+ Atomics.store(s, t, T(e, r));
13
10
  }
14
11
  function W(s, t = 0, e) {
15
12
  Atomics.store(s, t, e);
16
13
  }
17
- function ee(s, t, e, r, i, o) {
18
- let a = w(i, o);
19
- return Atomics.compareExchange(s, t, a, w(e, r)) === a;
14
+ function oe(s, t, e, r, i, o) {
15
+ let a = T(i, o);
16
+ return Atomics.compareExchange(s, t, a, T(e, r)) === a;
20
17
  }
21
- function $(s, t, e, r) {
18
+ function z(s, t, e, r) {
22
19
  return Atomics.compareExchange(s, t, r, e) === r;
23
20
  }
24
- function S(s) {
21
+ function A(s) {
25
22
  return {
26
23
  bufferPosition: s & 4095,
27
24
  bufferByteOffset: s >>> 12
28
25
  };
29
26
  }
30
- function w(s, t) {
27
+ function T(s, t) {
31
28
  return s + (t << 12);
32
29
  }
33
- class c {
34
- constructor(t, e) {
35
- l(this, "memory");
36
- l(this, "bufferPosition");
37
- l(this, "buffer");
38
- l(this, "data");
39
- this.memory = t, "buffer" in e ? (this.data = e.data, this.buffer = e.buffer, this.bufferPosition = this.memory.buffers.indexOf(e.buffer)) : (this.bufferPosition = e.bufferPosition, this.buffer = t.buffers[e.bufferPosition], this.data = new Uint32Array(this.buffer.buf, e.bufferByteOffset));
40
- }
30
+ class h {
31
+ memory;
32
+ bufferPosition;
41
33
  get bufferByteOffset() {
42
34
  return this.data.byteOffset;
43
35
  }
44
36
  get pointer() {
45
- return w(this.bufferPosition, this.bufferByteOffset);
37
+ return T(this.bufferPosition, this.bufferByteOffset);
38
+ }
39
+ buffer;
40
+ data;
41
+ constructor(t, e) {
42
+ this.memory = t, "buffer" in e ? (this.data = e.data, this.buffer = e.buffer, this.bufferPosition = this.memory.buffers.indexOf(e.buffer)) : (this.bufferPosition = e.bufferPosition, this.buffer = t.buffers[e.bufferPosition], this.data = new Uint32Array(this.buffer.buf, e.bufferByteOffset));
46
43
  }
47
44
  getArray(t, e, r) {
48
45
  return new t(this.data.buffer, this.data.byteOffset + e * t.BYTES_PER_ELEMENT, r);
@@ -63,15 +60,15 @@ class c {
63
60
  };
64
61
  }
65
62
  }
66
- const Z = 0, U = 1;
67
- function C(s, t = 0) {
68
- for (; Atomics.compareExchange(s, t, Z, U) !== Z; )
69
- "WorkerGlobalScope" in self && Atomics.wait(s, t, U);
63
+ const v = 0, F = 1;
64
+ function x(s, t = 0) {
65
+ for (; Atomics.compareExchange(s, t, v, F) !== v; )
66
+ "WorkerGlobalScope" in self && Atomics.wait(s, t, F);
70
67
  }
71
- function B(s, t = 0) {
72
- Atomics.compareExchange(s, t, U, Z) !== U && console.warn("We are unlocking when it was not locked!"), Atomics.notify(s, t);
68
+ function k(s, t = 0) {
69
+ Atomics.compareExchange(s, t, F, v) !== F && console.warn("We are unlocking when it was not locked!"), Atomics.notify(s, t);
73
70
  }
74
- const re = 1, It = {
71
+ const ae = 1, Ft = {
75
72
  5120: "i8",
76
73
  5121: "u8",
77
74
  5122: "i16",
@@ -79,45 +76,43 @@ const re = 1, It = {
79
76
  5124: "i32",
80
77
  5125: "u32",
81
78
  5126: "f32"
82
- }, Ut = {
79
+ }, xt = {
83
80
  f32: Float32Array,
84
81
  f64: Float64Array
85
- }, Ct = {
82
+ }, Rt = {
86
83
  i8: Int8Array,
87
84
  i16: Int16Array,
88
85
  i32: Int32Array
89
- }, Dt = {
86
+ }, $t = {
90
87
  u8: Uint8Array,
91
88
  u8c: Uint8ClampedArray,
92
89
  u16: Uint16Array,
93
90
  u32: Uint32Array
94
- }, Ft = {
95
- // eslint-disable-next-line
91
+ }, zt = {
96
92
  i64: BigInt64Array,
97
- // eslint-disable-next-line
98
93
  u64: BigUint64Array
99
- }, xt = {
100
- ...Ut,
101
- ...Ct,
102
- ...Dt
103
- }, Rt = (s) => {
104
- const t = It[s];
94
+ }, Yt = {
95
+ ...xt,
96
+ ...Rt,
97
+ ...$t
98
+ }, Ht = (s) => {
99
+ const t = Ft[s];
105
100
  return t !== void 0 ? t : s;
106
101
  };
107
- function $t(s, ...t) {
108
- const e = Ft[s];
109
- return new (e || xt[Rt(s)])(...t);
102
+ function Kt(s, ...t) {
103
+ const e = zt[s];
104
+ return new (e || Yt[Ht(s)])(...t);
110
105
  }
111
- const Q = 0, V = 1, tt = 2, et = 3, rt = 4, k = 5, it = 6, Y = 1, H = 2, st = 8 * 4, z = 0, K = 1, y = 2 * 4;
112
- class G {
106
+ const tt = 0, et = 1, rt = 2, it = 3, st = 4, g = 5, ot = 6, Y = 1, H = 2, at = 32, K = 0, G = 1, d = 8;
107
+ class V {
108
+ buf;
109
+ start;
110
+ u8;
111
+ u32;
112
+ state;
113
+ lock;
113
114
  constructor(t = {}) {
114
- l(this, "buf");
115
- l(this, "start");
116
- l(this, "u8");
117
- l(this, "u32");
118
- l(this, "state");
119
- l(this, "lock");
120
- if (this.buf = t.buf ? t.buf : new ArrayBuffer(t.size || 4096), this.start = t.start != null ? M(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, st / 4), this.lock = new Int32Array(this.buf, this.start + this.state.byteLength - 4, 1), !t.skipInitialization) {
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, at / 4), this.lock = new Int32Array(this.buf, this.start + this.state.byteLength - 4, 1), !t.skipInitialization) {
121
116
  const e = t.align || 8;
122
117
  if (e < 8)
123
118
  throw new Error(`invalid alignment: ${e}, must be a pow2 and >= 8`);
@@ -154,8 +149,8 @@ class G {
154
149
  return i && i.fill(r), i;
155
150
  }
156
151
  mallocAs(t, e) {
157
- const r = this.malloc(e * Yt[t]);
158
- return r ? $t(t, this.buf, r, e) : void 0;
152
+ const r = this.malloc(e * Gt[t]);
153
+ return r ? Kt(t, this.buf, r, e) : void 0;
159
154
  }
160
155
  calloc(t, e = 0) {
161
156
  const r = this.malloc(t);
@@ -164,33 +159,32 @@ class G {
164
159
  malloc(t) {
165
160
  if (t <= 0)
166
161
  return 0;
167
- C(this.lock);
168
- const e = M(t + y, this.align), r = this.end;
162
+ x(this.lock);
163
+ const e = N(t + d, this.align), r = this.end;
169
164
  let i = this.top, o = this._free, a = 0;
170
165
  for (; o; ) {
171
- const n = this.blockSize(o), f = o + n >= i;
172
- if (f || n >= e) {
173
- let u = this.mallocTop(
166
+ const f = this.blockSize(o), n = o + f >= i;
167
+ if (n || f >= e) {
168
+ let l = this.mallocTop(
174
169
  o,
175
170
  a,
176
- n,
171
+ f,
177
172
  e,
178
- f
173
+ n
179
174
  );
180
- return B(this.lock), u;
175
+ return k(this.lock), l;
181
176
  }
182
177
  a = o, o = this.blockNext(o);
183
178
  }
184
179
  if (o = i, i = o + e, i <= r) {
185
180
  this.initBlock(o, e, this._used), this._used = o, this.top = i;
186
- let n = _(o);
187
- return B(this.lock), n;
181
+ let f = _(o);
182
+ return k(this.lock), f;
188
183
  }
189
- return B(this.lock), 0;
184
+ return k(this.lock), 0;
190
185
  }
191
186
  mallocTop(t, e, r, i, o) {
192
- if (o && t + i > this.end)
193
- return 0;
187
+ if (o && t + i > this.end) return 0;
194
188
  if (e ? this.unlinkBlock(e, t) : this._free = this.blockNext(t), this.setBlockNext(t, this._used), this._used = t, o)
195
189
  this.top = t + this.setBlockSize(t, i);
196
190
  else if (this.doSplit) {
@@ -202,7 +196,7 @@ class G {
202
196
  realloc(t, e) {
203
197
  if (e <= 0)
204
198
  return 0;
205
- const r = L(t);
199
+ const r = P(t);
206
200
  let i = 0, o = this._used, a = 0;
207
201
  for (; o; ) {
208
202
  if (o === r) {
@@ -218,16 +212,15 @@ class G {
218
212
  ), _(i);
219
213
  }
220
214
  reallocBlock(t, e) {
221
- const r = this.blockSize(t), i = t + r, o = i >= this.top, a = M(e + y, this.align);
215
+ const r = this.blockSize(t), i = t + r, o = i >= this.top, a = N(e + d, this.align);
222
216
  if (a <= r) {
223
217
  if (this.doSplit) {
224
- const n = r - a;
225
- n >= this.minSplit ? this.splitBlock(t, a, n) : o && (this.top = t + a);
226
- } else
227
- o && (this.top = t + a);
218
+ const f = r - a;
219
+ f >= this.minSplit ? this.splitBlock(t, a, f) : o && (this.top = t + a);
220
+ } else o && (this.top = t + a);
228
221
  return [t, i];
229
222
  }
230
- return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, i]) : (this.free(t), [L(this.malloc(e)), i]);
223
+ return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, i]) : (this.free(t), [P(this.malloc(e)), i]);
231
224
  }
232
225
  reallocArray(t, e) {
233
226
  if (t.buffer !== this.buf)
@@ -246,11 +239,11 @@ class G {
246
239
  e = t.byteOffset;
247
240
  } else
248
241
  e = t;
249
- e = L(e);
242
+ e = P(e);
250
243
  let r = this._used;
251
244
  for (; r; ) {
252
245
  if (r === e)
253
- return this.blockSize(e) - y;
246
+ return this.blockSize(e) - d;
254
247
  r = this.blockNext(r);
255
248
  }
256
249
  }
@@ -267,14 +260,14 @@ class G {
267
260
  e = t.byteOffset;
268
261
  } else
269
262
  e = t;
270
- C(this.lock), e = L(e);
263
+ x(this.lock), e = P(e);
271
264
  let r = this._used, i = 0;
272
265
  for (; r; ) {
273
266
  if (r === e)
274
- return i ? this.unlinkBlock(i, r) : this._used = this.blockNext(r), this.insert(r), this.doCompact && this.compact(), B(this.lock), !0;
267
+ return i ? this.unlinkBlock(i, r) : this._used = this.blockNext(r), this.insert(r), this.doCompact && this.compact(), k(this.lock), !0;
275
268
  i = r, r = this.blockNext(r);
276
269
  }
277
- return B(this.lock), !1;
270
+ return k(this.lock), !1;
278
271
  }
279
272
  freeAll() {
280
273
  this._free = 0, this._used = 0, this.top = this.initialTop();
@@ -283,57 +276,57 @@ class G {
283
276
  return delete this.u8, delete this.u32, delete this.state, delete this.buf, !0;
284
277
  }
285
278
  get align() {
286
- return this.state[rt];
279
+ return this.state[st];
287
280
  }
288
281
  set align(t) {
289
- this.state[rt] = t;
282
+ this.state[st] = t;
290
283
  }
291
284
  get end() {
292
- return this.state[et];
285
+ return this.state[it];
293
286
  }
294
287
  set end(t) {
295
- this.state[et] = t;
288
+ this.state[it] = t;
296
289
  }
297
290
  get top() {
298
- return Atomics.load(this.state, tt);
291
+ return Atomics.load(this.state, rt);
299
292
  }
300
293
  set top(t) {
301
- Atomics.store(this.state, tt, t);
294
+ Atomics.store(this.state, rt, t);
302
295
  }
303
296
  get _free() {
304
- return Atomics.load(this.state, Q);
297
+ return Atomics.load(this.state, tt);
305
298
  }
306
299
  set _free(t) {
307
- Atomics.store(this.state, Q, t);
300
+ Atomics.store(this.state, tt, t);
308
301
  }
309
302
  get _used() {
310
- return Atomics.load(this.state, V);
303
+ return Atomics.load(this.state, et);
311
304
  }
312
305
  set _used(t) {
313
- Atomics.store(this.state, V, t);
306
+ Atomics.store(this.state, et, t);
314
307
  }
315
308
  get doCompact() {
316
- return !!(this.state[k] & Y);
309
+ return !!(this.state[g] & Y);
317
310
  }
318
311
  set doCompact(t) {
319
- t ? this.state[k] |= 1 << Y - 1 : this.state[k] &= ~Y;
312
+ t ? this.state[g] |= 1 << Y - 1 : this.state[g] &= ~Y;
320
313
  }
321
314
  get doSplit() {
322
- return !!(this.state[k] & H);
315
+ return !!(this.state[g] & H);
323
316
  }
324
317
  set doSplit(t) {
325
- t ? this.state[k] |= 1 << H - 1 : this.state[k] &= ~H;
318
+ t ? this.state[g] |= 1 << H - 1 : this.state[g] &= ~H;
326
319
  }
327
320
  get minSplit() {
328
- return this.state[it];
321
+ return this.state[ot];
329
322
  }
330
323
  set minSplit(t) {
331
- if (t <= y)
332
- throw new Error(`illegal min split threshold: ${t}, require at least ${y + 1}`);
333
- this.state[it] = t;
324
+ if (t <= d)
325
+ throw new Error(`illegal min split threshold: ${t}, require at least ${d + 1}`);
326
+ this.state[ot] = t;
334
327
  }
335
328
  blockSize(t) {
336
- return Atomics.load(this.u32, (t >> 2) + z);
329
+ return Atomics.load(this.u32, (t >> 2) + K);
337
330
  }
338
331
  /**
339
332
  * Sets & returns given block size.
@@ -342,10 +335,10 @@ class G {
342
335
  * @param size -
343
336
  */
344
337
  setBlockSize(t, e) {
345
- return Atomics.store(this.u32, (t >> 2) + z, e), e;
338
+ return Atomics.store(this.u32, (t >> 2) + K, e), e;
346
339
  }
347
340
  blockNext(t) {
348
- return Atomics.load(this.u32, (t >> 2) + K);
341
+ return Atomics.load(this.u32, (t >> 2) + G);
349
342
  }
350
343
  /**
351
344
  * Sets block next pointer to `next`. Use zero to indicate list end.
@@ -353,7 +346,7 @@ class G {
353
346
  * @param block -
354
347
  */
355
348
  setBlockNext(t, e) {
356
- Atomics.store(this.u32, (t >> 2) + K, e);
349
+ Atomics.store(this.u32, (t >> 2) + G, e);
357
350
  }
358
351
  /**
359
352
  * Initializes block header with given `size` and `next` pointer. Returns `block`.
@@ -364,7 +357,7 @@ class G {
364
357
  */
365
358
  initBlock(t, e, r) {
366
359
  const i = t >>> 2;
367
- return Atomics.store(this.u32, i + z, e), Atomics.store(this.u32, i + K, r), t;
360
+ return Atomics.store(this.u32, i + K, e), Atomics.store(this.u32, i + G, r), t;
368
361
  }
369
362
  unlinkBlock(t, e) {
370
363
  this.setBlockNext(t, this.blockNext(e));
@@ -379,7 +372,7 @@ class G {
379
372
  ), this.doCompact && this.compact();
380
373
  }
381
374
  initialTop(t = this.align) {
382
- return M(this.start + st + y, t) - y;
375
+ return N(this.start + at + d, t) - d;
383
376
  }
384
377
  /**
385
378
  * Traverses free list and attempts to recursively merge blocks
@@ -394,13 +387,13 @@ class G {
394
387
  if (i !== t) {
395
388
  const a = i - t + this.blockSize(i);
396
389
  this.setBlockSize(t, a);
397
- const n = this.blockNext(i);
398
- let f = this.blockNext(t);
399
- for (; f && f !== n; ) {
400
- const u = this.blockNext(f);
401
- this.setBlockNext(f, 0), f = u;
390
+ const f = this.blockNext(i);
391
+ let n = this.blockNext(t);
392
+ for (; n && n !== f; ) {
393
+ const l = this.blockNext(n);
394
+ this.setBlockNext(n, 0), n = l;
402
395
  }
403
- this.setBlockNext(t, n), o = !0;
396
+ this.setBlockNext(t, f), o = !0;
404
397
  }
405
398
  t + this.blockSize(t) >= this.top && (this.top = t, e ? this.unlinkBlock(e, t) : this._free = this.blockNext(t)), e = t, t = this.blockNext(t);
406
399
  }
@@ -418,7 +411,7 @@ class G {
418
411
  r ? this.setBlockNext(r, t) : this._free = t, this.setBlockNext(t, e);
419
412
  }
420
413
  }
421
- const _ = (s) => s > 0 ? s + y : 0, L = (s) => s > 0 ? s - y : 0, M = (s, t) => (t--, s + t & ~t), Yt = {
414
+ const _ = (s) => s > 0 ? s + d : 0, P = (s) => s > 0 ? s - d : 0, N = (s, t) => (t--, s + t & ~t), Gt = {
422
415
  u8: 1,
423
416
  u8c: 1,
424
417
  i8: 1,
@@ -430,7 +423,7 @@ const _ = (s) => s > 0 ? s + y : 0, L = (s) => s > 0 ? s - y : 0, M = (s, t) =>
430
423
  u64: 8,
431
424
  f32: 4,
432
425
  f64: 8
433
- }, Ht = [
426
+ }, Vt = [
434
427
  "B",
435
428
  "kB",
436
429
  "MB",
@@ -440,7 +433,7 @@ const _ = (s) => s > 0 ? s + y : 0, L = (s) => s > 0 ? s - y : 0, M = (s, t) =>
440
433
  "EB",
441
434
  "ZB",
442
435
  "YB"
443
- ], zt = [
436
+ ], Xt = [
444
437
  "B",
445
438
  "KiB",
446
439
  "MiB",
@@ -450,7 +443,7 @@ const _ = (s) => s > 0 ? s + y : 0, L = (s) => s > 0 ? s - y : 0, M = (s, t) =>
450
443
  "EiB",
451
444
  "ZiB",
452
445
  "YiB"
453
- ], Kt = [
446
+ ], Zt = [
454
447
  "b",
455
448
  "kbit",
456
449
  "Mbit",
@@ -460,7 +453,7 @@ const _ = (s) => s > 0 ? s + y : 0, L = (s) => s > 0 ? s - y : 0, M = (s, t) =>
460
453
  "Ebit",
461
454
  "Zbit",
462
455
  "Ybit"
463
- ], Gt = [
456
+ ], Wt = [
464
457
  "b",
465
458
  "kibit",
466
459
  "Mibit",
@@ -470,76 +463,109 @@ const _ = (s) => s > 0 ? s + y : 0, L = (s) => s > 0 ? s - y : 0, M = (s, t) =>
470
463
  "Eibit",
471
464
  "Zibit",
472
465
  "Yibit"
473
- ], ot = (s, t, e) => {
466
+ ], nt = (s, t, e) => {
474
467
  let r = s;
475
468
  return typeof t == "string" || Array.isArray(t) ? r = s.toLocaleString(t, e) : (t === !0 || e !== void 0) && (r = s.toLocaleString(void 0, e)), r;
469
+ }, wt = (s) => {
470
+ if (typeof s == "number")
471
+ return Math.log10(s);
472
+ const t = s.toString(10);
473
+ return t.length + Math.log10(`0.${t.slice(0, 15)}`);
474
+ }, vt = (s) => typeof s == "number" ? Math.log(s) : wt(s) * Math.log(10), jt = (s, t) => {
475
+ if (typeof s == "number")
476
+ return s / t;
477
+ const e = s / BigInt(t), r = s % BigInt(t);
478
+ return Number(e) + Number(r) / t;
479
+ }, ft = (s, t) => {
480
+ if (t === void 0)
481
+ return s;
482
+ if (typeof t != "number" || !Number.isSafeInteger(t) || t < 0)
483
+ throw new TypeError(`Expected fixedWidth to be a non-negative integer, got ${typeof t}: ${t}`);
484
+ return t === 0 ? s : s.length < t ? s.padStart(t, " ") : s;
485
+ }, qt = (s) => {
486
+ const { minimumFractionDigits: t, maximumFractionDigits: e } = s;
487
+ if (!(t === void 0 && e === void 0))
488
+ return {
489
+ ...t !== void 0 && { minimumFractionDigits: t },
490
+ ...e !== void 0 && { maximumFractionDigits: e },
491
+ roundingMode: "trunc"
492
+ };
476
493
  };
477
- function Xt(s, t) {
478
- if (!Number.isFinite(s))
494
+ function Jt(s, t) {
495
+ if (typeof s != "bigint" && !Number.isFinite(s))
479
496
  throw new TypeError(`Expected a finite number, got ${typeof s}: ${s}`);
480
497
  t = {
481
498
  bits: !1,
482
499
  binary: !1,
483
500
  space: !0,
501
+ nonBreakingSpace: !1,
484
502
  ...t
485
503
  };
486
- const e = t.bits ? t.binary ? Gt : Kt : t.binary ? zt : Ht, r = t.space ? " " : "";
487
- if (t.signed && s === 0)
488
- return ` 0${r}${e[0]}`;
489
- const i = s < 0, o = i ? "-" : t.signed ? "+" : "";
490
- i && (s = -s);
491
- let a;
492
- if (t.minimumFractionDigits !== void 0 && (a = { minimumFractionDigits: t.minimumFractionDigits }), t.maximumFractionDigits !== void 0 && (a = { maximumFractionDigits: t.maximumFractionDigits, ...a }), s < 1) {
493
- const p = ot(s, t.locale, a);
494
- return o + p + r + e[0];
495
- }
496
- const n = Math.min(Math.floor(t.binary ? Math.log(s) / Math.log(1024) : Math.log10(s) / 3), e.length - 1);
497
- s /= (t.binary ? 1024 : 1e3) ** n, a || (s = s.toPrecision(3));
498
- const f = ot(Number(s), t.locale, a), u = e[n];
499
- return o + f + r + u;
504
+ const e = t.bits ? t.binary ? Wt : Zt : t.binary ? Xt : Vt, r = t.space ? t.nonBreakingSpace ? " " : " " : "", i = typeof s == "number" ? s === 0 : s === 0n;
505
+ if (t.signed && i) {
506
+ const l = ` 0${r}${e[0]}`;
507
+ return ft(l, t.fixedWidth);
508
+ }
509
+ const o = s < 0, a = o ? "-" : t.signed ? "+" : "";
510
+ o && (s = -s);
511
+ const f = qt(t);
512
+ let n;
513
+ if (s < 1) {
514
+ const l = nt(s, t.locale, f);
515
+ n = a + l + r + e[0];
516
+ } else {
517
+ const l = Math.min(Math.floor(t.binary ? vt(s) / Math.log(1024) : wt(s) / 3), e.length - 1);
518
+ if (s = jt(s, (t.binary ? 1024 : 1e3) ** l), !f) {
519
+ const M = Math.max(3, Math.floor(s).toString().length);
520
+ s = s.toPrecision(M);
521
+ }
522
+ const S = nt(Number(s), t.locale, f), $ = e[l];
523
+ n = a + S + r + $;
524
+ }
525
+ return ft(n, t.fixedWidth);
500
526
  }
501
- const Wt = 8192, at = 0, X = 1, P = 2;
502
- class ie {
527
+ const Qt = 8192, lt = 0, X = 1, U = 2;
528
+ class ne {
529
+ buffers;
530
+ onGrowBufferHandlers = [];
531
+ isClone;
532
+ memory;
533
+ get bufferSize() {
534
+ return this.memory.data[lt];
535
+ }
503
536
  constructor(t) {
504
- l(this, "buffers");
505
- l(this, "onGrowBufferHandlers", []);
506
- l(this, "isClone");
507
- l(this, "memory");
508
537
  if (t && "buffers" in t)
509
- this.buffers = t.buffers.map((e) => new G({
538
+ this.buffers = t.buffers.map((e) => new V({
510
539
  buf: e,
511
540
  skipInitialization: !0
512
- })), this.memory = new c(this, {
541
+ })), this.memory = new h(this, {
513
542
  bufferPosition: 0,
514
543
  bufferByteOffset: 40
515
544
  }), this.isClone = !0;
516
545
  else {
517
546
  "SharedArrayBuffer" in globalThis || console.warn("SharedArrayBuffer is not working: falling back to ArrayBuffer");
518
- const e = (t == null ? void 0 : t.bufferSize) ?? Wt;
519
- if (e > q)
520
- throw new Error(`Buffer size ${e} is greater than max ${q} that we can reference with pointers`);
547
+ const e = t?.bufferSize ?? Qt;
548
+ if (e > J)
549
+ throw new Error(`Buffer size ${e} is greater than max ${J} that we can reference with pointers`);
521
550
  let r = this.createBuffer(e);
522
551
  this.buffers = [
523
552
  r
524
553
  ];
525
554
  const i = r.callocAs("u32", 3);
526
555
  if (i)
527
- this.memory = new c(this, {
556
+ this.memory = new h(this, {
528
557
  bufferPosition: 0,
529
558
  bufferByteOffset: i.byteOffset
530
559
  });
531
560
  else
532
561
  throw new Error("Failed to initialize first byte from buffer");
533
- this.memory.data[at] = e, this.memory.data[X] = 1, this.memory.data[P] = (t == null ? void 0 : t.autoGrowSize) ?? 100, this.isClone = !1;
534
- for (let o = 1; o < ((t == null ? void 0 : t.initialBuffers) ?? 1); o++)
562
+ this.memory.data[lt] = e, this.memory.data[X] = 1, this.memory.data[U] = t?.autoGrowSize ?? 100, this.isClone = !1;
563
+ for (let o = 1; o < (t?.initialBuffers ?? 1); o++)
535
564
  this.buffers.push(this.createBuffer(e));
536
565
  }
537
566
  }
538
- get bufferSize() {
539
- return this.memory.data[at];
540
- }
541
567
  addSharedBuffer(t) {
542
- this.buffers[t.bufferPosition] = new G({
568
+ this.buffers[t.bufferPosition] = new V({
543
569
  buf: t.buffer,
544
570
  skipInitialization: !0
545
571
  });
@@ -555,7 +581,7 @@ class ie {
555
581
  createBuffer(t) {
556
582
  const e = t ?? this.bufferSize;
557
583
  let r;
558
- return "SharedArrayBuffer" in globalThis ? r = new SharedArrayBuffer(e) : r = new ArrayBuffer(e), new G({
584
+ return "SharedArrayBuffer" in globalThis ? r = new SharedArrayBuffer(e) : r = new ArrayBuffer(e), new V({
559
585
  buf: r,
560
586
  // We can't use this unless we can 100% guarantee that every thread will stop using memory the instant it is freed
561
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
@@ -575,17 +601,17 @@ class ie {
575
601
  continue;
576
602
  const a = o.callocAs("u32", t);
577
603
  if (a)
578
- return i === this.buffers.length - 1 && Atomics.load(this.memory.data, X) === this.buffers.length && this.memory.data[P] < 100 && this.memory.data[P] > 0 && o.top / o.end > this.memory.data[P] / 100 && this.growBuffer(), new c(this, {
604
+ return i === this.buffers.length - 1 && Atomics.load(this.memory.data, X) === this.buffers.length && this.memory.data[U] < 100 && this.memory.data[U] > 0 && o.top / o.end > this.memory.data[U] / 100 && this.growBuffer(), new h(this, {
579
605
  data: a,
580
606
  buffer: o
581
607
  });
582
608
  }
583
- if (this.buffers.length >= J)
584
- throw new Error(`Can't initialize a new buffer since it would have a position greater than the max of ${J}`);
609
+ if (this.buffers.length >= Q)
610
+ throw new Error(`Can't initialize a new buffer since it would have a position greater than the max of ${Q}`);
585
611
  let e = this.growBuffer();
586
612
  const r = e.callocAs("u32", t);
587
613
  if (r)
588
- return new c(this, {
614
+ return new h(this, {
589
615
  data: r,
590
616
  buffer: e
591
617
  });
@@ -593,7 +619,7 @@ class ie {
593
619
  }
594
620
  getSharedAlloc(t) {
595
621
  if (this.buffers[t.bufferPosition] !== void 0)
596
- return new c(this, t);
622
+ return new h(this, t);
597
623
  }
598
624
  get currentUsed() {
599
625
  return this.totalAllocated - this.buffers.reduce((t, e) => t + e.stats().available, 0);
@@ -602,7 +628,7 @@ class ie {
602
628
  return this.buffers[0].buf.byteLength * this.buffers.length;
603
629
  }
604
630
  prettyMemory() {
605
- return `${ft(this.currentUsed)} / ${ft(this.totalAllocated)}`;
631
+ return `${ht(this.currentUsed)} / ${ht(this.totalAllocated)}`;
606
632
  }
607
633
  getSharedMemory() {
608
634
  return {
@@ -610,47 +636,39 @@ class ie {
610
636
  };
611
637
  }
612
638
  }
613
- function ft(s) {
614
- return Xt(s, {
639
+ function ht(s) {
640
+ return Jt(s, {
615
641
  binary: !0,
616
642
  minimumFractionDigits: 1,
617
643
  maximumFractionDigits: 1
618
644
  });
619
645
  }
620
- const nt = 4, lt = 1, E = 2;
621
- class d {
622
- constructor(t, e) {
623
- l(this, "memory");
624
- /* First block
625
- 32 index 0
626
- uint16 0 - next buffer position
627
- uint16 1 - next buffer index
628
- 32 index 1
629
- uint16 2 - last buffer position
630
- uint16 3 - last buffer index
631
- 32 index 2
632
- uint32 4 - length
633
- 32 index 3
634
- uint16 6 - type
635
- uint16 7 - data length (defaults to 1 number per data)
636
- */
637
- /* Other blocks
638
- 32 index 0
639
- uint16 0 - next buffer position
640
- uint16 1 - next buffer index
641
- 32 index 1 => data
642
- */
643
- l(this, "firstBlock");
644
- l(this, "uint16Array");
645
- l(this, "onDelete");
646
- if (this.memory = t, e && "firstBlock" in e)
647
- this.firstBlock = new c(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (E + 1) * Uint32Array.BYTES_PER_ELEMENT, 2);
648
- else {
649
- e && e.initWithBlock ? this.firstBlock = new c(t, e.initWithBlock) : this.firstBlock = t.allocUI32(nt), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (E + 1) * Uint32Array.BYTES_PER_ELEMENT, 2);
650
- const r = (e == null ? void 0 : e.type) ?? Uint32Array;
651
- r === Uint32Array ? this.type = 0 : r === Int32Array ? this.type = 1 : r === Float32Array && (this.type = 2), this.dataLength = (e == null ? void 0 : e.dataLength) ?? 1;
652
- }
653
- }
646
+ const ct = 4, ut = 1, E = 2;
647
+ class u {
648
+ static ALLOCATE_COUNT = ct;
649
+ memory;
650
+ /* First block
651
+ 32 index 0
652
+ uint16 0 - next buffer position
653
+ uint16 1 - next buffer index
654
+ 32 index 1
655
+ uint16 2 - last buffer position
656
+ uint16 3 - last buffer index
657
+ 32 index 2
658
+ uint32 4 - length
659
+ 32 index 3
660
+ uint16 6 - type
661
+ uint16 7 - data length (defaults to 1 number per data)
662
+ */
663
+ /* Other blocks
664
+ 32 index 0
665
+ uint16 0 - next buffer position
666
+ uint16 1 - next buffer index
667
+ 32 index 1 => data
668
+ */
669
+ firstBlock;
670
+ uint16Array;
671
+ onDelete;
654
672
  get length() {
655
673
  return Atomics.load(this.firstBlock.data, E);
656
674
  }
@@ -666,20 +684,29 @@ class d {
666
684
  set dataLength(t) {
667
685
  Atomics.store(this.uint16Array, 1, t);
668
686
  }
687
+ constructor(t, e) {
688
+ if (this.memory = t, e && "firstBlock" in e)
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
+ else {
691
+ e && e.initWithBlock ? this.firstBlock = new h(t, e.initWithBlock) : this.firstBlock = t.allocUI32(ct), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (E + 1) * Uint32Array.BYTES_PER_ELEMENT, 2);
692
+ const r = e?.type ?? Uint32Array;
693
+ r === Uint32Array ? this.type = 0 : r === Int32Array ? this.type = 1 : r === Float32Array && (this.type = 2), this.dataLength = e?.dataLength ?? 1;
694
+ }
695
+ }
669
696
  insert(t) {
670
697
  typeof t == "number" && (t = [t]);
671
698
  let e = this.dataLength;
672
699
  if (t.length > e)
673
700
  throw new Error(`Can't insert ${t.length} array into shared list of ${e} dataLength`);
674
- let r = this.memory.allocUI32(lt + e), i = this.getDataBlock(r.data), o = r.pointer;
675
- for (let f = 0; f < t.length; f++)
676
- i instanceof Int32Array || i instanceof Uint32Array ? Atomics.store(i, f, t[f]) : i[f] = t[f];
677
- let a, n = !1;
678
- for (; !n; )
679
- a = O(this.firstBlock.data, 1), n = $(this.firstBlock.data, 1, o, a);
701
+ let r = this.memory.allocUI32(ut + e), i = this.getDataBlock(r.data), o = r.pointer;
702
+ for (let n = 0; n < t.length; n++)
703
+ i instanceof Int32Array || i instanceof Uint32Array ? Atomics.store(i, n, t[n]) : i[n] = t[n];
704
+ let a, f = !1;
705
+ for (; !f; )
706
+ a = O(this.firstBlock.data, 1), f = z(this.firstBlock.data, 1, o, a);
680
707
  if (a) {
681
- let { bufferPosition: f, bufferByteOffset: u } = S(a), p = new Uint32Array(this.memory.buffers[f].buf, u, 1);
682
- W(p, 0, o);
708
+ let { bufferPosition: n, bufferByteOffset: l } = A(a), S = new Uint32Array(this.memory.buffers[n].buf, l, 1);
709
+ W(S, 0, o);
683
710
  } else
684
711
  W(this.firstBlock.data, 0, o);
685
712
  Atomics.add(this.firstBlock.data, E, 1);
@@ -708,37 +735,37 @@ class d {
708
735
  for (; !r; ) {
709
736
  if (t = O(this.firstBlock.data, 0), e = O(this.firstBlock.data, 1), !e)
710
737
  return;
711
- r = $(this.firstBlock.data, 1, 0, e);
738
+ r = z(this.firstBlock.data, 1, 0, e);
712
739
  }
713
740
  if (!t)
714
741
  return;
715
- $(this.firstBlock.data, 0, 0, t);
742
+ z(this.firstBlock.data, 0, 0, t);
716
743
  let i = 0, o = t;
717
744
  for (; o; ) {
718
- let { bufferPosition: a, bufferByteOffset: n } = S(o), f = this.memory.buffers[a];
719
- if (!f)
745
+ let { bufferPosition: a, bufferByteOffset: f } = A(o), n = this.memory.buffers[a];
746
+ if (!n)
720
747
  break;
721
- let u = new Uint32Array(f.buf, n, 2);
722
- o = O(u, 0), i++, this.onDelete && this.onDelete(this.getDataBlock(u)), f.free(u.byteOffset);
748
+ let l = new Uint32Array(n.buf, f, 2);
749
+ o = O(l, 0), i++, this.onDelete && this.onDelete(this.getDataBlock(l)), n.free(l.byteOffset);
723
750
  }
724
751
  Atomics.sub(this.firstBlock.data, E, i);
725
752
  }
726
753
  *[Symbol.iterator]() {
727
- let t = 0, { bufferPosition: e, bufferByteOffset: r } = h(this.firstBlock.data, 0), i = this.firstBlock.data, o = 0, a = 0;
754
+ let t = 0, { bufferPosition: e, bufferByteOffset: r } = c(this.firstBlock.data, 0), i = this.firstBlock.data, o = 0, a = 0;
728
755
  for (; r; ) {
729
- let n = this.memory.buffers[e];
730
- if (!n)
756
+ let f = this.memory.buffers[e];
757
+ if (!f)
731
758
  return;
732
- let f = new Uint32Array(n.buf, r, 2), u = this.getDataBlock(f), p = e, Mt = r;
733
- ({ bufferPosition: e, bufferByteOffset: r } = h(f, 0));
734
- let j = !0;
759
+ let n = new Uint32Array(f.buf, r, 2), l = this.getDataBlock(n), S = e, $ = r;
760
+ ({ bufferPosition: e, bufferByteOffset: r } = c(n, 0));
761
+ let M = !0;
735
762
  yield {
736
- data: u,
763
+ data: l,
737
764
  index: t,
738
765
  deleteCurrent: () => {
739
- A(i, 0, e, r), r || A(this.firstBlock.data, 1, o, a), this.onDelete && this.onDelete(this.getDataBlock(f)), n.free(f.byteOffset), Atomics.sub(this.firstBlock.data, E, 1), j = !1;
766
+ m(i, 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;
740
767
  }
741
- }, j && (i = f, o = p, a = Mt, t++);
768
+ }, M && (i = n, o = S, a = $, t++);
742
769
  }
743
770
  }
744
771
  forEach(t) {
@@ -751,7 +778,7 @@ class d {
751
778
  };
752
779
  }
753
780
  getDataBlock(t) {
754
- const e = t.byteOffset + lt * t.BYTES_PER_ELEMENT;
781
+ const e = t.byteOffset + ut * t.BYTES_PER_ELEMENT;
755
782
  switch (this.type) {
756
783
  case 1:
757
784
  return new Int32Array(t.buffer, e, this.dataLength);
@@ -764,35 +791,26 @@ class d {
764
791
  }
765
792
  }
766
793
  free() {
767
- let { bufferPosition: t, bufferByteOffset: e } = h(this.firstBlock.data, 0);
794
+ let { bufferPosition: t, bufferByteOffset: e } = c(this.firstBlock.data, 0);
768
795
  for (; e; ) {
769
- let r = new c(this.memory, {
796
+ let r = new h(this.memory, {
770
797
  bufferPosition: t,
771
798
  bufferByteOffset: e
772
799
  });
773
- ({ bufferPosition: t, bufferByteOffset: e } = h(r.data, 0)), this.onDelete && this.onDelete(this.getDataBlock(r.data)), r.free();
800
+ ({ bufferPosition: t, bufferByteOffset: e } = c(r.data, 0)), this.onDelete && this.onDelete(this.getDataBlock(r.data)), r.free();
774
801
  }
775
802
  this.firstBlock.free();
776
803
  }
777
804
  }
778
- l(d, "ALLOCATE_COUNT", nt);
779
- const ht = 10, F = class F {
780
- constructor(t, e) {
781
- l(this, "memory");
782
- // Memory order: Pointer, Lock, Length, MaxHash
783
- l(this, "pointerMemory");
784
- l(this, "lock");
785
- if (this.memory = t, e)
786
- this.pointerMemory = new c(t, e.firstBlock);
787
- else {
788
- this.pointerMemory = t.allocUI32(F.ALLOCATE_COUNT);
789
- let r = t.allocUI32(ht);
790
- A(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3, ht);
791
- }
792
- this.lock = new Int32Array(this.pointerMemory.data.buffer, this.pointerMemory.bufferByteOffset + Uint32Array.BYTES_PER_ELEMENT, 1);
793
- }
805
+ const dt = 10;
806
+ class Tt {
807
+ static ALLOCATE_COUNT = 4;
808
+ memory;
809
+ // Memory order: Pointer, Lock, Length, MaxHash
810
+ pointerMemory;
811
+ lock;
794
812
  get hashMemory() {
795
- return new c(this.memory, h(this.pointerMemory.data, 0));
813
+ return new h(this.memory, c(this.pointerMemory.data, 0));
796
814
  }
797
815
  get length() {
798
816
  return Atomics.load(this.pointerMemory.data, 2);
@@ -800,31 +818,41 @@ const ht = 10, F = class F {
800
818
  get maxHash() {
801
819
  return Atomics.load(this.pointerMemory.data, 3);
802
820
  }
821
+ constructor(t, e) {
822
+ if (this.memory = t, e)
823
+ this.pointerMemory = new h(t, e.firstBlock);
824
+ else {
825
+ this.pointerMemory = t.allocUI32(Tt.ALLOCATE_COUNT);
826
+ let r = t.allocUI32(dt);
827
+ m(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3, dt);
828
+ }
829
+ this.lock = new Int32Array(this.pointerMemory.data.buffer, this.pointerMemory.bufferByteOffset + Uint32Array.BYTES_PER_ELEMENT, 1);
830
+ }
803
831
  set(t, e) {
804
832
  this.length >= this.maxHash * 2 && this.growHashTable();
805
- let r = N(t);
833
+ let r = C(t);
806
834
  this.setHashKey(this.hashMemory, this.maxHash, r, e) && Atomics.add(this.pointerMemory.data, 2, 1);
807
835
  }
808
836
  setHashKey(t, e, r, i) {
809
- let o = this.hash(r, e), a, n = h(t.data, o);
810
- if (n.bufferByteOffset === 0) {
811
- a = new d(this.memory, {
837
+ let o = this.hash(r, e), a, f = c(t.data, o);
838
+ if (f.bufferByteOffset === 0) {
839
+ a = new u(this.memory, {
812
840
  dataLength: 2
813
841
  });
814
- let u = a.getSharedMemory();
815
- A(t.data, o, u.firstBlock.bufferPosition, u.firstBlock.bufferByteOffset);
842
+ let l = a.getSharedMemory();
843
+ m(t.data, o, l.firstBlock.bufferPosition, l.firstBlock.bufferByteOffset);
816
844
  } else
817
- a = new d(this.memory, {
818
- firstBlock: n
845
+ a = new u(this.memory, {
846
+ firstBlock: f
819
847
  });
820
- let f = !0;
821
- return a.deleteValue(r) && (f = !1), a.insert([r, i]), f;
848
+ let n = !0;
849
+ return a.deleteValue(r) && (n = !1), a.insert([r, i]), n;
822
850
  }
823
851
  get(t) {
824
- let e = N(t), r = this.hash(e, this.maxHash), i = h(this.hashMemory.data, r);
852
+ let e = C(t), r = this.hash(e, this.maxHash), i = c(this.hashMemory.data, r);
825
853
  if (i.bufferByteOffset === 0)
826
854
  return;
827
- let o = new d(this.memory, {
855
+ let o = new u(this.memory, {
828
856
  firstBlock: i
829
857
  });
830
858
  for (let { data: a } of o)
@@ -832,10 +860,10 @@ const ht = 10, F = class F {
832
860
  return a[1];
833
861
  }
834
862
  has(t) {
835
- let e = N(t), r = this.hash(e, this.maxHash), i = h(this.hashMemory.data, r);
863
+ let e = C(t), r = this.hash(e, this.maxHash), i = c(this.hashMemory.data, r);
836
864
  if (i.bufferByteOffset === 0)
837
865
  return !1;
838
- let o = new d(this.memory, {
866
+ let o = new u(this.memory, {
839
867
  firstBlock: i
840
868
  });
841
869
  for (let { data: a } of o)
@@ -844,40 +872,40 @@ const ht = 10, F = class F {
844
872
  return !1;
845
873
  }
846
874
  delete(t) {
847
- let e = N(t), r = this.hash(e, this.maxHash), i = h(this.hashMemory.data, r);
875
+ let e = C(t), r = this.hash(e, this.maxHash), i = c(this.hashMemory.data, r);
848
876
  if (i.bufferByteOffset === 0)
849
877
  return !1;
850
- let o = new d(this.memory, {
878
+ let o = new u(this.memory, {
851
879
  firstBlock: i
852
880
  });
853
- for (let { data: a, deleteCurrent: n } of o)
881
+ for (let { data: a, deleteCurrent: f } of o)
854
882
  if (a[0] === e)
855
- return n(), Atomics.sub(this.pointerMemory.data, 2, 1), !0;
883
+ return f(), Atomics.sub(this.pointerMemory.data, 2, 1), !0;
856
884
  return !1;
857
885
  }
858
886
  growHashTable() {
859
887
  let t = this.maxHash, e = t * 2, r = this.memory.allocUI32(e), i = this.hashMemory;
860
888
  for (let o = 0; o < t; o++) {
861
- let a = h(i.data, o);
889
+ let a = c(i.data, o);
862
890
  if (a.bufferByteOffset === 0)
863
891
  continue;
864
- let n = new d(this.memory, {
892
+ let f = new u(this.memory, {
865
893
  firstBlock: a
866
894
  });
867
- for (let { data: f } of n)
868
- this.setHashKey(r, e, f[0], f[1]);
895
+ for (let { data: n } of f)
896
+ this.setHashKey(r, e, n[0], n[1]);
869
897
  }
870
- A(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3, e);
898
+ m(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3, e);
871
899
  }
872
900
  hash(t, e) {
873
901
  return t % e;
874
902
  }
875
903
  free() {
876
904
  for (let t = 0; t < this.maxHash; t++) {
877
- let e = h(this.hashMemory.data, t);
905
+ let e = c(this.hashMemory.data, t);
878
906
  if (e.bufferByteOffset === 0)
879
907
  continue;
880
- new d(this.memory, {
908
+ new u(this.memory, {
881
909
  firstBlock: e
882
910
  }).free();
883
911
  }
@@ -888,13 +916,11 @@ const ht = 10, F = class F {
888
916
  firstBlock: this.pointerMemory.getSharedMemory()
889
917
  };
890
918
  }
891
- };
892
- l(F, "ALLOCATE_COUNT", 4);
893
- let ct = F;
894
- function N(s) {
895
- return typeof s == "number" ? s : typeof s == "string" ? Zt(s) : s;
896
919
  }
897
- function Zt(s) {
920
+ function C(s) {
921
+ return typeof s == "number" ? s : typeof s == "string" ? te(s) : s;
922
+ }
923
+ function te(s) {
898
924
  let t = s.length, e = 17 ^ t, r = 0, i;
899
925
  for (; t >= 4; )
900
926
  i = s.charCodeAt(r) & 255 | (s.charCodeAt(++r) & 255) << 8 | (s.charCodeAt(++r) & 255) << 16 | (s.charCodeAt(++r) & 255) << 14, i = (i & 65535) * 1540483477 + (((i >>> 16) * 1540483477 & 65535) << 16), i ^= i >>> 14, i = (i & 65535) * 1540483477 + (((i >>> 16) * 1540483477 & 65535) << 16), e = (e & 65535) * 1540483477 + (((e >>> 16) * 1540483477 & 65535) << 16) ^ i, t -= 4, ++r;
@@ -908,25 +934,25 @@ function Zt(s) {
908
934
  }
909
935
  return e ^= e >>> 13, e = (e & 65535) * 1540483477 + (((e >>> 16) * 1540483477 & 65535) << 16), e ^= e >>> 15, e = e >>> 0, e;
910
936
  }
911
- class se {
937
+ class fe {
938
+ memory;
939
+ list;
912
940
  constructor(t, e) {
913
- l(this, "memory");
914
- l(this, "list");
915
- this.memory = t, e ? this.list = new d(t, e) : this.list = new d(t);
941
+ this.memory = t, e ? this.list = new u(t, e) : this.list = new u(t);
916
942
  }
917
943
  get length() {
918
944
  return this.list.length;
919
945
  }
920
946
  insert(t) {
921
- this.list.insert(w(t.memory.bufferPosition, t.memory.bufferByteOffset));
947
+ this.list.insert(T(t.memory.bufferPosition, t.memory.bufferByteOffset));
922
948
  }
923
949
  delete(t) {
924
- return this.list.deleteValue(w(t.memory.bufferPosition, t.memory.bufferByteOffset));
950
+ return this.list.deleteValue(T(t.memory.bufferPosition, t.memory.bufferByteOffset));
925
951
  }
926
952
  *[Symbol.iterator]() {
927
953
  let t = this.list[Symbol.iterator]();
928
954
  for (let { data: e } of t) {
929
- let { bufferPosition: r, bufferByteOffset: i } = h(e, 0), o = new c(this.memory, {
955
+ let { bufferPosition: r, bufferByteOffset: i } = c(e, 0), o = new h(this.memory, {
930
956
  bufferPosition: r,
931
957
  bufferByteOffset: i
932
958
  });
@@ -951,21 +977,23 @@ class se {
951
977
  this.list.free();
952
978
  }
953
979
  }
954
- const ut = {
980
+ const yt = {
955
981
  1: Uint8Array,
956
982
  2: Uint16Array
957
- }, I = 0, dt = 1, yt = 2, mt = 3, x = class x {
983
+ }, I = 0, Bt = 1, mt = 2, bt = 3;
984
+ class Lt {
985
+ static ALLOCATE_COUNT = 4;
986
+ memory;
987
+ allocatedMemory;
988
+ lock;
989
+ cachedPointer;
990
+ cachedString;
958
991
  constructor(t, e) {
959
- l(this, "memory");
960
- l(this, "allocatedMemory");
961
- l(this, "lock");
962
- l(this, "cachedPointer");
963
- l(this, "cachedString");
964
- this.memory = t, typeof e == "string" ? (this.allocatedMemory = this.memory.allocUI32(x.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + mt * this.allocatedMemory.data.BYTES_PER_ELEMENT), this.updateString(e)) : (this.allocatedMemory = new c(t, e), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + mt * this.allocatedMemory.data.BYTES_PER_ELEMENT), "value" in e && this.updateString(e.value));
992
+ this.memory = t, typeof e == "string" ? (this.allocatedMemory = this.memory.allocUI32(Lt.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + bt * 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 + bt * this.allocatedMemory.data.BYTES_PER_ELEMENT), "value" in e && this.updateString(e.value));
965
993
  }
966
994
  updateString(t) {
967
995
  let e = this.createString(t);
968
- C(this.lock), W(this.allocatedMemory.data, I, e.pointer), Atomics.store(this.allocatedMemory.data, dt, t.length), Atomics.store(this.allocatedMemory.data, yt, e.charType), B(this.lock), this.cachedPointer = e.pointer, this.cachedString = t;
996
+ x(this.lock), W(this.allocatedMemory.data, I, e.pointer), Atomics.store(this.allocatedMemory.data, Bt, t.length), Atomics.store(this.allocatedMemory.data, mt, e.charType), k(this.lock), this.cachedPointer = e.pointer, this.cachedString = t;
969
997
  }
970
998
  createString(t) {
971
999
  if (t === "")
@@ -975,11 +1003,11 @@ const ut = {
975
1003
  /* ASCII */
976
1004
  };
977
1005
  let e = [];
978
- for (let f = 0; f < t.length; f++)
979
- e.push(t.charCodeAt(f));
980
- let i = Math.max(...e) > 255 ? 2 : 1, o = ut[i], a = this.memory.allocUI32(Math.ceil(t.length / (4 / o.BYTES_PER_ELEMENT))), n = new o(a.data.buffer, a.data.byteOffset, t.length);
981
- for (let f = 0; f < t.length; f++)
982
- n[f] = t.charCodeAt(f);
1006
+ for (let n = 0; n < t.length; n++)
1007
+ e.push(t.charCodeAt(n));
1008
+ let i = Math.max(...e) > 255 ? 2 : 1, o = yt[i], 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
+ for (let n = 0; n < t.length; n++)
1010
+ f[n] = t.charCodeAt(n);
983
1011
  return {
984
1012
  pointer: a.pointer,
985
1013
  charType: i
@@ -991,13 +1019,13 @@ const ut = {
991
1019
  return this.cachedString;
992
1020
  if (t === 0)
993
1021
  return "";
994
- let { bufferPosition: e, bufferByteOffset: r } = S(t);
995
- C(this.lock);
996
- let i = Atomics.load(this.allocatedMemory.data, yt), o = ut[i], a = Atomics.load(this.allocatedMemory.data, dt), n = new o(this.memory.buffers[e].buf, r, a), f = String.fromCharCode.apply(null, n);
997
- return B(this.lock), this.cachedPointer = t, this.cachedString = f, f;
1022
+ let { bufferPosition: e, bufferByteOffset: r } = A(t);
1023
+ x(this.lock);
1024
+ let i = Atomics.load(this.allocatedMemory.data, mt), o = yt[i], 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 k(this.lock), this.cachedPointer = t, this.cachedString = n, n;
998
1026
  }
999
1027
  set value(t) {
1000
- let { bufferPosition: e, bufferByteOffset: r } = h(this.allocatedMemory.data, I);
1028
+ let { bufferPosition: e, bufferByteOffset: r } = c(this.allocatedMemory.data, I);
1001
1029
  this.updateString(t), r && this.memory.buffers[e].free(r);
1002
1030
  }
1003
1031
  getSharedMemory() {
@@ -1007,33 +1035,19 @@ const ut = {
1007
1035
  return this.allocatedMemory.pointer;
1008
1036
  }
1009
1037
  free() {
1010
- let { bufferPosition: t, bufferByteOffset: e } = h(this.allocatedMemory.data, I);
1038
+ let { bufferPosition: t, bufferByteOffset: e } = c(this.allocatedMemory.data, I);
1011
1039
  e && this.memory.buffers[t].free(e), this.allocatedMemory.free();
1012
1040
  }
1013
- };
1014
- l(x, "ALLOCATE_COUNT", 4);
1015
- let bt = x;
1016
- const m = 1, Bt = 2, At = 3, vt = 4, R = class R {
1017
- constructor(t, e) {
1018
- l(this, "memory");
1019
- // Pointer, List Length, Buffer Length, Type/DataLength
1020
- l(this, "firstBlock");
1021
- l(this, "uint16Array");
1022
- l(this, "cachedFullDataBlock");
1023
- l(this, "cachedPointer");
1024
- if (this.memory = t, e && "firstBlock" in e)
1025
- this.firstBlock = new c(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + At * Uint32Array.BYTES_PER_ELEMENT, 2);
1026
- else {
1027
- this.firstBlock = t.allocUI32(R.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + At * Uint32Array.BYTES_PER_ELEMENT, 2);
1028
- let r = (e == null ? void 0 : e.dataLength) ?? 1, i = (e == null ? void 0 : e.bufferLength) ?? vt, o = t.allocUI32(i * r);
1029
- A(this.firstBlock.data, 0, o.bufferPosition, o.bufferByteOffset), this.bufferLength = i;
1030
- const a = (e == null ? void 0 : e.type) ?? Uint32Array;
1031
- a === Uint32Array ? this.type = 0 : a === Int32Array ? this.type = 1 : a === Float32Array && (this.type = 2), this.dataLength = r;
1032
- }
1033
- this.cachedPointer = this.firstBlock.data[0], this.cachedFullDataBlock = this.getFullDataBlock(this.dataLength);
1034
- }
1041
+ }
1042
+ const p = 0, b = 1, kt = 2, At = 3, Z = 4;
1043
+ class y {
1044
+ static ALLOCATE_COUNT = 4;
1045
+ memory;
1046
+ // Pointer, List Length, Buffer Length, Type/DataLength
1047
+ firstBlock;
1048
+ uint16Array;
1035
1049
  get length() {
1036
- return Atomics.load(this.firstBlock.data, m);
1050
+ return Atomics.load(this.firstBlock.data, b);
1037
1051
  }
1038
1052
  get type() {
1039
1053
  return this.uint16Array[0];
@@ -1048,120 +1062,137 @@ const m = 1, Bt = 2, At = 3, vt = 4, R = class R {
1048
1062
  Atomics.store(this.uint16Array, 1, t);
1049
1063
  }
1050
1064
  get bufferLength() {
1051
- return Atomics.load(this.firstBlock.data, Bt);
1065
+ return Atomics.load(this.firstBlock.data, kt);
1052
1066
  }
1053
1067
  set bufferLength(t) {
1054
- Atomics.store(this.firstBlock.data, Bt, t);
1068
+ Atomics.store(this.firstBlock.data, kt, t);
1069
+ }
1070
+ get pointer() {
1071
+ return this.firstBlock.pointer;
1072
+ }
1073
+ cachedFullDataBlock;
1074
+ cachedPointer;
1075
+ constructor(t, e) {
1076
+ if (this.memory = t, e && "firstBlock" in e) {
1077
+ if (this.firstBlock = new h(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + At * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in e || "dataLength" in e) {
1078
+ let r = t.allocUI32(Z * (e.dataLength ?? 1));
1079
+ m(this.firstBlock.data, p, r.bufferPosition, r.bufferByteOffset), this.bufferLength = Z, this.dataLength = e.dataLength ?? 1;
1080
+ }
1081
+ if ("type" in e) {
1082
+ const r = e?.type ?? Uint32Array;
1083
+ r === Uint32Array ? this.type = 0 : r === Int32Array ? this.type = 1 : r === Float32Array && (this.type = 2);
1084
+ }
1085
+ } else {
1086
+ this.firstBlock = t.allocUI32(y.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + At * Uint32Array.BYTES_PER_ELEMENT, 2);
1087
+ let r = e?.dataLength ?? 1, i = e?.bufferLength ?? Z, o = t.allocUI32(i * r);
1088
+ m(this.firstBlock.data, p, o.bufferPosition, o.bufferByteOffset), this.bufferLength = i;
1089
+ const a = e?.type ?? Uint32Array;
1090
+ a === Uint32Array ? this.type = 0 : a === Int32Array ? this.type = 1 : a === Float32Array && (this.type = 2), this.dataLength = r;
1091
+ }
1092
+ this.cachedPointer = this.firstBlock.data[0], this.cachedFullDataBlock = this.getFullDataBlock();
1055
1093
  }
1056
1094
  at(t) {
1057
1095
  let e = this.length;
1058
1096
  if (t >= e || t < 0)
1059
1097
  throw new Error(`${t} is out of bounds ${e}`);
1060
- let r = h(this.firstBlock.data, 0), i = new c(this.memory, r);
1061
- return this.getDataBlock(i.data, t);
1098
+ let r = this.getFullDataBlock();
1099
+ return this.getDataBlock(r, t);
1062
1100
  }
1063
1101
  get(t, e = 0) {
1064
1102
  if (e >= this.dataLength)
1065
1103
  throw new Error(`${e} is out of dataLength bounds ${this.dataLength}`);
1066
- return this.at(t)[e];
1104
+ if (t >= this.length || t < 0)
1105
+ throw new Error(`${t} is out of bounds ${this.length}`);
1106
+ return this.getFullDataBlock()[t * this.dataLength + e];
1067
1107
  }
1068
1108
  push(t) {
1069
1109
  typeof t == "number" && (t = [t]);
1070
1110
  let e = this.dataLength;
1071
1111
  if (t.length > e)
1072
1112
  throw new Error(`Can't insert ${t.length} array into shared list of ${e} dataLength`);
1073
- let r = this.getFullDataBlock(e), i = this.length;
1074
- return r.set(t, e * i), Atomics.add(this.firstBlock.data, m, m) + 1 >= this.bufferLength && this.growBuffer(), i;
1113
+ let r = this.getFullDataBlock(), i = this.length;
1114
+ return r.set(t, e * i), Atomics.add(this.firstBlock.data, b, 1) + 1 >= this.bufferLength && this.growBuffer(), i;
1075
1115
  }
1076
1116
  pop() {
1077
- let t = Atomics.sub(this.firstBlock.data, m, m), e = h(this.firstBlock.data, 0), r = new c(this.memory, e);
1078
- return this.getDataBlock(r.data, t - 1);
1117
+ let t = Atomics.sub(this.firstBlock.data, b, b), e = this.getFullDataBlock();
1118
+ return this.getDataBlock(e, t - 1);
1079
1119
  }
1080
1120
  deleteIndex(t) {
1081
1121
  let e = this.length;
1082
1122
  if (t >= e || t < 0)
1083
1123
  throw new Error(`${t} is out of bounds ${e}`);
1084
- let r = this.dataLength, i = this.getFullDataBlock(r);
1124
+ let r = this.dataLength, i = this.getFullDataBlock();
1085
1125
  for (let o = t; o < e; o++)
1086
1126
  for (let a = 0; a < r; a++)
1087
1127
  i[o * r + a] = i[(o + 1) * r + a];
1088
- Atomics.sub(this.firstBlock.data, m, m);
1128
+ Atomics.sub(this.firstBlock.data, b, b);
1089
1129
  }
1090
1130
  clear() {
1091
- this.firstBlock.data[m] = 0;
1131
+ this.firstBlock.data[b] = 0;
1092
1132
  }
1093
1133
  *[Symbol.iterator]() {
1094
- let t = h(this.firstBlock.data, 0), e = new c(this.memory, t);
1095
- for (let r = 0; r < this.length; r++)
1096
- yield this.getDataBlock(e.data, r);
1134
+ let t = this.getFullDataBlock();
1135
+ for (let e = 0; e < this.length; e++)
1136
+ yield this.getDataBlock(t, e);
1097
1137
  }
1098
- getFullDataBlock(t) {
1099
- let e = Atomics.load(this.firstBlock.data, 0);
1100
- if (this.cachedPointer === e && this.cachedFullDataBlock)
1138
+ getFullDataBlock() {
1139
+ let t = Atomics.load(this.firstBlock.data, p);
1140
+ if (this.cachedPointer === t && this.cachedFullDataBlock)
1101
1141
  return this.cachedFullDataBlock;
1102
- let r = S(e), i = new c(this.memory, r), o;
1142
+ let e = A(t), r = new h(this.memory, e), i;
1103
1143
  switch (this.type) {
1104
1144
  case 1:
1105
- o = new Int32Array(i.data.buffer, i.bufferByteOffset, t * this.bufferLength);
1145
+ i = new Int32Array(r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
1106
1146
  break;
1107
1147
  case 0:
1108
- o = new Uint32Array(i.data.buffer, i.bufferByteOffset, t * this.bufferLength);
1148
+ i = new Uint32Array(r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
1109
1149
  break;
1110
1150
  case 2:
1111
- o = new Float32Array(i.data.buffer, i.bufferByteOffset, t * this.bufferLength);
1151
+ i = new Float32Array(r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
1112
1152
  break;
1113
1153
  default:
1114
1154
  throw new Error(`Unknown data block type ${this.type}`);
1115
1155
  }
1116
- return this.cachedPointer = e, this.cachedFullDataBlock = o, o;
1156
+ return this.cachedPointer = t, this.cachedFullDataBlock = i, i;
1117
1157
  }
1118
1158
  getDataBlock(t, e) {
1119
- switch (this.type) {
1120
- case 1:
1121
- return new Int32Array(t.buffer, t.byteOffset + e * this.dataLength * 4, this.dataLength);
1122
- case 0:
1123
- return new Uint32Array(t.buffer, t.byteOffset + e * this.dataLength * 4, this.dataLength);
1124
- case 2:
1125
- return new Float32Array(t.buffer, t.byteOffset + e * this.dataLength * 4, this.dataLength);
1126
- default:
1127
- throw new Error(`Unknown data block type ${this.type}`);
1128
- }
1159
+ const r = e * this.dataLength;
1160
+ return t.subarray(r, r + this.dataLength);
1129
1161
  }
1130
1162
  growBuffer() {
1131
- let e = this.bufferLength * 2, r = this.dataLength, i = h(this.firstBlock.data, 0), o = new c(this.memory, i), a = this.getFullDataBlock(r), n = this.memory.allocUI32(e * r), f;
1163
+ let e = this.bufferLength * 2, r = this.dataLength, i = c(this.firstBlock.data, p), o = new h(this.memory, i), a = this.getFullDataBlock(), f = this.memory.allocUI32(e * r), n;
1132
1164
  switch (this.type) {
1133
1165
  case 1:
1134
- f = new Int32Array(n.data.buffer, n.bufferByteOffset, r * this.bufferLength);
1166
+ n = new Int32Array(f.data.buffer, f.bufferByteOffset, r * this.bufferLength);
1135
1167
  break;
1136
1168
  case 0:
1137
- f = new Uint32Array(n.data.buffer, n.bufferByteOffset, r * this.bufferLength);
1169
+ n = new Uint32Array(f.data.buffer, f.bufferByteOffset, r * this.bufferLength);
1138
1170
  break;
1139
1171
  case 2:
1140
- f = new Float32Array(n.data.buffer, n.bufferByteOffset, r * this.bufferLength);
1172
+ n = new Float32Array(f.data.buffer, f.bufferByteOffset, r * this.bufferLength);
1141
1173
  break;
1142
1174
  default:
1143
1175
  throw new Error(`Unknown data block type ${this.type}`);
1144
1176
  }
1145
- f.set(a), A(this.firstBlock.data, 0, n.bufferPosition, n.bufferByteOffset), this.bufferLength = e, o.free();
1177
+ n.set(a), m(this.firstBlock.data, p, f.bufferPosition, f.bufferByteOffset), this.bufferLength = e, o.free();
1146
1178
  }
1147
1179
  free() {
1148
- let t = h(this.firstBlock.data, 0);
1149
- new c(this.memory, t).free(), this.firstBlock.free();
1180
+ let t = c(this.firstBlock.data, p);
1181
+ new h(this.memory, t).free(), this.firstBlock.free();
1150
1182
  }
1151
1183
  getSharedMemory() {
1152
1184
  return {
1153
1185
  firstBlock: this.firstBlock.getSharedMemory()
1154
1186
  };
1155
1187
  }
1156
- };
1157
- l(R, "ALLOCATE_COUNT", 4);
1158
- let kt = R;
1159
- class jt {
1188
+ }
1189
+ class le {
1190
+ static ALLOCATE_COUNT = u.ALLOCATE_COUNT;
1191
+ heap;
1192
+ list;
1193
+ cache = /* @__PURE__ */ new Map();
1160
1194
  constructor(t, e) {
1161
- l(this, "heap");
1162
- l(this, "list");
1163
- l(this, "cache", /* @__PURE__ */ new Map());
1164
- e ? this.list = new d(t, e) : this.list = new d(t), this.heap = t, this.list.onDelete = (r) => {
1195
+ e ? this.list = new u(t, e) : this.list = new u(t), this.heap = t, this.list.onDelete = (r) => {
1165
1196
  let i = Atomics.load(r, 0);
1166
1197
  if (i) {
1167
1198
  let o = this.cache.get(i);
@@ -1226,100 +1257,246 @@ class jt {
1226
1257
  this.list.free(), this.cache.clear();
1227
1258
  }
1228
1259
  }
1229
- l(jt, "ALLOCATE_COUNT", d.ALLOCATE_COUNT);
1230
- const Et = new ArrayBuffer(4), gt = new Uint32Array(Et), D = new Uint16Array(Et);
1231
- function oe(s, t) {
1232
- return qt(Atomics.load(s, t));
1260
+ const D = 0, gt = 1, Et = 2, j = 3, pt = j + y.ALLOCATE_COUNT;
1261
+ class St {
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[Et];
1275
+ }
1276
+ set maxChunkSize(t) {
1277
+ Atomics.store(this.firstBlock.data, Et, 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 + gt * Uint32Array.BYTES_PER_ELEMENT, 2), this.pointerVector = new y(t, {
1297
+ firstBlock: {
1298
+ bufferPosition: this.firstBlock.bufferPosition,
1299
+ bufferByteOffset: this.firstBlock.bufferByteOffset + j * Uint32Array.BYTES_PER_ELEMENT
1300
+ }
1301
+ }), this.recycleVector = new y(t, {
1302
+ firstBlock: {
1303
+ bufferPosition: this.firstBlock.bufferPosition,
1304
+ bufferByteOffset: this.firstBlock.bufferByteOffset + pt * Uint32Array.BYTES_PER_ELEMENT
1305
+ }
1306
+ });
1307
+ else {
1308
+ this.firstBlock = t.allocUI32(St.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + gt * Uint32Array.BYTES_PER_ELEMENT, 2);
1309
+ let r = e?.dataLength ?? 1, i = e?.maxChunkSize ?? 100;
1310
+ this.pointerVector = new y(t, {
1311
+ type: Uint32Array,
1312
+ firstBlock: {
1313
+ bufferPosition: this.firstBlock.bufferPosition,
1314
+ bufferByteOffset: this.firstBlock.bufferByteOffset + j * 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 + pt * Uint32Array.BYTES_PER_ELEMENT
1321
+ }
1322
+ });
1323
+ let o = t.allocUI32(i * 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 = i;
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 i = this.getFullDataBlock(r), o = r % this.maxChunkSize;
1347
+ return i.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((i, o) => (i.push(...o), i), []), e = this.getFullDataBlock(0), r = 0;
1357
+ for (let i = 0; i < Atomics.load(this.firstBlock.data, D); i++)
1358
+ if (!t.includes(i)) {
1359
+ let o = Math.floor(i / this.maxChunkSize);
1360
+ o !== r && (e = this.getFullDataBlock(i), r = o), yield this.getDataBlock(e, i % 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 i = new h(this.memory, A(this.pointerVector.get(e))), o;
1372
+ switch (this.type) {
1373
+ case 1:
1374
+ o = new Int32Array(i.data.buffer, i.bufferByteOffset, this.dataLength * this.maxChunkSize);
1375
+ break;
1376
+ case 0:
1377
+ o = new Uint32Array(i.data.buffer, i.bufferByteOffset, this.dataLength * this.maxChunkSize);
1378
+ break;
1379
+ case 2:
1380
+ o = new Float32Array(i.data.buffer, i.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, A(e)).free();
1396
+ }
1397
+ this.pointerVector.free(), this.firstBlock.free();
1398
+ }
1399
+ getSharedMemory() {
1400
+ return {
1401
+ firstBlock: this.firstBlock.getSharedMemory()
1402
+ };
1403
+ }
1233
1404
  }
1234
- function ae(s, t, e, r) {
1235
- Atomics.store(s, t, Jt(e, r));
1405
+ const _t = new ArrayBuffer(4), Ot = new Uint32Array(_t), R = new Uint16Array(_t);
1406
+ function he(s, t) {
1407
+ return ee(Atomics.load(s, t));
1236
1408
  }
1237
- function qt(s) {
1238
- return gt[0] = s, [D[0], D[1]];
1409
+ function ce(s, t, e, r) {
1410
+ Atomics.store(s, t, re(e, r));
1239
1411
  }
1240
- function Jt(s, t) {
1241
- return D[0] = s, D[1] = t, gt[0];
1412
+ function ee(s) {
1413
+ return Ot[0] = s, [R[0], R[1]];
1414
+ }
1415
+ function re(s, t) {
1416
+ return R[0] = s, R[1] = t, Ot[0];
1242
1417
  }
1243
- const wt = new ArrayBuffer(8), Tt = new BigUint64Array(wt), b = new Uint16Array(wt);
1244
- function fe(s, t) {
1245
- return Tt[0] = Atomics.load(s, t), [b[0], b[1], b[2], b[3]];
1418
+ const Mt = new ArrayBuffer(8), Pt = new BigUint64Array(Mt), B = new Uint16Array(Mt);
1419
+ function ue(s, t) {
1420
+ return Pt[0] = Atomics.load(s, t), [B[0], B[1], B[2], B[3]];
1246
1421
  }
1247
- function ne(s, t, e, r, i, o = 0) {
1248
- b[0] = e, b[1] = r, b[2] = i, b[3] = o, Atomics.store(s, t, Tt[0]);
1422
+ function de(s, t, e, r, i, o = 0) {
1423
+ B[0] = e, B[1] = r, B[2] = i, B[3] = o, Atomics.store(s, t, Pt[0]);
1249
1424
  }
1250
- const pt = new ArrayBuffer(4), _t = new Float32Array(pt), Ot = new Int32Array(pt);
1251
- function le(s, t) {
1252
- return St(Atomics.load(s, t));
1425
+ const Nt = new ArrayBuffer(4), Ut = new Float32Array(Nt), Ct = new Int32Array(Nt);
1426
+ function ye(s, t) {
1427
+ return It(Atomics.load(s, t));
1253
1428
  }
1254
- function he(s, t, e) {
1255
- Atomics.store(s, t, Lt(e));
1429
+ function Be(s, t, e) {
1430
+ Atomics.store(s, t, Dt(e));
1256
1431
  }
1257
- function St(s) {
1258
- return Ot[0] = s, _t[0];
1432
+ function It(s) {
1433
+ return Ct[0] = s, Ut[0];
1259
1434
  }
1260
- function Lt(s) {
1261
- return _t[0] = s, Ot[0];
1435
+ function Dt(s) {
1436
+ return Ut[0] = s, Ct[0];
1262
1437
  }
1263
- function ce(s, t, e) {
1264
- return St(Atomics.exchange(s, t, Lt(e)));
1438
+ function me(s, t, e) {
1439
+ return It(Atomics.exchange(s, t, Dt(e)));
1265
1440
  }
1266
- const g = 0, v = 1, T = 2;
1267
- function ue(s, t = 0) {
1268
- for (; Atomics.compareExchange(s, t, g, v) === T; )
1269
- Atomics.wait(s, t, T);
1441
+ const w = 0, q = 1, L = 2;
1442
+ function be(s, t = 0) {
1443
+ for (; Atomics.compareExchange(s, t, w, q) === L; )
1444
+ Atomics.wait(s, t, L);
1270
1445
  Atomics.add(s, t + 1, 1);
1271
1446
  }
1272
- function de(s, t = 0) {
1273
- let e = Atomics.compareExchange(s, t, g, T);
1274
- for (; e !== g; )
1275
- Atomics.wait(s, t, e), e = Atomics.compareExchange(s, t, g, T);
1447
+ function ke(s, t = 0) {
1448
+ let e = Atomics.compareExchange(s, t, w, L);
1449
+ for (; e !== w; )
1450
+ Atomics.wait(s, t, e), e = Atomics.compareExchange(s, t, w, L);
1276
1451
  }
1277
- function ye(s, t = 0) {
1278
- Atomics.sub(s, t + 1, 1) - 1 <= 0 && (Atomics.compareExchange(s, t, v, g) !== v && console.warn("We are unlocking when it was not read locked!"), Atomics.notify(s, t));
1452
+ function Ae(s, t = 0) {
1453
+ Atomics.sub(s, t + 1, 1) - 1 <= 0 && (Atomics.compareExchange(s, t, q, w) !== q && console.warn("We are unlocking when it was not read locked!"), Atomics.notify(s, t));
1279
1454
  }
1280
- function me(s, t = 0) {
1281
- Atomics.compareExchange(s, t, T, g) !== T && console.warn("We are unlocking when it was not write locked!"), Atomics.notify(s, t);
1455
+ function ge(s, t = 0) {
1456
+ Atomics.compareExchange(s, t, L, w) !== L && console.warn("We are unlocking when it was not write locked!"), Atomics.notify(s, t);
1282
1457
  }
1283
- const be = 2;
1458
+ const Ee = 2;
1284
1459
  export {
1285
- c as AllocatedMemory,
1286
- Vt as BYTE_OFFSET_BIT_COUNT,
1287
- jt as CachedItemList,
1288
- q as MAX_BYTE_OFFSET_LENGTH,
1289
- J as MAX_POSITION_LENGTH,
1290
- G as MemoryBuffer,
1291
- ie as MemoryHeap,
1292
- te as POSITION_BIT_COUNT,
1293
- be as READ_WRITE_LOCK_ALLOCATE_COUNT,
1294
- re as SIMPLE_LOCK_ALLOCATE_COUNT,
1295
- d as SharedList,
1296
- ct as SharedMap,
1297
- se as SharedPointerList,
1298
- bt as SharedString,
1299
- kt as SharedVector,
1300
- Jt as convert16To32,
1301
- qt as convert32To16,
1302
- Lt as convertFloat32ToInt32,
1303
- St as convertInt32ToFloat32,
1304
- w as createPointer,
1305
- ce as exchangeFloat32,
1306
- S as getPointer,
1307
- oe as load16From32,
1308
- fe as load16From64,
1309
- le as loadFloat32,
1310
- h as loadPointer,
1460
+ h as AllocatedMemory,
1461
+ ie as BYTE_OFFSET_BIT_COUNT,
1462
+ le as CachedItemList,
1463
+ J as MAX_BYTE_OFFSET_LENGTH,
1464
+ Q as MAX_POSITION_LENGTH,
1465
+ V as MemoryBuffer,
1466
+ ne as MemoryHeap,
1467
+ se as POSITION_BIT_COUNT,
1468
+ Ee as READ_WRITE_LOCK_ALLOCATE_COUNT,
1469
+ ae as SIMPLE_LOCK_ALLOCATE_COUNT,
1470
+ u as SharedList,
1471
+ Tt as SharedMap,
1472
+ fe as SharedPointerList,
1473
+ St as SharedPool,
1474
+ Lt as SharedString,
1475
+ y as SharedVector,
1476
+ re as convert16To32,
1477
+ ee as convert32To16,
1478
+ Dt as convertFloat32ToInt32,
1479
+ It as convertInt32ToFloat32,
1480
+ T as createPointer,
1481
+ me as exchangeFloat32,
1482
+ A as getPointer,
1483
+ he as load16From32,
1484
+ ue as load16From64,
1485
+ ye as loadFloat32,
1486
+ c as loadPointer,
1311
1487
  O as loadRawPointer,
1312
- C as lock,
1313
- ue as readLock,
1314
- ye as readUnlock,
1315
- ee as replacePointer,
1316
- $ as replaceRawPointer,
1317
- ae as store16In32,
1318
- ne as store16In64,
1319
- he as storeFloat32,
1320
- A as storePointer,
1488
+ x as lock,
1489
+ be as readLock,
1490
+ Ae as readUnlock,
1491
+ oe as replacePointer,
1492
+ z as replaceRawPointer,
1493
+ ce as store16In32,
1494
+ de as store16In64,
1495
+ Be as storeFloat32,
1496
+ m as storePointer,
1321
1497
  W as storeRawPointer,
1322
- B as unlock,
1323
- de as writeLock,
1324
- me as writeUnlock
1498
+ k as unlock,
1499
+ ke as writeLock,
1500
+ ge as writeUnlock
1325
1501
  };
1502
+ //# sourceMappingURL=shared-memory-objects.js.map