@daneren2005/shared-memory-objects 1.0.0 → 1.1.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/LICENSE +21 -0
- package/dist/allocated-memory.js +38 -0
- package/dist/allocated-memory.js.map +1 -0
- package/dist/cached-item-list.js +76 -0
- package/dist/cached-item-list.js.map +1 -0
- package/dist/interfaces/pow2.js +2 -0
- package/dist/interfaces/pow2.js.map +1 -0
- package/dist/interfaces/typed-array-constructor.js +2 -0
- package/dist/interfaces/typed-array-constructor.js.map +1 -0
- package/dist/interfaces/typed-array.js +2 -0
- package/dist/interfaces/typed-array.js.map +1 -0
- package/dist/local-pool.js +95 -0
- package/dist/local-pool.js.map +1 -0
- package/dist/lock/read-write-lock.js +25 -0
- package/dist/lock/read-write-lock.js.map +1 -0
- package/dist/lock/simple-lock.js +14 -0
- package/dist/lock/simple-lock.js.map +1 -0
- package/dist/memory-buffer.js +327 -0
- package/dist/memory-buffer.js.map +1 -0
- package/dist/memory-heap.js +116 -0
- package/dist/memory-heap.js.map +1 -0
- package/dist/serialize-object.js +59 -0
- package/dist/serialize-object.js.map +1 -0
- package/dist/shared-list.js +165 -0
- package/dist/shared-list.js.map +1 -0
- package/dist/shared-map.js +140 -0
- package/dist/shared-map.js.map +1 -0
- package/dist/shared-pointer-list.js +50 -0
- package/dist/shared-pointer-list.js.map +1 -0
- package/dist/shared-pool.js +165 -0
- package/dist/shared-pool.js.map +1 -0
- package/dist/shared-string.js +79 -0
- package/dist/shared-string.js.map +1 -0
- package/dist/shared-vector.js +165 -0
- package/dist/shared-vector.js.map +1 -0
- package/dist/utils/16-from-32-array.js +20 -0
- package/dist/utils/16-from-32-array.js.map +1 -0
- package/dist/utils/16-from-64-array.js +12 -0
- package/dist/utils/16-from-64-array.js.map +1 -0
- package/dist/utils/atomic-math.js +36 -0
- package/dist/utils/atomic-math.js.map +1 -0
- package/dist/utils/float32-atomics.js +28 -0
- package/dist/utils/float32-atomics.js.map +1 -0
- package/dist/utils/float64-atomics.js +28 -0
- package/dist/utils/float64-atomics.js.map +1 -0
- package/dist/utils/pointer.js +44 -0
- package/dist/utils/pointer.js.map +1 -0
- package/dist/utils/typedarray.js +46 -0
- package/dist/utils/typedarray.js.map +1 -0
- package/package.json +6 -11
- package/dist/shared-memory-objects.js +0 -1578
- package/dist/shared-memory-objects.js.map +0 -1
- package/dist/shared-memory-objects.umd.cjs +0 -2
- package/dist/shared-memory-objects.umd.cjs.map +0 -1
- package/dist/src/main.d.ts +0 -22
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import E from "./allocated-memory.js";
|
|
2
|
+
import { lock as f, unlock as h } from "./lock/simple-lock.js";
|
|
3
|
+
import { storeRawPointer as p, loadRawPointer as S, getPointer as A, loadPointer as d } from "./utils/pointer.js";
|
|
4
|
+
const y = {
|
|
5
|
+
1: Uint8Array,
|
|
6
|
+
2: Uint16Array
|
|
7
|
+
}, c = 0, m = 1, g = 2, u = 3;
|
|
8
|
+
class M {
|
|
9
|
+
static ALLOCATE_COUNT = 4;
|
|
10
|
+
memory;
|
|
11
|
+
allocatedMemory;
|
|
12
|
+
lock;
|
|
13
|
+
cachedPointer;
|
|
14
|
+
cachedString;
|
|
15
|
+
constructor(t, e) {
|
|
16
|
+
this.memory = t, typeof e == "string" ? (this.allocatedMemory = this.memory.allocUI32(M.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + u * this.allocatedMemory.data.BYTES_PER_ELEMENT), this.updateString(e)) : (this.allocatedMemory = new E(t, e), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + u * this.allocatedMemory.data.BYTES_PER_ELEMENT), "value" in e && this.updateString(e.value));
|
|
17
|
+
}
|
|
18
|
+
updateString(t) {
|
|
19
|
+
let e = this.createString(t);
|
|
20
|
+
f(this.lock), p(this.allocatedMemory.data, c, e.pointer), Atomics.store(this.allocatedMemory.data, m, t.length), Atomics.store(this.allocatedMemory.data, g, e.charType), h(this.lock), this.cachedPointer = e.pointer, this.cachedString = t;
|
|
21
|
+
}
|
|
22
|
+
createString(t) {
|
|
23
|
+
if (t === "")
|
|
24
|
+
return {
|
|
25
|
+
pointer: 0,
|
|
26
|
+
charType: 1
|
|
27
|
+
/* ASCII */
|
|
28
|
+
};
|
|
29
|
+
let e = 0;
|
|
30
|
+
for (let o = 0; o < t.length; o++) {
|
|
31
|
+
let i = t.charCodeAt(o);
|
|
32
|
+
i > e && (e = i);
|
|
33
|
+
}
|
|
34
|
+
let r = e > 255 ? 2 : 1, s = y[r], a = this.memory.allocUI32(Math.ceil(t.length / (4 / s.BYTES_PER_ELEMENT))), n = new s(a.data.buffer, a.data.byteOffset, t.length);
|
|
35
|
+
for (let o = 0; o < t.length; o++)
|
|
36
|
+
n[o] = t.charCodeAt(o);
|
|
37
|
+
return {
|
|
38
|
+
pointer: a.pointer,
|
|
39
|
+
charType: r
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
get value() {
|
|
43
|
+
let t = S(this.allocatedMemory.data, c);
|
|
44
|
+
if (this.cachedPointer === t && this.cachedString !== void 0)
|
|
45
|
+
return this.cachedString;
|
|
46
|
+
if (t === 0)
|
|
47
|
+
return "";
|
|
48
|
+
let { bufferPosition: e, bufferByteOffset: r } = A(t);
|
|
49
|
+
f(this.lock);
|
|
50
|
+
let s = Atomics.load(this.allocatedMemory.data, g), a = y[s], n = Atomics.load(this.allocatedMemory.data, m), o = new a(this.memory.buffers[e].buf, r, n), i = C(o);
|
|
51
|
+
return h(this.lock), this.cachedPointer = t, this.cachedString = i, i;
|
|
52
|
+
}
|
|
53
|
+
set value(t) {
|
|
54
|
+
let { bufferPosition: e, bufferByteOffset: r } = d(this.allocatedMemory.data, c);
|
|
55
|
+
this.updateString(t), r && this.memory.buffers[e].free(r);
|
|
56
|
+
}
|
|
57
|
+
getSharedMemory() {
|
|
58
|
+
return this.allocatedMemory.getSharedMemory();
|
|
59
|
+
}
|
|
60
|
+
get pointer() {
|
|
61
|
+
return this.allocatedMemory.pointer;
|
|
62
|
+
}
|
|
63
|
+
free() {
|
|
64
|
+
let { bufferPosition: t, bufferByteOffset: e } = d(this.allocatedMemory.data, c);
|
|
65
|
+
e && this.memory.buffers[t].free(e), this.allocatedMemory.free();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function C(l) {
|
|
69
|
+
if (l.length <= 8192)
|
|
70
|
+
return String.fromCharCode.apply(null, l);
|
|
71
|
+
let e = "";
|
|
72
|
+
for (let r = 0; r < l.length; r += 8192)
|
|
73
|
+
e += String.fromCharCode.apply(null, l.subarray(r, r + 8192));
|
|
74
|
+
return e;
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
M as default
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=shared-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-string.js","sources":["../src/shared-string.ts"],"sourcesContent":["import AllocatedMemory from './allocated-memory';\nimport type { SharedAllocatedMemory } from './allocated-memory';\nimport { lock, unlock } from './lock/simple-lock';\nimport type MemoryHeap from './memory-heap';\nimport { getPointer, loadPointer, loadRawPointer, storeRawPointer } from './utils/pointer';\n\nenum CHAR_TYPE {\n\tUNDEFINED,\n\tASCII,\n\tUTF16\n}\nconst TYPED_ARRAY_MAP = {\n\t[CHAR_TYPE.ASCII]: Uint8Array,\n\t[CHAR_TYPE.UTF16]: Uint16Array\n};\n\nconst POINTER_INDEX = 0;\nconst LENGTH_INDEX = 1;\nconst TYPE_INDEX = 2;\nconst LOCK_INDEX = 3;\nexport default class SharedString {\n\tstatic readonly ALLOCATE_COUNT = 4;\n\n\tprivate memory: MemoryHeap;\n\tprivate allocatedMemory: AllocatedMemory;\n\tprivate lock: Int32Array;\n\n\tprivate cachedPointer?: number;\n\tprivate cachedString?: string;\n\t\n\tconstructor(memory: MemoryHeap, value: string | SharedStringConfig | SharedStringMemory) {\n\t\tthis.memory = memory;\n\n\t\tif(typeof value === 'string') {\n\t\t\tthis.allocatedMemory = this.memory.allocUI32(SharedString.ALLOCATE_COUNT);\n\t\t\tthis.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + LOCK_INDEX * this.allocatedMemory.data.BYTES_PER_ELEMENT);\n\t\t\tthis.updateString(value);\n\t\t} else {\n\t\t\tthis.allocatedMemory = new AllocatedMemory(memory, value);\n\t\t\tthis.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + LOCK_INDEX * this.allocatedMemory.data.BYTES_PER_ELEMENT);\n\n\t\t\t// We only allocated memory but didn't initialize the string yet\n\t\t\tif('value' in value) {\n\t\t\t\tthis.updateString(value.value);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate updateString(value: string) {\n\t\tlet stringMemory = this.createString(value);\n\n\t\tlock(this.lock);\n\t\tstoreRawPointer(this.allocatedMemory.data, POINTER_INDEX, stringMemory.pointer);\n\t\tAtomics.store(this.allocatedMemory.data, LENGTH_INDEX, value.length);\n\t\tAtomics.store(this.allocatedMemory.data, TYPE_INDEX, stringMemory.charType);\n\t\tunlock(this.lock);\n\n\t\tthis.cachedPointer = stringMemory.pointer;\n\t\tthis.cachedString = value;\n\t}\n\tprivate createString(value: string) {\n\t\tif(value === '') {\n\t\t\treturn {\n\t\t\t\tpointer: 0,\n\t\t\t\tcharType: CHAR_TYPE.ASCII\n\t\t\t};\n\t\t}\n\n\t\t// NOTE: Scan with a loop instead of Math.max(...charCodes) which blows the stack for large strings\n\t\tlet maxCharCode = 0;\n\t\tfor(let i = 0; i < value.length; i++) {\n\t\t\tlet charCode = value.charCodeAt(i);\n\t\t\tif(charCode > maxCharCode) {\n\t\t\t\tmaxCharCode = charCode;\n\t\t\t}\n\t\t}\n\t\tlet charType = maxCharCode > 255 ? CHAR_TYPE.UTF16 : CHAR_TYPE.ASCII;\n\n\t\tlet typedArray = TYPED_ARRAY_MAP[charType];\n\t\tlet allocatedMemory = this.memory.allocUI32(Math.ceil(value.length / (4 / typedArray.BYTES_PER_ELEMENT)));\n\t\tlet data = new typedArray(allocatedMemory.data.buffer as ArrayBuffer, allocatedMemory.data.byteOffset, value.length);\n\t\tfor(let i = 0; i < value.length; i++) {\n\t\t\tdata[i] = value.charCodeAt(i);\n\t\t}\n\n\t\treturn {\n\t\t\tpointer: allocatedMemory.pointer,\n\t\t\tcharType\n\t\t};\n\t}\n\n\tget value(): string {\n\t\tlet pointer = loadRawPointer(this.allocatedMemory.data, POINTER_INDEX);\n\t\tif(this.cachedPointer === pointer && this.cachedString !== undefined) {\n\t\t\treturn this.cachedString;\n\t\t} else if(pointer === 0) {\n\t\t\treturn '';\n\t\t}\n\t\tlet { bufferPosition, bufferByteOffset } = getPointer(pointer);\n\n\t\tlock(this.lock);\n\t\tlet charType = Atomics.load(this.allocatedMemory.data, TYPE_INDEX) as number;\n\t\t// @ts-expect-error\n\t\tlet typedArray = TYPED_ARRAY_MAP[charType];\n\t\tlet bufferLength = Atomics.load(this.allocatedMemory.data, LENGTH_INDEX);\n\n\t\tlet data = new typedArray(this.memory.buffers[bufferPosition].buf, bufferByteOffset, bufferLength);\n\t\tlet string = fromCharCodes(data);\n\t\t// NOTE: Do not unlock until after transforming the data since the second this is done it can free that memory block\n\t\tunlock(this.lock);\n\n\t\tthis.cachedPointer = pointer;\n\t\tthis.cachedString = string;\n\n\t\treturn string;\n\t}\n\tset value(value: string) {\n\t\tlet { bufferPosition: oldBufferPosition, bufferByteOffset: oldBufferByteOffset } = loadPointer(this.allocatedMemory.data, POINTER_INDEX);\n\t\tthis.updateString(value);\n\n\t\tif(oldBufferByteOffset) {\n\t\t\tthis.memory.buffers[oldBufferPosition].free(oldBufferByteOffset);\n\t\t}\n\t}\n\n\tgetSharedMemory(): SharedStringMemory {\n\t\treturn this.allocatedMemory.getSharedMemory();\n\t}\n\n\tget pointer() {\n\t\treturn this.allocatedMemory.pointer;\n\t}\n\n\tfree() {\n\t\tlet { bufferPosition, bufferByteOffset } = loadPointer(this.allocatedMemory.data, POINTER_INDEX);\n\t\tif(bufferByteOffset) {\n\t\t\tthis.memory.buffers[bufferPosition].free(bufferByteOffset);\n\t\t}\n\t\tthis.allocatedMemory.free();\n\t}\n}\n\n// String.fromCharCode.apply throws a RangeError (Maximum call stack size exceeded) when handed too many\n// arguments at once, so decode large buffers in chunks to support arbitrarily long strings\nfunction fromCharCodes(data: Uint8Array | Uint16Array): string {\n\tconst CHUNK_SIZE = 8192;\n\tif(data.length <= CHUNK_SIZE) {\n\t\treturn String.fromCharCode.apply(null, data as unknown as Array<number>);\n\t}\n\n\tlet string = '';\n\tfor(let i = 0; i < data.length; i += CHUNK_SIZE) {\n\t\tstring += String.fromCharCode.apply(null, data.subarray(i, i + CHUNK_SIZE) as unknown as Array<number>);\n\t}\n\n\treturn string;\n}\n\ninterface SharedStringConfig extends SharedStringMemory {\n\tvalue: string\n}\ntype SharedStringMemory = SharedAllocatedMemory;"],"names":["TYPED_ARRAY_MAP","POINTER_INDEX","LENGTH_INDEX","TYPE_INDEX","LOCK_INDEX","SharedString","memory","value","AllocatedMemory","stringMemory","lock","storeRawPointer","unlock","maxCharCode","i","charCode","charType","typedArray","allocatedMemory","data","pointer","loadRawPointer","bufferPosition","bufferByteOffset","getPointer","bufferLength","string","fromCharCodes","oldBufferPosition","oldBufferByteOffset","loadPointer"],"mappings":";;;AAWA,MAAMA,IAAkB;AAAA,EACtB,GAAkB;AAAA,EAClB,GAAkB;AACpB,GAEMC,IAAgB,GAChBC,IAAe,GACfC,IAAa,GACbC,IAAa;AACnB,MAAqBC,EAAa;AAAA,EACjC,OAAgB,iBAAiB;AAAA,EAEzB;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAER,YAAYC,GAAoBC,GAAyD;AACxF,SAAK,SAASD,GAEX,OAAOC,KAAU,YACnB,KAAK,kBAAkB,KAAK,OAAO,UAAUF,EAAa,cAAc,GACxE,KAAK,OA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,gBAAgB,MAAM7B,CAAa;AAC/F,IAAGsB,KACF,KAAK,OAAO,QAAQD,CAAc,EAAE,KAAKC,CAAgB,GAE1D,KAAK,gBAAgB,KAAA;AAAA,EACtB;AACD;AAIA,SAASI,EAAcR,GAAwC;AAE9D,MAAGA,EAAK,UAAU;AACjB,WAAO,OAAO,aAAa,MAAM,MAAMA,CAAgC;AAGxE,MAAIO,IAAS;AACb,WAAQZ,IAAI,GAAGA,IAAIK,EAAK,QAAQL,KAAK;AACpC,IAAAY,KAAU,OAAO,aAAa,MAAM,MAAMP,EAAK,SAASL,GAAGA,IAAI,IAAU,CAA6B;AAGvG,SAAOY;AACR;"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import f from "./allocated-memory.js";
|
|
2
|
+
import { storePointer as u, getPointer as L, loadPointer as d, storeRawPointer as b } from "./utils/pointer.js";
|
|
3
|
+
const h = 0, o = 1, B = 2, g = 3, k = 4;
|
|
4
|
+
class y {
|
|
5
|
+
static ALLOCATE_COUNT = 4;
|
|
6
|
+
memory;
|
|
7
|
+
// Pointer, List Length, Buffer Length, Type/DataLength
|
|
8
|
+
firstBlock;
|
|
9
|
+
uint16Array;
|
|
10
|
+
get length() {
|
|
11
|
+
return Atomics.load(this.firstBlock.data, o);
|
|
12
|
+
}
|
|
13
|
+
get type() {
|
|
14
|
+
return this.uint16Array[0];
|
|
15
|
+
}
|
|
16
|
+
set type(t) {
|
|
17
|
+
Atomics.store(this.uint16Array, 0, t);
|
|
18
|
+
}
|
|
19
|
+
get dataLength() {
|
|
20
|
+
return this.uint16Array[1] || 1;
|
|
21
|
+
}
|
|
22
|
+
set dataLength(t) {
|
|
23
|
+
Atomics.store(this.uint16Array, 1, t);
|
|
24
|
+
}
|
|
25
|
+
get bufferLength() {
|
|
26
|
+
return Atomics.load(this.firstBlock.data, B);
|
|
27
|
+
}
|
|
28
|
+
set bufferLength(t) {
|
|
29
|
+
Atomics.store(this.firstBlock.data, B, t);
|
|
30
|
+
}
|
|
31
|
+
get pointer() {
|
|
32
|
+
return this.firstBlock.pointer;
|
|
33
|
+
}
|
|
34
|
+
cachedFullDataBlock;
|
|
35
|
+
cachedPointer;
|
|
36
|
+
constructor(t, e) {
|
|
37
|
+
if (this.memory = t, e && "firstBlock" in e) {
|
|
38
|
+
if (this.firstBlock = new f(t, e.firstBlock), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + g * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in e || "dataLength" in e) {
|
|
39
|
+
const a = e.bufferLength ?? k;
|
|
40
|
+
let r = t.allocUI32(a * (e.dataLength ?? 1));
|
|
41
|
+
u(this.firstBlock.data, h, r.bufferPosition, r.bufferByteOffset), this.bufferLength = a, this.dataLength = e.dataLength ?? 1;
|
|
42
|
+
}
|
|
43
|
+
if ("type" in e) {
|
|
44
|
+
const a = e?.type ?? Uint32Array;
|
|
45
|
+
a === Uint32Array ? this.type = 0 : a === Int32Array ? this.type = 1 : a === Float32Array && (this.type = 2);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
this.firstBlock = t.allocUI32(y.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + g * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
49
|
+
let a = e?.dataLength ?? 1, r = e?.bufferLength ?? k, i = t.allocUI32(r * a);
|
|
50
|
+
u(this.firstBlock.data, h, i.bufferPosition, i.bufferByteOffset), this.bufferLength = r;
|
|
51
|
+
const s = e?.type ?? Uint32Array;
|
|
52
|
+
s === Uint32Array ? this.type = 0 : s === Int32Array ? this.type = 1 : s === Float32Array && (this.type = 2), this.dataLength = a;
|
|
53
|
+
}
|
|
54
|
+
this.cachedPointer = this.firstBlock.data[0], this.cachedFullDataBlock = this.getFullDataBlock();
|
|
55
|
+
}
|
|
56
|
+
at(t) {
|
|
57
|
+
let e = this.length;
|
|
58
|
+
if (t >= e || t < 0)
|
|
59
|
+
throw new Error(`${t} is out of bounds ${e}`);
|
|
60
|
+
let a = this.getFullDataBlock();
|
|
61
|
+
return this.getDataBlock(a, t);
|
|
62
|
+
}
|
|
63
|
+
get(t, e = 0) {
|
|
64
|
+
if (e >= this.dataLength)
|
|
65
|
+
throw new Error(`${e} is out of dataLength bounds ${this.dataLength}`);
|
|
66
|
+
if (t >= this.length || t < 0)
|
|
67
|
+
throw new Error(`${t} is out of bounds ${this.length}`);
|
|
68
|
+
return this.getFullDataBlock()[t * this.dataLength + e];
|
|
69
|
+
}
|
|
70
|
+
push(t) {
|
|
71
|
+
let e = this.dataLength;
|
|
72
|
+
const a = typeof t == "number";
|
|
73
|
+
if (!a && t.length > e)
|
|
74
|
+
throw new Error(`Can't insert ${t.length} array into shared list of ${e} dataLength`);
|
|
75
|
+
let r = this.getFullDataBlock(), i = this.length, s = e * i;
|
|
76
|
+
return a ? r[s] = t : r.set(t, s), Atomics.add(this.firstBlock.data, o, 1) + 1 >= this.bufferLength && this.growBuffer(), i;
|
|
77
|
+
}
|
|
78
|
+
pop() {
|
|
79
|
+
let t = Atomics.sub(this.firstBlock.data, o, 1), e = this.getFullDataBlock();
|
|
80
|
+
return this.getDataBlock(e, t - 1);
|
|
81
|
+
}
|
|
82
|
+
// Returns the first number irregardless of dataLength - faster way to pop if you don't care about the rest of the data block
|
|
83
|
+
popNumber() {
|
|
84
|
+
const t = Atomics.sub(this.firstBlock.data, o, 1);
|
|
85
|
+
return this.getFullDataBlock()[(t - 1) * this.dataLength];
|
|
86
|
+
}
|
|
87
|
+
deleteIndex(t) {
|
|
88
|
+
let e = this.length;
|
|
89
|
+
if (t >= e || t < 0)
|
|
90
|
+
throw new Error(`${t} is out of bounds ${e}`);
|
|
91
|
+
let a = this.dataLength, r = this.getFullDataBlock();
|
|
92
|
+
for (let i = t; i < e; i++)
|
|
93
|
+
for (let s = 0; s < a; s++)
|
|
94
|
+
r[i * a + s] = r[(i + 1) * a + s];
|
|
95
|
+
Atomics.sub(this.firstBlock.data, o, 1);
|
|
96
|
+
}
|
|
97
|
+
clear() {
|
|
98
|
+
this.firstBlock.data[o] = 0;
|
|
99
|
+
}
|
|
100
|
+
*[Symbol.iterator]() {
|
|
101
|
+
let t = this.getFullDataBlock(), e = this.dataLength, a = this.length * e;
|
|
102
|
+
for (let r = 0; r < a; r += e)
|
|
103
|
+
yield t.subarray(r, r + e);
|
|
104
|
+
}
|
|
105
|
+
// Significantly faster but won't be thread safe if anything is removing/adding to it during iteration
|
|
106
|
+
getCurrentArray() {
|
|
107
|
+
return this.getFullDataBlock().subarray(0, this.length * this.dataLength);
|
|
108
|
+
}
|
|
109
|
+
getFullDataBlock() {
|
|
110
|
+
let t = Atomics.load(this.firstBlock.data, h);
|
|
111
|
+
if (this.cachedPointer === t && this.cachedFullDataBlock)
|
|
112
|
+
return this.cachedFullDataBlock;
|
|
113
|
+
let e = L(t), a = new f(this.memory, e), r;
|
|
114
|
+
switch (this.type) {
|
|
115
|
+
case 1:
|
|
116
|
+
r = new Int32Array(a.data.buffer, a.bufferByteOffset, this.dataLength * this.bufferLength);
|
|
117
|
+
break;
|
|
118
|
+
case 0:
|
|
119
|
+
r = new Uint32Array(a.data.buffer, a.bufferByteOffset, this.dataLength * this.bufferLength);
|
|
120
|
+
break;
|
|
121
|
+
case 2:
|
|
122
|
+
r = new Float32Array(a.data.buffer, a.bufferByteOffset, this.dataLength * this.bufferLength);
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(`Unknown data block type ${this.type}`);
|
|
126
|
+
}
|
|
127
|
+
return this.cachedPointer = t, this.cachedFullDataBlock = r, r;
|
|
128
|
+
}
|
|
129
|
+
getDataBlock(t, e) {
|
|
130
|
+
const a = e * this.dataLength;
|
|
131
|
+
return t.subarray(a, a + this.dataLength);
|
|
132
|
+
}
|
|
133
|
+
growBuffer() {
|
|
134
|
+
let e = this.bufferLength * 2, a = this.dataLength, r = d(this.firstBlock.data, h), i = new f(this.memory, r), s = this.getFullDataBlock(), l = this.memory.allocUI32(e * a), n;
|
|
135
|
+
switch (this.type) {
|
|
136
|
+
case 1:
|
|
137
|
+
n = new Int32Array(l.data.buffer, l.bufferByteOffset, a * e);
|
|
138
|
+
break;
|
|
139
|
+
case 0:
|
|
140
|
+
n = new Uint32Array(l.data.buffer, l.bufferByteOffset, a * e);
|
|
141
|
+
break;
|
|
142
|
+
case 2:
|
|
143
|
+
n = new Float32Array(l.data.buffer, l.bufferByteOffset, a * e);
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
throw new Error(`Unknown data block type ${this.type}`);
|
|
147
|
+
}
|
|
148
|
+
n.set(s);
|
|
149
|
+
const c = l.pointer;
|
|
150
|
+
b(this.firstBlock.data, h, c), this.bufferLength = e, i.free(), this.cachedPointer = c, this.cachedFullDataBlock = n;
|
|
151
|
+
}
|
|
152
|
+
free() {
|
|
153
|
+
let t = d(this.firstBlock.data, h);
|
|
154
|
+
new f(this.memory, t).free(), this.firstBlock.free();
|
|
155
|
+
}
|
|
156
|
+
getSharedMemory() {
|
|
157
|
+
return {
|
|
158
|
+
firstBlock: this.firstBlock.getSharedMemory()
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
y as default
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=shared-vector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-vector.js","sources":["../src/shared-vector.ts"],"sourcesContent":["import type { SharedAllocatedMemory } from './allocated-memory';\nimport AllocatedMemory from './allocated-memory';\nimport type { TypedArrayConstructor } from './interfaces/typed-array-constructor';\nimport type MemoryHeap from './memory-heap';\nimport { getPointer, loadPointer, storePointer, storeRawPointer } from './utils/pointer';\n\nenum TYPE {\n\tuint32,\n\tint32,\n\tfloat32\n}\n\nconst VECTOR_INDEX = 0;\nconst LENGTH_INDEX = 1;\nconst BUFFER_LENGTH_INDEX = 2;\nconst TYPE_INDEX = 3;\nconst DEFAULT_SIZE = 4;\nexport default class SharedVector<T extends Uint32Array | Int32Array | Float32Array = Uint32Array> implements Iterable<T> {\n\tstatic readonly ALLOCATE_COUNT = 4;\n\tprivate memory: MemoryHeap;\n\n\t// Pointer, List Length, Buffer Length, Type/DataLength\n\tprivate firstBlock: AllocatedMemory;\n\tprivate uint16Array: Uint16Array;\n\n\tget length(): number {\n\t\treturn Atomics.load(this.firstBlock.data, LENGTH_INDEX);\n\t}\n\t\n\tget type(): number {\n\t\treturn this.uint16Array[0];\n\t}\n\tprivate set type(value: number) {\n\t\tAtomics.store(this.uint16Array, 0, value);\n\t}\n\tget dataLength(): number {\n\t\t// Can technically be initialized by passing memory without actually every being called - need to make sure dataLength is always at least one\n\t\treturn this.uint16Array[1] || 1;\n\t}\n\tprivate set dataLength(value: number) {\n\t\tAtomics.store(this.uint16Array, 1, value);\n\t}\n\n\tget bufferLength(): number {\n\t\treturn Atomics.load(this.firstBlock.data, BUFFER_LENGTH_INDEX);\n\t}\n\tprivate set bufferLength(value: number) {\n\t\tAtomics.store(this.firstBlock.data, BUFFER_LENGTH_INDEX, value);\n\t}\n\n\tget pointer() {\n\t\treturn this.firstBlock.pointer;\n\t}\n\n\tprivate cachedFullDataBlock?: T;\n\tprivate cachedPointer: number;\n\n\tconstructor(memory: MemoryHeap, config?: SharedVectorConfig<T> | SharedVectorMemory | SharedVectorMemory & SharedVectorConfig<T>) {\n\t\tthis.memory = memory;\n\n\t\tif(config && 'firstBlock' in config) {\n\t\t\tthis.firstBlock = new AllocatedMemory(memory, config.firstBlock);\n\t\t\tthis.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + TYPE_INDEX * Uint32Array.BYTES_PER_ELEMENT, 2);\n\n\t\t\t// Pre-allocating memory and setting up in specific memory location\n\t\t\tif('type' in config || 'dataLength' in config) {\n\t\t\t\tconst bufferLength = config.bufferLength ?? DEFAULT_SIZE;\n\t\t\t\tlet dataBlock = memory.allocUI32(bufferLength * (config.dataLength ?? 1));\n\t\t\t\tstorePointer(this.firstBlock.data, VECTOR_INDEX, dataBlock.bufferPosition, dataBlock.bufferByteOffset);\n\t\t\t\tthis.bufferLength = bufferLength;\n\t\t\t\tthis.dataLength = (config.dataLength ?? 1);\n\t\t\t}\n\t\t\tif('type' in config) {\n\t\t\t\tconst type = config?.type ?? Uint32Array;\n\t\t\t\tif(type === Uint32Array) {\n\t\t\t\t\tthis.type = TYPE.uint32;\n\t\t\t\t}\n\t\t\t\t// @ts-expect-error\n\t\t\t\telse if(type === Int32Array) {\n\t\t\t\t\tthis.type = TYPE.int32;\n\t\t\t\t}\n\t\t\t\t// @ts-expect-error\n\t\t\t\telse if(type === Float32Array) {\n\t\t\t\t\tthis.type = TYPE.float32;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.firstBlock = memory.allocUI32(SharedVector.ALLOCATE_COUNT);\n\t\t\tthis.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + TYPE_INDEX * Uint32Array.BYTES_PER_ELEMENT, 2);\n\n\t\t\tlet dataLength = config?.dataLength ?? 1;\n\t\t\tlet bufferLength = config?.bufferLength ?? DEFAULT_SIZE;\n\t\t\tlet dataBlock = memory.allocUI32(bufferLength * dataLength);\n\t\t\tstorePointer(this.firstBlock.data, VECTOR_INDEX, dataBlock.bufferPosition, dataBlock.bufferByteOffset);\n\t\t\tthis.bufferLength = bufferLength;\n\n\t\t\tconst type = config?.type ?? Uint32Array;\n\t\t\tif(type === Uint32Array) {\n\t\t\t\tthis.type = TYPE.uint32;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\telse if(type === Int32Array) {\n\t\t\t\tthis.type = TYPE.int32;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\telse if(type === Float32Array) {\n\t\t\t\tthis.type = TYPE.float32;\n\t\t\t}\n\t\t\tthis.dataLength = dataLength;\n\t\t}\n\n\t\tthis.cachedPointer = this.firstBlock.data[0];\n\t\tthis.cachedFullDataBlock = this.getFullDataBlock();\n\t}\n\n\tat(index: number): T {\n\t\tlet length = this.length;\n\t\tif(index >= length || index < 0) {\n\t\t\tthrow new Error(`${index} is out of bounds ${length}`);\n\t\t}\n\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\treturn this.getDataBlock(dataBlock, index);\n\t}\n\tget(index: number, dataIndex = 0): number {\n\t\tif(dataIndex >= this.dataLength) {\n\t\t\tthrow new Error(`${dataIndex} is out of dataLength bounds ${this.dataLength}`);\n\t\t} else if(index >= this.length || index < 0) {\n\t\t\tthrow new Error(`${index} is out of bounds ${this.length}`);\n\t\t}\n\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\treturn dataBlock[index * this.dataLength + dataIndex];\n\t}\n\n\tpush(values: number | Array<number>): number {\n\t\tlet dataLength = this.dataLength;\n\t\tconst isSingleNumber = typeof values === 'number';\n\t\tif(!isSingleNumber && values.length > dataLength) {\n\t\t\tthrow new Error(`Can't insert ${values.length} array into shared list of ${dataLength} dataLength`);\n\t\t}\n\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\tlet currentLength = this.length;\n\t\tlet startIndex = dataLength * currentLength;\n\t\tif(isSingleNumber) {\n\t\t\tdataBlock[startIndex] = values;\n\t\t} else {\n\t\t\tdataBlock.set(values, startIndex);\n\t\t}\n\n\t\tlet newLength = Atomics.add(this.firstBlock.data, LENGTH_INDEX, 1) + 1;\n\t\tif(newLength >= this.bufferLength) {\n\t\t\tthis.growBuffer();\n\t\t}\n\n\t\treturn currentLength;\n\t}\n\n\tpop(): T {\n\t\tlet oldLength = Atomics.sub(this.firstBlock.data, LENGTH_INDEX, 1);\n\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\treturn this.getDataBlock(dataBlock, oldLength - 1);\n\t}\n\n\t// Returns the first number irregardless of dataLength - faster way to pop if you don't care about the rest of the data block\n\tpopNumber(): number {\n\t\tconst oldLength = Atomics.sub(this.firstBlock.data, LENGTH_INDEX, 1);\n\t\tconst dataBlock = this.getFullDataBlock();\n\t\treturn dataBlock[(oldLength - 1) * this.dataLength];\n\t}\n\n\tdeleteIndex(index: number) {\n\t\tlet length = this.length;\n\t\tif(index >= length || index < 0) {\n\t\t\tthrow new Error(`${index} is out of bounds ${length}`);\n\t\t}\n\n\t\tlet dataLength = this.dataLength;\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\tfor(let i = index; i < length; i++) {\n\t\t\tfor(let j = 0; j < dataLength; j++) {\n\t\t\t\tdataBlock[i * dataLength + j] = dataBlock[(i + 1) * dataLength + j];\n\t\t\t}\n\t\t}\n\n\t\tAtomics.sub(this.firstBlock.data, LENGTH_INDEX, 1);\n\t}\n\n\tclear() {\n\t\tthis.firstBlock.data[LENGTH_INDEX] = 0;\n\t}\n\n\t*[Symbol.iterator]() {\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\tlet dataLength = this.dataLength;\n\t\tlet totalDataEntries = this.length * dataLength;\n\n\t\tfor(let i = 0; i < totalDataEntries; i += dataLength) {\n\t\t\tyield dataBlock.subarray(i, i + dataLength) as T;\n\t\t}\n\t}\n\n\t// Significantly faster but won't be thread safe if anything is removing/adding to it during iteration\n\tgetCurrentArray(): T {\n\t\tlet dataBlock = this.getFullDataBlock();\n\t\treturn dataBlock.subarray(0, this.length * this.dataLength) as T;\n\t}\n\n\tprivate getFullDataBlock(): T {\n\t\tlet pointerNumber = Atomics.load(this.firstBlock.data, VECTOR_INDEX);\n\t\tif(this.cachedPointer === pointerNumber && this.cachedFullDataBlock) {\n\t\t\treturn this.cachedFullDataBlock;\n\t\t}\n\n\t\tlet pointer = getPointer(pointerNumber);\n\t\tlet rawData = new AllocatedMemory(this.memory, pointer);\n\n\t\tlet data: T;\n\t\tswitch(this.type) {\n\t\t\tcase TYPE.int32:\n\t\t\t\tdata = new Int32Array(rawData.data.buffer, rawData.bufferByteOffset, this.dataLength * this.bufferLength) as T;\n\t\t\t\tbreak;\n\t\t\tcase TYPE.uint32:\n\t\t\t\tdata = new Uint32Array(rawData.data.buffer, rawData.bufferByteOffset, this.dataLength * this.bufferLength) as T;\n\t\t\t\tbreak;\n\t\t\tcase TYPE.float32:\n\t\t\t\tdata = new Float32Array(rawData.data.buffer, rawData.bufferByteOffset, this.dataLength * this.bufferLength) as T;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unknown data block type ${this.type}`);\n\t\t}\n\n\t\tthis.cachedPointer = pointerNumber;\n\t\tthis.cachedFullDataBlock = data;\n\n\t\treturn data;\n\t}\n\tprivate getDataBlock(rawData: T, index: number): T {\n\t\tconst start = index * this.dataLength;\n\t\treturn rawData.subarray(start, start + this.dataLength) as T;\n\t}\n\n\tprivate growBuffer() {\n\t\tlet oldBufferLength = this.bufferLength;\n\t\tlet newBufferLength = oldBufferLength * 2;\n\t\tlet dataLength = this.dataLength;\n\n\t\tlet oldPointer = loadPointer(this.firstBlock.data, VECTOR_INDEX);\n\t\tlet oldDataMemory = new AllocatedMemory(this.memory, oldPointer);\n\t\tlet oldDataBlock = this.getFullDataBlock();\n\t\tlet newDataBlock = this.memory.allocUI32(newBufferLength * dataLength);\n\n\t\tlet newData: T;\n\t\tswitch(this.type) {\n\t\t\tcase TYPE.int32:\n\t\t\t\tnewData = new Int32Array(newDataBlock.data.buffer, newDataBlock.bufferByteOffset, dataLength * newBufferLength) as T;\n\t\t\t\tbreak;\n\t\t\tcase TYPE.uint32:\n\t\t\t\tnewData = new Uint32Array(newDataBlock.data.buffer, newDataBlock.bufferByteOffset, dataLength * newBufferLength) as T;\n\t\t\t\tbreak;\n\t\t\tcase TYPE.float32:\n\t\t\t\tnewData = new Float32Array(newDataBlock.data.buffer, newDataBlock.bufferByteOffset, dataLength * newBufferLength) as T;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unknown data block type ${this.type}`);\n\t\t}\n\n\t\t// Copy old buffer into new buffer\n\t\tnewData.set(oldDataBlock);\n\n\t\tconst newPointer = newDataBlock.pointer;\n\t\tstoreRawPointer(this.firstBlock.data, VECTOR_INDEX, newPointer);\n\t\tthis.bufferLength = newBufferLength;\n\t\toldDataMemory.free();\n\n\t\tthis.cachedPointer = newPointer;\n\t\tthis.cachedFullDataBlock = newData;\n\t}\n\n\tfree() {\n\t\tlet pointer = loadPointer(this.firstBlock.data, VECTOR_INDEX);\n\t\tlet dataMemory = new AllocatedMemory(this.memory, pointer);\n\n\t\tdataMemory.free();\n\t\tthis.firstBlock.free();\n\t}\n\n\tgetSharedMemory(): SharedVectorMemory {\n\t\treturn {\n\t\t\tfirstBlock: this.firstBlock.getSharedMemory()\n\t\t};\n\t}\n}\n\ninterface SharedVectorConfig<T extends Uint32Array | Int32Array | Float32Array> {\n\ttype?: TypedArrayConstructor<T>\n\tdataLength?: number\n\n\tbufferLength?: number\n}\ninterface SharedVectorMemory {\n\tfirstBlock: SharedAllocatedMemory\n}\n\nexport type { SharedVectorConfig, SharedVectorMemory };"],"names":["VECTOR_INDEX","LENGTH_INDEX","BUFFER_LENGTH_INDEX","TYPE_INDEX","DEFAULT_SIZE","SharedVector","value","memory","config","AllocatedMemory","bufferLength","dataBlock","storePointer","type","dataLength","index","length","dataIndex","values","isSingleNumber","currentLength","startIndex","oldLength","j","totalDataEntries","i","pointerNumber","pointer","getPointer","rawData","data","start","newBufferLength","oldPointer","loadPointer","oldDataMemory","oldDataBlock","newDataBlock","newData","newPointer","storeRawPointer"],"mappings":";;AAYA,MAAMA,IAAe,GACfC,IAAe,GACfC,IAAsB,GACtBC,IAAa,GACbC,IAAe;AACrB,MAAqBC,EAAqG;AAAA,EACzH,OAAgB,iBAAiB;AAAA,EACzB;AAAA;AAAA,EAGA;AAAA,EACA;AAAA,EAER,IAAI,SAAiB;AACpB,WAAO,QAAQ,KAAK,KAAK,WAAW,MAAMJ,CAAY;AAAA,EACvD;AAAA,EAEA,IAAI,OAAe;AAClB,WAAO,KAAK,YAAY,CAAC;AAAA,EAC1B;AAAA,EACA,IAAY,KAAKK,GAAe;AAC/B,YAAQ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r, c, u) {
|
|
6
|
+
Atomics.store(n, r, f(c, u));
|
|
7
|
+
}
|
|
8
|
+
function i(n) {
|
|
9
|
+
return e[0] = n, [t[0], t[1]];
|
|
10
|
+
}
|
|
11
|
+
function f(n, r) {
|
|
12
|
+
return t[0] = n, t[1] = r, e[0];
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
f as convert16To32,
|
|
16
|
+
i as convert32To16,
|
|
17
|
+
a as load16From32,
|
|
18
|
+
s as store16In32
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=16-from-32-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"16-from-32-array.js","sources":["../../src/utils/16-from-32-array.ts"],"sourcesContent":["const buffer = new ArrayBuffer(4);\nconst uint32Array = new Uint32Array(buffer);\nconst uint16Array = new Uint16Array(buffer);\n\nexport function load16From32(data: Uint32Array, index: number): [number, number] {\n\treturn convert32To16(Atomics.load(data, index));\n}\n\nexport function store16In32(data: Uint32Array, index: number, value1: number, value2: number) {\n\tAtomics.store(data, index, convert16To32(value1, value2));\n}\n\nexport function convert32To16(value: number): [number, number] {\n\tuint32Array[0] = value;\n\n\treturn [uint16Array[0], uint16Array[1]];\n}\nexport function convert16To32(value1: number, value2: number): number {\n\tuint16Array[0] = value1;\n\tuint16Array[1] = value2;\n\n\treturn uint32Array[0];\n}"],"names":["buffer","uint32Array","uint16Array","load16From32","data","index","convert32To16","store16In32","value1","value2","convert16To32","value"],"mappings":"AAAA,MAAMA,IAAS,IAAI,YAAY,CAAC,GAC1BC,IAAc,IAAI,YAAYD,CAAM,GACpCE,IAAc,IAAI,YAAYF,CAAM;AAEnC,SAASG,EAAaC,GAAmBC,GAAiC;AAChF,SAAOC,EAAc,QAAQ,KAAKF,GAAMC,CAAK,CAAC;AAC/C;AAEO,SAASE,EAAYH,GAAmBC,GAAeG,GAAgBC,GAAgB;AAC7F,UAAQ,MAAML,GAAMC,GAAOK,EAAcF,GAAQC,CAAM,CAAC;AACzD;AAEO,SAASH,EAAcK,GAAiC;AAC9D,SAAAV,EAAY,CAAC,IAAIU,GAEV,CAACT,EAAY,CAAC,GAAGA,EAAY,CAAC,CAAC;AACvC;AACO,SAASQ,EAAcF,GAAgBC,GAAwB;AACrE,SAAAP,EAAY,CAAC,IAAIM,GACjBN,EAAY,CAAC,IAAIO,GAEVR,EAAY,CAAC;AACrB;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const o = new ArrayBuffer(8), e = new BigUint64Array(o), r = new Uint16Array(o);
|
|
2
|
+
function u(n, t) {
|
|
3
|
+
return e[0] = Atomics.load(n, t), [r[0], r[1], r[2], r[3]];
|
|
4
|
+
}
|
|
5
|
+
function A(n, t, i, a, c, s = 0) {
|
|
6
|
+
r[0] = i, r[1] = a, r[2] = c, r[3] = s, Atomics.store(n, t, e[0]);
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
u as load16From64,
|
|
10
|
+
A as store16In64
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=16-from-64-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"16-from-64-array.js","sources":["../../src/utils/16-from-64-array.ts"],"sourcesContent":["const buffer = new ArrayBuffer(8);\nconst uint64Array = new BigUint64Array(buffer);\nconst uint16Array = new Uint16Array(buffer);\n\nexport function load16From64(data: BigUint64Array, index: number): [number, number, number, number] {\n\tuint64Array[0] = Atomics.load(data, index);\n\t\n\treturn [uint16Array[0], uint16Array[1], uint16Array[2], uint16Array[3]];\n}\n\nexport function store16In64(data: BigUint64Array, index: number, value1: number, value2: number, value3: number, value4: number = 0) {\n\tuint16Array[0] = value1;\n\tuint16Array[1] = value2;\n\tuint16Array[2] = value3;\n\tuint16Array[3] = value4;\n\n\tAtomics.store(data, index, uint64Array[0]);\n}"],"names":["buffer","uint64Array","uint16Array","load16From64","data","index","store16In64","value1","value2","value3","value4"],"mappings":"AAAA,MAAMA,IAAS,IAAI,YAAY,CAAC,GAC1BC,IAAc,IAAI,eAAeD,CAAM,GACvCE,IAAc,IAAI,YAAYF,CAAM;AAEnC,SAASG,EAAaC,GAAsBC,GAAiD;AACnG,SAAAJ,EAAY,CAAC,IAAI,QAAQ,KAAKG,GAAMC,CAAK,GAElC,CAACH,EAAY,CAAC,GAAGA,EAAY,CAAC,GAAGA,EAAY,CAAC,GAAGA,EAAY,CAAC,CAAC;AACvE;AAEO,SAASI,EAAYF,GAAsBC,GAAeE,GAAgBC,GAAgBC,GAAgBC,IAAiB,GAAG;AACpI,EAAAR,EAAY,CAAC,IAAIK,GACjBL,EAAY,CAAC,IAAIM,GACjBN,EAAY,CAAC,IAAIO,GACjBP,EAAY,CAAC,IAAIQ,GAEjB,QAAQ,MAAMN,GAAMC,GAAOJ,EAAY,CAAC,CAAC;AAC1C;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { compareExchangeFloat32 as n, loadFloat32 as u } from "./float32-atomics.js";
|
|
2
|
+
function i(e, l, a, c) {
|
|
3
|
+
let t, o;
|
|
4
|
+
do
|
|
5
|
+
t = Atomics.load(e, l), o = Math.min(t + a, c);
|
|
6
|
+
while (Atomics.compareExchange(e, l, t, o) !== t);
|
|
7
|
+
return o;
|
|
8
|
+
}
|
|
9
|
+
function d(e, l, a, c) {
|
|
10
|
+
let t, o;
|
|
11
|
+
do
|
|
12
|
+
t = Atomics.load(e, l), o = Math.max(t - a, c);
|
|
13
|
+
while (Atomics.compareExchange(e, l, t, o) !== t);
|
|
14
|
+
return o;
|
|
15
|
+
}
|
|
16
|
+
function h(e, l, a, c) {
|
|
17
|
+
let t, o;
|
|
18
|
+
do
|
|
19
|
+
t = u(e, l), o = Math.min(t + a, c);
|
|
20
|
+
while (n(e, l, t, o) !== t);
|
|
21
|
+
return o;
|
|
22
|
+
}
|
|
23
|
+
function r(e, l, a, c) {
|
|
24
|
+
let t, o;
|
|
25
|
+
do
|
|
26
|
+
t = u(e, l), o = Math.max(t - a, c);
|
|
27
|
+
while (n(e, l, t, o) !== t);
|
|
28
|
+
return o;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
h as addAtomicFloat32,
|
|
32
|
+
i as addAtomicInt,
|
|
33
|
+
r as subtractAtomicFloat,
|
|
34
|
+
d as subtractAtomicInt
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=atomic-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic-math.js","sources":["../../src/utils/atomic-math.ts"],"sourcesContent":["import { compareExchangeFloat32, loadFloat32 } from './float32-atomics';\n\nexport function addAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, max: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = Atomics.load(array, index);\n\t\tnewValue = Math.min(oldValue + amount, max);\n\t} while(Atomics.compareExchange(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}\n\nexport function subtractAtomicInt(array: Uint32Array | Int32Array, index: number, amount: number, min: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = Atomics.load(array, index);\n\t\tnewValue = Math.max(oldValue - amount, min);\n\t} while(Atomics.compareExchange(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}\n\nexport function addAtomicFloat32(array: Float32Array, index: number, amount: number, max: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = loadFloat32(array, index);\n\t\tnewValue = Math.min(oldValue + amount, max);\n\t} while(compareExchangeFloat32(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}\n\nexport function subtractAtomicFloat(array: Float32Array, index: number, amount: number, min: number) {\n\tlet oldValue;\n\tlet newValue;\n\tdo {\n\t\toldValue = loadFloat32(array, index);\n\t\tnewValue = Math.max(oldValue - amount, min);\n\t} while(compareExchangeFloat32(array, index, oldValue, newValue) !== oldValue);\n\n\treturn newValue;\n}"],"names":["addAtomicInt","array","index","amount","max","oldValue","newValue","subtractAtomicInt","min","addAtomicFloat32","loadFloat32","compareExchangeFloat32","subtractAtomicFloat"],"mappings":";AAEO,SAASA,EAAaC,GAAiCC,GAAeC,GAAgBC,GAAa;AACzG,MAAIC,GACAC;AACJ;AACC,IAAAD,IAAW,QAAQ,KAAKJ,GAAOC,CAAK,GACpCI,IAAW,KAAK,IAAID,IAAWF,GAAQC,CAAG;AAAA,SACnC,QAAQ,gBAAgBH,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAEtE,SAAOC;AACR;AAEO,SAASC,EAAkBN,GAAiCC,GAAeC,GAAgBK,GAAa;AAC9G,MAAIH,GACAC;AACJ;AACC,IAAAD,IAAW,QAAQ,KAAKJ,GAAOC,CAAK,GACpCI,IAAW,KAAK,IAAID,IAAWF,GAAQK,CAAG;AAAA,SACnC,QAAQ,gBAAgBP,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAEtE,SAAOC;AACR;AAEO,SAASG,EAAiBR,GAAqBC,GAAeC,GAAgBC,GAAa;AACjG,MAAIC,GACAC;AACJ;AACC,IAAAD,IAAWK,EAAYT,GAAOC,CAAK,GACnCI,IAAW,KAAK,IAAID,IAAWF,GAAQC,CAAG;AAAA,SACnCO,EAAuBV,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAErE,SAAOC;AACR;AAEO,SAASM,EAAoBX,GAAqBC,GAAeC,GAAgBK,GAAa;AACpG,MAAIH,GACAC;AACJ;AACC,IAAAD,IAAWK,EAAYT,GAAOC,CAAK,GACnCI,IAAW,KAAK,IAAID,IAAWF,GAAQK,CAAG;AAAA,SACnCG,EAAuBV,GAAOC,GAAOG,GAAUC,CAAQ,MAAMD;AAErE,SAAOC;AACR;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const f = new ArrayBuffer(4), c = new Float32Array(f), i = new Int32Array(f);
|
|
2
|
+
function s(n, e) {
|
|
3
|
+
return n instanceof Float32Array && (n = new Int32Array(n.buffer, n.byteOffset, n.length)), t(Atomics.load(n, e));
|
|
4
|
+
}
|
|
5
|
+
function u(n, e, r) {
|
|
6
|
+
n instanceof Float32Array && (n = new Int32Array(n.buffer, n.byteOffset, n.length)), Atomics.store(n, e, o(r));
|
|
7
|
+
}
|
|
8
|
+
function t(n) {
|
|
9
|
+
return i[0] = n, c[0];
|
|
10
|
+
}
|
|
11
|
+
function o(n) {
|
|
12
|
+
return c[0] = n, i[0];
|
|
13
|
+
}
|
|
14
|
+
function y(n, e, r) {
|
|
15
|
+
return n instanceof Float32Array && (n = new Int32Array(n.buffer, n.byteOffset, n.length)), t(Atomics.exchange(n, e, o(r)));
|
|
16
|
+
}
|
|
17
|
+
function A(n, e, r, l) {
|
|
18
|
+
return n instanceof Float32Array && (n = new Int32Array(n.buffer, n.byteOffset, n.length)), t(Atomics.compareExchange(n, e, o(r), o(l)));
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
A as compareExchangeFloat32,
|
|
22
|
+
o as convertFloat32ToInt32,
|
|
23
|
+
t as convertInt32ToFloat32,
|
|
24
|
+
y as exchangeFloat32,
|
|
25
|
+
s as loadFloat32,
|
|
26
|
+
u as storeFloat32
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=float32-atomics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"float32-atomics.js","sources":["../../src/utils/float32-atomics.ts"],"sourcesContent":["// For doing Atomic operations on floats in SharedArrayBuffers\nconst buffer = new ArrayBuffer(4);\nconst float32 = new Float32Array(buffer);\nconst int32 = new Int32Array(buffer);\n\nexport function loadFloat32(data: Int32Array | Uint32Array | Float32Array, index: number) {\n\tif(data instanceof Float32Array) {\n\t\tdata = new Int32Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\treturn convertInt32ToFloat32(Atomics.load(data, index));\n}\nexport function storeFloat32(data: Int32Array | Uint32Array | Float32Array, index: number, value: number) {\n\tif(data instanceof Float32Array) {\n\t\tdata = new Int32Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\tAtomics.store(data, index, convertFloat32ToInt32(value));\n}\n\nexport function convertInt32ToFloat32(value: number) {\n\tint32[0] = value;\n\n\treturn float32[0];\n}\nexport function convertFloat32ToInt32(value: number) {\n\tfloat32[0] = value;\n\n\treturn int32[0];\n}\n\nexport function exchangeFloat32(data: Int32Array | Uint32Array | Float32Array, index: number, value: number) {\n\tif(data instanceof Float32Array) {\n\t\tdata = new Int32Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\treturn convertInt32ToFloat32(Atomics.exchange(data, index, convertFloat32ToInt32(value)));\n}\n\nexport function compareExchangeFloat32(data: Int32Array | Uint32Array | Float32Array, index: number, expectedValue: number, replacementValue: number) {\n\tif(data instanceof Float32Array) {\n\t\tdata = new Int32Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\treturn convertInt32ToFloat32(Atomics.compareExchange(data, index, convertFloat32ToInt32(expectedValue), convertFloat32ToInt32(replacementValue)));\n}"],"names":["buffer","float32","int32","loadFloat32","data","index","convertInt32ToFloat32","storeFloat32","value","convertFloat32ToInt32","exchangeFloat32","compareExchangeFloat32","expectedValue","replacementValue"],"mappings":"AACA,MAAMA,IAAS,IAAI,YAAY,CAAC,GAC1BC,IAAU,IAAI,aAAaD,CAAM,GACjCE,IAAQ,IAAI,WAAWF,CAAM;AAE5B,SAASG,EAAYC,GAA+CC,GAAe;AACzF,SAAGD,aAAgB,iBAClBA,IAAO,IAAI,WAAWA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAGzDE,EAAsB,QAAQ,KAAKF,GAAMC,CAAK,CAAC;AACvD;AACO,SAASE,EAAaH,GAA+CC,GAAeG,GAAe;AACzG,EAAGJ,aAAgB,iBAClBA,IAAO,IAAI,WAAWA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAGhE,QAAQ,MAAMA,GAAMC,GAAOI,EAAsBD,CAAK,CAAC;AACxD;AAEO,SAASF,EAAsBE,GAAe;AACpD,SAAAN,EAAM,CAAC,IAAIM,GAEJP,EAAQ,CAAC;AACjB;AACO,SAASQ,EAAsBD,GAAe;AACpD,SAAAP,EAAQ,CAAC,IAAIO,GAENN,EAAM,CAAC;AACf;AAEO,SAASQ,EAAgBN,GAA+CC,GAAeG,GAAe;AAC5G,SAAGJ,aAAgB,iBAClBA,IAAO,IAAI,WAAWA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAGzDE,EAAsB,QAAQ,SAASF,GAAMC,GAAOI,EAAsBD,CAAK,CAAC,CAAC;AACzF;AAEO,SAASG,EAAuBP,GAA+CC,GAAeO,GAAuBC,GAA0B;AACrJ,SAAGT,aAAgB,iBAClBA,IAAO,IAAI,WAAWA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAGzDE,EAAsB,QAAQ,gBAAgBF,GAAMC,GAAOI,EAAsBG,CAAa,GAAGH,EAAsBI,CAAgB,CAAC,CAAC;AACjJ;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const f = new ArrayBuffer(8), c = new Float64Array(f), i = new BigInt64Array(f);
|
|
2
|
+
function s(n, e) {
|
|
3
|
+
return n instanceof Float64Array && (n = new BigInt64Array(n.buffer, n.byteOffset, n.length)), t(Atomics.load(n, e));
|
|
4
|
+
}
|
|
5
|
+
function u(n, e, r) {
|
|
6
|
+
n instanceof Float64Array && (n = new BigInt64Array(n.buffer, n.byteOffset, n.length)), Atomics.store(n, e, o(r));
|
|
7
|
+
}
|
|
8
|
+
function t(n) {
|
|
9
|
+
return i[0] = n, c[0];
|
|
10
|
+
}
|
|
11
|
+
function o(n) {
|
|
12
|
+
return c[0] = n, i[0];
|
|
13
|
+
}
|
|
14
|
+
function y(n, e, r) {
|
|
15
|
+
return n instanceof Float64Array && (n = new BigInt64Array(n.buffer, n.byteOffset, n.length)), t(Atomics.exchange(n, e, o(r)));
|
|
16
|
+
}
|
|
17
|
+
function A(n, e, r, l) {
|
|
18
|
+
return n instanceof Float64Array && (n = new BigInt64Array(n.buffer, n.byteOffset, n.length)), t(Atomics.compareExchange(n, e, o(r), o(l)));
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
A as compareExchangeFloat64,
|
|
22
|
+
o as convertFloat64ToInt64,
|
|
23
|
+
t as convertInt64ToFloat64,
|
|
24
|
+
y as exchangeFloat64,
|
|
25
|
+
s as loadFloat64,
|
|
26
|
+
u as storeFloat64
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=float64-atomics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"float64-atomics.js","sources":["../../src/utils/float64-atomics.ts"],"sourcesContent":["// For doing Atomic operations on floats in SharedArrayBuffers\nconst buffer = new ArrayBuffer(8);\nconst float64 = new Float64Array(buffer);\nconst int64 = new BigInt64Array(buffer);\n\nexport function loadFloat64(data: BigInt64Array | Float64Array, index: number) {\n\tif(data instanceof Float64Array) {\n\t\tdata = new BigInt64Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\treturn convertInt64ToFloat64(Atomics.load(data, index));\n}\nexport function storeFloat64(data: BigInt64Array | Float64Array, index: number, value: number) {\n\tif(data instanceof Float64Array) {\n\t\tdata = new BigInt64Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\tAtomics.store(data, index, convertFloat64ToInt64(value));\n}\n\nexport function convertInt64ToFloat64(value: bigint) {\n\tint64[0] = value;\n\n\treturn float64[0];\n}\nexport function convertFloat64ToInt64(value: number) {\n\tfloat64[0] = value;\n\n\treturn int64[0];\n}\n\nexport function exchangeFloat64(data: BigInt64Array | Float64Array, index: number, value: number) {\n\tif(data instanceof Float64Array) {\n\t\tdata = new BigInt64Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\treturn convertInt64ToFloat64(Atomics.exchange(data, index, convertFloat64ToInt64(value)));\n}\n\nexport function compareExchangeFloat64(data: BigInt64Array | Float64Array, index: number, expectedValue: number, replacementValue: number) {\n\tif(data instanceof Float64Array) {\n\t\tdata = new BigInt64Array(data.buffer, data.byteOffset, data.length);\n\t}\n\n\treturn convertInt64ToFloat64(Atomics.compareExchange(data, index, convertFloat64ToInt64(expectedValue), convertFloat64ToInt64(replacementValue)));\n}"],"names":["buffer","float64","int64","loadFloat64","data","index","convertInt64ToFloat64","storeFloat64","value","convertFloat64ToInt64","exchangeFloat64","compareExchangeFloat64","expectedValue","replacementValue"],"mappings":"AACA,MAAMA,IAAS,IAAI,YAAY,CAAC,GAC1BC,IAAU,IAAI,aAAaD,CAAM,GACjCE,IAAQ,IAAI,cAAcF,CAAM;AAE/B,SAASG,EAAYC,GAAoCC,GAAe;AAC9E,SAAGD,aAAgB,iBAClBA,IAAO,IAAI,cAAcA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAG5DE,EAAsB,QAAQ,KAAKF,GAAMC,CAAK,CAAC;AACvD;AACO,SAASE,EAAaH,GAAoCC,GAAeG,GAAe;AAC9F,EAAGJ,aAAgB,iBAClBA,IAAO,IAAI,cAAcA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAGnE,QAAQ,MAAMA,GAAMC,GAAOI,EAAsBD,CAAK,CAAC;AACxD;AAEO,SAASF,EAAsBE,GAAe;AACpD,SAAAN,EAAM,CAAC,IAAIM,GAEJP,EAAQ,CAAC;AACjB;AACO,SAASQ,EAAsBD,GAAe;AACpD,SAAAP,EAAQ,CAAC,IAAIO,GAENN,EAAM,CAAC;AACf;AAEO,SAASQ,EAAgBN,GAAoCC,GAAeG,GAAe;AACjG,SAAGJ,aAAgB,iBAClBA,IAAO,IAAI,cAAcA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAG5DE,EAAsB,QAAQ,SAASF,GAAMC,GAAOI,EAAsBD,CAAK,CAAC,CAAC;AACzF;AAEO,SAASG,EAAuBP,GAAoCC,GAAeO,GAAuBC,GAA0B;AAC1I,SAAGT,aAAgB,iBAClBA,IAAO,IAAI,cAAcA,EAAK,QAAQA,EAAK,YAAYA,EAAK,MAAM,IAG5DE,EAAsB,QAAQ,gBAAgBF,GAAMC,GAAOI,EAAsBG,CAAa,GAAGH,EAAsBI,CAAgB,CAAC,CAAC;AACjJ;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const _ = 20, I = 12, s = Math.pow(2, 20), a = Math.pow(2, 12);
|
|
2
|
+
function u(t, o = 0) {
|
|
3
|
+
return O(Atomics.load(t, o));
|
|
4
|
+
}
|
|
5
|
+
function f(t, o = 0) {
|
|
6
|
+
return Atomics.load(t, o);
|
|
7
|
+
}
|
|
8
|
+
function N(t, o = 0, n, e) {
|
|
9
|
+
Atomics.store(t, o, r(n, e));
|
|
10
|
+
}
|
|
11
|
+
function P(t, o = 0, n) {
|
|
12
|
+
Atomics.store(t, o, n);
|
|
13
|
+
}
|
|
14
|
+
function B(t, o, n, e, c, i) {
|
|
15
|
+
let T = r(c, i);
|
|
16
|
+
return Atomics.compareExchange(t, o, T, r(n, e)) === T;
|
|
17
|
+
}
|
|
18
|
+
function E(t, o, n, e) {
|
|
19
|
+
return Atomics.compareExchange(t, o, e, n) === e;
|
|
20
|
+
}
|
|
21
|
+
function O(t) {
|
|
22
|
+
return {
|
|
23
|
+
bufferPosition: t & 4095,
|
|
24
|
+
bufferByteOffset: t >>> 12
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function r(t, o) {
|
|
28
|
+
return t + (o << 12);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
_ as BYTE_OFFSET_BIT_COUNT,
|
|
32
|
+
s as MAX_BYTE_OFFSET_LENGTH,
|
|
33
|
+
a as MAX_POSITION_LENGTH,
|
|
34
|
+
I as POSITION_BIT_COUNT,
|
|
35
|
+
r as createPointer,
|
|
36
|
+
O as getPointer,
|
|
37
|
+
u as loadPointer,
|
|
38
|
+
f as loadRawPointer,
|
|
39
|
+
B as replacePointer,
|
|
40
|
+
E as replaceRawPointer,
|
|
41
|
+
N as storePointer,
|
|
42
|
+
P as storeRawPointer
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointer.js","sources":["../../src/utils/pointer.ts"],"sourcesContent":["// bottom 12 bits (4096) for bufferPosition\n// top 20 bits (1MB) for bufferByteOffset\nconst BYTE_OFFSET_BIT_COUNT = 20;\nconst POSITION_BIT_COUNT = 32 - BYTE_OFFSET_BIT_COUNT;\nconst MAX_BYTE_OFFSET_LENGTH = Math.pow(2, BYTE_OFFSET_BIT_COUNT);\nconst MAX_POSITION_LENGTH = Math.pow(2, POSITION_BIT_COUNT);\n\nexport function loadPointer(data: Uint32Array, index: number = 0) {\n\treturn getPointer(Atomics.load(data, index));\n}\nexport function loadRawPointer(data: Uint32Array, index: number = 0) {\n\treturn Atomics.load(data, index);\n}\n\nexport function storePointer(data: Uint32Array, index: number = 0, bufferPosition: number, bufferByteOffset: number) {\n\tAtomics.store(data, index, createPointer(bufferPosition, bufferByteOffset));\n}\nexport function storeRawPointer(data: Uint32Array, index: number = 0, pointer: number) {\n\tAtomics.store(data, index, pointer);\n}\n\nexport function replacePointer(data: Uint32Array, index: number, newBufferPosition: number, newBufferByteOffset: number, oldBufferPosition: number, oldBufferByteOffset: number) {\n\tlet oldPointer = createPointer(oldBufferPosition, oldBufferByteOffset);\n\treturn Atomics.compareExchange(data, index, oldPointer, createPointer(newBufferPosition, newBufferByteOffset)) === oldPointer;\n}\nexport function replaceRawPointer(data: Uint32Array, index: number, newPointer: number, oldPointer: number): boolean {\n\treturn Atomics.compareExchange(data, index, oldPointer, newPointer) === oldPointer;\n}\n\nexport function getPointer(value: number) {\n\treturn {\n\t\tbufferPosition: value & 0b00000000000000000000111111111111,\n\t\tbufferByteOffset: value >>> POSITION_BIT_COUNT\n\t};\n}\nexport function createPointer(bufferPosition: number, bufferByteOffset: number) {\n\treturn bufferPosition + (bufferByteOffset << POSITION_BIT_COUNT);\n}\n\nexport { BYTE_OFFSET_BIT_COUNT, POSITION_BIT_COUNT, MAX_BYTE_OFFSET_LENGTH, MAX_POSITION_LENGTH };"],"names":["BYTE_OFFSET_BIT_COUNT","POSITION_BIT_COUNT","MAX_BYTE_OFFSET_LENGTH","MAX_POSITION_LENGTH","loadPointer","data","index","getPointer","loadRawPointer","storePointer","bufferPosition","bufferByteOffset","createPointer","storeRawPointer","pointer","replacePointer","newBufferPosition","newBufferByteOffset","oldBufferPosition","oldBufferByteOffset","oldPointer","replaceRawPointer","newPointer","value"],"mappings":"AAEA,MAAMA,IAAwB,IACxBC,IAAqB,IACrBC,IAAyB,KAAK,IAAI,GAAG,EAAqB,GAC1DC,IAAsB,KAAK,IAAI,GAAG,EAAkB;AAEnD,SAASC,EAAYC,GAAmBC,IAAgB,GAAG;AACjE,SAAOC,EAAW,QAAQ,KAAKF,GAAMC,CAAK,CAAC;AAC5C;AACO,SAASE,EAAeH,GAAmBC,IAAgB,GAAG;AACpE,SAAO,QAAQ,KAAKD,GAAMC,CAAK;AAChC;AAEO,SAASG,EAAaJ,GAAmBC,IAAgB,GAAGI,GAAwBC,GAA0B;AACpH,UAAQ,MAAMN,GAAMC,GAAOM,EAAcF,GAAgBC,CAAgB,CAAC;AAC3E;AACO,SAASE,EAAgBR,GAAmBC,IAAgB,GAAGQ,GAAiB;AACtF,UAAQ,MAAMT,GAAMC,GAAOQ,CAAO;AACnC;AAEO,SAASC,EAAeV,GAAmBC,GAAeU,GAA2BC,GAA6BC,GAA2BC,GAA6B;AAChL,MAAIC,IAAaR,EAAcM,GAAmBC,CAAmB;AACrE,SAAO,QAAQ,gBAAgBd,GAAMC,GAAOc,GAAYR,EAAcI,GAAmBC,CAAmB,CAAC,MAAMG;AACpH;AACO,SAASC,EAAkBhB,GAAmBC,GAAegB,GAAoBF,GAA6B;AACpH,SAAO,QAAQ,gBAAgBf,GAAMC,GAAOc,GAAYE,CAAU,MAAMF;AACzE;AAEO,SAASb,EAAWgB,GAAe;AACzC,SAAO;AAAA,IACN,gBAAgBA,IAAQ;AAAA,IACxB,kBAAkBA,MAAU;AAAA,EAAA;AAE9B;AACO,SAASX,EAAcF,GAAwBC,GAA0B;AAC/E,SAAOD,KAAkBC,KAAoB;AAC9C;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const A = {
|
|
2
|
+
5120: "i8",
|
|
3
|
+
5121: "u8",
|
|
4
|
+
5122: "i16",
|
|
5
|
+
5123: "u16",
|
|
6
|
+
5124: "i32",
|
|
7
|
+
5125: "u32",
|
|
8
|
+
5126: "f32"
|
|
9
|
+
}, a = {
|
|
10
|
+
f32: Float32Array,
|
|
11
|
+
f64: Float64Array
|
|
12
|
+
}, i = {
|
|
13
|
+
i8: Int8Array,
|
|
14
|
+
i16: Int16Array,
|
|
15
|
+
i32: Int32Array
|
|
16
|
+
}, o = {
|
|
17
|
+
u8: Uint8Array,
|
|
18
|
+
u8c: Uint8ClampedArray,
|
|
19
|
+
u16: Uint16Array,
|
|
20
|
+
u32: Uint32Array
|
|
21
|
+
}, R = {
|
|
22
|
+
i64: BigInt64Array,
|
|
23
|
+
u64: BigUint64Array
|
|
24
|
+
}, c = {
|
|
25
|
+
...a,
|
|
26
|
+
...i,
|
|
27
|
+
...o
|
|
28
|
+
}, y = (r) => {
|
|
29
|
+
const t = A[r];
|
|
30
|
+
return t !== void 0 ? t : r;
|
|
31
|
+
};
|
|
32
|
+
function T(r, ...t) {
|
|
33
|
+
const n = R[r];
|
|
34
|
+
return new (n || c[y(r)])(...t);
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
R as BIGINT_ARRAY_CTORS,
|
|
38
|
+
a as FLOAT_ARRAY_CTORS,
|
|
39
|
+
A as GL2TYPE,
|
|
40
|
+
i as INT_ARRAY_CTORS,
|
|
41
|
+
c as TYPEDARRAY_CTORS,
|
|
42
|
+
o as UINT_ARRAY_CTORS,
|
|
43
|
+
y as asNativeType,
|
|
44
|
+
T as typedArray
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=typedarray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedarray.js","sources":["../../src/utils/typedarray.js"],"sourcesContent":["// Copied from @thi.ng/api/typedarray\n// TODO: rewrite without this but for now just forked in order to add Atomics to base library\n\nvar GLType = /* @__PURE__ */ ((GLType2) => {\n\tGLType2[GLType2['I8'] = 5120] = 'I8';\n\tGLType2[GLType2['U8'] = 5121] = 'U8';\n\tGLType2[GLType2['I16'] = 5122] = 'I16';\n\tGLType2[GLType2['U16'] = 5123] = 'U16';\n\tGLType2[GLType2['I32'] = 5124] = 'I32';\n\tGLType2[GLType2['U32'] = 5125] = 'U32';\n\tGLType2[GLType2['F32'] = 5126] = 'F32';\n\treturn GLType2;\n})(GLType || {});\nconst GL2TYPE = {\n\t[5120 /* I8 */]: 'i8',\n\t[5121 /* U8 */]: 'u8',\n\t[5122 /* I16 */]: 'i16',\n\t[5123 /* U16 */]: 'u16',\n\t[5124 /* I32 */]: 'i32',\n\t[5125 /* U32 */]: 'u32',\n\t[5126 /* F32 */]: 'f32'\n};\nconst TYPE2GL = {\n\ti8: 5120 /* I8 */,\n\tu8: 5121 /* U8 */,\n\tu8c: 5121 /* U8 */,\n\ti16: 5122 /* I16 */,\n\tu16: 5123 /* U16 */,\n\ti32: 5124 /* I32 */,\n\tu32: 5125 /* U32 */,\n\tf32: 5126 /* F32 */,\n\tf64: void 0\n};\nconst SIZEOF = {\n\tu8: 1,\n\tu8c: 1,\n\ti8: 1,\n\tu16: 2,\n\ti16: 2,\n\tu32: 4,\n\ti32: 4,\n\ti64: 8,\n\tu64: 8,\n\tf32: 4,\n\tf64: 8\n};\nconst BIT_SHIFTS = {\n\ti8: 0,\n\tu8: 0,\n\tu8c: 0,\n\ti16: 1,\n\tu16: 1,\n\ti32: 2,\n\tu32: 2,\n\ti64: 3,\n\tu64: 3,\n\tf32: 2,\n\tf64: 3\n};\nconst FLOAT_ARRAY_CTORS = {\n\tf32: Float32Array,\n\tf64: Float64Array\n};\nconst INT_ARRAY_CTORS = {\n\ti8: Int8Array,\n\ti16: Int16Array,\n\ti32: Int32Array\n};\nconst UINT_ARRAY_CTORS = {\n\tu8: Uint8Array,\n\tu8c: Uint8ClampedArray,\n\tu16: Uint16Array,\n\tu32: Uint32Array\n};\nconst BIGINT_ARRAY_CTORS = {\n\ti64: BigInt64Array,\n\tu64: BigUint64Array\n};\nconst TYPEDARRAY_CTORS = {\n\t...FLOAT_ARRAY_CTORS,\n\t...INT_ARRAY_CTORS,\n\t...UINT_ARRAY_CTORS\n};\nconst asNativeType = (type) => {\n\tconst t = GL2TYPE[type];\n\treturn t !== void 0 ? t : type;\n};\nconst asGLType = (type) => {\n\tconst t = TYPE2GL[type];\n\treturn t !== void 0 ? t : type;\n};\nconst asInt = (...args) => args.map((x) => x | 0);\nconst sizeOf = (type) => SIZEOF[type] || SIZEOF[asNativeType(type)];\nfunction typedArray(type, ...xs) {\n\tconst ctor = BIGINT_ARRAY_CTORS[type];\n\treturn new (ctor || TYPEDARRAY_CTORS[asNativeType(type)])(...xs);\n}\nfunction typedArrayOfVec(type, data, stride) {\n\tconst $data = Array.isArray(data) ? data : [...data];\n\tif(stride === void 0)\n\t\tstride = $data[0].length;\n\tconst num = $data.length;\n\tconst res = typedArray(type, num * stride);\n\tfor(let i = 0, j = 0; i < num; i++, j += stride) {\n\t\tres.set($data[i], j);\n\t}\n\treturn res;\n}\nconst typedArrayType = (x) => {\n\tif(Array.isArray(x))\n\t\treturn 'f64';\n\tfor(let id in TYPEDARRAY_CTORS) {\n\t\tif(x instanceof TYPEDARRAY_CTORS[id])\n\t\t\treturn id;\n\t}\n\treturn 'f64';\n};\nconst uintTypeForSize = (x) => x <= 256 ? 'u8' : x <= 65536 ? 'u16' : 'u32';\nconst intTypeForSize = (x) => x >= -128 && x < 128 ? 'i8' : x >= -32768 && x < 32768 ? 'i16' : 'i32';\nconst uintTypeForBits = (x) => x > 16 ? 'u32' : x > 8 ? 'u16' : 'u8';\nconst intTypeForBits = (x) => x > 16 ? 'i32' : x > 8 ? 'i16' : 'i8';\nconst narrowInt = (t) => t === 'i64' ? 'i32' : t === 'i32' ? 'i16' : t === 'i16' ? 'i8' : 'i8';\nconst widenInt = (t) => t === 'i8' ? 'i16' : t === 'i16' ? 'i32' : t === 'i32' ? 'i64' : 'i64';\nconst narrowUint = (t) => t === 'u64' ? 'u32' : t === 'u32' ? 'u16' : t === 'u16' ? 'u8' : 'u8';\nconst widenUint = (t) => t === 'u8' || t === 'u8c' ? 'u16' : t === 'u16' ? 'u32' : t === 'u32' ? 'u64' : 'u64';\nconst narrowFloat = (t) => t === 'f64' ? 'f32' : 'f32';\nconst widenFloat = (t) => t === 'f32' ? 'f64' : 'f64';\nconst narrowType = (t) => t[0] === 'i' ? narrowInt(t) : t[0] === 'u' ? narrowUint(t) : narrowFloat(t);\nconst widenType = (t) => t[0] === 'i' ? widenInt(t) : t[0] === 'u' ? widenUint(t) : widenFloat(t);\nexport {\n\tBIGINT_ARRAY_CTORS,\n\tBIT_SHIFTS,\n\tFLOAT_ARRAY_CTORS,\n\tGL2TYPE,\n\tGLType,\n\tINT_ARRAY_CTORS,\n\tSIZEOF,\n\tTYPE2GL,\n\tTYPEDARRAY_CTORS,\n\tUINT_ARRAY_CTORS,\n\tasGLType,\n\tasInt,\n\tasNativeType,\n\tintTypeForBits,\n\tintTypeForSize,\n\tnarrowFloat,\n\tnarrowInt,\n\tnarrowType,\n\tnarrowUint,\n\tsizeOf,\n\ttypedArray,\n\ttypedArrayOfVec,\n\ttypedArrayType,\n\tuintTypeForBits,\n\tuintTypeForSize,\n\twidenFloat,\n\twidenInt,\n\twidenType,\n\twidenUint\n};\n"],"names":["GL2TYPE","FLOAT_ARRAY_CTORS","INT_ARRAY_CTORS","UINT_ARRAY_CTORS","BIGINT_ARRAY_CTORS","TYPEDARRAY_CTORS","asNativeType","type","typedArray","xs","ctor"],"mappings":"AAaK,MAACA,IAAU;AAAA,EACd,MAAgB;AAAA,EAChB,MAAgB;AAAA,EAChB,MAAiB;AAAA,EACjB,MAAiB;AAAA,EACjB,MAAiB;AAAA,EACjB,MAAiB;AAAA,EACjB,MAAiB;AACnB,GAsCMC,IAAoB;AAAA,EACzB,KAAK;AAAA,EACL,KAAK;AACN,GACMC,IAAkB;AAAA,EACvB,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AACN,GACMC,IAAmB;AAAA,EACxB,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN,GACMC,IAAqB;AAAA,EAC1B,KAAK;AAAA,EACL,KAAK;AACN,GACMC,IAAmB;AAAA,EACxB,GAAGJ;AAAA,EACH,GAAGC;AAAA,EACH,GAAGC;AACJ,GACMG,IAAe,CAACC,MAAS;AAC9B,QAAM,IAAIP,EAAQO,CAAI;AACtB,SAAO,MAAM,SAAS,IAAIA;AAC3B;AAOA,SAASC,EAAWD,MAASE,GAAI;AAChC,QAAMC,IAAON,EAAmBG,CAAI;AACpC,SAAO,KAAKG,KAAQL,EAAiBC,EAAaC,CAAI,CAAC,GAAG,GAAGE,CAAE;AAChE;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daneren2005/shared-memory-objects",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"author": "daneren2005@gmail.com",
|
|
5
5
|
"description": "Creating objects with a SharedArrayBuffer",
|
|
6
6
|
"homepage": "https://github.com/daneren2005/shared-memory-objects#readme",
|
|
@@ -16,30 +16,25 @@
|
|
|
16
16
|
"url": "https://github.com/daneren2005/shared-memory-objects/issues"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
19
20
|
"files": [
|
|
20
21
|
"dist/"
|
|
21
22
|
],
|
|
22
|
-
"main": "./dist/shared-memory-objects.js",
|
|
23
23
|
"exports": {
|
|
24
|
-
"
|
|
24
|
+
"./*": {
|
|
25
25
|
"import": {
|
|
26
|
-
"types": "./dist/src
|
|
27
|
-
"default": "./dist
|
|
28
|
-
},
|
|
29
|
-
"require": {
|
|
30
|
-
"types": "./dist/src/main.d.ts",
|
|
31
|
-
"default": "./dist/shared-memory-objects.js"
|
|
26
|
+
"types": "./dist/src/*.d.ts",
|
|
27
|
+
"default": "./dist/*.js"
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
},
|
|
35
|
-
"types": "./dist/src/main.d.ts",
|
|
36
31
|
"scripts": {
|
|
37
32
|
"build": "vite build",
|
|
38
33
|
"dev": "vite",
|
|
39
34
|
"lint": "eslint",
|
|
40
35
|
"lint:fix": "eslint --fix",
|
|
41
36
|
"preview": "vite preview",
|
|
42
|
-
"publish": "npm publish --access public",
|
|
37
|
+
"publish:manual": "npm publish --access public",
|
|
43
38
|
"release": "semantic-release",
|
|
44
39
|
"start": "npm run dev",
|
|
45
40
|
"test:bench": "vitest bench",
|