@daneren2005/shared-memory-objects 1.5.0 → 1.5.2

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.
@@ -1,15 +1,15 @@
1
1
  import { getPointer as e, loadRawPointer as t, storeRawPointer as n } from "../utils/pointer.js";
2
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-stack.js";
7
- import f from "../shared-pool.js";
8
- import { readLock as p, readUnlock as m, writeLock as h, writeUnlock as g } from "../lock/read-write-lock.js";
3
+ import { readLock as i, readUnlock as a, writeLock as o, writeUnlock as s } from "../lock/read-write-lock.js";
4
+ import { ARRAY_TYPE as c, getArrayTypeCode as l, getByteMultipler as u, makeArrayView as d } from "../utils/array-type.js";
5
+ import { lock as f, unlock as p } from "../lock/simple-lock.js";
6
+ import m from "../shared-map.js";
7
+ import h from "../shared-stack.js";
8
+ import g from "../shared-pool.js";
9
9
  import { addCandidate as _, candidateLimit as v, distanceSquaredToRect as y } from "./spatial-neighbors.js";
10
10
  import { getSpatialMapCapacity as ee, getSpatialPoolChunkSize as te } from "./spatial-entity.js";
11
11
  //#region src/spatial/shared-spatial-map.ts
12
- var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k = 1, A = 2, j = 8, M = 256, re = 255, N = 0, P = 1, F = 2, I = 3, L = 4, R = 5, z = 6, B = 7, V = 0, H = 1, U = 2, W = 3, G = 4, K = 5, q = 6, J = 7, Y = 8, X = 16777216, ie = X, ae = 4294967295, oe = 73856093, se = 19349663, ce = 50, le = 256, Z = 1, Q = 2, ue = 1e6, de = 4, fe = Float32Array, pe = class a {
12
+ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k = 1, A = 2, j = 8, M = 256, re = 255, N = 0, P = 1, F = 2, I = 3, L = 4, R = 5, z = 6, B = 7, V = 0, H = 1, U = 2, W = 3, G = 4, K = 5, q = 6, J = 7, Y = 8, X = 16777216, ie = X, ae = 4294967295, oe = 73856093, se = 19349663, ce = 50, le = 256, Z = 1, Q = 2, ue = 1e6, de = 4, fe = Float32Array, pe = class l {
13
13
  static ALLOCATE_COUNT = 11;
14
14
  memory;
15
15
  firstBlock;
@@ -60,46 +60,46 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
60
60
  get type() {
61
61
  return this.coordType;
62
62
  }
63
- constructor(s, c) {
64
- if (this.memory = s, c && "firstBlock" in c) this.firstBlock = new r(s, c.firstBlock), this.coordType = this.firstBlock.data[T], this.bucketPointers = new d(s, { firstBlock: e(t(this.firstBlock.data, b), s.positionBits) }), this.entityPool = new f(s, { firstBlock: e(t(this.firstBlock.data, x), s.positionBits) }), this.slotPool = new f(s, { firstBlock: e(t(this.firstBlock.data, S), s.positionBits) }), this.idMap = new u(s, { firstBlock: e(t(this.firstBlock.data, C), s.positionBits) }), this.bucketCount = Atomics.load(this.firstBlock.data, w), this.maxBucketCount = this.firstBlock.data[ne], this.nullIndex = ge(this.coordType);
63
+ constructor(i, a) {
64
+ if (this.memory = i, a && "firstBlock" in a) this.firstBlock = new r(i, a.firstBlock), this.coordType = this.firstBlock.data[T], this.bucketPointers = new h(i, { firstBlock: e(t(this.firstBlock.data, b), i.positionBits) }), this.entityPool = new g(i, { firstBlock: e(t(this.firstBlock.data, x), i.positionBits) }), this.slotPool = new g(i, { firstBlock: e(t(this.firstBlock.data, S), i.positionBits) }), this.idMap = new m(i, { firstBlock: e(t(this.firstBlock.data, C), i.positionBits) }), this.bucketCount = Atomics.load(this.firstBlock.data, w), this.maxBucketCount = this.firstBlock.data[ne], this.nullIndex = ge(this.coordType);
65
65
  else {
66
- let e = c?.gridSize ?? ce;
67
- this.bucketCount = Math.min(1073741824, Math.max(1, Math.floor(c?.buckets ?? le)));
68
- let t = c?.maxEntities ?? ue, r = c?.maxSlots ?? t * de;
69
- if (this.maxBucketCount = Math.min(1073741824, Math.max(this.bucketCount, Math.floor(c?.maxBuckets ?? _e(r * 2)))), this.coordType = me(c?.type), this.nullIndex = ge(this.coordType), this.coordType === i.float32 && (t > X || r > X)) throw Error(`Float32 SharedSpatialMap supports at most ${X} entities and slots; pass type: Float64Array for more`);
70
- let l = {
66
+ let e = a?.gridSize ?? ce;
67
+ this.bucketCount = Math.min(1073741824, Math.max(1, Math.floor(a?.buckets ?? le)));
68
+ let t = a?.maxEntities ?? ue, r = a?.maxSlots ?? t * de;
69
+ if (this.maxBucketCount = Math.min(1073741824, Math.max(this.bucketCount, Math.floor(a?.maxBuckets ?? _e(r * 2)))), this.coordType = me(a?.type), this.nullIndex = ge(this.coordType), this.coordType === c.float32 && (t > X || r > X)) throw Error(`Float32 SharedSpatialMap supports at most ${X} entities and slots; pass type: Float64Array for more`);
70
+ let o = {
71
71
  type: he(this.coordType),
72
72
  dataLength: Y,
73
73
  maxLength: t,
74
- maxChunkSize: te(t, Y, o(this.coordType), s.maxAllocationLength)
75
- }, p = {
74
+ maxChunkSize: te(t, Y, u(this.coordType), i.maxAllocationLength)
75
+ }, s = {
76
76
  type: he(this.coordType),
77
77
  dataLength: B,
78
78
  maxLength: r,
79
- maxChunkSize: te(r, B, o(this.coordType), s.maxAllocationLength)
80
- }, m = f.getAllocateCount(s, l), h = f.getAllocateCount(s, p), g = u.ALLOCATE_COUNT, _ = a.ALLOCATE_COUNT;
81
- this.firstBlock = s.allocUI32(_ + m + h + g), this.firstBlock.data[w] = this.bucketCount, this.firstBlock.data[T] = this.coordType, this.firstBlock.data[ne] = this.maxBucketCount;
79
+ maxChunkSize: te(r, B, u(this.coordType), i.maxAllocationLength)
80
+ }, d = g.getAllocateCount(i, o), f = g.getAllocateCount(i, s), p = m.ALLOCATE_COUNT, _ = l.ALLOCATE_COUNT;
81
+ this.firstBlock = i.allocUI32(_ + d + f + p), this.firstBlock.data[w] = this.bucketCount, this.firstBlock.data[T] = this.coordType, this.firstBlock.data[ne] = this.maxBucketCount;
82
82
  let v = this.getConfigView();
83
- v[0] = e, this.bucketPointers = new d(s), n(this.firstBlock.data, b, this.bucketPointers.pointer), this.appendBucketSegments(this.bucketCount);
84
- let y = this.firstBlock.getSubAllocation(_, m);
85
- this.entityPool = new f(s, {
83
+ v[0] = e, this.bucketPointers = new h(i), n(this.firstBlock.data, b, this.bucketPointers.pointer), this.appendBucketSegments(this.bucketCount);
84
+ let y = this.firstBlock.getSubAllocation(_, d);
85
+ this.entityPool = new g(i, {
86
86
  firstBlock: y,
87
- ...l
87
+ ...o
88
88
  }), n(this.firstBlock.data, x, y.pointer);
89
- let E = this.firstBlock.getSubAllocation(_ + m, h);
90
- this.slotPool = new f(s, {
89
+ let E = this.firstBlock.getSubAllocation(_ + d, f);
90
+ this.slotPool = new g(i, {
91
91
  firstBlock: E,
92
- ...p
92
+ ...s
93
93
  }), n(this.firstBlock.data, S, E.pointer);
94
- let D = this.firstBlock.getSubAllocation(_ + m + h, g);
95
- this.idMap = new u(s, {
94
+ let D = this.firstBlock.getSubAllocation(_ + d + f, p);
95
+ this.idMap = new m(i, {
96
96
  firstBlock: D,
97
- capacity: ee(t, s.maxAllocationLength)
97
+ capacity: ee(t, i.maxAllocationLength)
98
98
  }), n(this.firstBlock.data, C, D.pointer);
99
99
  }
100
100
  this.bucketMask = $(this.bucketCount), this.tableLock = new Int32Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + D * Uint32Array.BYTES_PER_ELEMENT, 2);
101
- let l = this.getConfigView();
102
- this.cellSize = l[0];
101
+ let o = this.getConfigView();
102
+ this.cellSize = o[0];
103
103
  }
104
104
  get pointer() {
105
105
  return this.firstBlock.pointer;
@@ -109,41 +109,41 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
109
109
  for (let n of this.bucketPointers) t += new r(this.memory, e(n, this.memory.positionBits)).usedMemory;
110
110
  return t;
111
111
  }
112
- insert(e, t, n, r = 0, i = 0) {
113
- p(this.tableLock);
112
+ insert(e, t, n, r = 0, o = 0) {
113
+ i(this.tableLock);
114
114
  try {
115
- this.syncBucketCount(), this.insertLocked(e, t, n, r, i);
115
+ this.syncBucketCount(), this.insertLocked(e, t, n, r, o);
116
116
  } finally {
117
- m(this.tableLock);
117
+ a(this.tableLock);
118
118
  }
119
119
  this.growBucketsIfNeeded();
120
120
  }
121
121
  bulkInsert(e) {
122
122
  let t = /* @__PURE__ */ new Map();
123
123
  for (let n of e) t.set(n.id, n);
124
- let n = Array.from(t.values()), r = this.idMap.getAll(n.map((e) => e.id)), i = [], a = 0, o = 0;
124
+ let n = Array.from(t.values()), r = this.idMap.getAll(n.map((e) => e.id)), o = [], s = 0, c = 0;
125
125
  for (let e = 0; e < n.length; e++) if (r[e] === void 0) {
126
126
  let t = n[e];
127
- o++, a += (this.colOf(t.x + (t.width ?? 0)) - this.colOf(t.x) + 1) * (this.rowOf(t.y + (t.height ?? 0)) - this.rowOf(t.y) + 1);
127
+ c++, s += (this.colOf(t.x + (t.width ?? 0)) - this.colOf(t.x) + 1) * (this.rowOf(t.y + (t.height ?? 0)) - this.rowOf(t.y) + 1);
128
128
  }
129
- this.ensureBucketCapacity(this.slotPool.length + a);
130
- let s = this.entityPool.reserveContiguous(o), c = this.slotPool.reserveContiguous(a);
131
- p(this.tableLock);
129
+ this.ensureBucketCapacity(this.slotPool.length + s);
130
+ let l = this.entityPool.reserveContiguous(c), u = this.slotPool.reserveContiguous(s);
131
+ i(this.tableLock);
132
132
  try {
133
133
  this.syncBucketCount();
134
134
  for (let e = 0; e < n.length; e++) {
135
- let t = n[e], a = t.width ?? 0, o = t.height ?? 0;
135
+ let t = n[e], i = t.width ?? 0, a = t.height ?? 0;
136
136
  if (r[e] !== void 0) {
137
- this.updateLocked(t.id, t.x, t.y, a, o);
137
+ this.updateLocked(t.id, t.x, t.y, i, a);
138
138
  continue;
139
139
  }
140
- let l = this.colOf(t.x), u = this.rowOf(t.y), d = this.colOf(t.x + a), f = this.rowOf(t.y + o), p = s++, m = this.entityPool.blockFor(p), h = this.entityPool.blockOffset(p);
141
- m[h + V] = l, m[h + H] = u, m[h + U] = d, m[h + W] = f, m[h + G] = t.x, m[h + K] = t.y, m[h + q] = a, m[h + J] = o, i.push([t.id, p]);
142
- for (let e = u; e <= f; e++) for (let n = l; n <= d; n++) this.linkReservedBucket(n, e, c++, t.id, p, l, u);
140
+ let s = this.colOf(t.x), c = this.rowOf(t.y), d = this.colOf(t.x + i), f = this.rowOf(t.y + a), p = l++, m = this.entityPool.blockFor(p), h = this.entityPool.blockOffset(p);
141
+ m[h + V] = s, m[h + H] = c, m[h + U] = d, m[h + W] = f, m[h + G] = t.x, m[h + K] = t.y, m[h + q] = i, m[h + J] = a, o.push([t.id, p]);
142
+ for (let e = c; e <= f; e++) for (let n = s; n <= d; n++) this.linkReservedBucket(n, e, u++, t.id, p, s, c);
143
143
  }
144
- this.idMap.setAll(i);
144
+ this.idMap.setAll(o);
145
145
  } finally {
146
- m(this.tableLock);
146
+ a(this.tableLock);
147
147
  }
148
148
  this.growBucketsForBulk();
149
149
  }
@@ -157,20 +157,20 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
157
157
  let u = this.entityPool.push(l);
158
158
  this.idMap.set(e, u), this.linkRange(e, u, a, o, s, c);
159
159
  }
160
- update(e, t, n, r = 0, i = 0) {
161
- let a = this.idMap.get(e);
162
- if (a !== void 0) {
163
- let e = this.entityPool.blockFor(a), o = this.entityPool.blockOffset(a), s = this.colOf(t), c = this.rowOf(n), l = this.colOf(t + r), u = this.rowOf(n + i);
164
- if (s === e[o + V] && c === e[o + H] && l === e[o + U] && u === e[o + W]) {
165
- e[o + G] = t, e[o + K] = n, e[o + q] = r, e[o + J] = i;
160
+ update(e, t, n, r = 0, o = 0) {
161
+ let s = this.idMap.get(e);
162
+ if (s !== void 0) {
163
+ let e = this.entityPool.blockFor(s), i = this.entityPool.blockOffset(s), a = this.colOf(t), c = this.rowOf(n), l = this.colOf(t + r), u = this.rowOf(n + o);
164
+ if (a === e[i + V] && c === e[i + H] && l === e[i + U] && u === e[i + W]) {
165
+ e[i + G] = t, e[i + K] = n, e[i + q] = r, e[i + J] = o;
166
166
  return;
167
167
  }
168
168
  }
169
- p(this.tableLock);
169
+ i(this.tableLock);
170
170
  try {
171
- this.syncBucketCount(), this.updateLocked(e, t, n, r, i);
171
+ this.syncBucketCount(), this.updateLocked(e, t, n, r, o);
172
172
  } finally {
173
- m(this.tableLock);
173
+ a(this.tableLock);
174
174
  }
175
175
  this.growBucketsIfNeeded();
176
176
  }
@@ -188,11 +188,11 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
188
188
  this.relinkRange(e, a, f, p, m, h, c, l, u, d), o[s + V] = f, o[s + H] = p, o[s + U] = m, o[s + W] = h, o[s + G] = t, o[s + K] = n, o[s + q] = r, o[s + J] = i;
189
189
  }
190
190
  remove(e) {
191
- p(this.tableLock);
191
+ i(this.tableLock);
192
192
  try {
193
193
  return this.syncBucketCount(), this.removeLocked(e);
194
194
  } finally {
195
- m(this.tableLock);
195
+ a(this.tableLock);
196
196
  }
197
197
  }
198
198
  removeLocked(e) {
@@ -208,12 +208,12 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
208
208
  let a = [];
209
209
  return this.searchInto(a, e, t, n, r, i), a;
210
210
  }
211
- searchInto(e, t, n, r, i, a) {
212
- p(this.tableLock);
211
+ searchInto(e, t, n, r, o, s) {
212
+ i(this.tableLock);
213
213
  try {
214
- return this.syncBucketCount(), this.searchIntoLocked(e, t, n, r, i, a);
214
+ return this.syncBucketCount(), this.searchIntoLocked(e, t, n, r, o, s);
215
215
  } finally {
216
- m(this.tableLock);
216
+ a(this.tableLock);
217
217
  }
218
218
  }
219
219
  searchIntoLocked(e, t, n, r, i, a) {
@@ -232,12 +232,12 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
232
232
  }
233
233
  return e;
234
234
  }
235
- neighbors(e, t, n, r, i) {
236
- p(this.tableLock);
235
+ neighbors(e, t, n, r, o) {
236
+ i(this.tableLock);
237
237
  try {
238
- return this.syncBucketCount(), this.neighborsLocked(e, t, n, r, i);
238
+ return this.syncBucketCount(), this.neighborsLocked(e, t, n, r, o);
239
239
  } finally {
240
- m(this.tableLock);
240
+ a(this.tableLock);
241
241
  }
242
242
  }
243
243
  neighborsLocked(e, t, n, r, i) {
@@ -282,7 +282,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
282
282
  return n === 1 ? d.id === void 0 ? [] : [d.id] : o.map((e) => e.id);
283
283
  }
284
284
  clear() {
285
- h(this.tableLock);
285
+ o(this.tableLock);
286
286
  try {
287
287
  this.syncBucketCount();
288
288
  for (let e = 0; e < this.bucketPointers.length; e++) {
@@ -295,7 +295,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
295
295
  for (let [t] of this.idMap) e.push(t);
296
296
  for (let t of e) this.idMap.delete(t);
297
297
  } finally {
298
- g(this.tableLock);
298
+ s(this.tableLock);
299
299
  }
300
300
  }
301
301
  free() {
@@ -306,7 +306,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
306
306
  return { firstBlock: this.firstBlock.getSharedMemory() };
307
307
  }
308
308
  getConfigView() {
309
- return s(this.coordType, this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + E * Uint32Array.BYTES_PER_ELEMENT, 1);
309
+ return d(this.coordType, this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + E * Uint32Array.BYTES_PER_ELEMENT, 1);
310
310
  }
311
311
  colOf(e) {
312
312
  return Math.floor(e / this.cellSize);
@@ -347,25 +347,25 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
347
347
  growBucketsIfNeeded() {
348
348
  let e = Atomics.load(this.firstBlock.data, w);
349
349
  if (!(e >= this.maxBucketCount || this.slotPool.length * Q <= e * Z)) {
350
- h(this.tableLock);
350
+ o(this.tableLock);
351
351
  try {
352
352
  if (this.syncBucketCount(), this.slotPool.length * Q <= this.bucketCount * Z) return;
353
353
  let e = Math.min(this.bucketCount * 2, this.maxBucketCount);
354
354
  if (e === this.bucketCount) return;
355
355
  this.resizeBuckets(e);
356
356
  } finally {
357
- g(this.tableLock);
357
+ s(this.tableLock);
358
358
  }
359
359
  }
360
360
  }
361
361
  ensureBucketCapacity(e) {
362
362
  let t = Math.ceil(e * Q / Z), n = Math.min(_e(t), this.maxBucketCount);
363
363
  if (!(n <= Atomics.load(this.firstBlock.data, w))) {
364
- h(this.tableLock);
364
+ o(this.tableLock);
365
365
  try {
366
366
  this.syncBucketCount(), n > this.bucketCount && this.resizeBuckets(n);
367
367
  } finally {
368
- g(this.tableLock);
368
+ s(this.tableLock);
369
369
  }
370
370
  }
371
371
  }
@@ -396,18 +396,18 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
396
396
  }
397
397
  linkIntoBucket(e, t, n) {
398
398
  n[P] = e, n[F] = t;
399
- let r = this.slotPool, i = r.push(n), a = this.bucketOf(e, t), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], u = this.bucketOffset(a), d = u + O;
400
- c(o, d);
401
- let f = u + k;
402
- r.set(i, R, s[f]), s[f] = i, l(o, d);
399
+ let r = this.slotPool, i = r.push(n), a = this.bucketOf(e, t), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], c = this.bucketOffset(a), l = c + O;
400
+ f(o, l);
401
+ let u = c + k;
402
+ r.set(i, R, s[u]), s[u] = i, p(o, l);
403
403
  }
404
404
  linkReservedBucket(e, t, n, r, i, a, o) {
405
- let s = this.slotPool, u = s.blockFor(n), d = s.blockOffset(n);
406
- u[d + N] = r, u[d + P] = e, u[d + F] = t, u[d + I] = a, u[d + L] = o, u[d + z] = i;
407
- let f = this.bucketOf(e, t), p = this.getBucketSegment(f), m = this.bucketHeadSegments[f >>> j], h = this.bucketOffset(f), g = h + O;
408
- c(p, g);
405
+ let s = this.slotPool, c = s.blockFor(n), l = s.blockOffset(n);
406
+ c[l + N] = r, c[l + P] = e, c[l + F] = t, c[l + I] = a, c[l + L] = o, c[l + z] = i;
407
+ let u = this.bucketOf(e, t), d = this.getBucketSegment(u), m = this.bucketHeadSegments[u >>> j], h = this.bucketOffset(u), g = h + O;
408
+ f(d, g);
409
409
  let _ = h + k;
410
- u[d + R] = m[_], m[_] = n, l(p, g);
410
+ c[l + R] = m[_], m[_] = n, p(d, g);
411
411
  }
412
412
  relinkRange(e, t, n, r, i, a, o, s, c, l) {
413
413
  let u = n > o ? n : o, d = i < c ? i : c, f = r > s ? r : s, p = a < l ? a : l, m = u <= d && f <= p, h = this.slotScratch;
@@ -427,18 +427,18 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
427
427
  }
428
428
  }
429
429
  refreshAnchorInBucket(e, t, n, r, i, a) {
430
- let o = this.nullIndex, s = this.getBucketSegment(e), u = this.bucketOffset(e), d = u + O;
431
- c(s, d);
432
- let f = this.slotPool, p = this.bucketHeadSegments[e >>> j][u + k];
433
- for (; p !== o;) {
434
- let e = f.blockFor(p), o = f.blockOffset(p);
430
+ let o = this.nullIndex, s = this.getBucketSegment(e), c = this.bucketOffset(e), l = c + O;
431
+ f(s, l);
432
+ let u = this.slotPool, d = this.bucketHeadSegments[e >>> j][c + k];
433
+ for (; d !== o;) {
434
+ let e = u.blockFor(d), o = u.blockOffset(d);
435
435
  if (e[o + N] === t && e[o + P] === n && e[o + F] === r) {
436
436
  e[o + I] = i, e[o + L] = a;
437
437
  break;
438
438
  }
439
- p = e[o + R];
439
+ d = e[o + R];
440
440
  }
441
- l(s, d);
441
+ p(s, l);
442
442
  }
443
443
  unlinkRange(e, t, n, r, i) {
444
444
  let a = this.nullIndex, o = this.slotPool;
@@ -448,65 +448,65 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
448
448
  }
449
449
  }
450
450
  collectBucket(e, t, n, r, i, a, o, s) {
451
- let u = this.nullIndex, d = r + k, f = r + O;
452
- c(t, f);
453
- let p = n[d], m = this.slotPool;
454
- for (; p !== u;) {
455
- let t = m.blockFor(p), n = m.blockOffset(p);
451
+ let c = this.nullIndex, l = r + k, u = r + O;
452
+ f(t, u);
453
+ let d = n[l], m = this.slotPool;
454
+ for (; d !== c;) {
455
+ let t = m.blockFor(d), n = m.blockOffset(d);
456
456
  if (t[n + P] === i && t[n + F] === a) {
457
457
  let r = t[n + I], c = t[n + L];
458
458
  i === (r > o ? r : o) && a === (c > s ? c : s) && e.push(t[n + N]);
459
459
  }
460
- p = t[n + R];
460
+ d = t[n + R];
461
461
  }
462
- l(t, f);
462
+ p(t, u);
463
463
  }
464
464
  collectNeighborBucket(e, t, n) {
465
465
  let r = this.bucketOf(t, n), i = this.getBucketSegment(r), a = this.bucketHeadSegments[r >>> j], o = this.bucketOffset(r), s = o + k;
466
466
  if (a[s] === this.nullIndex) return;
467
- let u = o + O;
468
- c(i, u);
469
- let d = a[s];
470
- for (; d !== this.nullIndex;) {
471
- let r = this.slotPool.blockFor(d), i = this.slotPool.blockOffset(d);
472
- r[i + P] === t && r[i + F] === n && e.push(r[i + N]), d = r[i + R];
467
+ let c = o + O;
468
+ f(i, c);
469
+ let l = a[s];
470
+ for (; l !== this.nullIndex;) {
471
+ let r = this.slotPool.blockFor(l), i = this.slotPool.blockOffset(l);
472
+ r[i + P] === t && r[i + F] === n && e.push(r[i + N]), l = r[i + R];
473
473
  }
474
- l(i, u);
474
+ p(i, c);
475
475
  }
476
476
  collectNearestBucket(e, t, n, r, i) {
477
- let a = this.bucketOf(t, n), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], u = this.bucketOffset(a), d = u + k;
478
- if (s[d] === this.nullIndex) return;
479
- let f = u + O;
480
- c(o, f);
481
- let p = s[d];
482
- for (; p !== this.nullIndex;) {
483
- let a = this.slotPool.blockFor(p), o = this.slotPool.blockOffset(p);
477
+ let a = this.bucketOf(t, n), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], c = this.bucketOffset(a), l = c + k;
478
+ if (s[l] === this.nullIndex) return;
479
+ let u = c + O;
480
+ f(o, u);
481
+ let d = s[l];
482
+ for (; d !== this.nullIndex;) {
483
+ let a = this.slotPool.blockFor(d), o = this.slotPool.blockOffset(d);
484
484
  if (a[o + P] === t && a[o + F] === n) {
485
485
  let t = a[o + z], n = this.entityPool.blockFor(t), s = this.entityPool.blockOffset(t), c = a[o + N], l = this.entityBlockDistanceSquared(n, s, r, i);
486
486
  (l < e.distance || l === e.distance && (e.id === void 0 || c < e.id)) && (e.id = c, e.distance = l);
487
487
  }
488
- p = a[o + R];
488
+ d = a[o + R];
489
489
  }
490
- l(o, f);
490
+ p(o, u);
491
491
  }
492
- collectNeighborCandidates(e, t, n, r, i, a, o, s, u) {
493
- let d = this.bucketOf(t, n), f = this.getBucketSegment(d), p = this.bucketHeadSegments[d >>> j], m = this.bucketOffset(d), h = m + k;
494
- if (p[h] === this.nullIndex) return;
492
+ collectNeighborCandidates(e, t, n, r, i, a, o, s, c) {
493
+ let l = this.bucketOf(t, n), u = this.getBucketSegment(l), d = this.bucketHeadSegments[l >>> j], m = this.bucketOffset(l), h = m + k;
494
+ if (d[h] === this.nullIndex) return;
495
495
  let g = m + O;
496
- c(f, g);
497
- let v = p[h];
496
+ f(u, g);
497
+ let v = d[h];
498
498
  for (; v !== this.nullIndex;) {
499
- let c = this.slotPool.blockFor(v), l = this.slotPool.blockOffset(v);
500
- if (c[l + P] === t && c[l + F] === n) {
501
- let d = c[l + z], f = this.entityPool.blockFor(d), p = this.entityPool.blockOffset(d), m = f[p + V], h = f[p + U], g = f[p + H], v = f[p + W];
499
+ let l = this.slotPool.blockFor(v), u = this.slotPool.blockOffset(v);
500
+ if (l[u + P] === t && l[u + F] === n) {
501
+ let d = l[u + z], f = this.entityPool.blockFor(d), p = this.entityPool.blockOffset(d), m = f[p + V], h = f[p + U], g = f[p + H], v = f[p + W];
502
502
  if (t === (r < m ? m : r > h ? h : r) && n === (i < g ? g : i > v ? v : i)) {
503
503
  let t = this.entityBlockDistanceSquared(f, p, a, o);
504
- t <= u && _(e, c[l + N], t, s);
504
+ t <= c && _(e, l[u + N], t, s);
505
505
  }
506
506
  }
507
- v = c[l + R];
507
+ v = l[u + R];
508
508
  }
509
- l(f, g);
509
+ p(u, g);
510
510
  }
511
511
  addEntityCandidate(e, t, n, r, i, a, o) {
512
512
  let s = this.entityDistanceSquared(n, r, i);
@@ -521,27 +521,27 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
521
521
  return y(n, r, i, a, i + e[t + q], a + e[t + J]);
522
522
  }
523
523
  unlinkFromBucket(e, t, n, r) {
524
- let i = this.nullIndex, a = this.getBucketSegment(e), o = this.bucketHeadSegments[e >>> j], s = this.bucketOffset(e), u = s + O;
525
- c(a, u);
526
- let d = s + k, f = this.slotPool, p = i, m = o[d];
524
+ let i = this.nullIndex, a = this.getBucketSegment(e), o = this.bucketHeadSegments[e >>> j], s = this.bucketOffset(e), c = s + O;
525
+ f(a, c);
526
+ let l = s + k, u = this.slotPool, d = i, m = o[l];
527
527
  for (; m !== i;) {
528
- let e = f.blockFor(m), s = f.blockOffset(m), c = e[s + R];
529
- if (e[s + N] === t && e[s + P] === n && e[s + F] === r) return p === i ? o[d] = c : f.set(p, R, c), l(a, u), m;
530
- p = m, m = c;
528
+ let e = u.blockFor(m), s = u.blockOffset(m), f = e[s + R];
529
+ if (e[s + N] === t && e[s + P] === n && e[s + F] === r) return d === i ? o[l] = f : u.set(d, R, f), p(a, c), m;
530
+ d = m, m = f;
531
531
  }
532
- return l(a, u), i;
532
+ return p(a, c), i;
533
533
  }
534
534
  };
535
535
  function me(e) {
536
- let t = a(e ?? fe);
537
- if (t !== i.float32 && t !== i.float64) throw Error("SharedSpatialMap must be Float32Array or Float64Array");
536
+ let t = l(e ?? fe);
537
+ if (t !== c.float32 && t !== c.float64) throw Error("SharedSpatialMap must be Float32Array or Float64Array");
538
538
  return t;
539
539
  }
540
540
  function he(e) {
541
- return o(e) === 2 ? Float64Array : Float32Array;
541
+ return u(e) === 2 ? Float64Array : Float32Array;
542
542
  }
543
543
  function ge(e) {
544
- return e === i.float32 ? ie : ae;
544
+ return e === c.float32 ? ie : ae;
545
545
  }
546
546
  function $(e) {
547
547
  return e & e - 1 ? -1 : e - 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daneren2005/shared-memory-objects",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
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",