@daneren2005/shared-memory-objects 1.6.2 → 1.6.3

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.
Files changed (45) hide show
  1. package/dist/allocated-memory.js +1 -2
  2. package/dist/cached-item-list.js +1 -2
  3. package/dist/constant-string.js +13 -14
  4. package/dist/local-pool.js +5 -6
  5. package/dist/lock/read-write-lock.js +0 -1
  6. package/dist/lock/simple-lock.js +0 -1
  7. package/dist/memory-buffer.js +1 -2
  8. package/dist/memory-heap.js +24 -25
  9. package/dist/serialize-object.js +4 -5
  10. package/dist/shared-list.js +43 -44
  11. package/dist/shared-map.js +74 -75
  12. package/dist/shared-pointer-list.js +15 -16
  13. package/dist/shared-pool.d.ts +1 -0
  14. package/dist/shared-pool.js +36 -32
  15. package/dist/shared-pool.js.map +1 -1
  16. package/dist/shared-stack.js +33 -34
  17. package/dist/shared-string.js +19 -20
  18. package/dist/shared-vector.js +23 -24
  19. package/dist/spatial/shared-quadtree.js +81 -82
  20. package/dist/spatial/shared-quadtree.js.map +1 -1
  21. package/dist/spatial/shared-spatial-grid.js +104 -110
  22. package/dist/spatial/shared-spatial-grid.js.map +1 -1
  23. package/dist/spatial/shared-spatial-map.js +189 -190
  24. package/dist/spatial/shared-spatial-map.js.map +1 -1
  25. package/dist/spatial/spatial-entity.js +1 -2
  26. package/dist/spatial/spatial-neighbors.js +1 -2
  27. package/dist/utils/16-from-32-array.js +1 -2
  28. package/dist/utils/16-from-32-float.js +1 -2
  29. package/dist/utils/16-from-32-int.js +1 -2
  30. package/dist/utils/16-from-32-uint.js +1 -2
  31. package/dist/utils/16-from-64-array.js +1 -2
  32. package/dist/utils/16-from-64-float.js +1 -2
  33. package/dist/utils/16-from-64-int.js +1 -2
  34. package/dist/utils/16-from-64-uint.js +1 -2
  35. package/dist/utils/32-from-64-float.js +1 -2
  36. package/dist/utils/32-from-64-int.js +1 -2
  37. package/dist/utils/32-from-64-uint.js +1 -2
  38. package/dist/utils/array-type.js +1 -2
  39. package/dist/utils/atomic-math.js +1 -2
  40. package/dist/utils/float32-atomics.js +1 -2
  41. package/dist/utils/float64-atomics.js +1 -2
  42. package/dist/utils/hash.js +1 -2
  43. package/dist/utils/pointer.js +1 -2
  44. package/dist/utils/typedarray.js +1 -2
  45. package/package.json +11 -11
@@ -1,8 +1,8 @@
1
- import { getPointer as e, storePointer as t } from "./utils/pointer.js";
2
- import n from "./allocated-memory.js";
3
- import { getArrayTypeCode as r, getByteMultipler as i, makeArrayView as a } from "./utils/array-type.js";
4
- import { lock as o, unlock as s } from "./lock/simple-lock.js";
5
- //#region src/shared-stack.ts
1
+ import e from "./allocated-memory.js";
2
+ import { lock as t, unlock as n } from "./lock/simple-lock.js";
3
+ import { getPointer as r, storePointer as i } from "./utils/pointer.js";
4
+ import { getArrayTypeCode as a, getByteMultipler as o, makeArrayView as s } from "./utils/array-type.js";
5
+ // src/shared-stack.ts
6
6
  var c = 0, l = 1, u = 2, d = 3, f = 4, p = 5, m = 6, h = 7, g = 4, _ = 20, v = 22, y = (1 << v) - 1, b = 4194302, x = 1 << v, S = class v {
7
7
  static BASE_ALLOCATE_COUNT = 8;
8
8
  static DEFAULT_ALLOCATE_COUNT = this.BASE_ALLOCATE_COUNT + _;
@@ -75,28 +75,28 @@ var c = 0, l = 1, u = 2, d = 3, f = 4, p = 5, m = 6, h = 7, g = 4, _ = 20, v = 2
75
75
  }
76
76
  get usedMemory() {
77
77
  let t = this.ownsFirstBlock ? this.firstBlock.usedMemory : 0;
78
- for (let r = 0; r < this.segmentCount; r++) {
79
- let i = e(Atomics.load(this.firstBlock.data, h + r), this.memory.positionBits);
80
- t += new n(this.memory, i).usedMemory;
78
+ for (let n = 0; n < this.segmentCount; n++) {
79
+ let i = r(Atomics.load(this.firstBlock.data, h + n), this.memory.positionBits);
80
+ t += new e(this.memory, i).usedMemory;
81
81
  }
82
82
  return t;
83
83
  }
84
- constructor(e, t) {
85
- if (this.memory = e, t && "firstBlock" in t) {
86
- if (t.firstBlock instanceof n) this.firstBlock = t.firstBlock;
84
+ constructor(t, n) {
85
+ if (this.memory = t, n && "firstBlock" in n) {
86
+ if (n.firstBlock instanceof e) this.firstBlock = n.firstBlock;
87
87
  else {
88
- let r = new Uint32Array(e.buffers[t.firstBlock.bufferPosition].buf, t.firstBlock.bufferByteOffset + d * Uint32Array.BYTES_PER_ELEMENT, 1)[0];
89
- this.firstBlock = new n(e, {
88
+ let r = new Uint32Array(t.buffers[n.firstBlock.bufferPosition].buf, n.firstBlock.bufferByteOffset + d * Uint32Array.BYTES_PER_ELEMENT, 1)[0];
89
+ this.firstBlock = new e(t, {
90
90
  length: v.BASE_ALLOCATE_COUNT + r,
91
- ...t.firstBlock
91
+ ...n.firstBlock
92
92
  });
93
93
  }
94
- this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + l * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in t || "baseSegmentLength" in t || "maxLength" in t ? (this.initialize(t), this.ownsFirstBlock = !1) : this.ownsFirstBlock = !0;
94
+ this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + l * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in n || "baseSegmentLength" in n || "maxLength" in n ? (this.initialize(n), this.ownsFirstBlock = !1) : this.ownsFirstBlock = !0;
95
95
  } else {
96
- let n = i(r(t?.type ?? Uint32Array)), a = t?.baseSegmentLength ?? g, o = this.resolveMaxSegmentLength(a, t?.maxSegmentLength, n), s = this.resolveMaxSegments(t?.maxLength, a, o);
97
- this.firstBlock = e.allocUI32(v.BASE_ALLOCATE_COUNT + s), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + l * Uint32Array.BYTES_PER_ELEMENT, 2), this.ownsFirstBlock = !0, this.initialize(t);
96
+ let e = o(a(n?.type ?? Uint32Array)), r = n?.baseSegmentLength ?? g, i = this.resolveMaxSegmentLength(r, n?.maxSegmentLength, e), s = this.resolveMaxSegments(n?.maxLength, r, i);
97
+ this.firstBlock = t.allocUI32(v.BASE_ALLOCATE_COUNT + s), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + l * Uint32Array.BYTES_PER_ELEMENT, 2), this.ownsFirstBlock = !0, this.initialize(n);
98
98
  }
99
- if (this.growLock = new Int32Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + m * Uint32Array.BYTES_PER_ELEMENT, 1), this.cachedByteMultipler = i(this.type), this.cachedBaseSegmentLength = this.baseSegmentLength, this.cachedMaxSegmentLength = this.maxSegmentLength, this.cachedCapSegmentCount = 32 - Math.clz32(this.cachedMaxSegmentLength / this.cachedBaseSegmentLength | 0), this.cachedGeometricCapacity = this.cachedBaseSegmentLength * ((1 << this.cachedCapSegmentCount) - 1), this.maxLength = v.getCapacity(this.maxSegments, this.cachedBaseSegmentLength, this.cachedMaxSegmentLength), this.maxLength > b) throw Error(`SharedStack maxLength ${this.maxLength} exceeds the ${b} the versioned length counter can address`);
99
+ if (this.growLock = new Int32Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + m * Uint32Array.BYTES_PER_ELEMENT, 1), this.cachedByteMultipler = o(this.type), this.cachedBaseSegmentLength = this.baseSegmentLength, this.cachedMaxSegmentLength = this.maxSegmentLength, this.cachedCapSegmentCount = 32 - Math.clz32(this.cachedMaxSegmentLength / this.cachedBaseSegmentLength | 0), this.cachedGeometricCapacity = this.cachedBaseSegmentLength * ((1 << this.cachedCapSegmentCount) - 1), this.maxLength = v.getCapacity(this.maxSegments, this.cachedBaseSegmentLength, this.cachedMaxSegmentLength), this.maxLength > b) throw Error(`SharedStack maxLength ${this.maxLength} exceeds the ${b} the versioned length counter can address`);
100
100
  }
101
101
  resolveMaxSegmentLength(e, t, n = 1) {
102
102
  let r = v.getMaxSegmentLength(this.memory.maxAllocationLength, e, n);
@@ -112,8 +112,8 @@ var c = 0, l = 1, u = 2, d = 3, f = 4, p = 5, m = 6, h = 7, g = 4, _ = 20, v = 2
112
112
  return Math.min(r, i);
113
113
  }
114
114
  initialize(e) {
115
- let n = r(e?.type ?? Uint32Array), a = i(n), o = e?.baseSegmentLength ?? g, s = this.resolveMaxSegmentLength(o, e?.maxSegmentLength, a), c = this.memory.allocUI32(o * (a + 1));
116
- t(this.firstBlock.data, h, c.bufferPosition, c.bufferByteOffset, this.memory.positionBits), this.baseSegmentLength = o, this.maxSegmentLength = s, this.maxSegments = this.resolveMaxSegments(e?.maxLength, o, s), this.segmentCount = 1, this.type = n;
115
+ let t = a(e?.type ?? Uint32Array), n = o(t), r = e?.baseSegmentLength ?? g, s = this.resolveMaxSegmentLength(r, e?.maxSegmentLength, n), c = this.memory.allocUI32(r * (n + 1));
116
+ i(this.firstBlock.data, h, c.bufferPosition, c.bufferByteOffset, this.memory.positionBits), this.baseSegmentLength = r, this.maxSegmentLength = s, this.maxSegments = this.resolveMaxSegments(e?.maxLength, r, s), this.segmentCount = 1, this.type = t;
117
117
  }
118
118
  at(e) {
119
119
  let t = this.length;
@@ -184,28 +184,28 @@ var c = 0, l = 1, u = 2, d = 3, f = 4, p = 5, m = 6, h = 7, g = 4, _ = 20, v = 2
184
184
  let e = this.length, t = this.cachedMaxSegmentLength, n = this.baseSegmentLength, r = 0, i = this.getSegment(r), a = 0;
185
185
  for (let o = 0; o < e; o++) yield i[a], a++, a >= n && (r++, i = this.getSegment(r), a = 0, n = Math.min(n * 2, t));
186
186
  }
187
- getSegment(r) {
188
- if (this.cachedSegments[r]) return this.cachedSegments[r];
189
- let i = r < this.cachedCapSegmentCount ? this.cachedBaseSegmentLength << r : this.cachedMaxSegmentLength, c;
190
- if (r >= this.segmentCount) {
191
- o(this.growLock);
187
+ getSegment(a) {
188
+ if (this.cachedSegments[a]) return this.cachedSegments[a];
189
+ let o = a < this.cachedCapSegmentCount ? this.cachedBaseSegmentLength << a : this.cachedMaxSegmentLength, c;
190
+ if (a >= this.segmentCount) {
191
+ t(this.growLock);
192
192
  try {
193
- r >= this.segmentCount && (c = this.memory.allocUI32(i * (this.cachedByteMultipler + 1)), t(this.firstBlock.data, h + r, c.bufferPosition, c.bufferByteOffset, this.memory.positionBits), Atomics.add(this.firstBlock.data, p, 1));
193
+ a >= this.segmentCount && (c = this.memory.allocUI32(o * (this.cachedByteMultipler + 1)), i(this.firstBlock.data, h + a, c.bufferPosition, c.bufferByteOffset, this.memory.positionBits), Atomics.add(this.firstBlock.data, p, 1));
194
194
  } finally {
195
- s(this.growLock);
195
+ n(this.growLock);
196
196
  }
197
197
  }
198
198
  if (!c) {
199
- let t = Atomics.load(this.firstBlock.data, h + r), i = e(t, this.memory.positionBits);
200
- c = new n(this.memory, i);
199
+ let t = Atomics.load(this.firstBlock.data, h + a), n = r(t, this.memory.positionBits);
200
+ c = new e(this.memory, n);
201
201
  }
202
- let l = a(this.type, c.data.buffer, c.bufferByteOffset, i), u = c.bufferByteOffset + i * this.cachedByteMultipler * Uint32Array.BYTES_PER_ELEMENT;
203
- return this.cachedSequences[r] = new Int32Array(c.data.buffer, u, i), this.cachedSegments[r] = l, l;
202
+ let l = s(this.type, c.data.buffer, c.bufferByteOffset, o), u = c.bufferByteOffset + o * this.cachedByteMultipler * Uint32Array.BYTES_PER_ELEMENT;
203
+ return this.cachedSequences[a] = new Int32Array(c.data.buffer, u, o), this.cachedSegments[a] = l, l;
204
204
  }
205
205
  free() {
206
206
  for (let t = 0; t < this.segmentCount; t++) {
207
- let r = Atomics.load(this.firstBlock.data, h + t), i = e(r, this.memory.positionBits);
208
- new n(this.memory, i).free();
207
+ let n = Atomics.load(this.firstBlock.data, h + t), i = r(n, this.memory.positionBits);
208
+ new e(this.memory, i).free();
209
209
  }
210
210
  this.ownsFirstBlock && this.firstBlock.free();
211
211
  }
@@ -213,7 +213,6 @@ var c = 0, l = 1, u = 2, d = 3, f = 4, p = 5, m = 6, h = 7, g = 4, _ = 20, v = 2
213
213
  return { firstBlock: this.firstBlock.getSharedMemory() };
214
214
  }
215
215
  };
216
- //#endregion
217
216
  export { S as default };
218
217
 
219
218
  //# sourceMappingURL=shared-stack.js.map
@@ -1,7 +1,7 @@
1
- import { getPointer as e, loadPointer as t, loadRawPointer as n, storeRawPointer as r } from "./utils/pointer.js";
2
- import i from "./allocated-memory.js";
3
- import { lock as a, unlock as o } from "./lock/simple-lock.js";
4
- //#region src/shared-string.ts
1
+ import e from "./allocated-memory.js";
2
+ import { lock as t, unlock as n } from "./lock/simple-lock.js";
3
+ import { getPointer as r, loadPointer as i, loadRawPointer as a, storeRawPointer as o } from "./utils/pointer.js";
4
+ // src/shared-string.ts
5
5
  var s = {
6
6
  1: Uint8Array,
7
7
  2: Uint16Array
@@ -12,12 +12,12 @@ var s = {
12
12
  lock;
13
13
  cachedPointer;
14
14
  cachedString;
15
- constructor(e, t) {
16
- this.memory = e, typeof t == "string" ? (this.allocatedMemory = this.memory.allocUI32(f.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + d * this.allocatedMemory.data.BYTES_PER_ELEMENT), this.updateString(t)) : (this.allocatedMemory = new i(e, t), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + d * this.allocatedMemory.data.BYTES_PER_ELEMENT), "value" in t && this.updateString(t.value));
15
+ constructor(t, n) {
16
+ this.memory = t, typeof n == "string" ? (this.allocatedMemory = this.memory.allocUI32(f.ALLOCATE_COUNT), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + d * this.allocatedMemory.data.BYTES_PER_ELEMENT), this.updateString(n)) : (this.allocatedMemory = new e(t, n), this.lock = new Int32Array(this.allocatedMemory.data.buffer, this.allocatedMemory.bufferByteOffset + d * this.allocatedMemory.data.BYTES_PER_ELEMENT), "value" in n && this.updateString(n.value));
17
17
  }
18
18
  updateString(e) {
19
- let t = this.createString(e);
20
- a(this.lock), r(this.allocatedMemory.data, c, t.pointer), Atomics.store(this.allocatedMemory.data, l, e.length), Atomics.store(this.allocatedMemory.data, u, t.charType), o(this.lock), this.cachedPointer = t.pointer, this.cachedString = e;
19
+ let r = this.createString(e);
20
+ t(this.lock), o(this.allocatedMemory.data, c, r.pointer), Atomics.store(this.allocatedMemory.data, l, e.length), Atomics.store(this.allocatedMemory.data, u, r.charType), n(this.lock), this.cachedPointer = r.pointer, this.cachedString = e;
21
21
  }
22
22
  createString(e) {
23
23
  if (e === "") return {
@@ -37,17 +37,17 @@ var s = {
37
37
  };
38
38
  }
39
39
  get value() {
40
- let t = n(this.allocatedMemory.data, c);
41
- if (this.cachedPointer === t && this.cachedString !== void 0) return this.cachedString;
42
- if (t === 0) return "";
43
- let { bufferPosition: r, bufferByteOffset: i } = e(t, this.memory.positionBits);
44
- a(this.lock);
45
- let d = s[Atomics.load(this.allocatedMemory.data, u)], f = Atomics.load(this.allocatedMemory.data, l), m = p(new d(this.memory.buffers[r].buf, i, f));
46
- return o(this.lock), this.cachedPointer = t, this.cachedString = m, m;
40
+ let e = a(this.allocatedMemory.data, c);
41
+ if (this.cachedPointer === e && this.cachedString !== void 0) return this.cachedString;
42
+ if (e === 0) return "";
43
+ let { bufferPosition: i, bufferByteOffset: o } = r(e, this.memory.positionBits);
44
+ t(this.lock);
45
+ let d = s[Atomics.load(this.allocatedMemory.data, u)], f = Atomics.load(this.allocatedMemory.data, l), m = p(new d(this.memory.buffers[i].buf, o, f));
46
+ return n(this.lock), this.cachedPointer = e, this.cachedString = m, m;
47
47
  }
48
48
  set value(e) {
49
- let { bufferPosition: n, bufferByteOffset: r } = t(this.allocatedMemory.data, c, this.memory.positionBits);
50
- this.updateString(e), r && this.memory.buffers[n].free(r);
49
+ let { bufferPosition: t, bufferByteOffset: n } = i(this.allocatedMemory.data, c, this.memory.positionBits);
50
+ this.updateString(e), n && this.memory.buffers[t].free(n);
51
51
  }
52
52
  getSharedMemory() {
53
53
  return this.allocatedMemory.getSharedMemory();
@@ -56,8 +56,8 @@ var s = {
56
56
  return this.allocatedMemory.pointer;
57
57
  }
58
58
  free() {
59
- let { bufferPosition: e, bufferByteOffset: n } = t(this.allocatedMemory.data, c, this.memory.positionBits);
60
- n && this.memory.buffers[e].free(n), this.allocatedMemory.free();
59
+ let { bufferPosition: e, bufferByteOffset: t } = i(this.allocatedMemory.data, c, this.memory.positionBits);
60
+ t && this.memory.buffers[e].free(t), this.allocatedMemory.free();
61
61
  }
62
62
  };
63
63
  function p(e) {
@@ -67,7 +67,6 @@ function p(e) {
67
67
  for (let r = 0; r < e.length; r += t) n += String.fromCharCode.apply(null, e.subarray(r, r + t));
68
68
  return n;
69
69
  }
70
- //#endregion
71
70
  export { f as default };
72
71
 
73
72
  //# sourceMappingURL=shared-string.js.map
@@ -1,7 +1,7 @@
1
- import { getPointer as e, loadPointer as t, storePointer as n, storeRawPointer as r } from "./utils/pointer.js";
2
- import i from "./allocated-memory.js";
1
+ import e from "./allocated-memory.js";
2
+ import { getPointer as t, loadPointer as n, storePointer as r, storeRawPointer as i } from "./utils/pointer.js";
3
3
  import { getArrayTypeCode as a, getByteMultipler as o, makeArrayView as s } from "./utils/array-type.js";
4
- //#region src/shared-vector.ts
4
+ // src/shared-vector.ts
5
5
  var c = 0, l = 1, u = 2, d = 3, f = 4, p = class p {
6
6
  static ALLOCATE_COUNT = 4;
7
7
  memory;
@@ -36,24 +36,24 @@ var c = 0, l = 1, u = 2, d = 3, f = 4, p = class p {
36
36
  return this.firstBlock.pointer;
37
37
  }
38
38
  get usedMemory() {
39
- let e = new i(this.memory, t(this.firstBlock.data, c, this.memory.positionBits));
40
- return this.firstBlock.usedMemory + e.usedMemory;
39
+ let t = new e(this.memory, n(this.firstBlock.data, c, this.memory.positionBits));
40
+ return this.firstBlock.usedMemory + t.usedMemory;
41
41
  }
42
42
  cachedFullDataBlock;
43
43
  cachedPointer;
44
- constructor(e, t) {
45
- if (this.memory = e, t && "firstBlock" in t) {
46
- if (this.firstBlock = new i(e, {
44
+ constructor(t, n) {
45
+ if (this.memory = t, n && "firstBlock" in n) {
46
+ if (this.firstBlock = new e(t, {
47
47
  length: p.ALLOCATE_COUNT,
48
- ...t.firstBlock
49
- }), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + d * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in t || "dataLength" in t) {
50
- let r = a(t.type ?? Uint32Array), i = o(r), s = t.bufferLength ?? f, l = e.allocUI32(s * (t.dataLength ?? 1) * i);
51
- n(this.firstBlock.data, c, l.bufferPosition, l.bufferByteOffset, e.positionBits), this.bufferLength = s, this.dataLength = t.dataLength ?? 1, this.type = r;
48
+ ...n.firstBlock
49
+ }), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + d * Uint32Array.BYTES_PER_ELEMENT, 2), "type" in n || "dataLength" in n) {
50
+ let e = a(n.type ?? Uint32Array), i = o(e), s = n.bufferLength ?? f, l = t.allocUI32(s * (n.dataLength ?? 1) * i);
51
+ r(this.firstBlock.data, c, l.bufferPosition, l.bufferByteOffset, t.positionBits), this.bufferLength = s, this.dataLength = n.dataLength ?? 1, this.type = e;
52
52
  }
53
53
  } else {
54
- this.firstBlock = e.allocUI32(p.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + d * Uint32Array.BYTES_PER_ELEMENT, 2);
55
- let r = t?.dataLength ?? 1, i = t?.bufferLength ?? f, s = a(t?.type ?? Uint32Array), l = e.allocUI32(i * r * o(s));
56
- n(this.firstBlock.data, c, l.bufferPosition, l.bufferByteOffset, e.positionBits), this.bufferLength = i, this.type = s, this.dataLength = r;
54
+ this.firstBlock = t.allocUI32(p.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + d * Uint32Array.BYTES_PER_ELEMENT, 2);
55
+ let e = n?.dataLength ?? 1, i = n?.bufferLength ?? f, s = a(n?.type ?? Uint32Array), l = t.allocUI32(i * e * o(s));
56
+ r(this.firstBlock.data, c, l.bufferPosition, l.bufferByteOffset, t.positionBits), this.bufferLength = i, this.type = s, this.dataLength = e;
57
57
  }
58
58
  this.cachedByteMultipler = o(this.type), this.cachedPointer = this.firstBlock.data[0], this.cachedFullDataBlock = this.getFullDataBlock();
59
59
  }
@@ -102,30 +102,29 @@ var c = 0, l = 1, u = 2, d = 3, f = 4, p = class p {
102
102
  return this.getFullDataBlock().subarray(0, this.length * this.dataLength);
103
103
  }
104
104
  getFullDataBlock() {
105
- let t = Atomics.load(this.firstBlock.data, c);
106
- if (this.cachedPointer === t && this.cachedFullDataBlock) return this.cachedFullDataBlock;
107
- let n = e(t, this.memory.positionBits), r = new i(this.memory, n), a = s(this.type, r.data.buffer, r.bufferByteOffset, this.dataLength * this.bufferLength);
108
- return this.cachedPointer = t, this.cachedFullDataBlock = a, a;
105
+ let n = Atomics.load(this.firstBlock.data, c);
106
+ if (this.cachedPointer === n && this.cachedFullDataBlock) return this.cachedFullDataBlock;
107
+ let r = t(n, this.memory.positionBits), i = new e(this.memory, r), a = s(this.type, i.data.buffer, i.bufferByteOffset, this.dataLength * this.bufferLength);
108
+ return this.cachedPointer = n, this.cachedFullDataBlock = a, a;
109
109
  }
110
110
  getDataBlock(e, t) {
111
111
  let n = t * this.dataLength;
112
112
  return e.subarray(n, n + this.dataLength);
113
113
  }
114
114
  growBuffer() {
115
- let e = this.bufferLength * 2, n = this.dataLength, a = t(this.firstBlock.data, c, this.memory.positionBits), o = new i(this.memory, a), l = this.getFullDataBlock(), u = this.memory.allocUI32(e * n * this.cachedByteMultipler), d = s(this.type, u.data.buffer, u.bufferByteOffset, n * e);
115
+ let t = this.bufferLength * 2, r = this.dataLength, a = n(this.firstBlock.data, c, this.memory.positionBits), o = new e(this.memory, a), l = this.getFullDataBlock(), u = this.memory.allocUI32(t * r * this.cachedByteMultipler), d = s(this.type, u.data.buffer, u.bufferByteOffset, r * t);
116
116
  d.set(l);
117
117
  let f = u.pointer;
118
- r(this.firstBlock.data, c, f), this.bufferLength = e, o.free(), this.cachedPointer = f, this.cachedFullDataBlock = d;
118
+ i(this.firstBlock.data, c, f), this.bufferLength = t, o.free(), this.cachedPointer = f, this.cachedFullDataBlock = d;
119
119
  }
120
120
  free() {
121
- let e = t(this.firstBlock.data, c, this.memory.positionBits);
122
- new i(this.memory, e).free(), this.firstBlock.free();
121
+ let t = n(this.firstBlock.data, c, this.memory.positionBits);
122
+ new e(this.memory, t).free(), this.firstBlock.free();
123
123
  }
124
124
  getSharedMemory() {
125
125
  return { firstBlock: this.firstBlock.getSharedMemory() };
126
126
  }
127
127
  };
128
- //#endregion
129
128
  export { p as default };
130
129
 
131
130
  //# sourceMappingURL=shared-vector.js.map
@@ -1,13 +1,13 @@
1
- import { getPointer as e, loadRawPointer as t, storeRawPointer as n } from "../utils/pointer.js";
2
- import r from "../allocated-memory.js";
3
- import { ARRAY_TYPE as i, getArrayTypeCode as a, getByteMultipler as o, makeArrayView as s } from "../utils/array-type.js";
4
- import { lock as c, unlock as l } from "../lock/simple-lock.js";
5
- import u from "../shared-map.js";
6
- import d from "../shared-pool.js";
1
+ import e from "../allocated-memory.js";
2
+ import t from "../shared-pool.js";
3
+ import n from "../shared-map.js";
4
+ import { lock as r, unlock as i } from "../lock/simple-lock.js";
5
+ import { getPointer as a, loadRawPointer as o, storeRawPointer as s } from "../utils/pointer.js";
6
+ import { ARRAY_TYPE as c, getArrayTypeCode as l, getByteMultipler as u, makeArrayView as d } from "../utils/array-type.js";
7
7
  import { MinPriorityQueue as f, addCandidate as p, candidateLimit as m, distanceSquaredToRect as h } from "./spatial-neighbors.js";
8
8
  import { getSpatialMapCapacity as g, getSpatialPoolChunkSize as _ } from "./spatial-entity.js";
9
- //#region src/spatial/shared-quadtree.ts
10
- var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0, k = 1, A = 2, j = 3, M = 4, N = 5, P = 6, F = 7, I = 16777216, L = I, R = 4294967295, z = 4, B = 1e6, V = Float32Array, H = class a {
9
+ // src/spatial/shared-quadtree.ts
10
+ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0, k = 1, A = 2, j = 3, M = 4, N = 5, P = 6, F = 7, I = 16777216, L = I, R = 4294967295, z = 4, B = 1e6, V = Float32Array, H = class l {
11
11
  static ALLOCATE_COUNT = 14;
12
12
  memory;
13
13
  firstBlock;
@@ -46,42 +46,42 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
46
46
  get type() {
47
47
  return this.coordType;
48
48
  }
49
- constructor(s, c) {
50
- if (this.memory = s, c && "firstBlock" in c) this.firstBlock = new r(s, c.firstBlock), this.coordType = this.firstBlock.data[C], this.pool = new d(s, { firstBlock: e(t(this.firstBlock.data, y), s.positionBits) }), this.idMap = new u(s, { firstBlock: e(t(this.firstBlock.data, b), s.positionBits) }), this.maxLevels = this.firstBlock.data[x], this.nodeCount = this.firstBlock.data[S], this.nullIndex = G(this.coordType);
49
+ constructor(r, i) {
50
+ if (this.memory = r, i && "firstBlock" in i) this.firstBlock = new e(r, i.firstBlock), this.coordType = this.firstBlock.data[C], this.pool = new t(r, { firstBlock: a(o(this.firstBlock.data, y), r.positionBits) }), this.idMap = new n(r, { firstBlock: a(o(this.firstBlock.data, b), r.positionBits) }), this.maxLevels = this.firstBlock.data[x], this.nodeCount = this.firstBlock.data[S], this.nullIndex = G(this.coordType);
51
51
  else {
52
- let e = c?.bounds ?? {
52
+ let e = i?.bounds ?? {
53
53
  x: 0,
54
54
  y: 0,
55
55
  width: 0,
56
56
  height: 0
57
- }, t = c?.maxEntities ?? B;
58
- if (this.maxLevels = c?.maxLevels ?? z, this.nodeCount = a.getNodeCount(this.maxLevels), this.coordType = U(c?.type), this.nullIndex = G(this.coordType), this.coordType === i.float32 && t > I) throw Error(`Float32 SharedQuadtree supports at most ${I} entities; pass type: Float64Array for more`);
59
- let r = {
57
+ }, a = i?.maxEntities ?? B;
58
+ if (this.maxLevels = i?.maxLevels ?? z, this.nodeCount = l.getNodeCount(this.maxLevels), this.coordType = U(i?.type), this.nullIndex = G(this.coordType), this.coordType === c.float32 && a > I) throw Error(`Float32 SharedQuadtree supports at most ${I} entities; pass type: Float64Array for more`);
59
+ let o = {
60
60
  type: W(this.coordType),
61
61
  dataLength: F,
62
- maxLength: t,
63
- maxChunkSize: _(t, F, o(this.coordType), s.maxAllocationLength)
64
- }, l = d.getAllocateCount(s, r), f = u.ALLOCATE_COUNT;
65
- this.firstBlock = s.allocUI32(a.ALLOCATE_COUNT + l + f), this.firstBlock.data[x] = this.maxLevels, this.firstBlock.data[S] = this.nodeCount, this.firstBlock.data[C] = this.coordType;
62
+ maxLength: a,
63
+ maxChunkSize: _(a, F, u(this.coordType), r.maxAllocationLength)
64
+ }, d = t.getAllocateCount(r, o), f = n.ALLOCATE_COUNT;
65
+ this.firstBlock = r.allocUI32(l.ALLOCATE_COUNT + d + f), this.firstBlock.data[x] = this.maxLevels, this.firstBlock.data[S] = this.nodeCount, this.firstBlock.data[C] = this.coordType;
66
66
  let p = this.getBoundsView();
67
67
  p[0] = e.x, p[1] = e.y, p[2] = e.width, p[3] = e.height;
68
- let m = s.allocUI32(this.nodeCount * D), h = new Uint32Array(m.data.buffer, m.bufferByteOffset, this.nodeCount * D);
68
+ let m = r.allocUI32(this.nodeCount * D), h = new Uint32Array(m.data.buffer, m.bufferByteOffset, this.nodeCount * D);
69
69
  for (let e = 0; e < this.nodeCount; e++) h[e * D + E] = this.nullIndex;
70
- n(this.firstBlock.data, v, m.pointer);
71
- let w = this.firstBlock.getSubAllocation(a.ALLOCATE_COUNT, l);
72
- this.pool = new d(s, {
70
+ s(this.firstBlock.data, v, m.pointer);
71
+ let w = this.firstBlock.getSubAllocation(l.ALLOCATE_COUNT, d);
72
+ this.pool = new t(r, {
73
73
  firstBlock: w,
74
- ...r
75
- }), n(this.firstBlock.data, y, w.pointer);
76
- let T = this.firstBlock.getSubAllocation(a.ALLOCATE_COUNT + l, f);
77
- this.idMap = new u(s, {
74
+ ...o
75
+ }), s(this.firstBlock.data, y, w.pointer);
76
+ let T = this.firstBlock.getSubAllocation(l.ALLOCATE_COUNT + d, f);
77
+ this.idMap = new n(r, {
78
78
  firstBlock: T,
79
- capacity: g(t, s.maxAllocationLength)
80
- }), n(this.firstBlock.data, b, T.pointer);
79
+ capacity: g(a, r.maxAllocationLength)
80
+ }), s(this.firstBlock.data, b, T.pointer);
81
81
  }
82
- let l = this.getBoundsView();
83
- this.rootX = l[0], this.rootY = l[1], this.rootWidth = l[2], this.rootHeight = l[3];
84
- let f = new r(s, e(t(this.firstBlock.data, v), s.positionBits));
82
+ let d = this.getBoundsView();
83
+ this.rootX = d[0], this.rootY = d[1], this.rootWidth = d[2], this.rootHeight = d[3];
84
+ let f = new e(r, a(o(this.firstBlock.data, v), r.positionBits));
85
85
  this.nodeInts = new Int32Array(f.data.buffer, f.bufferByteOffset, this.nodeCount * D), this.nodeHeads = new Uint32Array(f.data.buffer, f.bufferByteOffset, this.nodeCount * D);
86
86
  }
87
87
  static getNodeCount(e) {
@@ -91,8 +91,8 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
91
91
  return this.firstBlock.pointer;
92
92
  }
93
93
  get usedMemory() {
94
- let n = new r(this.memory, e(t(this.firstBlock.data, v), this.memory.positionBits));
95
- return this.firstBlock.usedMemory + n.usedMemory + this.pool.usedMemory + this.idMap.usedMemory;
94
+ let t = new e(this.memory, a(o(this.firstBlock.data, v), this.memory.positionBits));
95
+ return this.firstBlock.usedMemory + t.usedMemory + this.pool.usedMemory + this.idMap.usedMemory;
96
96
  }
97
97
  insert(e, t, n, r = 0, i = 0) {
98
98
  if (this.idMap.get(e) !== void 0) {
@@ -119,19 +119,19 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
119
119
  }
120
120
  this.idMap.setAll(i);
121
121
  }
122
- update(e, t, n, r = 0, i = 0) {
123
- let a = this.idMap.get(e);
124
- if (a === void 0) {
125
- this.insert(e, t, n, r, i);
122
+ update(e, t, n, a = 0, o = 0) {
123
+ let s = this.idMap.get(e);
124
+ if (s === void 0) {
125
+ this.insert(e, t, n, a, o);
126
126
  return;
127
127
  }
128
- let o = this.pool.blockFor(a), s = this.pool.blockOffset(a), u = o[s + N], d = this.locate(t, n, r, i);
128
+ let c = this.pool.blockFor(s), l = this.pool.blockOffset(s), u = c[l + N], d = this.locate(t, n, a, o);
129
129
  if (u === d) {
130
- c(this.nodeInts, u * D + T), o[s + k] = t, o[s + A] = n, o[s + j] = r, o[s + M] = i, l(this.nodeInts, u * D + T);
130
+ r(this.nodeInts, u * D + T), c[l + k] = t, c[l + A] = n, c[l + j] = a, c[l + M] = o, i(this.nodeInts, u * D + T);
131
131
  return;
132
132
  }
133
133
  let f = Math.min(u, d), p = Math.max(u, d);
134
- c(this.nodeInts, f * D + T), c(this.nodeInts, p * D + T), this.unlinkNoLock(u, a), o[s + k] = t, o[s + A] = n, o[s + j] = r, o[s + M] = i, o[s + N] = d, this.linkNoLock(d, a), l(this.nodeInts, p * D + T), l(this.nodeInts, f * D + T);
134
+ r(this.nodeInts, f * D + T), r(this.nodeInts, p * D + T), this.unlinkNoLock(u, s), c[l + k] = t, c[l + A] = n, c[l + j] = a, c[l + M] = o, c[l + N] = d, this.linkNoLock(d, s), i(this.nodeInts, p * D + T), i(this.nodeInts, f * D + T);
135
135
  }
136
136
  remove(e) {
137
137
  let t = this.idMap.get(e);
@@ -252,13 +252,13 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
252
252
  for (let t of e) this.idMap.delete(t);
253
253
  }
254
254
  free() {
255
- new r(this.memory, e(t(this.firstBlock.data, v), this.memory.positionBits)).free(), this.pool.free(), this.idMap.free(), this.firstBlock.free();
255
+ new e(this.memory, a(o(this.firstBlock.data, v), this.memory.positionBits)).free(), this.pool.free(), this.idMap.free(), this.firstBlock.free();
256
256
  }
257
257
  getSharedMemory() {
258
258
  return { firstBlock: this.firstBlock.getSharedMemory() };
259
259
  }
260
260
  getBoundsView() {
261
- return s(this.coordType, this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + w * Uint32Array.BYTES_PER_ELEMENT, 4);
261
+ return d(this.coordType, this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + w * Uint32Array.BYTES_PER_ELEMENT, 4);
262
262
  }
263
263
  locate(e, t, n, r) {
264
264
  let i = 0, a = this.rootX, o = this.rootY, s = this.rootWidth, c = this.rootHeight;
@@ -272,52 +272,52 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
272
272
  }
273
273
  return i;
274
274
  }
275
- collect(e, t, n, r, i, a, o, s, u, d, f) {
275
+ collect(e, t, n, a, o, s, c, l, u, d, f) {
276
276
  let p = t * D + E;
277
277
  if (this.nodeHeads[p] !== this.nullIndex) {
278
278
  let n = t * D + T;
279
- c(this.nodeInts, n);
280
- let r = this.nodeHeads[p], i = this.pool;
281
- for (; r !== this.nullIndex;) {
282
- let t = i.blockFor(r), n = i.blockOffset(r);
283
- e.push(t[n + O]), r = t[n + P];
279
+ r(this.nodeInts, n);
280
+ let a = this.nodeHeads[p], o = this.pool;
281
+ for (; a !== this.nullIndex;) {
282
+ let t = o.blockFor(a), n = o.blockOffset(a);
283
+ e.push(t[n + O]), a = t[n + P];
284
284
  }
285
- l(this.nodeInts, n);
285
+ i(this.nodeInts, n);
286
286
  }
287
- if (o >= this.maxLevels) return;
288
- let m = n + i / 2, h = r + a / 2, g = i / 2, _ = a / 2, v = s < m, y = s + d > m, b = u < h, x = u + f > h;
289
- b && v && this.collect(e, t * 4 + 1, n, r, g, _, o + 1, s, u, d, f), b && y && this.collect(e, t * 4 + 2, m, r, g, _, o + 1, s, u, d, f), x && v && this.collect(e, t * 4 + 3, n, h, g, _, o + 1, s, u, d, f), x && y && this.collect(e, t * 4 + 4, m, h, g, _, o + 1, s, u, d, f);
287
+ if (c >= this.maxLevels) return;
288
+ let m = n + o / 2, h = a + s / 2, g = o / 2, _ = s / 2, v = l < m, y = l + d > m, b = u < h, x = u + f > h;
289
+ b && v && this.collect(e, t * 4 + 1, n, a, g, _, c + 1, l, u, d, f), b && y && this.collect(e, t * 4 + 2, m, a, g, _, c + 1, l, u, d, f), x && v && this.collect(e, t * 4 + 3, n, h, g, _, c + 1, l, u, d, f), x && y && this.collect(e, t * 4 + 4, m, h, g, _, c + 1, l, u, d, f);
290
290
  }
291
- collectNeighborNode(e, t, n, r, i) {
292
- let a = t * D + E;
293
- if (this.nodeHeads[a] === this.nullIndex) return;
294
- let o = t * D + T;
295
- c(this.nodeInts, o);
296
- let s = this.nodeHeads[a];
297
- for (; s !== this.nullIndex;) {
298
- let t = this.pool.blockFor(s), a = this.pool.blockOffset(s), o = t[a + O], c = h(n, r, t[a + k], t[a + A], t[a + k] + t[a + j], t[a + A] + t[a + M]);
299
- c <= i && e.push({
300
- id: o,
301
- distance: c
302
- }), s = t[a + P];
291
+ collectNeighborNode(e, t, n, a, o) {
292
+ let s = t * D + E;
293
+ if (this.nodeHeads[s] === this.nullIndex) return;
294
+ let c = t * D + T;
295
+ r(this.nodeInts, c);
296
+ let l = this.nodeHeads[s];
297
+ for (; l !== this.nullIndex;) {
298
+ let t = this.pool.blockFor(l), r = this.pool.blockOffset(l), i = t[r + O], s = h(n, a, t[r + k], t[r + A], t[r + k] + t[r + j], t[r + A] + t[r + M]);
299
+ s <= o && e.push({
300
+ id: i,
301
+ distance: s
302
+ }), l = t[r + P];
303
303
  }
304
- l(this.nodeInts, o);
304
+ i(this.nodeInts, c);
305
305
  }
306
- collectNearestNode(e, t, n, r) {
307
- let i = t * D + E;
308
- if (this.nodeHeads[i] === this.nullIndex) return;
309
- let a = t * D + T;
310
- c(this.nodeInts, a);
311
- let o = this.nodeHeads[i];
312
- for (; o !== this.nullIndex;) {
313
- let t = this.pool.blockFor(o), i = this.pool.blockOffset(o), a = t[i + O], s = h(n, r, t[i + k], t[i + A], t[i + k] + t[i + j], t[i + A] + t[i + M]);
314
- (s < e.distance || s === e.distance && (e.id === void 0 || a < e.id)) && (e.id = a, e.distance = s), o = t[i + P];
306
+ collectNearestNode(e, t, n, a) {
307
+ let o = t * D + E;
308
+ if (this.nodeHeads[o] === this.nullIndex) return;
309
+ let s = t * D + T;
310
+ r(this.nodeInts, s);
311
+ let c = this.nodeHeads[o];
312
+ for (; c !== this.nullIndex;) {
313
+ let t = this.pool.blockFor(c), r = this.pool.blockOffset(c), i = t[r + O], o = h(n, a, t[r + k], t[r + A], t[r + k] + t[r + j], t[r + A] + t[r + M]);
314
+ (o < e.distance || o === e.distance && (e.id === void 0 || i < e.id)) && (e.id = i, e.distance = o), c = t[r + P];
315
315
  }
316
- l(this.nodeInts, a);
316
+ i(this.nodeInts, s);
317
317
  }
318
318
  linkIntoNode(e, t) {
319
319
  let n = e * D + T;
320
- c(this.nodeInts, n), this.linkNoLock(e, t), l(this.nodeInts, n);
320
+ r(this.nodeInts, n), this.linkNoLock(e, t), i(this.nodeInts, n);
321
321
  }
322
322
  linkNoLock(e, t) {
323
323
  let n = e * D + E;
@@ -325,7 +325,7 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
325
325
  }
326
326
  unlinkFromNode(e, t) {
327
327
  let n = e * D + T;
328
- c(this.nodeInts, n), this.unlinkNoLock(e, t), l(this.nodeInts, n);
328
+ r(this.nodeInts, n), this.unlinkNoLock(e, t), i(this.nodeInts, n);
329
329
  }
330
330
  unlinkNoLock(e, t) {
331
331
  let n = e * D + E, r = this.nodeHeads[n], i = this.pool.get(t, P);
@@ -345,17 +345,16 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = 6, T = 0, E = 1, D = 2, O = 0,
345
345
  }
346
346
  };
347
347
  function U(e) {
348
- let t = a(e ?? V);
349
- if (t !== i.float32 && t !== i.float64) throw Error("SharedQuadtree must be Float32Array or Float64Array");
348
+ let t = l(e ?? V);
349
+ if (t !== c.float32 && t !== c.float64) throw Error("SharedQuadtree must be Float32Array or Float64Array");
350
350
  return t;
351
351
  }
352
352
  function W(e) {
353
- return o(e) === 2 ? Float64Array : Float32Array;
353
+ return u(e) === 2 ? Float64Array : Float32Array;
354
354
  }
355
355
  function G(e) {
356
- return e === i.float32 ? L : R;
356
+ return e === c.float32 ? L : R;
357
357
  }
358
- //#endregion
359
358
  export { H as default };
360
359
 
361
360
  //# sourceMappingURL=shared-quadtree.js.map