@daneren2005/shared-memory-objects 0.0.11 → 0.0.12
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 +82 -3
- package/dist/shared-memory-objects.js +539 -508
- package/dist/shared-memory-objects.js.map +1 -0
- package/dist/shared-memory-objects.umd.cjs +2 -1
- package/dist/shared-memory-objects.umd.cjs.map +1 -0
- package/dist/src/shared-pool.d.ts +39 -0
- package/dist/src/shared-vector.d.ts +2 -1
- package/package.json +23 -23
|
@@ -1,49 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 qt = 20, Jt = 12, V = Math.pow(2, 20), j = Math.pow(2, 12);
|
|
2
|
+
function h(i, t = 0) {
|
|
3
|
+
return L(Atomics.load(i, t));
|
|
7
4
|
}
|
|
8
|
-
function
|
|
9
|
-
return Atomics.load(
|
|
5
|
+
function S(i, t = 0) {
|
|
6
|
+
return Atomics.load(i, t);
|
|
10
7
|
}
|
|
11
|
-
function
|
|
12
|
-
Atomics.store(
|
|
8
|
+
function m(i, t = 0, e, r) {
|
|
9
|
+
Atomics.store(i, t, w(e, r));
|
|
13
10
|
}
|
|
14
|
-
function
|
|
15
|
-
Atomics.store(
|
|
11
|
+
function Z(i, t = 0, e) {
|
|
12
|
+
Atomics.store(i, t, e);
|
|
16
13
|
}
|
|
17
|
-
function
|
|
18
|
-
let a = w(
|
|
19
|
-
return Atomics.compareExchange(
|
|
14
|
+
function Qt(i, t, e, r, s, o) {
|
|
15
|
+
let a = w(s, o);
|
|
16
|
+
return Atomics.compareExchange(i, t, a, w(e, r)) === a;
|
|
20
17
|
}
|
|
21
|
-
function
|
|
22
|
-
return Atomics.compareExchange(
|
|
18
|
+
function R(i, t, e, r) {
|
|
19
|
+
return Atomics.compareExchange(i, t, r, e) === r;
|
|
23
20
|
}
|
|
24
|
-
function
|
|
21
|
+
function L(i) {
|
|
25
22
|
return {
|
|
26
|
-
bufferPosition:
|
|
27
|
-
bufferByteOffset:
|
|
23
|
+
bufferPosition: i & 4095,
|
|
24
|
+
bufferByteOffset: i >>> 12
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
|
-
function w(
|
|
31
|
-
return
|
|
27
|
+
function w(i, t) {
|
|
28
|
+
return i + (t << 12);
|
|
32
29
|
}
|
|
33
30
|
class c {
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
}
|
|
31
|
+
memory;
|
|
32
|
+
bufferPosition;
|
|
41
33
|
get bufferByteOffset() {
|
|
42
34
|
return this.data.byteOffset;
|
|
43
35
|
}
|
|
44
36
|
get pointer() {
|
|
45
37
|
return w(this.bufferPosition, this.bufferByteOffset);
|
|
46
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));
|
|
43
|
+
}
|
|
47
44
|
getArray(t, e, r) {
|
|
48
45
|
return new t(this.data.buffer, this.data.byteOffset + e * t.BYTES_PER_ELEMENT, r);
|
|
49
46
|
}
|
|
@@ -63,15 +60,15 @@ class c {
|
|
|
63
60
|
};
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
|
-
const
|
|
67
|
-
function
|
|
68
|
-
for (; Atomics.compareExchange(
|
|
69
|
-
"WorkerGlobalScope" in self && Atomics.wait(
|
|
63
|
+
const W = 0, C = 1;
|
|
64
|
+
function D(i, t = 0) {
|
|
65
|
+
for (; Atomics.compareExchange(i, t, W, C) !== W; )
|
|
66
|
+
"WorkerGlobalScope" in self && Atomics.wait(i, t, C);
|
|
70
67
|
}
|
|
71
|
-
function
|
|
72
|
-
Atomics.compareExchange(
|
|
68
|
+
function b(i, t = 0) {
|
|
69
|
+
Atomics.compareExchange(i, t, C, W) !== C && console.warn("We are unlocking when it was not locked!"), Atomics.notify(i, t);
|
|
73
70
|
}
|
|
74
|
-
const
|
|
71
|
+
const te = 1, Pt = {
|
|
75
72
|
5120: "i8",
|
|
76
73
|
5121: "u8",
|
|
77
74
|
5122: "i16",
|
|
@@ -79,67 +76,65 @@ const re = 1, It = {
|
|
|
79
76
|
5124: "i32",
|
|
80
77
|
5125: "u32",
|
|
81
78
|
5126: "f32"
|
|
82
|
-
},
|
|
79
|
+
}, Nt = {
|
|
83
80
|
f32: Float32Array,
|
|
84
81
|
f64: Float64Array
|
|
85
|
-
},
|
|
82
|
+
}, It = {
|
|
86
83
|
i8: Int8Array,
|
|
87
84
|
i16: Int16Array,
|
|
88
85
|
i32: Int32Array
|
|
89
|
-
},
|
|
86
|
+
}, Ut = {
|
|
90
87
|
u8: Uint8Array,
|
|
91
88
|
u8c: Uint8ClampedArray,
|
|
92
89
|
u16: Uint16Array,
|
|
93
90
|
u32: Uint32Array
|
|
94
|
-
},
|
|
95
|
-
// eslint-disable-next-line
|
|
91
|
+
}, Ct = {
|
|
96
92
|
i64: BigInt64Array,
|
|
97
|
-
// eslint-disable-next-line
|
|
98
93
|
u64: BigUint64Array
|
|
99
|
-
},
|
|
100
|
-
...
|
|
101
|
-
...
|
|
102
|
-
...
|
|
103
|
-
},
|
|
104
|
-
const t =
|
|
105
|
-
return t !== void 0 ? t :
|
|
94
|
+
}, Dt = {
|
|
95
|
+
...Nt,
|
|
96
|
+
...It,
|
|
97
|
+
...Ut
|
|
98
|
+
}, Ft = (i) => {
|
|
99
|
+
const t = Pt[i];
|
|
100
|
+
return t !== void 0 ? t : i;
|
|
106
101
|
};
|
|
107
|
-
function
|
|
108
|
-
const e =
|
|
109
|
-
return new (e ||
|
|
102
|
+
function xt(i, ...t) {
|
|
103
|
+
const e = Ct[i];
|
|
104
|
+
return new (e || Dt[Ft(i)])(...t);
|
|
110
105
|
}
|
|
111
|
-
const
|
|
112
|
-
class
|
|
106
|
+
const q = 0, J = 1, Q = 2, tt = 3, et = 4, A = 5, rt = 6, $ = 1, Y = 2, it = 32, H = 0, z = 1, d = 8;
|
|
107
|
+
class K {
|
|
108
|
+
buf;
|
|
109
|
+
start;
|
|
110
|
+
u8;
|
|
111
|
+
u32;
|
|
112
|
+
state;
|
|
113
|
+
lock;
|
|
113
114
|
constructor(t = {}) {
|
|
114
|
-
|
|
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 ? P(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, it / 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`);
|
|
124
|
-
const r = this.initialTop(e),
|
|
125
|
-
if (r >=
|
|
119
|
+
const r = this.initialTop(e), s = t.end != null ? Math.min(t.end, this.buf.byteLength) : this.buf.byteLength;
|
|
120
|
+
if (r >= s)
|
|
126
121
|
throw new Error(
|
|
127
122
|
`insufficient address range (0x${this.start.toString(
|
|
128
123
|
16
|
|
129
|
-
)} - 0x${
|
|
124
|
+
)} - 0x${s.toString(16)})`
|
|
130
125
|
);
|
|
131
|
-
this.align = e, this.doCompact = t.compact !== !1, this.doSplit = t.split !== !1, this.minSplit = t.minSplit || 16, this.end =
|
|
126
|
+
this.align = e, this.doCompact = t.compact !== !1, this.doSplit = t.split !== !1, this.minSplit = t.minSplit || 16, this.end = s, this.top = r, this._free = 0, this._used = 0;
|
|
132
127
|
}
|
|
133
128
|
}
|
|
134
129
|
stats() {
|
|
135
130
|
const t = (r) => {
|
|
136
|
-
let
|
|
131
|
+
let s = 0, o = 0;
|
|
137
132
|
for (; r; )
|
|
138
|
-
if (
|
|
133
|
+
if (s++, o += this.blockSize(r), r = this.blockNext(r), r > this.end) {
|
|
139
134
|
console.error(`Trying to get stats for block past end of buffer: ${r} > ${this.end}`);
|
|
140
135
|
break;
|
|
141
136
|
}
|
|
142
|
-
return { count:
|
|
137
|
+
return { count: s, size: o };
|
|
143
138
|
}, e = t(this._free);
|
|
144
139
|
return {
|
|
145
140
|
free: e,
|
|
@@ -150,12 +145,12 @@ class G {
|
|
|
150
145
|
};
|
|
151
146
|
}
|
|
152
147
|
callocAs(t, e, r = 0) {
|
|
153
|
-
const
|
|
154
|
-
return
|
|
148
|
+
const s = this.mallocAs(t, e);
|
|
149
|
+
return s && s.fill(r), s;
|
|
155
150
|
}
|
|
156
151
|
mallocAs(t, e) {
|
|
157
|
-
const r = this.malloc(e *
|
|
158
|
-
return r ?
|
|
152
|
+
const r = this.malloc(e * Rt[t]);
|
|
153
|
+
return r ? xt(t, this.buf, r, e) : void 0;
|
|
159
154
|
}
|
|
160
155
|
calloc(t, e = 0) {
|
|
161
156
|
const r = this.malloc(t);
|
|
@@ -164,70 +159,68 @@ class G {
|
|
|
164
159
|
malloc(t) {
|
|
165
160
|
if (t <= 0)
|
|
166
161
|
return 0;
|
|
167
|
-
|
|
168
|
-
const e =
|
|
169
|
-
let
|
|
162
|
+
D(this.lock);
|
|
163
|
+
const e = P(t + d, this.align), r = this.end;
|
|
164
|
+
let s = this.top, o = this._free, a = 0;
|
|
170
165
|
for (; o; ) {
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
let
|
|
166
|
+
const f = this.blockSize(o), n = o + f >= s;
|
|
167
|
+
if (n || f >= e) {
|
|
168
|
+
let l = this.mallocTop(
|
|
174
169
|
o,
|
|
175
170
|
a,
|
|
176
|
-
|
|
171
|
+
f,
|
|
177
172
|
e,
|
|
178
|
-
|
|
173
|
+
n
|
|
179
174
|
);
|
|
180
|
-
return
|
|
175
|
+
return b(this.lock), l;
|
|
181
176
|
}
|
|
182
177
|
a = o, o = this.blockNext(o);
|
|
183
178
|
}
|
|
184
|
-
if (o =
|
|
185
|
-
this.initBlock(o, e, this._used), this._used = o, this.top =
|
|
186
|
-
let
|
|
187
|
-
return
|
|
179
|
+
if (o = s, s = o + e, s <= r) {
|
|
180
|
+
this.initBlock(o, e, this._used), this._used = o, this.top = s;
|
|
181
|
+
let f = _(o);
|
|
182
|
+
return b(this.lock), f;
|
|
188
183
|
}
|
|
189
|
-
return
|
|
184
|
+
return b(this.lock), 0;
|
|
190
185
|
}
|
|
191
|
-
mallocTop(t, e, r,
|
|
192
|
-
if (o && t +
|
|
193
|
-
return 0;
|
|
186
|
+
mallocTop(t, e, r, s, o) {
|
|
187
|
+
if (o && t + s > 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
|
-
this.top = t + this.setBlockSize(t,
|
|
189
|
+
this.top = t + this.setBlockSize(t, s);
|
|
196
190
|
else if (this.doSplit) {
|
|
197
|
-
const a = r -
|
|
198
|
-
a >= this.minSplit && this.splitBlock(t,
|
|
191
|
+
const a = r - s;
|
|
192
|
+
a >= this.minSplit && this.splitBlock(t, s, a);
|
|
199
193
|
}
|
|
200
194
|
return _(t);
|
|
201
195
|
}
|
|
202
196
|
realloc(t, e) {
|
|
203
197
|
if (e <= 0)
|
|
204
198
|
return 0;
|
|
205
|
-
const r =
|
|
206
|
-
let
|
|
199
|
+
const r = M(t);
|
|
200
|
+
let s = 0, o = this._used, a = 0;
|
|
207
201
|
for (; o; ) {
|
|
208
202
|
if (o === r) {
|
|
209
|
-
[
|
|
203
|
+
[s, a] = this.reallocBlock(o, e);
|
|
210
204
|
break;
|
|
211
205
|
}
|
|
212
206
|
o = this.blockNext(o);
|
|
213
207
|
}
|
|
214
|
-
return
|
|
215
|
-
_(
|
|
208
|
+
return s && s !== r && this.u8.copyWithin(
|
|
209
|
+
_(s),
|
|
216
210
|
_(r),
|
|
217
211
|
a
|
|
218
|
-
), _(
|
|
212
|
+
), _(s);
|
|
219
213
|
}
|
|
220
214
|
reallocBlock(t, e) {
|
|
221
|
-
const r = this.blockSize(t),
|
|
215
|
+
const r = this.blockSize(t), s = t + r, o = s >= this.top, a = P(e + d, this.align);
|
|
222
216
|
if (a <= r) {
|
|
223
217
|
if (this.doSplit) {
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
} else
|
|
227
|
-
|
|
228
|
-
return [t, i];
|
|
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);
|
|
221
|
+
return [t, s];
|
|
229
222
|
}
|
|
230
|
-
return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t,
|
|
223
|
+
return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, s]) : (this.free(t), [M(this.malloc(e)), s]);
|
|
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 =
|
|
242
|
+
e = M(e);
|
|
250
243
|
let r = this._used;
|
|
251
244
|
for (; r; ) {
|
|
252
245
|
if (r === e)
|
|
253
|
-
return this.blockSize(e) -
|
|
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
|
-
|
|
271
|
-
let r = this._used,
|
|
263
|
+
D(this.lock), e = M(e);
|
|
264
|
+
let r = this._used, s = 0;
|
|
272
265
|
for (; r; ) {
|
|
273
266
|
if (r === e)
|
|
274
|
-
return
|
|
275
|
-
|
|
267
|
+
return s ? this.unlinkBlock(s, r) : this._used = this.blockNext(r), this.insert(r), this.doCompact && this.compact(), b(this.lock), !0;
|
|
268
|
+
s = r, r = this.blockNext(r);
|
|
276
269
|
}
|
|
277
|
-
return
|
|
270
|
+
return b(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[
|
|
279
|
+
return this.state[et];
|
|
287
280
|
}
|
|
288
281
|
set align(t) {
|
|
289
|
-
this.state[
|
|
282
|
+
this.state[et] = t;
|
|
290
283
|
}
|
|
291
284
|
get end() {
|
|
292
|
-
return this.state[
|
|
285
|
+
return this.state[tt];
|
|
293
286
|
}
|
|
294
287
|
set end(t) {
|
|
295
|
-
this.state[
|
|
288
|
+
this.state[tt] = t;
|
|
296
289
|
}
|
|
297
290
|
get top() {
|
|
298
|
-
return Atomics.load(this.state,
|
|
291
|
+
return Atomics.load(this.state, Q);
|
|
299
292
|
}
|
|
300
293
|
set top(t) {
|
|
301
|
-
Atomics.store(this.state,
|
|
294
|
+
Atomics.store(this.state, Q, t);
|
|
302
295
|
}
|
|
303
296
|
get _free() {
|
|
304
|
-
return Atomics.load(this.state,
|
|
297
|
+
return Atomics.load(this.state, q);
|
|
305
298
|
}
|
|
306
299
|
set _free(t) {
|
|
307
|
-
Atomics.store(this.state,
|
|
300
|
+
Atomics.store(this.state, q, t);
|
|
308
301
|
}
|
|
309
302
|
get _used() {
|
|
310
|
-
return Atomics.load(this.state,
|
|
303
|
+
return Atomics.load(this.state, J);
|
|
311
304
|
}
|
|
312
305
|
set _used(t) {
|
|
313
|
-
Atomics.store(this.state,
|
|
306
|
+
Atomics.store(this.state, J, t);
|
|
314
307
|
}
|
|
315
308
|
get doCompact() {
|
|
316
|
-
return !!(this.state[
|
|
309
|
+
return !!(this.state[A] & $);
|
|
317
310
|
}
|
|
318
311
|
set doCompact(t) {
|
|
319
|
-
t ? this.state[
|
|
312
|
+
t ? this.state[A] |= 1 << $ - 1 : this.state[A] &= ~$;
|
|
320
313
|
}
|
|
321
314
|
get doSplit() {
|
|
322
|
-
return !!(this.state[
|
|
315
|
+
return !!(this.state[A] & Y);
|
|
323
316
|
}
|
|
324
317
|
set doSplit(t) {
|
|
325
|
-
t ? this.state[
|
|
318
|
+
t ? this.state[A] |= 1 << Y - 1 : this.state[A] &= ~Y;
|
|
326
319
|
}
|
|
327
320
|
get minSplit() {
|
|
328
|
-
return this.state[
|
|
321
|
+
return this.state[rt];
|
|
329
322
|
}
|
|
330
323
|
set minSplit(t) {
|
|
331
|
-
if (t <=
|
|
332
|
-
throw new Error(`illegal min split threshold: ${t}, require at least ${
|
|
333
|
-
this.state[
|
|
324
|
+
if (t <= d)
|
|
325
|
+
throw new Error(`illegal min split threshold: ${t}, require at least ${d + 1}`);
|
|
326
|
+
this.state[rt] = t;
|
|
334
327
|
}
|
|
335
328
|
blockSize(t) {
|
|
336
|
-
return Atomics.load(this.u32, (t >> 2) +
|
|
329
|
+
return Atomics.load(this.u32, (t >> 2) + H);
|
|
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) +
|
|
338
|
+
return Atomics.store(this.u32, (t >> 2) + H, e), e;
|
|
346
339
|
}
|
|
347
340
|
blockNext(t) {
|
|
348
|
-
return Atomics.load(this.u32, (t >> 2) +
|
|
341
|
+
return Atomics.load(this.u32, (t >> 2) + z);
|
|
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) +
|
|
349
|
+
Atomics.store(this.u32, (t >> 2) + z, e);
|
|
357
350
|
}
|
|
358
351
|
/**
|
|
359
352
|
* Initializes block header with given `size` and `next` pointer. Returns `block`.
|
|
@@ -363,8 +356,8 @@ class G {
|
|
|
363
356
|
* @param next -
|
|
364
357
|
*/
|
|
365
358
|
initBlock(t, e, r) {
|
|
366
|
-
const
|
|
367
|
-
return Atomics.store(this.u32,
|
|
359
|
+
const s = t >>> 2;
|
|
360
|
+
return Atomics.store(this.u32, s + H, e), Atomics.store(this.u32, s + z, 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
|
|
375
|
+
return P(this.start + it + d, t) - d;
|
|
383
376
|
}
|
|
384
377
|
/**
|
|
385
378
|
* Traverses free list and attempts to recursively merge blocks
|
|
@@ -387,20 +380,20 @@ class G {
|
|
|
387
380
|
* have been merged. Only called if `compact` option is enabled.
|
|
388
381
|
*/
|
|
389
382
|
compact() {
|
|
390
|
-
let t = this._free, e = 0, r = 0,
|
|
383
|
+
let t = this._free, e = 0, r = 0, s, o = !1;
|
|
391
384
|
for (; t; ) {
|
|
392
|
-
for (
|
|
393
|
-
|
|
394
|
-
if (
|
|
395
|
-
const a =
|
|
385
|
+
for (s = t, r = this.blockNext(t); r && s + this.blockSize(s) === r; )
|
|
386
|
+
s = r, r = this.blockNext(r);
|
|
387
|
+
if (s !== t) {
|
|
388
|
+
const a = s - t + this.blockSize(s);
|
|
396
389
|
this.setBlockSize(t, a);
|
|
397
|
-
const
|
|
398
|
-
let
|
|
399
|
-
for (;
|
|
400
|
-
const
|
|
401
|
-
this.setBlockNext(
|
|
390
|
+
const f = this.blockNext(s);
|
|
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,
|
|
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 _ = (
|
|
414
|
+
const _ = (i) => i > 0 ? i + d : 0, M = (i) => i > 0 ? i - d : 0, P = (i, t) => (t--, i + t & ~t), Rt = {
|
|
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
|
-
},
|
|
426
|
+
}, $t = [
|
|
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
|
-
],
|
|
436
|
+
], Yt = [
|
|
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
|
-
],
|
|
446
|
+
], Ht = [
|
|
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
|
-
],
|
|
456
|
+
], zt = [
|
|
464
457
|
"b",
|
|
465
458
|
"kibit",
|
|
466
459
|
"Mibit",
|
|
@@ -470,43 +463,79 @@ 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
|
-
],
|
|
474
|
-
let r =
|
|
475
|
-
return typeof t == "string" || Array.isArray(t) ? r =
|
|
466
|
+
], st = (i, t, e) => {
|
|
467
|
+
let r = i;
|
|
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
|
+
}, bt = (i) => {
|
|
470
|
+
if (typeof i == "number")
|
|
471
|
+
return Math.log10(i);
|
|
472
|
+
const t = i.toString(10);
|
|
473
|
+
return t.length + Math.log10(`0.${t.slice(0, 15)}`);
|
|
474
|
+
}, Kt = (i) => typeof i == "number" ? Math.log(i) : bt(i) * Math.log(10), Gt = (i, t) => {
|
|
475
|
+
if (typeof i == "number")
|
|
476
|
+
return i / t;
|
|
477
|
+
const e = i / BigInt(t), r = i % BigInt(t);
|
|
478
|
+
return Number(e) + Number(r) / t;
|
|
479
|
+
}, ot = (i, t) => {
|
|
480
|
+
if (t === void 0)
|
|
481
|
+
return i;
|
|
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 ? i : i.length < t ? i.padStart(t, " ") : i;
|
|
485
|
+
}, Xt = (i) => {
|
|
486
|
+
const { minimumFractionDigits: t, maximumFractionDigits: e } = i;
|
|
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
|
|
478
|
-
if (!Number.isFinite(
|
|
479
|
-
throw new TypeError(`Expected a finite number, got ${typeof
|
|
494
|
+
function Zt(i, t) {
|
|
495
|
+
if (typeof i != "bigint" && !Number.isFinite(i))
|
|
496
|
+
throw new TypeError(`Expected a finite number, got ${typeof i}: ${i}`);
|
|
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 ?
|
|
487
|
-
if (t.signed && s
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
504
|
+
const e = t.bits ? t.binary ? zt : Ht : t.binary ? Yt : $t, r = t.space ? t.nonBreakingSpace ? " " : " " : "", s = typeof i == "number" ? i === 0 : i === 0n;
|
|
505
|
+
if (t.signed && s) {
|
|
506
|
+
const l = ` 0${r}${e[0]}`;
|
|
507
|
+
return ot(l, t.fixedWidth);
|
|
508
|
+
}
|
|
509
|
+
const o = i < 0, a = o ? "-" : t.signed ? "+" : "";
|
|
510
|
+
o && (i = -i);
|
|
511
|
+
const f = Xt(t);
|
|
512
|
+
let n;
|
|
513
|
+
if (i < 1) {
|
|
514
|
+
const l = st(i, t.locale, f);
|
|
515
|
+
n = a + l + r + e[0];
|
|
516
|
+
} else {
|
|
517
|
+
const l = Math.min(Math.floor(t.binary ? Kt(i) / Math.log(1024) : bt(i) / 3), e.length - 1);
|
|
518
|
+
if (i = Gt(i, (t.binary ? 1024 : 1e3) ** l), !f) {
|
|
519
|
+
const O = Math.max(3, Math.floor(i).toString().length);
|
|
520
|
+
i = i.toPrecision(O);
|
|
521
|
+
}
|
|
522
|
+
const T = st(Number(i), t.locale, f), x = e[l];
|
|
523
|
+
n = a + T + r + x;
|
|
524
|
+
}
|
|
525
|
+
return ot(n, t.fixedWidth);
|
|
500
526
|
}
|
|
501
|
-
const Wt = 8192, at = 0,
|
|
502
|
-
class
|
|
527
|
+
const Wt = 8192, at = 0, G = 1, N = 2;
|
|
528
|
+
class ee {
|
|
529
|
+
buffers;
|
|
530
|
+
onGrowBufferHandlers = [];
|
|
531
|
+
isClone;
|
|
532
|
+
memory;
|
|
533
|
+
get bufferSize() {
|
|
534
|
+
return this.memory.data[at];
|
|
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
|
|
538
|
+
this.buffers = t.buffers.map((e) => new K({
|
|
510
539
|
buf: e,
|
|
511
540
|
skipInitialization: !0
|
|
512
541
|
})), this.memory = new c(this, {
|
|
@@ -515,38 +544,35 @@ class ie {
|
|
|
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 =
|
|
519
|
-
if (e >
|
|
520
|
-
throw new Error(`Buffer size ${e} is greater than max ${
|
|
547
|
+
const e = t?.bufferSize ?? Wt;
|
|
548
|
+
if (e > V)
|
|
549
|
+
throw new Error(`Buffer size ${e} is greater than max ${V} that we can reference with pointers`);
|
|
521
550
|
let r = this.createBuffer(e);
|
|
522
551
|
this.buffers = [
|
|
523
552
|
r
|
|
524
553
|
];
|
|
525
|
-
const
|
|
526
|
-
if (
|
|
554
|
+
const s = r.callocAs("u32", 3);
|
|
555
|
+
if (s)
|
|
527
556
|
this.memory = new c(this, {
|
|
528
557
|
bufferPosition: 0,
|
|
529
|
-
bufferByteOffset:
|
|
558
|
+
bufferByteOffset: s.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[
|
|
534
|
-
for (let o = 1; o < (
|
|
562
|
+
this.memory.data[at] = e, this.memory.data[G] = 1, this.memory.data[N] = 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
|
|
568
|
+
this.buffers[t.bufferPosition] = new K({
|
|
543
569
|
buf: t.buffer,
|
|
544
570
|
skipInitialization: !0
|
|
545
571
|
});
|
|
546
572
|
}
|
|
547
573
|
growBuffer() {
|
|
548
574
|
const t = this.createBuffer();
|
|
549
|
-
let e = Atomics.add(this.memory.data,
|
|
575
|
+
let e = Atomics.add(this.memory.data, G, 1);
|
|
550
576
|
return this.buffers[e] = t, this.onGrowBufferHandlers.forEach((r) => r({
|
|
551
577
|
bufferPosition: e,
|
|
552
578
|
buffer: t.buf
|
|
@@ -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
|
|
584
|
+
return "SharedArrayBuffer" in globalThis ? r = new SharedArrayBuffer(e) : r = new ArrayBuffer(e), new K({
|
|
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
|
|
@@ -569,19 +595,19 @@ class ie {
|
|
|
569
595
|
}
|
|
570
596
|
allocUI32(t) {
|
|
571
597
|
t = Math.ceil(t);
|
|
572
|
-
for (let
|
|
573
|
-
const o = this.buffers[
|
|
598
|
+
for (let s = 0; s < this.buffers.length; s++) {
|
|
599
|
+
const o = this.buffers[s];
|
|
574
600
|
if (!o)
|
|
575
601
|
continue;
|
|
576
602
|
const a = o.callocAs("u32", t);
|
|
577
603
|
if (a)
|
|
578
|
-
return
|
|
604
|
+
return s === this.buffers.length - 1 && Atomics.load(this.memory.data, G) === this.buffers.length && this.memory.data[N] < 100 && this.memory.data[N] > 0 && o.top / o.end > this.memory.data[N] / 100 && this.growBuffer(), new c(this, {
|
|
579
605
|
data: a,
|
|
580
606
|
buffer: o
|
|
581
607
|
});
|
|
582
608
|
}
|
|
583
|
-
if (this.buffers.length >=
|
|
584
|
-
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 >= j)
|
|
610
|
+
throw new Error(`Can't initialize a new buffer since it would have a position greater than the max of ${j}`);
|
|
585
611
|
let e = this.growBuffer();
|
|
586
612
|
const r = e.callocAs("u32", t);
|
|
587
613
|
if (r)
|
|
@@ -602,7 +628,7 @@ class ie {
|
|
|
602
628
|
return this.buffers[0].buf.byteLength * this.buffers.length;
|
|
603
629
|
}
|
|
604
630
|
prettyMemory() {
|
|
605
|
-
return `${
|
|
631
|
+
return `${nt(this.currentUsed)} / ${nt(this.totalAllocated)}`;
|
|
606
632
|
}
|
|
607
633
|
getSharedMemory() {
|
|
608
634
|
return {
|
|
@@ -610,49 +636,41 @@ class ie {
|
|
|
610
636
|
};
|
|
611
637
|
}
|
|
612
638
|
}
|
|
613
|
-
function
|
|
614
|
-
return
|
|
639
|
+
function nt(i) {
|
|
640
|
+
return Zt(i, {
|
|
615
641
|
binary: !0,
|
|
616
642
|
minimumFractionDigits: 1,
|
|
617
643
|
maximumFractionDigits: 1
|
|
618
644
|
});
|
|
619
645
|
}
|
|
620
|
-
const
|
|
621
|
-
class
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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 ft = 4, lt = 1, g = 2;
|
|
647
|
+
class u {
|
|
648
|
+
static ALLOCATE_COUNT = ft;
|
|
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
|
-
return Atomics.load(this.firstBlock.data,
|
|
673
|
+
return Atomics.load(this.firstBlock.data, g);
|
|
656
674
|
}
|
|
657
675
|
get type() {
|
|
658
676
|
return Atomics.load(this.uint16Array, 0);
|
|
@@ -666,28 +684,37 @@ 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 c(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (g + 1) * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
690
|
+
else {
|
|
691
|
+
e && e.initWithBlock ? this.firstBlock = new c(t, e.initWithBlock) : this.firstBlock = t.allocUI32(ft), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + (g + 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),
|
|
675
|
-
for (let
|
|
676
|
-
|
|
677
|
-
let a,
|
|
678
|
-
for (; !
|
|
679
|
-
a =
|
|
701
|
+
let r = this.memory.allocUI32(lt + e), s = this.getDataBlock(r.data), o = r.pointer;
|
|
702
|
+
for (let n = 0; n < t.length; n++)
|
|
703
|
+
s instanceof Int32Array || s instanceof Uint32Array ? Atomics.store(s, n, t[n]) : s[n] = t[n];
|
|
704
|
+
let a, f = !1;
|
|
705
|
+
for (; !f; )
|
|
706
|
+
a = S(this.firstBlock.data, 1), f = R(this.firstBlock.data, 1, o, a);
|
|
680
707
|
if (a) {
|
|
681
|
-
let { bufferPosition:
|
|
682
|
-
|
|
708
|
+
let { bufferPosition: n, bufferByteOffset: l } = L(a), T = new Uint32Array(this.memory.buffers[n].buf, l, 1);
|
|
709
|
+
Z(T, 0, o);
|
|
683
710
|
} else
|
|
684
|
-
|
|
685
|
-
Atomics.add(this.firstBlock.data,
|
|
711
|
+
Z(this.firstBlock.data, 0, o);
|
|
712
|
+
Atomics.add(this.firstBlock.data, g, 1);
|
|
686
713
|
}
|
|
687
714
|
deleteMatch(t) {
|
|
688
|
-
for (let { data: e, index: r, deleteCurrent:
|
|
715
|
+
for (let { data: e, index: r, deleteCurrent: s } of this)
|
|
689
716
|
if (t(e, r))
|
|
690
|
-
return
|
|
717
|
+
return s(), !0;
|
|
691
718
|
return !1;
|
|
692
719
|
}
|
|
693
720
|
deleteIndex(t) {
|
|
@@ -706,39 +733,39 @@ class d {
|
|
|
706
733
|
clear() {
|
|
707
734
|
let t, e, r = !1;
|
|
708
735
|
for (; !r; ) {
|
|
709
|
-
if (t =
|
|
736
|
+
if (t = S(this.firstBlock.data, 0), e = S(this.firstBlock.data, 1), !e)
|
|
710
737
|
return;
|
|
711
|
-
r =
|
|
738
|
+
r = R(this.firstBlock.data, 1, 0, e);
|
|
712
739
|
}
|
|
713
740
|
if (!t)
|
|
714
741
|
return;
|
|
715
|
-
|
|
716
|
-
let
|
|
742
|
+
R(this.firstBlock.data, 0, 0, t);
|
|
743
|
+
let s = 0, o = t;
|
|
717
744
|
for (; o; ) {
|
|
718
|
-
let { bufferPosition: a, bufferByteOffset:
|
|
719
|
-
if (!
|
|
745
|
+
let { bufferPosition: a, bufferByteOffset: f } = L(o), n = this.memory.buffers[a];
|
|
746
|
+
if (!n)
|
|
720
747
|
break;
|
|
721
|
-
let
|
|
722
|
-
o =
|
|
748
|
+
let l = new Uint32Array(n.buf, f, 2);
|
|
749
|
+
o = S(l, 0), s++, this.onDelete && this.onDelete(this.getDataBlock(l)), n.free(l.byteOffset);
|
|
723
750
|
}
|
|
724
|
-
Atomics.sub(this.firstBlock.data,
|
|
751
|
+
Atomics.sub(this.firstBlock.data, g, s);
|
|
725
752
|
}
|
|
726
753
|
*[Symbol.iterator]() {
|
|
727
|
-
let t = 0, { bufferPosition: e, bufferByteOffset: r } = h(this.firstBlock.data, 0),
|
|
754
|
+
let t = 0, { bufferPosition: e, bufferByteOffset: r } = h(this.firstBlock.data, 0), s = this.firstBlock.data, o = 0, a = 0;
|
|
728
755
|
for (; r; ) {
|
|
729
|
-
let
|
|
730
|
-
if (!
|
|
756
|
+
let f = this.memory.buffers[e];
|
|
757
|
+
if (!f)
|
|
731
758
|
return;
|
|
732
|
-
let
|
|
733
|
-
({ bufferPosition: e, bufferByteOffset: r } = h(
|
|
734
|
-
let
|
|
759
|
+
let n = new Uint32Array(f.buf, r, 2), l = this.getDataBlock(n), T = e, x = r;
|
|
760
|
+
({ bufferPosition: e, bufferByteOffset: r } = h(n, 0));
|
|
761
|
+
let O = !0;
|
|
735
762
|
yield {
|
|
736
|
-
data:
|
|
763
|
+
data: l,
|
|
737
764
|
index: t,
|
|
738
765
|
deleteCurrent: () => {
|
|
739
|
-
|
|
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, g, 1), O = !1;
|
|
740
767
|
}
|
|
741
|
-
},
|
|
768
|
+
}, O && (s = n, o = T, a = x, t++);
|
|
742
769
|
}
|
|
743
770
|
}
|
|
744
771
|
forEach(t) {
|
|
@@ -775,22 +802,13 @@ class d {
|
|
|
775
802
|
this.firstBlock.free();
|
|
776
803
|
}
|
|
777
804
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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 ht = 10;
|
|
806
|
+
class At {
|
|
807
|
+
static ALLOCATE_COUNT = 4;
|
|
808
|
+
memory;
|
|
809
|
+
// Memory order: Pointer, Lock, Length, MaxHash
|
|
810
|
+
pointerMemory;
|
|
811
|
+
lock;
|
|
794
812
|
get hashMemory() {
|
|
795
813
|
return new c(this.memory, h(this.pointerMemory.data, 0));
|
|
796
814
|
}
|
|
@@ -800,43 +818,53 @@ 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 c(t, e.firstBlock);
|
|
824
|
+
else {
|
|
825
|
+
this.pointerMemory = t.allocUI32(At.ALLOCATE_COUNT);
|
|
826
|
+
let r = t.allocUI32(ht);
|
|
827
|
+
m(this.pointerMemory.data, 0, r.bufferPosition, r.bufferByteOffset), Atomics.store(this.pointerMemory.data, 3, ht);
|
|
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 =
|
|
833
|
+
let r = I(t);
|
|
806
834
|
this.setHashKey(this.hashMemory, this.maxHash, r, e) && Atomics.add(this.pointerMemory.data, 2, 1);
|
|
807
835
|
}
|
|
808
|
-
setHashKey(t, e, r,
|
|
809
|
-
let o = this.hash(r, e), a,
|
|
810
|
-
if (
|
|
811
|
-
a = new
|
|
836
|
+
setHashKey(t, e, r, s) {
|
|
837
|
+
let o = this.hash(r, e), a, f = h(t.data, o);
|
|
838
|
+
if (f.bufferByteOffset === 0) {
|
|
839
|
+
a = new u(this.memory, {
|
|
812
840
|
dataLength: 2
|
|
813
841
|
});
|
|
814
|
-
let
|
|
815
|
-
|
|
842
|
+
let l = a.getSharedMemory();
|
|
843
|
+
m(t.data, o, l.firstBlock.bufferPosition, l.firstBlock.bufferByteOffset);
|
|
816
844
|
} else
|
|
817
|
-
a = new
|
|
818
|
-
firstBlock:
|
|
845
|
+
a = new u(this.memory, {
|
|
846
|
+
firstBlock: f
|
|
819
847
|
});
|
|
820
|
-
let
|
|
821
|
-
return a.deleteValue(r) && (
|
|
848
|
+
let n = !0;
|
|
849
|
+
return a.deleteValue(r) && (n = !1), a.insert([r, s]), n;
|
|
822
850
|
}
|
|
823
851
|
get(t) {
|
|
824
|
-
let e =
|
|
825
|
-
if (
|
|
852
|
+
let e = I(t), r = this.hash(e, this.maxHash), s = h(this.hashMemory.data, r);
|
|
853
|
+
if (s.bufferByteOffset === 0)
|
|
826
854
|
return;
|
|
827
|
-
let o = new
|
|
828
|
-
firstBlock:
|
|
855
|
+
let o = new u(this.memory, {
|
|
856
|
+
firstBlock: s
|
|
829
857
|
});
|
|
830
858
|
for (let { data: a } of o)
|
|
831
859
|
if (a[0] === e)
|
|
832
860
|
return a[1];
|
|
833
861
|
}
|
|
834
862
|
has(t) {
|
|
835
|
-
let e =
|
|
836
|
-
if (
|
|
863
|
+
let e = I(t), r = this.hash(e, this.maxHash), s = h(this.hashMemory.data, r);
|
|
864
|
+
if (s.bufferByteOffset === 0)
|
|
837
865
|
return !1;
|
|
838
|
-
let o = new
|
|
839
|
-
firstBlock:
|
|
866
|
+
let o = new u(this.memory, {
|
|
867
|
+
firstBlock: s
|
|
840
868
|
});
|
|
841
869
|
for (let { data: a } of o)
|
|
842
870
|
if (a[0] === e)
|
|
@@ -844,30 +872,30 @@ const ht = 10, F = class F {
|
|
|
844
872
|
return !1;
|
|
845
873
|
}
|
|
846
874
|
delete(t) {
|
|
847
|
-
let e =
|
|
848
|
-
if (
|
|
875
|
+
let e = I(t), r = this.hash(e, this.maxHash), s = h(this.hashMemory.data, r);
|
|
876
|
+
if (s.bufferByteOffset === 0)
|
|
849
877
|
return !1;
|
|
850
|
-
let o = new
|
|
851
|
-
firstBlock:
|
|
878
|
+
let o = new u(this.memory, {
|
|
879
|
+
firstBlock: s
|
|
852
880
|
});
|
|
853
|
-
for (let { data: a, deleteCurrent:
|
|
881
|
+
for (let { data: a, deleteCurrent: f } of o)
|
|
854
882
|
if (a[0] === e)
|
|
855
|
-
return
|
|
883
|
+
return f(), Atomics.sub(this.pointerMemory.data, 2, 1), !0;
|
|
856
884
|
return !1;
|
|
857
885
|
}
|
|
858
886
|
growHashTable() {
|
|
859
|
-
let t = this.maxHash, e = t * 2, r = this.memory.allocUI32(e),
|
|
887
|
+
let t = this.maxHash, e = t * 2, r = this.memory.allocUI32(e), s = this.hashMemory;
|
|
860
888
|
for (let o = 0; o < t; o++) {
|
|
861
|
-
let a = h(
|
|
889
|
+
let a = h(s.data, o);
|
|
862
890
|
if (a.bufferByteOffset === 0)
|
|
863
891
|
continue;
|
|
864
|
-
let
|
|
892
|
+
let f = new u(this.memory, {
|
|
865
893
|
firstBlock: a
|
|
866
894
|
});
|
|
867
|
-
for (let { data:
|
|
868
|
-
this.setHashKey(r, e,
|
|
895
|
+
for (let { data: n } of f)
|
|
896
|
+
this.setHashKey(r, e, n[0], n[1]);
|
|
869
897
|
}
|
|
870
|
-
|
|
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;
|
|
@@ -877,7 +905,7 @@ const ht = 10, F = class F {
|
|
|
877
905
|
let e = h(this.hashMemory.data, t);
|
|
878
906
|
if (e.bufferByteOffset === 0)
|
|
879
907
|
continue;
|
|
880
|
-
new
|
|
908
|
+
new u(this.memory, {
|
|
881
909
|
firstBlock: e
|
|
882
910
|
}).free();
|
|
883
911
|
}
|
|
@@ -888,31 +916,29 @@ 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
|
|
898
|
-
|
|
920
|
+
function I(i) {
|
|
921
|
+
return typeof i == "number" ? i : typeof i == "string" ? vt(i) : i;
|
|
922
|
+
}
|
|
923
|
+
function vt(i) {
|
|
924
|
+
let t = i.length, e = 17 ^ t, r = 0, s;
|
|
899
925
|
for (; t >= 4; )
|
|
900
|
-
|
|
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;
|
|
901
927
|
switch (t) {
|
|
902
928
|
case 3:
|
|
903
|
-
e ^= (
|
|
929
|
+
e ^= (i.charCodeAt(r + 2) & 255) << 16;
|
|
904
930
|
case 2:
|
|
905
|
-
e ^= (
|
|
931
|
+
e ^= (i.charCodeAt(r + 1) & 255) << 8;
|
|
906
932
|
case 1:
|
|
907
|
-
e ^=
|
|
933
|
+
e ^= i.charCodeAt(r) & 255, e = (e & 65535) * 1540483477 + (((e >>> 16) * 1540483477 & 65535) << 16);
|
|
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
|
|
937
|
+
class re {
|
|
938
|
+
memory;
|
|
939
|
+
list;
|
|
912
940
|
constructor(t, e) {
|
|
913
|
-
|
|
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;
|
|
@@ -926,9 +952,9 @@ class se {
|
|
|
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:
|
|
955
|
+
let { bufferPosition: r, bufferByteOffset: s } = h(e, 0), o = new c(this.memory, {
|
|
930
956
|
bufferPosition: r,
|
|
931
|
-
bufferByteOffset:
|
|
957
|
+
bufferByteOffset: s
|
|
932
958
|
});
|
|
933
959
|
yield this.createItem(o);
|
|
934
960
|
}
|
|
@@ -951,21 +977,23 @@ class se {
|
|
|
951
977
|
this.list.free();
|
|
952
978
|
}
|
|
953
979
|
}
|
|
954
|
-
const
|
|
980
|
+
const ct = {
|
|
955
981
|
1: Uint8Array,
|
|
956
982
|
2: Uint16Array
|
|
957
|
-
},
|
|
983
|
+
}, U = 0, ut = 1, dt = 2, yt = 3;
|
|
984
|
+
class gt {
|
|
985
|
+
static ALLOCATE_COUNT = 4;
|
|
986
|
+
memory;
|
|
987
|
+
allocatedMemory;
|
|
988
|
+
lock;
|
|
989
|
+
cachedPointer;
|
|
990
|
+
cachedString;
|
|
958
991
|
constructor(t, e) {
|
|
959
|
-
|
|
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(gt.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + yt * 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 + yt * 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
|
-
|
|
996
|
+
D(this.lock), Z(this.allocatedMemory.data, U, e.pointer), Atomics.store(this.allocatedMemory.data, ut, t.length), Atomics.store(this.allocatedMemory.data, dt, e.charType), b(this.lock), this.cachedPointer = e.pointer, this.cachedString = t;
|
|
969
997
|
}
|
|
970
998
|
createString(t) {
|
|
971
999
|
if (t === "")
|
|
@@ -975,29 +1003,29 @@ const ut = {
|
|
|
975
1003
|
/* ASCII */
|
|
976
1004
|
};
|
|
977
1005
|
let e = [];
|
|
978
|
-
for (let
|
|
979
|
-
e.push(t.charCodeAt(
|
|
980
|
-
let
|
|
981
|
-
for (let
|
|
982
|
-
n
|
|
1006
|
+
for (let n = 0; n < t.length; n++)
|
|
1007
|
+
e.push(t.charCodeAt(n));
|
|
1008
|
+
let s = Math.max(...e) > 255 ? 2 : 1, o = ct[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
|
+
for (let n = 0; n < t.length; n++)
|
|
1010
|
+
f[n] = t.charCodeAt(n);
|
|
983
1011
|
return {
|
|
984
1012
|
pointer: a.pointer,
|
|
985
|
-
charType:
|
|
1013
|
+
charType: s
|
|
986
1014
|
};
|
|
987
1015
|
}
|
|
988
1016
|
get value() {
|
|
989
|
-
let t =
|
|
1017
|
+
let t = S(this.allocatedMemory.data, U);
|
|
990
1018
|
if (this.cachedPointer === t && this.cachedString !== void 0)
|
|
991
1019
|
return this.cachedString;
|
|
992
1020
|
if (t === 0)
|
|
993
1021
|
return "";
|
|
994
|
-
let { bufferPosition: e, bufferByteOffset: r } =
|
|
995
|
-
|
|
996
|
-
let
|
|
997
|
-
return
|
|
1022
|
+
let { bufferPosition: e, bufferByteOffset: r } = L(t);
|
|
1023
|
+
D(this.lock);
|
|
1024
|
+
let s = Atomics.load(this.allocatedMemory.data, dt), o = ct[s], a = Atomics.load(this.allocatedMemory.data, ut), f = new o(this.memory.buffers[e].buf, r, a), n = String.fromCharCode.apply(null, f);
|
|
1025
|
+
return b(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,
|
|
1028
|
+
let { bufferPosition: e, bufferByteOffset: r } = h(this.allocatedMemory.data, U);
|
|
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,
|
|
1038
|
+
let { bufferPosition: t, bufferByteOffset: e } = h(this.allocatedMemory.data, U);
|
|
1011
1039
|
e && this.memory.buffers[t].free(e), this.allocatedMemory.free();
|
|
1012
1040
|
}
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
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 k = 0, B = 1, mt = 2, Bt = 3, X = 4;
|
|
1043
|
+
class kt {
|
|
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,
|
|
1050
|
+
return Atomics.load(this.firstBlock.data, B);
|
|
1037
1051
|
}
|
|
1038
1052
|
get type() {
|
|
1039
1053
|
return this.uint16Array[0];
|
|
@@ -1048,104 +1062,122 @@ 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,
|
|
1065
|
+
return Atomics.load(this.firstBlock.data, mt);
|
|
1052
1066
|
}
|
|
1053
1067
|
set bufferLength(t) {
|
|
1054
|
-
Atomics.store(this.firstBlock.data,
|
|
1068
|
+
Atomics.store(this.firstBlock.data, mt, 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 c(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + Bt * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in e || "dataLength" in e) {
|
|
1078
|
+
let r = t.allocUI32(X * (e.dataLength ?? 1));
|
|
1079
|
+
m(this.firstBlock.data, k, r.bufferPosition, r.bufferByteOffset), this.bufferLength = X, 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(kt.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + Bt * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
1087
|
+
let r = e?.dataLength ?? 1, s = e?.bufferLength ?? X, o = t.allocUI32(s * r);
|
|
1088
|
+
m(this.firstBlock.data, k, o.bufferPosition, o.bufferByteOffset), this.bufferLength = s;
|
|
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 =
|
|
1061
|
-
return this.getDataBlock(
|
|
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
|
-
|
|
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(
|
|
1074
|
-
return r.set(t, e *
|
|
1113
|
+
let r = this.getFullDataBlock(), s = this.length;
|
|
1114
|
+
return r.set(t, e * s), Atomics.add(this.firstBlock.data, B, 1) + 1 >= this.bufferLength && this.growBuffer(), s;
|
|
1075
1115
|
}
|
|
1076
1116
|
pop() {
|
|
1077
|
-
let t = Atomics.sub(this.firstBlock.data,
|
|
1078
|
-
return this.getDataBlock(
|
|
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,
|
|
1124
|
+
let r = this.dataLength, s = this.getFullDataBlock();
|
|
1085
1125
|
for (let o = t; o < e; o++)
|
|
1086
1126
|
for (let a = 0; a < r; a++)
|
|
1087
|
-
|
|
1088
|
-
Atomics.sub(this.firstBlock.data,
|
|
1127
|
+
s[o * r + a] = s[(o + 1) * r + a];
|
|
1128
|
+
Atomics.sub(this.firstBlock.data, B, B);
|
|
1089
1129
|
}
|
|
1090
1130
|
clear() {
|
|
1091
|
-
this.firstBlock.data[
|
|
1131
|
+
this.firstBlock.data[B] = 0;
|
|
1092
1132
|
}
|
|
1093
1133
|
*[Symbol.iterator]() {
|
|
1094
|
-
let t =
|
|
1095
|
-
for (let
|
|
1096
|
-
yield this.getDataBlock(
|
|
1134
|
+
let t = this.getFullDataBlock();
|
|
1135
|
+
for (let e = 0; e < this.length; e++)
|
|
1136
|
+
yield this.getDataBlock(t, e);
|
|
1097
1137
|
}
|
|
1098
|
-
getFullDataBlock(
|
|
1099
|
-
let
|
|
1100
|
-
if (this.cachedPointer ===
|
|
1138
|
+
getFullDataBlock() {
|
|
1139
|
+
let t = Atomics.load(this.firstBlock.data, k);
|
|
1140
|
+
if (this.cachedPointer === t && this.cachedFullDataBlock)
|
|
1101
1141
|
return this.cachedFullDataBlock;
|
|
1102
|
-
let
|
|
1142
|
+
let e = L(t), r = new c(this.memory, e), s;
|
|
1103
1143
|
switch (this.type) {
|
|
1104
1144
|
case 1:
|
|
1105
|
-
|
|
1145
|
+
s = new Int32Array(r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
|
|
1106
1146
|
break;
|
|
1107
1147
|
case 0:
|
|
1108
|
-
|
|
1148
|
+
s = new Uint32Array(r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
|
|
1109
1149
|
break;
|
|
1110
1150
|
case 2:
|
|
1111
|
-
|
|
1151
|
+
s = 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 =
|
|
1156
|
+
return this.cachedPointer = t, this.cachedFullDataBlock = s, s;
|
|
1117
1157
|
}
|
|
1118
1158
|
getDataBlock(t, e) {
|
|
1119
|
-
|
|
1120
|
-
|
|
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,
|
|
1163
|
+
let e = this.bufferLength * 2, r = this.dataLength, s = h(this.firstBlock.data, k), o = new c(this.memory, s), a = this.getFullDataBlock(), f = this.memory.allocUI32(e * r), n;
|
|
1132
1164
|
switch (this.type) {
|
|
1133
1165
|
case 1:
|
|
1134
|
-
|
|
1166
|
+
n = new Int32Array(f.data.buffer, f.bufferByteOffset, r * this.bufferLength);
|
|
1135
1167
|
break;
|
|
1136
1168
|
case 0:
|
|
1137
|
-
|
|
1169
|
+
n = new Uint32Array(f.data.buffer, f.bufferByteOffset, r * this.bufferLength);
|
|
1138
1170
|
break;
|
|
1139
1171
|
case 2:
|
|
1140
|
-
|
|
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
|
-
|
|
1177
|
+
n.set(a), m(this.firstBlock.data, k, f.bufferPosition, f.bufferByteOffset), this.bufferLength = e, o.free();
|
|
1146
1178
|
}
|
|
1147
1179
|
free() {
|
|
1148
|
-
let t = h(this.firstBlock.data,
|
|
1180
|
+
let t = h(this.firstBlock.data, k);
|
|
1149
1181
|
new c(this.memory, t).free(), this.firstBlock.free();
|
|
1150
1182
|
}
|
|
1151
1183
|
getSharedMemory() {
|
|
@@ -1153,19 +1185,18 @@ const m = 1, Bt = 2, At = 3, vt = 4, R = class R {
|
|
|
1153
1185
|
firstBlock: this.firstBlock.getSharedMemory()
|
|
1154
1186
|
};
|
|
1155
1187
|
}
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1188
|
+
}
|
|
1189
|
+
class ie {
|
|
1190
|
+
static ALLOCATE_COUNT = u.ALLOCATE_COUNT;
|
|
1191
|
+
heap;
|
|
1192
|
+
list;
|
|
1193
|
+
cache = /* @__PURE__ */ new Map();
|
|
1160
1194
|
constructor(t, e) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
if (i) {
|
|
1167
|
-
let o = this.cache.get(i);
|
|
1168
|
-
o || (o = this.initItem(i)), o && (o.free(), this.cache.delete(i));
|
|
1195
|
+
e ? this.list = new u(t, e) : this.list = new u(t), this.heap = t, this.list.onDelete = (r) => {
|
|
1196
|
+
let s = Atomics.load(r, 0);
|
|
1197
|
+
if (s) {
|
|
1198
|
+
let o = this.cache.get(s);
|
|
1199
|
+
o || (o = this.initItem(s)), o && (o.free(), this.cache.delete(s));
|
|
1169
1200
|
}
|
|
1170
1201
|
};
|
|
1171
1202
|
}
|
|
@@ -1188,11 +1219,11 @@ class jt {
|
|
|
1188
1219
|
*[Symbol.iterator]() {
|
|
1189
1220
|
let t = this.list[Symbol.iterator]();
|
|
1190
1221
|
for (let { data: e, deleteCurrent: r } of t) {
|
|
1191
|
-
let
|
|
1192
|
-
if (!
|
|
1222
|
+
let s = Atomics.load(e, 0);
|
|
1223
|
+
if (!s)
|
|
1193
1224
|
continue;
|
|
1194
|
-
let o = this.cache.get(
|
|
1195
|
-
o || (o = this.initItem(
|
|
1225
|
+
let o = this.cache.get(s);
|
|
1226
|
+
o || (o = this.initItem(s), o && this.cache.set(s, o)), o && (yield {
|
|
1196
1227
|
item: o,
|
|
1197
1228
|
deleteCurrent: r
|
|
1198
1229
|
});
|
|
@@ -1226,100 +1257,100 @@ class jt {
|
|
|
1226
1257
|
this.list.free(), this.cache.clear();
|
|
1227
1258
|
}
|
|
1228
1259
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
return qt(Atomics.load(s, t));
|
|
1260
|
+
const Et = new ArrayBuffer(4), wt = new Uint32Array(Et), F = new Uint16Array(Et);
|
|
1261
|
+
function se(i, t) {
|
|
1262
|
+
return Vt(Atomics.load(i, t));
|
|
1233
1263
|
}
|
|
1234
|
-
function
|
|
1235
|
-
Atomics.store(
|
|
1264
|
+
function oe(i, t, e, r) {
|
|
1265
|
+
Atomics.store(i, t, jt(e, r));
|
|
1236
1266
|
}
|
|
1237
|
-
function
|
|
1238
|
-
return
|
|
1267
|
+
function Vt(i) {
|
|
1268
|
+
return wt[0] = i, [F[0], F[1]];
|
|
1239
1269
|
}
|
|
1240
|
-
function
|
|
1241
|
-
return
|
|
1270
|
+
function jt(i, t) {
|
|
1271
|
+
return F[0] = i, F[1] = t, wt[0];
|
|
1242
1272
|
}
|
|
1243
|
-
const
|
|
1244
|
-
function
|
|
1245
|
-
return Tt[0] = Atomics.load(
|
|
1273
|
+
const pt = new ArrayBuffer(8), Tt = new BigUint64Array(pt), y = new Uint16Array(pt);
|
|
1274
|
+
function ae(i, t) {
|
|
1275
|
+
return Tt[0] = Atomics.load(i, t), [y[0], y[1], y[2], y[3]];
|
|
1246
1276
|
}
|
|
1247
|
-
function ne(
|
|
1248
|
-
|
|
1277
|
+
function ne(i, t, e, r, s, o = 0) {
|
|
1278
|
+
y[0] = e, y[1] = r, y[2] = s, y[3] = o, Atomics.store(i, t, Tt[0]);
|
|
1249
1279
|
}
|
|
1250
|
-
const
|
|
1251
|
-
function
|
|
1252
|
-
return
|
|
1280
|
+
const _t = new ArrayBuffer(4), St = new Float32Array(_t), Lt = new Int32Array(_t);
|
|
1281
|
+
function fe(i, t) {
|
|
1282
|
+
return Ot(Atomics.load(i, t));
|
|
1253
1283
|
}
|
|
1254
|
-
function
|
|
1255
|
-
Atomics.store(
|
|
1284
|
+
function le(i, t, e) {
|
|
1285
|
+
Atomics.store(i, t, Mt(e));
|
|
1256
1286
|
}
|
|
1257
|
-
function
|
|
1258
|
-
return
|
|
1287
|
+
function Ot(i) {
|
|
1288
|
+
return Lt[0] = i, St[0];
|
|
1259
1289
|
}
|
|
1260
|
-
function
|
|
1261
|
-
return
|
|
1290
|
+
function Mt(i) {
|
|
1291
|
+
return St[0] = i, Lt[0];
|
|
1262
1292
|
}
|
|
1263
|
-
function
|
|
1264
|
-
return
|
|
1293
|
+
function he(i, t, e) {
|
|
1294
|
+
return Ot(Atomics.exchange(i, t, Mt(e)));
|
|
1265
1295
|
}
|
|
1266
|
-
const
|
|
1267
|
-
function
|
|
1268
|
-
for (; Atomics.compareExchange(
|
|
1269
|
-
Atomics.wait(
|
|
1270
|
-
Atomics.add(
|
|
1296
|
+
const E = 0, v = 1, p = 2;
|
|
1297
|
+
function ce(i, t = 0) {
|
|
1298
|
+
for (; Atomics.compareExchange(i, t, E, v) === p; )
|
|
1299
|
+
Atomics.wait(i, t, p);
|
|
1300
|
+
Atomics.add(i, t + 1, 1);
|
|
1271
1301
|
}
|
|
1272
|
-
function
|
|
1273
|
-
let e = Atomics.compareExchange(
|
|
1274
|
-
for (; e !==
|
|
1275
|
-
Atomics.wait(
|
|
1302
|
+
function ue(i, t = 0) {
|
|
1303
|
+
let e = Atomics.compareExchange(i, t, E, p);
|
|
1304
|
+
for (; e !== E; )
|
|
1305
|
+
Atomics.wait(i, t, e), e = Atomics.compareExchange(i, t, E, p);
|
|
1276
1306
|
}
|
|
1277
|
-
function
|
|
1278
|
-
Atomics.sub(
|
|
1307
|
+
function de(i, t = 0) {
|
|
1308
|
+
Atomics.sub(i, t + 1, 1) - 1 <= 0 && (Atomics.compareExchange(i, t, v, E) !== v && console.warn("We are unlocking when it was not read locked!"), Atomics.notify(i, t));
|
|
1279
1309
|
}
|
|
1280
|
-
function
|
|
1281
|
-
Atomics.compareExchange(
|
|
1310
|
+
function ye(i, t = 0) {
|
|
1311
|
+
Atomics.compareExchange(i, t, p, E) !== p && console.warn("We are unlocking when it was not write locked!"), Atomics.notify(i, t);
|
|
1282
1312
|
}
|
|
1283
|
-
const
|
|
1313
|
+
const me = 2;
|
|
1284
1314
|
export {
|
|
1285
1315
|
c as AllocatedMemory,
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1316
|
+
qt as BYTE_OFFSET_BIT_COUNT,
|
|
1317
|
+
ie as CachedItemList,
|
|
1318
|
+
V as MAX_BYTE_OFFSET_LENGTH,
|
|
1319
|
+
j as MAX_POSITION_LENGTH,
|
|
1320
|
+
K as MemoryBuffer,
|
|
1321
|
+
ee as MemoryHeap,
|
|
1322
|
+
Jt as POSITION_BIT_COUNT,
|
|
1323
|
+
me as READ_WRITE_LOCK_ALLOCATE_COUNT,
|
|
1324
|
+
te as SIMPLE_LOCK_ALLOCATE_COUNT,
|
|
1325
|
+
u as SharedList,
|
|
1326
|
+
At as SharedMap,
|
|
1327
|
+
re as SharedPointerList,
|
|
1328
|
+
gt as SharedString,
|
|
1299
1329
|
kt as SharedVector,
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1330
|
+
jt as convert16To32,
|
|
1331
|
+
Vt as convert32To16,
|
|
1332
|
+
Mt as convertFloat32ToInt32,
|
|
1333
|
+
Ot as convertInt32ToFloat32,
|
|
1304
1334
|
w as createPointer,
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1335
|
+
he as exchangeFloat32,
|
|
1336
|
+
L as getPointer,
|
|
1337
|
+
se as load16From32,
|
|
1338
|
+
ae as load16From64,
|
|
1339
|
+
fe as loadFloat32,
|
|
1310
1340
|
h as loadPointer,
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1341
|
+
S as loadRawPointer,
|
|
1342
|
+
D as lock,
|
|
1343
|
+
ce as readLock,
|
|
1344
|
+
de as readUnlock,
|
|
1345
|
+
Qt as replacePointer,
|
|
1346
|
+
R as replaceRawPointer,
|
|
1347
|
+
oe as store16In32,
|
|
1318
1348
|
ne as store16In64,
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1349
|
+
le as storeFloat32,
|
|
1350
|
+
m as storePointer,
|
|
1351
|
+
Z as storeRawPointer,
|
|
1352
|
+
b as unlock,
|
|
1353
|
+
ue as writeLock,
|
|
1354
|
+
ye as writeUnlock
|
|
1325
1355
|
};
|
|
1356
|
+
//# sourceMappingURL=shared-memory-objects.js.map
|