@the-w1zard/dx 1.0.8 → 1.0.9
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.html +823 -121
- package/README.md +288 -107
- package/dist/index.js +12967 -0
- package/package.json +21 -6
- package/src/dx.d.ts +2 -10
- package/src/array.js +0 -221
- package/src/array.ts +0 -301
- package/src/boolean_byte.js +0 -22
- package/src/boolean_byte.ts +0 -23
- package/src/class.js +0 -1
- package/src/class.ts +0 -0
- package/src/date.js +0 -649
- package/src/date.ts +0 -660
- package/src/error.js +0 -60
- package/src/error.ts +0 -81
- package/src/index.js +0 -18
- package/src/index.ts +0 -18
- package/src/iterator.js +0 -386
- package/src/iterator.ts +0 -407
- package/src/map.js +0 -495
- package/src/map.ts +0 -513
- package/src/map_byte.js +0 -483
- package/src/map_byte.ts +0 -422
- package/src/number.js +0 -178
- package/src/number.ts +0 -212
- package/src/object.js +0 -217
- package/src/object.ts +0 -291
- package/src/promise.js +0 -206
- package/src/promise.ts +0 -309
- package/src/reg_ex.js +0 -479
- package/src/reg_ex.ts +0 -423
- package/src/set.js +0 -227
- package/src/set.ts +0 -198
- package/src/set_byte.js +0 -261
- package/src/set_byte.ts +0 -223
- package/src/soa_codec.js +0 -28
- package/src/soa_codec.ts +0 -27
- package/src/string.js +0 -133
- package/src/string.ts +0 -175
- package/src/unit8array.js +0 -272
- package/src/unit8array.ts +0 -374
- package/src/url_search_params.js +0 -172
- package/src/url_search_params.ts +0 -187
- package/src/weak_map.js +0 -136
- package/src/weak_map.ts +0 -155
- package/src/weak_set.js +0 -92
- package/src/weak_set.ts +0 -101
package/src/map_byte.js
DELETED
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
const sameValue128 = (a, b) => {
|
|
3
|
-
if (a === b)
|
|
4
|
-
return true;
|
|
5
|
-
if (a instanceof Float64Array && b instanceof Float64Array) {
|
|
6
|
-
if (a.length !== b.length)
|
|
7
|
-
return false;
|
|
8
|
-
for (let i = 0; i < a.length; i++)
|
|
9
|
-
if (!Object.is(a[i], b[i]))
|
|
10
|
-
return false;
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
return Object.is(a, b);
|
|
14
|
-
};
|
|
15
|
-
export class M2BI {
|
|
16
|
-
cap;
|
|
17
|
-
stride;
|
|
18
|
-
pidToSlot;
|
|
19
|
-
slotToPid;
|
|
20
|
-
vals;
|
|
21
|
-
#size = 0;
|
|
22
|
-
#subs;
|
|
23
|
-
#hist;
|
|
24
|
-
#histLimit = 0;
|
|
25
|
-
#strict = false;
|
|
26
|
-
#iterating = 0;
|
|
27
|
-
#batching = 0;
|
|
28
|
-
#pending;
|
|
29
|
-
#derived;
|
|
30
|
-
#dependents;
|
|
31
|
-
constructor(maxParticles, stride = 1, seed) {
|
|
32
|
-
this.cap = maxParticles;
|
|
33
|
-
this.stride = stride;
|
|
34
|
-
this.pidToSlot = new Int32Array(maxParticles).fill(-1);
|
|
35
|
-
this.slotToPid = new Int32Array(maxParticles).fill(-1);
|
|
36
|
-
this.vals = new Float64Array(maxParticles * stride);
|
|
37
|
-
if (seed)
|
|
38
|
-
for (const [pid, v] of seed)
|
|
39
|
-
this.s(v, pid);
|
|
40
|
-
}
|
|
41
|
-
get size() { return this.#size; }
|
|
42
|
-
// ---------------------------------------------------------------- internals
|
|
43
|
-
#emit(e) {
|
|
44
|
-
if (this.#batching > 0) {
|
|
45
|
-
this.#pending ??= new Map();
|
|
46
|
-
const pending = this.#pending.get(e.pid);
|
|
47
|
-
this.#pending.set(e.pid, pending ? { ...e, prev: pending.prev, batch: true } : { ...e, batch: true });
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this.#record(e);
|
|
51
|
-
this.#subs?.forEach((sub) => { try {
|
|
52
|
-
sub(e);
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
process.emitWarning(err);
|
|
56
|
-
} });
|
|
57
|
-
}
|
|
58
|
-
#record(e) {
|
|
59
|
-
if (!this.#hist)
|
|
60
|
-
return;
|
|
61
|
-
this.#hist.push(e);
|
|
62
|
-
if (this.#hist.length > this.#histLimit)
|
|
63
|
-
this.#hist.splice(0, this.#hist.length - this.#histLimit);
|
|
64
|
-
}
|
|
65
|
-
#invalidate(pid) {
|
|
66
|
-
const deps = this.#dependents?.get(pid);
|
|
67
|
-
if (!deps)
|
|
68
|
-
return;
|
|
69
|
-
for (const dk of deps) {
|
|
70
|
-
const d = this.#derived?.get(dk);
|
|
71
|
-
if (!d || d.dirty)
|
|
72
|
-
continue;
|
|
73
|
-
d.dirty = true;
|
|
74
|
-
this.#emit({ op: "dirty", pid: dk, has: d.has });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
#computeDerived(pid, d) {
|
|
78
|
-
const vals = d.deps.map((dep) => this.g(dep));
|
|
79
|
-
const next = d.fn(...vals);
|
|
80
|
-
const had = d.has;
|
|
81
|
-
const prev = d.value;
|
|
82
|
-
d.value = next;
|
|
83
|
-
d.has = true;
|
|
84
|
-
d.dirty = false;
|
|
85
|
-
if (!had || !sameValue128(prev, next)) {
|
|
86
|
-
this.#emit({ op: had ? "upd" : "set", pid, v: next, prev, has: true });
|
|
87
|
-
}
|
|
88
|
-
return next;
|
|
89
|
-
}
|
|
90
|
-
#assertNotIterating(op) {
|
|
91
|
-
if (this.#strict && this.#iterating > 0) {
|
|
92
|
-
throw new Error(`M2BI.${op}() during iteration. Snapshot keys first, or disable $strict().`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
#readSlot(slot) {
|
|
96
|
-
return this.stride === 1 ? this.vals[slot] : this.vals.subarray(slot * this.stride, slot * this.stride + this.stride);
|
|
97
|
-
}
|
|
98
|
-
#writeSlot(slot, v) {
|
|
99
|
-
if (this.stride === 1)
|
|
100
|
-
this.vals[slot] = v;
|
|
101
|
-
else
|
|
102
|
-
this.vals.set(v, slot * this.stride);
|
|
103
|
-
}
|
|
104
|
-
#fresh() { return new _a(this.cap, this.stride); } // [sibling-store factory]
|
|
105
|
-
// ---------------------------------------------------------------- subs / batch
|
|
106
|
-
on(fn) { (this.#subs ??= new Set()).add(fn); return () => this.off(fn); } // [ON]
|
|
107
|
-
off(fn) { this.#subs?.delete(fn); } // [OFF]
|
|
108
|
-
batch(fn) {
|
|
109
|
-
this.#batching++;
|
|
110
|
-
this.#pending ??= new Map();
|
|
111
|
-
try {
|
|
112
|
-
fn();
|
|
113
|
-
}
|
|
114
|
-
finally {
|
|
115
|
-
this.#batching--;
|
|
116
|
-
if (this.#batching === 0) {
|
|
117
|
-
const events = [...this.#pending.values()];
|
|
118
|
-
this.#pending = undefined;
|
|
119
|
-
for (const e of events) {
|
|
120
|
-
this.#record(e);
|
|
121
|
-
this.#subs?.forEach(sub => sub(e));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
// ---------------------------------------------------------------- core CRUD
|
|
128
|
-
s(v, pid) {
|
|
129
|
-
this.#assertNotIterating("s");
|
|
130
|
-
let slot = this.pidToSlot[pid];
|
|
131
|
-
const has = slot !== -1;
|
|
132
|
-
const prev = has ? this.#readSlot(slot) : undefined;
|
|
133
|
-
if (!has) {
|
|
134
|
-
slot = this.#size;
|
|
135
|
-
this.pidToSlot[pid] = slot;
|
|
136
|
-
this.slotToPid[slot] = pid;
|
|
137
|
-
this.#size++;
|
|
138
|
-
}
|
|
139
|
-
this.#writeSlot(slot, v);
|
|
140
|
-
this.#invalidate(pid);
|
|
141
|
-
this.#emit({ op: has ? "upd" : "set", pid, v, prev, has });
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
mutate(pid, fn) {
|
|
145
|
-
this.#assertNotIterating("mutate");
|
|
146
|
-
if (!this.h(pid))
|
|
147
|
-
return undefined;
|
|
148
|
-
const next = fn(this.g(pid), true);
|
|
149
|
-
this.s(next, pid);
|
|
150
|
-
return next;
|
|
151
|
-
}
|
|
152
|
-
d(pid) {
|
|
153
|
-
this.#assertNotIterating("delete");
|
|
154
|
-
const slot = this.pidToSlot[pid];
|
|
155
|
-
if (slot === -1)
|
|
156
|
-
return false;
|
|
157
|
-
const prev = this.#readSlot(slot);
|
|
158
|
-
const lastSlot = this.#size - 1;
|
|
159
|
-
const lastPid = this.slotToPid[lastSlot];
|
|
160
|
-
if (slot !== lastSlot) {
|
|
161
|
-
this.#writeSlot(slot, this.#readSlot(lastSlot));
|
|
162
|
-
this.slotToPid[slot] = lastPid;
|
|
163
|
-
this.pidToSlot[lastPid] = slot;
|
|
164
|
-
}
|
|
165
|
-
this.pidToSlot[pid] = -1;
|
|
166
|
-
this.slotToPid[lastSlot] = -1;
|
|
167
|
-
this.#size--;
|
|
168
|
-
this.#invalidate(pid);
|
|
169
|
-
this.#emit({ op: "del", pid, prev, has: false });
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
c() {
|
|
173
|
-
this.#assertNotIterating("clear");
|
|
174
|
-
for (let i = this.#size - 1; i >= 0; i--) {
|
|
175
|
-
const pid = this.slotToPid[i];
|
|
176
|
-
const prev = this.#readSlot(i);
|
|
177
|
-
this.pidToSlot[pid] = -1;
|
|
178
|
-
this.slotToPid[i] = -1;
|
|
179
|
-
this.#invalidate(pid);
|
|
180
|
-
this.#emit({ op: "del", pid, prev, has: false });
|
|
181
|
-
}
|
|
182
|
-
this.#size = 0;
|
|
183
|
-
}
|
|
184
|
-
dv(pid, deps, fn) {
|
|
185
|
-
(this.#derived ??= new Map()).set(pid, { deps, fn, dirty: true, has: false });
|
|
186
|
-
for (const dep of deps) {
|
|
187
|
-
const set = (this.#dependents ??= new Map());
|
|
188
|
-
if (!set.has(dep))
|
|
189
|
-
set.set(dep, new Set());
|
|
190
|
-
set.get(dep).add(pid);
|
|
191
|
-
}
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
dirty(...pids) {
|
|
195
|
-
for (const pid of pids) {
|
|
196
|
-
const d = this.#derived?.get(pid);
|
|
197
|
-
if (d && !d.dirty) {
|
|
198
|
-
d.dirty = true;
|
|
199
|
-
this.#emit({ op: "dirty", pid, has: d.has });
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
g(pid) {
|
|
205
|
-
const d = this.#derived?.get(pid);
|
|
206
|
-
if (d)
|
|
207
|
-
return d.dirty || !d.has ? this.#computeDerived(pid, d) : d.value;
|
|
208
|
-
const slot = this.pidToSlot[pid];
|
|
209
|
-
return slot === -1 ? undefined : this.#readSlot(slot);
|
|
210
|
-
}
|
|
211
|
-
h(pid) {
|
|
212
|
-
const d = this.#derived?.get(pid);
|
|
213
|
-
if (d) {
|
|
214
|
-
if (d.dirty || !d.has)
|
|
215
|
-
this.#computeDerived(pid, d);
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
return this.pidToSlot[pid] !== -1;
|
|
219
|
-
}
|
|
220
|
-
// ---------------------------------------------------------------- debug
|
|
221
|
-
$debug(limit = 256) { this.#hist ??= []; this.#histLimit = limit; return this; } // [$DEBUG]
|
|
222
|
-
$strict() { this.#strict = true; return this; } // [$STRICT]
|
|
223
|
-
$history() { return this.#hist ? [...this.#hist] : []; } // [$HISTORY]
|
|
224
|
-
$why(pid) {
|
|
225
|
-
if (!this.#hist)
|
|
226
|
-
return undefined;
|
|
227
|
-
for (let i = this.#hist.length - 1; i >= 0; i--)
|
|
228
|
-
if (this.#hist[i].pid === pid)
|
|
229
|
-
return this.#hist[i];
|
|
230
|
-
return undefined;
|
|
231
|
-
}
|
|
232
|
-
$diff(other) {
|
|
233
|
-
const add = [];
|
|
234
|
-
const del = [];
|
|
235
|
-
const chg = [];
|
|
236
|
-
for (const [pid, v] of this) {
|
|
237
|
-
if (!other.has(pid))
|
|
238
|
-
add.push([pid, v]);
|
|
239
|
-
else if (!sameValue128(other.get(pid), v))
|
|
240
|
-
chg.push([pid, v, other.get(pid)]);
|
|
241
|
-
}
|
|
242
|
-
for (const pid of other.keys())
|
|
243
|
-
if (!this.has(pid))
|
|
244
|
-
del.push(pid);
|
|
245
|
-
return { add, del, chg };
|
|
246
|
-
}
|
|
247
|
-
// ---------------------------------------------------------------- iteration (dense slots, no hashing)
|
|
248
|
-
*entries() {
|
|
249
|
-
this.#iterating++;
|
|
250
|
-
try {
|
|
251
|
-
for (let i = 0; i < this.#size; i++)
|
|
252
|
-
yield [this.slotToPid[i], this.#readSlot(i)];
|
|
253
|
-
}
|
|
254
|
-
finally {
|
|
255
|
-
this.#iterating--;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
*keys() {
|
|
259
|
-
this.#iterating++;
|
|
260
|
-
try {
|
|
261
|
-
for (let i = 0; i < this.#size; i++)
|
|
262
|
-
yield this.slotToPid[i];
|
|
263
|
-
}
|
|
264
|
-
finally {
|
|
265
|
-
this.#iterating--;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
*values() {
|
|
269
|
-
this.#iterating++;
|
|
270
|
-
try {
|
|
271
|
-
for (let i = 0; i < this.#size; i++)
|
|
272
|
-
yield this.#readSlot(i);
|
|
273
|
-
}
|
|
274
|
-
finally {
|
|
275
|
-
this.#iterating--;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
[Symbol.iterator]() { return this.entries(); }
|
|
279
|
-
// ---------------------------------------------------------------- alias / has/has-not helpers
|
|
280
|
-
has = this.h; // [has alias]
|
|
281
|
-
get = this.g; // [get alias]
|
|
282
|
-
delete = this.d; // [delete alias]
|
|
283
|
-
clear = this.c; // [clear alias]
|
|
284
|
-
f = this.forEach.bind(this); // [FOR EACH]
|
|
285
|
-
forEach(fn) { for (const [pid, v] of this)
|
|
286
|
-
fn(v, pid, this); }
|
|
287
|
-
// ---------------------------------------------------------------- sugar
|
|
288
|
-
swap(value, pid) {
|
|
289
|
-
const previous = this.has(pid) ? this.get(pid) : value;
|
|
290
|
-
this.s(value, pid);
|
|
291
|
-
return previous;
|
|
292
|
-
}
|
|
293
|
-
take(pid) { const value = this.g(pid); this.d(pid); return value; } // [TAKE]
|
|
294
|
-
peek(pid) { return this.h(pid) ? this.g(pid) : false; } // [PEEK]
|
|
295
|
-
getOrI(value, pid) {
|
|
296
|
-
if (this.h(pid))
|
|
297
|
-
return this.g(pid);
|
|
298
|
-
this.s(value, pid);
|
|
299
|
-
return value;
|
|
300
|
-
}
|
|
301
|
-
getOrM(make, pid) {
|
|
302
|
-
if (this.h(pid))
|
|
303
|
-
return this.g(pid);
|
|
304
|
-
const value = make();
|
|
305
|
-
this.s(value, pid);
|
|
306
|
-
return value;
|
|
307
|
-
}
|
|
308
|
-
update(pid, fn, initial) {
|
|
309
|
-
const has = this.h(pid);
|
|
310
|
-
const old = has ? this.g(pid) : (initial === undefined ? 0 : initial);
|
|
311
|
-
const next = fn(old, has);
|
|
312
|
-
this.s(next, pid);
|
|
313
|
-
return next;
|
|
314
|
-
}
|
|
315
|
-
setIfAbsent(value, pid) {
|
|
316
|
-
if (this.h(pid))
|
|
317
|
-
return false;
|
|
318
|
-
this.s(value, pid);
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
setIfPresent(value, pid) {
|
|
322
|
-
if (!this.h(pid))
|
|
323
|
-
return false;
|
|
324
|
-
this.s(value, pid);
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
replace(value, pid) { return this.setIfPresent(value, pid); } // [REPLACE]
|
|
328
|
-
inc(pid, by = 1) {
|
|
329
|
-
return this.update(pid, (old) => ((old ?? 0) + by), 0);
|
|
330
|
-
}
|
|
331
|
-
touch(pid) { return this.setIfAbsent(0, pid); } // [SWTOUCHAP]
|
|
332
|
-
// ---------------------------------------------------------------- transforms (produce new M2BI, same cap/stride)
|
|
333
|
-
mapValues(fn) {
|
|
334
|
-
const out = this.#fresh();
|
|
335
|
-
for (const [pid, v] of this)
|
|
336
|
-
out.s(fn(v, pid), pid);
|
|
337
|
-
return out;
|
|
338
|
-
}
|
|
339
|
-
mapKeys(fn) {
|
|
340
|
-
const out = this.#fresh(); // target pids must still fit within cap
|
|
341
|
-
for (const [pid, v] of this)
|
|
342
|
-
out.s(v, fn(v, pid));
|
|
343
|
-
return out;
|
|
344
|
-
}
|
|
345
|
-
filterKV(pred) {
|
|
346
|
-
for (const pid of [...this.keys()])
|
|
347
|
-
if (!pred(this.g(pid), pid))
|
|
348
|
-
this.d(pid);
|
|
349
|
-
return this;
|
|
350
|
-
}
|
|
351
|
-
filterKeys(pred) { return this.filterKV(pred); } // [FILTERKEYS]
|
|
352
|
-
partition(pred) {
|
|
353
|
-
const yes = this.#fresh(), no = this.#fresh();
|
|
354
|
-
for (const [pid, v] of this)
|
|
355
|
-
(pred(v, pid) ? yes : no).s(v, pid);
|
|
356
|
-
return [yes, no];
|
|
357
|
-
}
|
|
358
|
-
find(pred) {
|
|
359
|
-
for (const [pid, v] of this)
|
|
360
|
-
if (pred(v, pid))
|
|
361
|
-
return [pid, v];
|
|
362
|
-
return undefined;
|
|
363
|
-
}
|
|
364
|
-
findKey(pred) {
|
|
365
|
-
for (const [pid, v] of this)
|
|
366
|
-
if (pred(v, pid))
|
|
367
|
-
return pid;
|
|
368
|
-
return undefined;
|
|
369
|
-
}
|
|
370
|
-
findValue(pred) {
|
|
371
|
-
for (const [pid, v] of this)
|
|
372
|
-
if (pred(v, pid))
|
|
373
|
-
return v;
|
|
374
|
-
return undefined;
|
|
375
|
-
}
|
|
376
|
-
some(pred) {
|
|
377
|
-
for (const [pid, v] of this)
|
|
378
|
-
if (pred(v, pid))
|
|
379
|
-
return true;
|
|
380
|
-
return false;
|
|
381
|
-
}
|
|
382
|
-
every(pred) {
|
|
383
|
-
for (const [pid, v] of this)
|
|
384
|
-
if (!pred(v, pid))
|
|
385
|
-
return false;
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
reduce(fn, initial) {
|
|
389
|
-
let acc = initial;
|
|
390
|
-
for (const [pid, v] of this)
|
|
391
|
-
acc = fn(acc, v, pid);
|
|
392
|
-
return acc;
|
|
393
|
-
}
|
|
394
|
-
forEachKV(fn) { for (const [pid, v] of this)
|
|
395
|
-
fn(v, pid, this); } // [FOREACH]
|
|
396
|
-
invert() {
|
|
397
|
-
const out = new Map(); // values aren't valid pids/Int32 slots in general -> plain Map, not M2BI
|
|
398
|
-
for (const [pid, v] of this)
|
|
399
|
-
out.set(this.stride === 1 ? String(v) : Array.from(v).join(","), pid);
|
|
400
|
-
return out;
|
|
401
|
-
}
|
|
402
|
-
unique(fn) {
|
|
403
|
-
const out = this.#fresh();
|
|
404
|
-
const seen = new Set();
|
|
405
|
-
for (const [pid, v] of this) {
|
|
406
|
-
const keyFor = fn ? fn(v, pid) : pid;
|
|
407
|
-
const dedupeKey = this.stride === 1 ? String(v) : Array.from(v).join(",");
|
|
408
|
-
if (!seen.has(dedupeKey)) {
|
|
409
|
-
seen.add(dedupeKey);
|
|
410
|
-
out.s(v, keyFor);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return out;
|
|
414
|
-
}
|
|
415
|
-
pick(pids) {
|
|
416
|
-
const out = this.#fresh();
|
|
417
|
-
for (const pid of pids)
|
|
418
|
-
if (this.h(pid))
|
|
419
|
-
out.s(this.g(pid), pid);
|
|
420
|
-
return out;
|
|
421
|
-
}
|
|
422
|
-
omit(pids) {
|
|
423
|
-
const omitted = new Set(pids);
|
|
424
|
-
const out = this.#fresh();
|
|
425
|
-
for (const [pid, v] of this)
|
|
426
|
-
if (!omitted.has(pid))
|
|
427
|
-
out.s(v, pid);
|
|
428
|
-
return out;
|
|
429
|
-
}
|
|
430
|
-
merge(other) {
|
|
431
|
-
for (const [pid, v] of other)
|
|
432
|
-
this.s(v, pid);
|
|
433
|
-
return this;
|
|
434
|
-
}
|
|
435
|
-
clearAndSet(entries) {
|
|
436
|
-
return this.batch(() => { this.clear(); for (const [pid, v] of entries)
|
|
437
|
-
this.s(v, pid); });
|
|
438
|
-
}
|
|
439
|
-
toObject() {
|
|
440
|
-
const out = {};
|
|
441
|
-
for (const [pid, v] of this)
|
|
442
|
-
out[pid] = v;
|
|
443
|
-
return out;
|
|
444
|
-
}
|
|
445
|
-
toValues() { return [...this.values()]; } // [TOVALUES]
|
|
446
|
-
toKeys() { return [...this.keys()]; } // [TOKEYS]
|
|
447
|
-
toArray() { return [...this.entries()]; } // [TOARRAY]
|
|
448
|
-
group(fn) {
|
|
449
|
-
const out = new Map();
|
|
450
|
-
for (const [pid, v] of this) {
|
|
451
|
-
const k = fn(v, pid);
|
|
452
|
-
if (!out.has(k))
|
|
453
|
-
out.set(k, []);
|
|
454
|
-
out.get(k).push(v);
|
|
455
|
-
}
|
|
456
|
-
return out;
|
|
457
|
-
}
|
|
458
|
-
clone() {
|
|
459
|
-
return new _a(this.cap, this.stride, this.entries());
|
|
460
|
-
}
|
|
461
|
-
equals(other) {
|
|
462
|
-
if (other === this)
|
|
463
|
-
return true;
|
|
464
|
-
if (this.size !== other.size)
|
|
465
|
-
return false;
|
|
466
|
-
for (const [pid, v] of this)
|
|
467
|
-
if (!other.has(pid) || !sameValue128(other.get(pid), v))
|
|
468
|
-
return false;
|
|
469
|
-
return true;
|
|
470
|
-
}
|
|
471
|
-
// ---------------------------------------------------------------- statics
|
|
472
|
-
static fromObject(obj, maxParticles, stride = 1) {
|
|
473
|
-
return new _a(maxParticles, stride, Object.entries(obj).map(([k, v]) => [Number(k), v]));
|
|
474
|
-
}
|
|
475
|
-
static fromEntries(entries, maxParticles, stride = 1) {
|
|
476
|
-
return new _a(maxParticles, stride, entries);
|
|
477
|
-
}
|
|
478
|
-
static from(map, maxParticles, stride = 1) {
|
|
479
|
-
return new _a(maxParticles, stride, map);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
_a = M2BI;
|
|
483
|
-
globalThis.M2B = M2BI;
|