@daneren2005/shared-memory-objects 0.0.7 → 0.0.8
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daneren2005/shared-memory-objects",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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",
|
|
@@ -3,22 +3,24 @@ const buffer = new ArrayBuffer(4);
|
|
|
3
3
|
const float32 = new Float32Array(buffer);
|
|
4
4
|
const int32 = new Int32Array(buffer);
|
|
5
5
|
|
|
6
|
-
function loadFloat32(data: Int32Array, index: number) {
|
|
6
|
+
export function loadFloat32(data: Int32Array | Uint32Array, index: number) {
|
|
7
7
|
return convertInt32ToFloat32(Atomics.load(data, index));
|
|
8
8
|
}
|
|
9
|
-
function storeFloat32(data: Int32Array, index: number, value: number) {
|
|
9
|
+
export function storeFloat32(data: Int32Array | Uint32Array, index: number, value: number) {
|
|
10
10
|
Atomics.store(data, index, convertFloat32ToInt32(value));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function convertInt32ToFloat32(value: number) {
|
|
13
|
+
export function convertInt32ToFloat32(value: number) {
|
|
14
14
|
int32[0] = value;
|
|
15
15
|
|
|
16
16
|
return float32[0];
|
|
17
17
|
}
|
|
18
|
-
function convertFloat32ToInt32(value: number) {
|
|
18
|
+
export function convertFloat32ToInt32(value: number) {
|
|
19
19
|
float32[0] = value;
|
|
20
20
|
|
|
21
21
|
return int32[0];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export
|
|
24
|
+
export function exchangeFloat32(data: Int32Array | Uint32Array, index: number, value: number) {
|
|
25
|
+
return convertInt32ToFloat32(Atomics.exchange(data, index, convertFloat32ToInt32(value)));
|
|
26
|
+
}
|