@daneren2005/shared-memory-objects 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -56
- package/dist/{src/allocated-memory.d.ts → allocated-memory.d.ts} +6 -4
- package/dist/allocated-memory.js +47 -37
- package/dist/allocated-memory.js.map +1 -1
- package/dist/{src/cached-item-list.d.ts → cached-item-list.d.ts} +5 -4
- package/dist/cached-item-list.js +75 -75
- package/dist/cached-item-list.js.map +1 -1
- package/dist/constant-string.d.ts +15 -0
- package/dist/constant-string.js +67 -0
- package/dist/constant-string.js.map +1 -0
- package/dist/interfaces/pow2.js +0 -2
- package/dist/interfaces/typed-array-constructor.js +0 -2
- package/dist/interfaces/typed-array.js +0 -2
- package/dist/{src/local-pool.d.ts → local-pool.d.ts} +2 -2
- package/dist/local-pool.js +89 -94
- package/dist/local-pool.js.map +1 -1
- package/dist/lock/read-write-lock.js +15 -21
- package/dist/lock/read-write-lock.js.map +1 -1
- package/dist/lock/simple-lock.js +9 -12
- package/dist/lock/simple-lock.js.map +1 -1
- package/dist/{src/memory-buffer.d.ts → memory-buffer.d.ts} +8 -5
- package/dist/memory-buffer.js +269 -326
- package/dist/memory-buffer.js.map +1 -1
- package/dist/{src/memory-heap.d.ts → memory-heap.d.ts} +4 -2
- package/dist/memory-heap.js +105 -115
- package/dist/memory-heap.js.map +1 -1
- package/dist/{src/serialize-object.d.ts → serialize-object.d.ts} +2 -2
- package/dist/serialize-object.js +43 -55
- package/dist/serialize-object.js.map +1 -1
- package/dist/{src/shared-list.d.ts → shared-list.d.ts} +11 -5
- package/dist/shared-list.js +162 -164
- package/dist/shared-list.js.map +1 -1
- package/dist/{src/shared-map.d.ts → shared-map.d.ts} +2 -2
- package/dist/shared-map.js +105 -138
- package/dist/shared-map.js.map +1 -1
- package/dist/{src/shared-pointer-list.d.ts → shared-pointer-list.d.ts} +4 -3
- package/dist/shared-pointer-list.js +49 -48
- package/dist/shared-pointer-list.js.map +1 -1
- package/dist/{src/shared-pool.d.ts → shared-pool.d.ts} +15 -8
- package/dist/shared-pool.js +151 -164
- package/dist/shared-pool.js.map +1 -1
- package/dist/shared-stack.d.ts +59 -0
- package/dist/shared-stack.js +221 -0
- package/dist/shared-stack.js.map +1 -0
- package/dist/{src/shared-string.d.ts → shared-string.d.ts} +2 -2
- package/dist/shared-string.js +72 -78
- package/dist/shared-string.js.map +1 -1
- package/dist/{src/shared-vector.d.ts → shared-vector.d.ts} +5 -4
- package/dist/shared-vector.js +150 -164
- package/dist/shared-vector.js.map +1 -1
- package/dist/utils/16-from-32-array.js +14 -16
- package/dist/utils/16-from-32-array.js.map +1 -1
- package/dist/utils/16-from-64-array.js +15 -10
- package/dist/utils/16-from-64-array.js.map +1 -1
- package/dist/utils/atomic-math.js +30 -32
- package/dist/utils/atomic-math.js.map +1 -1
- package/dist/utils/float32-atomics.js +18 -22
- package/dist/utils/float32-atomics.js.map +1 -1
- package/dist/utils/float64-atomics.js +18 -22
- package/dist/utils/float64-atomics.js.map +1 -1
- package/dist/utils/pointer.js +34 -44
- package/dist/utils/pointer.js.map +1 -1
- package/dist/{src/utils → utils}/typedarray.d.ts +47 -47
- package/dist/utils/typedarray.js +36 -43
- package/dist/utils/typedarray.js.map +1 -1
- package/package.json +23 -22
- package/dist/interfaces/pow2.js.map +0 -1
- package/dist/interfaces/typed-array-constructor.js.map +0 -1
- package/dist/interfaces/typed-array.js.map +0 -1
- /package/dist/{src/interfaces → interfaces}/pow2.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/typed-array-constructor.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/typed-array.d.ts +0 -0
- /package/dist/{src/lock → lock}/read-write-lock.d.ts +0 -0
- /package/dist/{src/lock → lock}/simple-lock.d.ts +0 -0
- /package/dist/{src/utils → utils}/16-from-32-array.d.ts +0 -0
- /package/dist/{src/utils → utils}/16-from-64-array.d.ts +0 -0
- /package/dist/{src/utils → utils}/atomic-math.d.ts +0 -0
- /package/dist/{src/utils → utils}/float32-atomics.d.ts +0 -0
- /package/dist/{src/utils → utils}/float64-atomics.d.ts +0 -0
- /package/dist/{src/utils → utils}/pointer.d.ts +0 -0
package/dist/memory-buffer.js
CHANGED
|
@@ -1,327 +1,270 @@
|
|
|
1
|
-
import { lock as
|
|
2
|
-
import { typedArray as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return Atomics.store(this.u32, i + p, e), Atomics.store(this.u32, i + b, s), t;
|
|
258
|
-
}
|
|
259
|
-
unlinkBlock(t, e) {
|
|
260
|
-
this.setBlockNext(t, this.blockNext(e));
|
|
261
|
-
}
|
|
262
|
-
splitBlock(t, e, s) {
|
|
263
|
-
this.insert(
|
|
264
|
-
this.initBlock(
|
|
265
|
-
t + this.setBlockSize(t, e),
|
|
266
|
-
s,
|
|
267
|
-
0
|
|
268
|
-
)
|
|
269
|
-
), this.doCompact && this.compact();
|
|
270
|
-
}
|
|
271
|
-
initialTop(t = this.align) {
|
|
272
|
-
return k(this.start + w + n, t) - n;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Traverses free list and attempts to recursively merge blocks
|
|
276
|
-
* occupying consecutive memory regions. Returns true if any blocks
|
|
277
|
-
* have been merged. Only called if `compact` option is enabled.
|
|
278
|
-
*/
|
|
279
|
-
compact() {
|
|
280
|
-
let t = this._free, e = 0, s = 0, i, o = !1;
|
|
281
|
-
for (; t; ) {
|
|
282
|
-
for (i = t, s = this.blockNext(t); s && i + this.blockSize(i) === s; )
|
|
283
|
-
i = s, s = this.blockNext(s);
|
|
284
|
-
if (i !== t) {
|
|
285
|
-
const l = i - t + this.blockSize(i);
|
|
286
|
-
this.setBlockSize(t, l);
|
|
287
|
-
const h = this.blockNext(i);
|
|
288
|
-
let c = this.blockNext(t);
|
|
289
|
-
for (; c && c !== h; ) {
|
|
290
|
-
const S = this.blockNext(c);
|
|
291
|
-
this.setBlockNext(c, 0), c = S;
|
|
292
|
-
}
|
|
293
|
-
this.setBlockNext(t, h), o = !0;
|
|
294
|
-
}
|
|
295
|
-
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);
|
|
296
|
-
}
|
|
297
|
-
return o;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Inserts given block into list of free blocks, sorted by address.
|
|
301
|
-
*
|
|
302
|
-
* @param block -
|
|
303
|
-
*/
|
|
304
|
-
insert(t) {
|
|
305
|
-
let e = this._free, s = 0;
|
|
306
|
-
for (; e && !(t <= e); )
|
|
307
|
-
s = e, e = this.blockNext(e);
|
|
308
|
-
s ? this.setBlockNext(s, t) : this._free = t, this.setBlockNext(t, e);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
const f = (r) => r > 0 ? r + n : 0, d = (r) => r > 0 ? r - n : 0, k = (r, t) => (t--, r + t & ~t), M = {
|
|
312
|
-
u8: 1,
|
|
313
|
-
u8c: 1,
|
|
314
|
-
i8: 1,
|
|
315
|
-
u16: 2,
|
|
316
|
-
i16: 2,
|
|
317
|
-
u32: 4,
|
|
318
|
-
i32: 4,
|
|
319
|
-
i64: 8,
|
|
320
|
-
u64: 8,
|
|
321
|
-
f32: 4,
|
|
322
|
-
f64: 8
|
|
323
|
-
};
|
|
324
|
-
export {
|
|
325
|
-
C as default
|
|
1
|
+
import { lock as e, unlock as t } from "./lock/simple-lock.js";
|
|
2
|
+
import { typedArray as n } from "./utils/typedarray.js";
|
|
3
|
+
//#region src/memory-buffer.ts
|
|
4
|
+
var r = 0, i = 1, a = 2, o = 3, s = 4, c = 5, l = 6, u = 1, d = 2, f = {
|
|
5
|
+
u8: 1,
|
|
6
|
+
u8c: 1,
|
|
7
|
+
i8: 1,
|
|
8
|
+
u16: 2,
|
|
9
|
+
i16: 2,
|
|
10
|
+
u32: 4,
|
|
11
|
+
i32: 4,
|
|
12
|
+
i64: 8,
|
|
13
|
+
u64: 8,
|
|
14
|
+
f32: 4,
|
|
15
|
+
f64: 8
|
|
16
|
+
}, p = 32, m = 0, h = 1, g = 8, _ = class {
|
|
17
|
+
buf;
|
|
18
|
+
start;
|
|
19
|
+
u8;
|
|
20
|
+
u32;
|
|
21
|
+
state;
|
|
22
|
+
lock;
|
|
23
|
+
constructor(e = {}) {
|
|
24
|
+
if (this.buf = e.buf ? e.buf : new ArrayBuffer(e.size || 4096), this.start = e.start == null ? 0 : b(Math.max(e.start, 0), 4), this.u8 = new Uint8Array(this.buf), this.u32 = new Uint32Array(this.buf), this.state = new Uint32Array(this.buf, this.start, 8), this.lock = new Int32Array(this.buf, this.start + this.state.byteLength - 4, 1), !e.skipInitialization) {
|
|
25
|
+
let t = e.align || 8;
|
|
26
|
+
if (t < 8) throw Error(`invalid alignment: ${t}, must be a pow2 and >= 8`);
|
|
27
|
+
let n = this.initialTop(t), r = e.end == null ? this.buf.byteLength : Math.min(e.end, this.buf.byteLength);
|
|
28
|
+
if (n >= r) throw Error(`insufficient address range (0x${this.start.toString(16)} - 0x${r.toString(16)})`);
|
|
29
|
+
this.align = t, this.doCompact = e.compact !== !1, this.doSplit = e.split !== !1, this.minSplit = e.minSplit || 16, this.end = r, this.top = n, this._free = 0, this._used = 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
stats() {
|
|
33
|
+
let e = (e) => {
|
|
34
|
+
let t = 0, n = 0;
|
|
35
|
+
for (; e;) if (t++, n += this.blockSize(e), e = this.blockNext(e), e > this.end) {
|
|
36
|
+
console.error(`Trying to get stats for block past end of buffer: ${e} > ${this.end}`);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
count: t,
|
|
41
|
+
size: n
|
|
42
|
+
};
|
|
43
|
+
}, t = e(this._free);
|
|
44
|
+
return {
|
|
45
|
+
free: t,
|
|
46
|
+
used: e(this._used),
|
|
47
|
+
top: this.top,
|
|
48
|
+
available: this.end - this.top + t.size,
|
|
49
|
+
total: this.buf.byteLength
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
callocAs(e, t, n = 0) {
|
|
53
|
+
let r = this.mallocAs(e, t);
|
|
54
|
+
return r && r.fill(n), r;
|
|
55
|
+
}
|
|
56
|
+
mallocAs(e, t) {
|
|
57
|
+
let r = this.malloc(t * f[e]);
|
|
58
|
+
return r ? n(e, this.buf, r, t) : void 0;
|
|
59
|
+
}
|
|
60
|
+
calloc(e, t = 0) {
|
|
61
|
+
let n = this.malloc(e);
|
|
62
|
+
return n && this.u8.fill(t, n, n + e), n;
|
|
63
|
+
}
|
|
64
|
+
malloc(n) {
|
|
65
|
+
if (n <= 0) return 0;
|
|
66
|
+
e(this.lock);
|
|
67
|
+
let r = b(n + 8, this.align), i = this.end, a = this.top, o = this._free, s = 0;
|
|
68
|
+
for (; o;) {
|
|
69
|
+
let e = this.blockSize(o), n = o + e >= a;
|
|
70
|
+
if (n || e >= r) {
|
|
71
|
+
let i = this.mallocTop(o, s, e, r, n);
|
|
72
|
+
return t(this.lock), i;
|
|
73
|
+
}
|
|
74
|
+
s = o, o = this.blockNext(o);
|
|
75
|
+
}
|
|
76
|
+
if (o = a, a = o + r, a <= i) {
|
|
77
|
+
this.initBlock(o, r, this._used), this._used = o, this.top = a;
|
|
78
|
+
let e = v(o);
|
|
79
|
+
return t(this.lock), e;
|
|
80
|
+
}
|
|
81
|
+
return t(this.lock), 0;
|
|
82
|
+
}
|
|
83
|
+
mallocTop(e, t, n, r, i) {
|
|
84
|
+
if (i && e + r > this.end) return 0;
|
|
85
|
+
if (t ? this.unlinkBlock(t, e) : this._free = this.blockNext(e), this.setBlockNext(e, this._used), this._used = e, i) this.top = e + this.setBlockSize(e, r);
|
|
86
|
+
else if (this.doSplit) {
|
|
87
|
+
let t = n - r;
|
|
88
|
+
t >= this.minSplit && this.splitBlock(e, r, t);
|
|
89
|
+
}
|
|
90
|
+
return v(e);
|
|
91
|
+
}
|
|
92
|
+
realloc(e, t) {
|
|
93
|
+
if (t <= 0) return 0;
|
|
94
|
+
let n = y(e), r = 0, i = this._used, a = 0;
|
|
95
|
+
for (; i;) {
|
|
96
|
+
if (i === n) {
|
|
97
|
+
[r, a] = this.reallocBlock(i, t);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
i = this.blockNext(i);
|
|
101
|
+
}
|
|
102
|
+
return r && r !== n && this.u8.copyWithin(v(r), v(n), a), v(r);
|
|
103
|
+
}
|
|
104
|
+
reallocBlock(e, t) {
|
|
105
|
+
let n = this.blockSize(e), r = e + n, i = r >= this.top, a = b(t + 8, this.align);
|
|
106
|
+
if (a <= n) {
|
|
107
|
+
if (this.doSplit) {
|
|
108
|
+
let t = n - a;
|
|
109
|
+
t >= this.minSplit ? this.splitBlock(e, a, t) : i && (this.top = e + a);
|
|
110
|
+
} else i && (this.top = e + a);
|
|
111
|
+
return [e, r];
|
|
112
|
+
}
|
|
113
|
+
return i && e + a < this.end ? (this.top = e + this.setBlockSize(e, a), [e, r]) : (this.free(e), [y(this.malloc(t)), r]);
|
|
114
|
+
}
|
|
115
|
+
reallocArray(e, t) {
|
|
116
|
+
if (e.buffer !== this.buf) return;
|
|
117
|
+
let n = this.realloc(e.byteOffset, t * e.BYTES_PER_ELEMENT);
|
|
118
|
+
return n ? new e.constructor(this.buf, n, t) : void 0;
|
|
119
|
+
}
|
|
120
|
+
bytesFor(e) {
|
|
121
|
+
let t;
|
|
122
|
+
if (typeof e != "number") {
|
|
123
|
+
if (e.buffer !== this.buf) return;
|
|
124
|
+
t = e.byteOffset;
|
|
125
|
+
} else t = e;
|
|
126
|
+
t = y(t);
|
|
127
|
+
let n = this._used;
|
|
128
|
+
for (; n;) {
|
|
129
|
+
if (n === t) return this.blockSize(t) - 8;
|
|
130
|
+
n = this.blockNext(n);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
lengthOf(e) {
|
|
134
|
+
let t = this.bytesFor(e);
|
|
135
|
+
if (t) return t / this.u32.BYTES_PER_ELEMENT;
|
|
136
|
+
}
|
|
137
|
+
free(n) {
|
|
138
|
+
let r;
|
|
139
|
+
if (typeof n != "number") {
|
|
140
|
+
if (n.buffer !== this.buf) return !1;
|
|
141
|
+
r = n.byteOffset;
|
|
142
|
+
} else r = n;
|
|
143
|
+
e(this.lock), r = y(r);
|
|
144
|
+
let i = this._used, a = 0;
|
|
145
|
+
for (; i;) {
|
|
146
|
+
if (i === r) return a ? this.unlinkBlock(a, i) : this._used = this.blockNext(i), this.insert(i), this.doCompact && this.compact(), t(this.lock), !0;
|
|
147
|
+
a = i, i = this.blockNext(i);
|
|
148
|
+
}
|
|
149
|
+
return t(this.lock), !1;
|
|
150
|
+
}
|
|
151
|
+
freeAll() {
|
|
152
|
+
this._free = 0, this._used = 0, this.top = this.initialTop();
|
|
153
|
+
}
|
|
154
|
+
release() {
|
|
155
|
+
return delete this.u8, delete this.u32, delete this.state, delete this.buf, !0;
|
|
156
|
+
}
|
|
157
|
+
get align() {
|
|
158
|
+
return this.state[s];
|
|
159
|
+
}
|
|
160
|
+
set align(e) {
|
|
161
|
+
this.state[s] = e;
|
|
162
|
+
}
|
|
163
|
+
get end() {
|
|
164
|
+
return this.state[o];
|
|
165
|
+
}
|
|
166
|
+
set end(e) {
|
|
167
|
+
this.state[o] = e;
|
|
168
|
+
}
|
|
169
|
+
get top() {
|
|
170
|
+
return Atomics.load(this.state, a);
|
|
171
|
+
}
|
|
172
|
+
set top(e) {
|
|
173
|
+
Atomics.store(this.state, a, e);
|
|
174
|
+
}
|
|
175
|
+
get isEmpty() {
|
|
176
|
+
return this._used === 0;
|
|
177
|
+
}
|
|
178
|
+
get _free() {
|
|
179
|
+
return Atomics.load(this.state, r);
|
|
180
|
+
}
|
|
181
|
+
set _free(e) {
|
|
182
|
+
Atomics.store(this.state, r, e);
|
|
183
|
+
}
|
|
184
|
+
get _used() {
|
|
185
|
+
return Atomics.load(this.state, i);
|
|
186
|
+
}
|
|
187
|
+
set _used(e) {
|
|
188
|
+
Atomics.store(this.state, i, e);
|
|
189
|
+
}
|
|
190
|
+
get doCompact() {
|
|
191
|
+
return !!(this.state[c] & u);
|
|
192
|
+
}
|
|
193
|
+
set doCompact(e) {
|
|
194
|
+
e ? this.state[c] |= 1 : this.state[c] &= -2;
|
|
195
|
+
}
|
|
196
|
+
get doSplit() {
|
|
197
|
+
return !!(this.state[c] & d);
|
|
198
|
+
}
|
|
199
|
+
set doSplit(e) {
|
|
200
|
+
e ? this.state[c] |= 2 : this.state[c] &= -3;
|
|
201
|
+
}
|
|
202
|
+
get minSplit() {
|
|
203
|
+
return this.state[l];
|
|
204
|
+
}
|
|
205
|
+
set minSplit(e) {
|
|
206
|
+
if (e <= 8) throw Error(`illegal min split threshold: ${e}, require at least 9`);
|
|
207
|
+
this.state[l] = e;
|
|
208
|
+
}
|
|
209
|
+
blockSize(e) {
|
|
210
|
+
return Atomics.load(this.u32, (e >> 2) + m);
|
|
211
|
+
}
|
|
212
|
+
setBlockSize(e, t) {
|
|
213
|
+
return Atomics.store(this.u32, (e >> 2) + m, t), t;
|
|
214
|
+
}
|
|
215
|
+
blockNext(e) {
|
|
216
|
+
return Atomics.load(this.u32, (e >> 2) + h);
|
|
217
|
+
}
|
|
218
|
+
setBlockNext(e, t) {
|
|
219
|
+
Atomics.store(this.u32, (e >> 2) + h, t);
|
|
220
|
+
}
|
|
221
|
+
initBlock(e, t, n) {
|
|
222
|
+
let r = e >>> 2;
|
|
223
|
+
return Atomics.store(this.u32, r + m, t), Atomics.store(this.u32, r + h, n), e;
|
|
224
|
+
}
|
|
225
|
+
unlinkBlock(e, t) {
|
|
226
|
+
this.setBlockNext(e, this.blockNext(t));
|
|
227
|
+
}
|
|
228
|
+
splitBlock(e, t, n) {
|
|
229
|
+
this.insert(this.initBlock(e + this.setBlockSize(e, t), n, 0)), this.doCompact && this.compact();
|
|
230
|
+
}
|
|
231
|
+
initialTop(e = this.align) {
|
|
232
|
+
return b(this.start + 32 + 8, e) - 8;
|
|
233
|
+
}
|
|
234
|
+
compact() {
|
|
235
|
+
let e = this._free, t = 0, n = 0, r, i = !1;
|
|
236
|
+
for (; e;) {
|
|
237
|
+
for (r = e, n = this.blockNext(e); n && r + this.blockSize(r) === n;) r = n, n = this.blockNext(n);
|
|
238
|
+
if (r !== e) {
|
|
239
|
+
let t = r - e + this.blockSize(r);
|
|
240
|
+
this.setBlockSize(e, t);
|
|
241
|
+
let n = this.blockNext(r), a = this.blockNext(e);
|
|
242
|
+
for (; a && a !== n;) {
|
|
243
|
+
let e = this.blockNext(a);
|
|
244
|
+
this.setBlockNext(a, 0), a = e;
|
|
245
|
+
}
|
|
246
|
+
this.setBlockNext(e, n), i = !0;
|
|
247
|
+
}
|
|
248
|
+
e + this.blockSize(e) >= this.top && (this.top = e, t ? this.unlinkBlock(t, e) : this._free = this.blockNext(e)), t = e, e = this.blockNext(e);
|
|
249
|
+
}
|
|
250
|
+
return i;
|
|
251
|
+
}
|
|
252
|
+
insert(e) {
|
|
253
|
+
let t = this._free, n = 0;
|
|
254
|
+
for (; t && !(e <= t);) n = t, t = this.blockNext(t);
|
|
255
|
+
n ? this.setBlockNext(n, e) : this._free = e, this.setBlockNext(e, t);
|
|
256
|
+
}
|
|
326
257
|
};
|
|
327
|
-
|
|
258
|
+
function v(e) {
|
|
259
|
+
return e > 0 ? e + 8 : 0;
|
|
260
|
+
}
|
|
261
|
+
function y(e) {
|
|
262
|
+
return e > 0 ? e - 8 : 0;
|
|
263
|
+
}
|
|
264
|
+
function b(e, t) {
|
|
265
|
+
return t--, e + t & ~t;
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { g as SIZEOF_MEM_BLOCK, p as SIZEOF_STATE, _ as default };
|
|
269
|
+
|
|
270
|
+
//# sourceMappingURL=memory-buffer.js.map
|