@woosh/meep-engine 2.105.0 → 2.106.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/build/meep.cjs CHANGED
@@ -251,7 +251,9 @@ class InMemoryDescriptor extends BaseDescription {
251
251
 
252
252
  function equal(a, b, m) {
253
253
  if (a !== b) {
254
- const message = m !== undefined ? m : `${a} !== ${b}`;
254
+ const details = `${a} !== ${b}`;
255
+
256
+ const message = (m !== undefined && m !== "") ? `${m}. ${details}` : details;
255
257
  throw new Error(message);
256
258
  }
257
259
  }
@@ -60141,6 +60143,8 @@ class HashMap {
60141
60143
  this.#bin_count = 2 ** this.#bin_count_power_of_two;
60142
60144
  this.#bin_count_mask = this.#bin_count - 1;
60143
60145
 
60146
+ const old_entry_allocation_count = this.#entries_allocated_count;
60147
+
60144
60148
  this.#entries_allocated_count = 2 ** this.#entries_count_power_of_two;
60145
60149
 
60146
60150
  const BinsArray = UintArrayForCount(this.#entries_allocated_count + ENTRY_BASE);
@@ -60152,7 +60156,7 @@ class HashMap {
60152
60156
 
60153
60157
  this.#entries = new_entries;
60154
60158
 
60155
- array_copy(old_entries, 0, new_entries, 0, min2(old_entries.length, this.#entries_allocated_count));
60159
+ array_copy(old_entries, 0, new_entries, 0, min2(old_entry_allocation_count, this.#entries_allocated_count));
60156
60160
 
60157
60161
  if (this.#size > 0) {
60158
60162
  // re-hash
@@ -60222,6 +60226,7 @@ class HashMap {
60222
60226
 
60223
60227
  if (this.#entries[i] !== undefined) {
60224
60228
  const entry = this.#entries[i];
60229
+
60225
60230
  entry.hash = hash;
60226
60231
  entry.key = k;
60227
60232
  entry.value = v;
@@ -60298,7 +60303,9 @@ class HashMap {
60298
60303
 
60299
60304
  const entry_index = this.#allocate_entry(key, value, raw_hash);
60300
60305
 
60301
- this.#bins[bin_index] = entry_index + ENTRY_BASE;
60306
+ const bin_value = entry_index + ENTRY_BASE;
60307
+
60308
+ this.#bins[bin_index] = bin_value;
60302
60309
 
60303
60310
  break;
60304
60311
 
@@ -60528,7 +60535,11 @@ class HashMap {
60528
60535
 
60529
60536
  let written_entries = 0;
60530
60537
 
60531
- for (let existing_entry_index = this.#entries_start; existing_entry_index < entries_bound; existing_entry_index++) {
60538
+ for (
60539
+ let existing_entry_index = this.#entries_start;
60540
+ existing_entry_index < entries_bound;
60541
+ existing_entry_index++
60542
+ ) {
60532
60543
  const entry = entries[existing_entry_index];
60533
60544
 
60534
60545
  const hash = entry.hash;
@@ -61082,6 +61093,22 @@ class Cache {
61082
61093
  let element = this.data.get(key);
61083
61094
 
61084
61095
  if (element === undefined) {
61096
+ //compute weight
61097
+ const elementWeight = this.computeElementWeight(key, value);
61098
+
61099
+ /**
61100
+ * It's possible that element being added is larger than cache's capacity,
61101
+ * in which case entire cache will be evicted, but there still won't be enough space
61102
+ * @type {number}
61103
+ */
61104
+ const weightTarget = this.#maxWeight - elementWeight;
61105
+
61106
+ if (weightTarget < 0) {
61107
+ // Special case
61108
+ // element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
61109
+ return;
61110
+ }
61111
+
61085
61112
  element = new CacheElement();
61086
61113
 
61087
61114
  element.key = key;
@@ -61099,25 +61126,8 @@ class Cache {
61099
61126
  this.__last = element;
61100
61127
  }
61101
61128
 
61102
- //compute weight
61103
- const elementWeight = this.computeElementWeight(key, value);
61104
-
61105
61129
  element.weight = elementWeight;
61106
61130
 
61107
-
61108
- /**
61109
- * It's possible that element being added is larger than cache's capacity,
61110
- * in which case entire cache will be evicted, but there still won't be enough space
61111
- * @type {number}
61112
- */
61113
- const weightTarget = this.#maxWeight - elementWeight;
61114
-
61115
- if (weightTarget < 0) {
61116
- // Special case
61117
- // element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
61118
- return;
61119
- }
61120
-
61121
61131
  //evict elements until there is enough space for the element
61122
61132
  this.evictUntilWeight(weightTarget);
61123
61133
 
@@ -61130,9 +61140,14 @@ class Cache {
61130
61140
  // check if value is the same
61131
61141
  if (value === element.value) ; else {
61132
61142
  // replace value, adjust weight
61133
- this.#weight -= this.valueWeigher(element.value);
61134
- this.#weight += this.valueWeigher(value);
61143
+ this.#weight -= element.weight;
61144
+
61145
+ const elementWeight = this.computeElementWeight(key, value);
61146
+
61147
+ this.#weight += elementWeight;
61135
61148
 
61149
+ // assign new values
61150
+ element.weight = elementWeight;
61136
61151
  element.value = value;
61137
61152
  }
61138
61153