@woosh/meep-engine 2.165.7 → 2.167.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.
Files changed (146) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/package.json +1 -1
  3. package/src/CORRECTNESS_HUNT_2026_07_24.md +142 -0
  4. package/src/core/binary/BinaryBuffer.js +1 -1
  5. package/src/core/binary/EncodingBinaryBuffer.d.ts.map +1 -1
  6. package/src/core/binary/EncodingBinaryBuffer.js +3 -1
  7. package/src/core/cache/Cache.d.ts.map +1 -1
  8. package/src/core/cache/Cache.js +0 -4
  9. package/src/core/cache/CacheElement.d.ts.map +1 -1
  10. package/src/core/cache/CacheElement.js +4 -0
  11. package/src/core/cache/FrequencySketch.d.ts +0 -21
  12. package/src/core/cache/FrequencySketch.d.ts.map +1 -1
  13. package/src/core/cache/FrequencySketch.js +66 -65
  14. package/src/core/cache/wtinylfu/CacheElementWTinylfu.d.ts +17 -0
  15. package/src/core/cache/wtinylfu/CacheElementWTinylfu.d.ts.map +1 -0
  16. package/src/core/cache/wtinylfu/CacheElementWTinylfu.js +18 -0
  17. package/src/core/cache/wtinylfu/CacheRegionType.d.ts +10 -0
  18. package/src/core/cache/wtinylfu/CacheRegionType.d.ts.map +1 -0
  19. package/src/core/cache/wtinylfu/CacheRegionType.js +10 -0
  20. package/src/core/cache/wtinylfu/CacheRegionWTinylfu.d.ts +66 -0
  21. package/src/core/cache/wtinylfu/CacheRegionWTinylfu.d.ts.map +1 -0
  22. package/src/core/cache/wtinylfu/CacheRegionWTinylfu.js +183 -0
  23. package/src/core/cache/wtinylfu/CacheWTinylfu.d.ts +279 -0
  24. package/src/core/cache/wtinylfu/CacheWTinylfu.d.ts.map +1 -0
  25. package/src/core/cache/wtinylfu/CacheWTinylfu.js +807 -0
  26. package/src/core/cache/wtinylfu/benchmark/CacheWTinylfu.bench.md +243 -0
  27. package/src/core/cache/wtinylfu/wtinylfuDecisions.d.ts +80 -0
  28. package/src/core/cache/wtinylfu/wtinylfuDecisions.d.ts.map +1 -0
  29. package/src/core/cache/wtinylfu/wtinylfuDecisions.js +102 -0
  30. package/src/core/collection/RingBuffer.d.ts.map +1 -1
  31. package/src/core/collection/RingBuffer.js +15 -3
  32. package/src/core/collection/map/HashMap.d.ts +1 -1
  33. package/src/core/collection/map/HashMap.d.ts.map +1 -1
  34. package/src/core/collection/map/HashMap.js +5 -17
  35. package/src/core/geom/2d/line/line2_compute_segment_point_distance_sqr.d.ts.map +1 -1
  36. package/src/core/geom/2d/line/line2_compute_segment_point_distance_sqr.js +5 -0
  37. package/src/core/geom/ConicRay.d.ts.map +1 -1
  38. package/src/core/geom/ConicRay.js +9 -2
  39. package/src/core/geom/Quaternion.d.ts.map +1 -1
  40. package/src/core/geom/Quaternion.js +7 -3
  41. package/src/core/math/build_gaussian_kernel_1d.d.ts +2 -2
  42. package/src/core/math/build_gaussian_kernel_1d.d.ts.map +1 -1
  43. package/src/core/math/build_gaussian_kernel_1d.js +4 -2
  44. package/src/core/math/build_gaussian_kernel_2d.d.ts +2 -2
  45. package/src/core/math/build_gaussian_kernel_2d.d.ts.map +1 -1
  46. package/src/core/math/build_gaussian_kernel_2d.js +4 -2
  47. package/src/core/math/gaussian.d.ts +2 -2
  48. package/src/core/math/gaussian.js +2 -2
  49. package/src/core/math/spline/spline3_bezier_bounds.d.ts.map +1 -1
  50. package/src/core/math/spline/spline3_bezier_bounds.js +10 -3
  51. package/src/core/math/spline/spline3_bezier_to_hermite.d.ts +8 -7
  52. package/src/core/math/spline/spline3_bezier_to_hermite.d.ts.map +1 -1
  53. package/src/core/math/spline/spline3_bezier_to_hermite.js +13 -12
  54. package/src/core/math/spline/spline3_hermite_bounds.d.ts.map +1 -1
  55. package/src/core/math/spline/spline3_hermite_bounds.js +10 -3
  56. package/src/core/math/spline/spline3_hermite_bounds_t.d.ts.map +1 -1
  57. package/src/core/math/spline/spline3_hermite_bounds_t.js +115 -109
  58. package/src/core/math/spline/spline3_hermite_to_bezier.d.ts +2 -0
  59. package/src/core/math/spline/spline3_hermite_to_bezier.d.ts.map +1 -1
  60. package/src/core/math/spline/spline3_hermite_to_bezier.js +2 -0
  61. package/src/core/math/statistics/computeStatisticalMean.js +1 -1
  62. package/src/core/math/statistics/gaussian_amplitude.d.ts.map +1 -1
  63. package/src/core/math/statistics/gaussian_amplitude.js +3 -1
  64. package/src/engine/animation/clip/ecd_bind_animation_curve.d.ts.map +1 -1
  65. package/src/engine/animation/clip/ecd_bind_animation_curve.js +10 -1
  66. package/src/engine/animation/clip/hemisphere_align_quaternion_values.d.ts +20 -0
  67. package/src/engine/animation/clip/hemisphere_align_quaternion_values.d.ts.map +1 -0
  68. package/src/engine/animation/clip/hemisphere_align_quaternion_values.js +37 -0
  69. package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts.map +1 -1
  70. package/src/engine/animation/keyed2/AnimationTrackPlayback.js +5 -1
  71. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  72. package/src/engine/ecs/EntityComponentDataset.js +5 -21
  73. package/src/engine/ecs/fow/FogOfWar.d.ts +22 -0
  74. package/src/engine/ecs/fow/FogOfWar.d.ts.map +1 -1
  75. package/src/engine/ecs/fow/FogOfWar.js +202 -54
  76. package/src/engine/ecs/fow/FogOfWarEdgeMode.d.ts +16 -0
  77. package/src/engine/ecs/fow/FogOfWarEdgeMode.d.ts.map +1 -0
  78. package/src/engine/ecs/fow/FogOfWarEdgeMode.js +39 -0
  79. package/src/engine/ecs/fow/FogOfWarSystem.d.ts.map +1 -1
  80. package/src/engine/ecs/fow/FogOfWarSystem.js +1 -0
  81. package/src/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.d.ts.map +1 -1
  82. package/src/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +3 -0
  83. package/src/engine/ecs/fow/shader/FogOfWarRenderer.d.ts +7 -0
  84. package/src/engine/ecs/fow/shader/FogOfWarRenderer.d.ts.map +1 -1
  85. package/src/engine/ecs/fow/shader/FogOfWarRenderer.js +155 -145
  86. package/src/engine/ecs/fow/shader/screenSpaceFogOfWarShader.d.ts.map +1 -1
  87. package/src/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +33 -8
  88. package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.d.ts.map +1 -1
  89. package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +3 -1
  90. package/src/engine/graphics/GraphicsEngine.d.ts +5 -1
  91. package/src/engine/graphics/GraphicsEngine.d.ts.map +1 -1
  92. package/src/engine/graphics/GraphicsEngine.js +14 -3
  93. package/src/engine/graphics/composit/CompositLayer.d.ts.map +1 -1
  94. package/src/engine/graphics/composit/CompositLayer.js +258 -255
  95. package/src/engine/graphics/composit/LayerCompositer.d.ts +12 -0
  96. package/src/engine/graphics/composit/LayerCompositer.d.ts.map +1 -1
  97. package/src/engine/graphics/composit/LayerCompositer.js +19 -10
  98. package/src/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.d.ts +1 -1
  99. package/src/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.d.ts.map +1 -1
  100. package/src/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +10 -4
  101. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.d.ts +6 -0
  102. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.d.ts.map +1 -1
  103. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +21 -0
  104. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.d.ts.map +1 -1
  105. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +5 -23
  106. package/src/engine/graphics/ecs/path/tube/build/estimatePathViaIterativeIntegral.d.ts.map +1 -1
  107. package/src/engine/graphics/ecs/path/tube/build/estimatePathViaIterativeIntegral.js +6 -4
  108. package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
  109. package/src/engine/graphics/ecs/water/WaterSystem.js +9 -3
  110. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts +12 -0
  111. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts.map +1 -1
  112. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +46 -9
  113. package/src/engine/graphics/particles/particular/engine/ParticularEngine.d.ts +5 -0
  114. package/src/engine/graphics/particles/particular/engine/ParticularEngine.d.ts.map +1 -1
  115. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +8 -0
  116. package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.d.ts +7 -0
  117. package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.d.ts.map +1 -1
  118. package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.js +8 -0
  119. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts +10 -2
  120. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts.map +1 -1
  121. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +42 -10
  122. package/src/engine/graphics/render/buffer/FrameBuffer.d.ts.map +1 -1
  123. package/src/engine/graphics/render/buffer/FrameBuffer.js +5 -2
  124. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts +13 -1
  125. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts.map +1 -1
  126. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +40 -7
  127. package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.d.ts.map +1 -1
  128. package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +10 -4
  129. package/src/engine/graphics/render/forward_plus/LightManager.d.ts.map +1 -1
  130. package/src/engine/graphics/render/forward_plus/LightManager.js +1235 -1232
  131. package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.d.ts +5 -0
  132. package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.d.ts.map +1 -1
  133. package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +11 -10
  134. package/src/engine/graphics/trail/tube/TubeX.d.ts.map +1 -1
  135. package/src/engine/graphics/trail/tube/TubeX.js +557 -555
  136. package/src/engine/graphics/trail/x/RibbonXPlugin.d.ts +12 -1
  137. package/src/engine/graphics/trail/x/RibbonXPlugin.d.ts.map +1 -1
  138. package/src/engine/graphics/trail/x/RibbonXPlugin.js +15 -8
  139. package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
  140. package/src/engine/input/ecs/systems/InputControllerSystem.js +9 -6
  141. package/src/engine/navigation/ecs/components/Path.d.ts +5 -2
  142. package/src/engine/navigation/ecs/components/Path.d.ts.map +1 -1
  143. package/src/engine/navigation/ecs/components/Path.js +10 -4
  144. package/src/engine/navigation/ecs/path_following/PathFollowingSystem.js +1 -1
  145. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  146. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +3 -3
@@ -84,30 +84,9 @@ export class FrequencySketch<T> {
84
84
  * @param {number} input_hash the element to add
85
85
  */
86
86
  increment(input_hash: number): void;
87
- /**
88
- * Increments the specified counter by 1 if it is not already at the maximum value (15).
89
- *
90
- * @param {number} i the table index (8 counters)
91
- * @param {number} j the counter to increment
92
- * @returns {boolean} if incremented
93
- */
94
- incrementAt(i: number, j: number): boolean;
95
87
  /**
96
88
  * Reduces every counter by half of its original value.
97
89
  */
98
90
  reset(): void;
99
- /**
100
- * Returns the table index for the counter at the specified depth.
101
- * @param {number} item the element's hash
102
- * @param {number} i the counter depth
103
- * @returns {number} the table index
104
- */
105
- indexOf(item: number, i: number): number;
106
- /**
107
- * Applies a supplemental hash function to a given hash code, which defends against poor quality
108
- * @param {number} v
109
- * @returns {number}
110
- */
111
- spread(v: number): number;
112
91
  }
113
92
  //# sourceMappingURL=FrequencySketch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrequencySketch.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/FrequencySketch.js"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH;IACI;;;OAGG;IACH,YAFU,MAAM,CAED;IACf;;;OAGG;IACH,WAFU,MAAM,CAEF;IACd;;;OAGG;IACH,OAFU,WAAW,GAAC,IAAI,CAEb;IACb;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;;;;OAMG;IACH,4BAFW,MAAM,QAsBhB;IAED;;;;;OAKG;IACH,oBAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,MAAM,CAclB;IAED;;;;;;;OAOG;IACH,sBAFW,MAAM,QAwBhB;IAED;;;;;;OAMG;IACH,eAJW,MAAM,KACN,MAAM,GACJ,OAAO,CAgBnB;IAED;;OAEG;IACH,cAaC;IAED;;;;;OAKG;IACH,cAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAOlB;IAED;;;;OAIG;IACH,UAHW,MAAM,GACJ,MAAM,CASlB;CACJ"}
1
+ {"version":3,"file":"FrequencySketch.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/FrequencySketch.js"],"names":[],"mappings":"AAsEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH;IACI;;;OAGG;IACH,YAFU,MAAM,CAED;IACf;;;OAGG;IACH,WAFU,MAAM,CAEF;IACd;;;OAGG;IACH,OAFU,WAAW,GAAC,IAAI,CAEb;IACb;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;;;;OAMG;IACH,4BAFW,MAAM,QAsBhB;IAED;;;;;OAKG;IACH,oBAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,MAAM,CAgBlB;IAED;;;;;;;OAOG;IACH,sBAFW,MAAM,QAwBhB;IAED;;OAEG;IACH,cAaC;CACJ"}
@@ -19,6 +19,55 @@ const ONE_MASK = 0x11111111;
19
19
  */
20
20
  const MAX_INT_32 = 2147483647;
21
21
 
22
+ /**
23
+ * Applies a supplemental hash function to a given hash code, which defends against poor quality hashes.
24
+ * @param {number} v
25
+ * @returns {number}
26
+ */
27
+ function spread(v) {
28
+ let x = v;
29
+
30
+ x = ((x >>> 16) ^ x) * 0x45d9f3b;
31
+ x = ((x >>> 16) ^ x) * 0x45d9f3b;
32
+
33
+ return (x >>> 16) ^ x;
34
+ }
35
+
36
+ /**
37
+ * Returns the table index for the counter at the specified depth.
38
+ * @param {number} item the element's hash
39
+ * @param {number} i the counter depth
40
+ * @param {number} tableMask the table-size mask
41
+ * @returns {number} the table index
42
+ */
43
+ function indexOf(item, i, tableMask) {
44
+ let hash = (item + SEED[i]) * SEED[i];
45
+ hash += (hash >>> 16);
46
+
47
+ return hash & tableMask;
48
+ }
49
+
50
+ /**
51
+ * Increments the specified counter by 1 if it is not already at the maximum value (15).
52
+ * @param {Uint32Array} table the counter table
53
+ * @param {number} i the table index (8 counters)
54
+ * @param {number} j the counter to increment
55
+ * @returns {boolean} if incremented
56
+ */
57
+ function incrementAt(table, i, j) {
58
+ const offset = j << 2;
59
+ const mask = (0xF << offset);
60
+
61
+ const existing_table_value = table[i];
62
+
63
+ if ((existing_table_value & mask) !== mask) {
64
+ table[i] = existing_table_value + (1 << offset);
65
+ return true;
66
+ }
67
+
68
+ return false;
69
+ }
70
+
22
71
  /**
23
72
  * A probabilistic multiset for estimating the popularity of an element within a time window. The
24
73
  * maximum frequency of an element is limited to 15 (4-bits) and an aging process periodically
@@ -121,13 +170,15 @@ export class FrequencySketch {
121
170
  * @returns {number} the estimated number of occurrences of the element; possibly zero but never negative
122
171
  */
123
172
  frequency(input_hash) {
124
- const hash = this.spread(input_hash);
173
+ const table = this.table;
174
+ const tableMask = this.tableMask;
175
+ const hash = spread(input_hash);
125
176
  const start = (hash & 3) << 2;
126
177
  let frequency = MAX_INT_32;
127
178
 
128
179
  for (let i = 0; i < 4; i++) {
129
- const index = this.indexOf(hash, i);
130
- const count = (this.table[index] >>> ((start + i) << 2)) & 0xf;
180
+ const index = indexOf(hash, i, tableMask);
181
+ const count = (table[index] >>> ((start + i) << 2)) & 0xf;
131
182
  frequency = min2(frequency, count);
132
183
  }
133
184
 
@@ -143,21 +194,21 @@ export class FrequencySketch {
143
194
  * @param {number} input_hash the element to add
144
195
  */
145
196
  increment(input_hash) {
146
- const hash = this.spread(input_hash);
197
+ const table = this.table;
198
+ const tableMask = this.tableMask;
199
+ const hash = spread(input_hash);
147
200
  const start = (hash & 3) << 2;
148
201
 
149
202
  // Loop unrolling improves throughput by 5m ops/s
150
- const index0 = this.indexOf(hash, 0);
151
- const index1 = this.indexOf(hash, 1);
152
- const index2 = this.indexOf(hash, 2);
153
- const index3 = this.indexOf(hash, 3);
154
-
155
- // Evaluate all four counters unconditionally; `||` would short-circuit and skip the remaining
156
- // increments as soon as the first one returned true, so only one of the four counters would ever advance.
157
- const added0 = this.incrementAt(index0, start);
158
- const added1 = this.incrementAt(index1, start + 1);
159
- const added2 = this.incrementAt(index2, start + 2);
160
- const added3 = this.incrementAt(index3, start + 3);
203
+ const index0 = indexOf(hash, 0, tableMask);
204
+ const index1 = indexOf(hash, 1, tableMask);
205
+ const index2 = indexOf(hash, 2, tableMask);
206
+ const index3 = indexOf(hash, 3, tableMask);
207
+
208
+ const added0 = incrementAt(table, index0, start);
209
+ const added1 = incrementAt(table, index1, start + 1);
210
+ const added2 = incrementAt(table, index2, start + 2);
211
+ const added3 = incrementAt(table, index3, start + 3);
161
212
 
162
213
  const added = added0 || added1 || added2 || added3;
163
214
 
@@ -166,29 +217,6 @@ export class FrequencySketch {
166
217
  }
167
218
  }
168
219
 
169
- /**
170
- * Increments the specified counter by 1 if it is not already at the maximum value (15).
171
- *
172
- * @param {number} i the table index (8 counters)
173
- * @param {number} j the counter to increment
174
- * @returns {boolean} if incremented
175
- */
176
- incrementAt(i, j) {
177
- const offset = j << 2;
178
- const mask = (0xF << offset);
179
-
180
- const table = this.table;
181
-
182
- const existing_table_value = table[i];
183
-
184
- if ((existing_table_value & mask) !== mask) {
185
- table[i] = existing_table_value + (1 << offset);
186
- return true;
187
- }
188
-
189
- return false;
190
- }
191
-
192
220
  /**
193
221
  * Reduces every counter by half of its original value.
194
222
  */
@@ -206,31 +234,4 @@ export class FrequencySketch {
206
234
 
207
235
  this.size = (this.size >>> 1) - (count >>> 2);
208
236
  }
209
-
210
- /**
211
- * Returns the table index for the counter at the specified depth.
212
- * @param {number} item the element's hash
213
- * @param {number} i the counter depth
214
- * @returns {number} the table index
215
- */
216
- indexOf(item, i) {
217
- let hash = (item + SEED[i]) * SEED[i];
218
- hash += (hash >>> 16);
219
-
220
- return hash & this.tableMask;
221
- }
222
-
223
- /**
224
- * Applies a supplemental hash function to a given hash code, which defends against poor quality
225
- * @param {number} v
226
- * @returns {number}
227
- */
228
- spread(v) {
229
- let x = v;
230
-
231
- x = ((x >>> 16) ^ x) * 0x45d9f3b;
232
- x = ((x >>> 16) ^ x) * 0x45d9f3b;
233
-
234
- return (x >>> 16) ^ x;
235
- }
236
237
  }
@@ -0,0 +1,17 @@
1
+ export class CacheElementWTinylfu extends CacheElement<any, any> {
2
+ constructor();
3
+ /**
4
+ *
5
+ * @type {CacheRegionType}
6
+ */
7
+ region: CacheRegionType;
8
+ /**
9
+ * Cached key hash (keyHashFunction(key)), computed once at admission so the frequency-sketch paths
10
+ * (increment / frequency / admission duel) never recompute it.
11
+ * @type {number}
12
+ */
13
+ keyHash: number;
14
+ }
15
+ import { CacheElement } from "../CacheElement.js";
16
+ import { CacheRegionType } from "./CacheRegionType.js";
17
+ //# sourceMappingURL=CacheElementWTinylfu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheElementWTinylfu.d.ts","sourceRoot":"","sources":["../../../../../src/core/cache/wtinylfu/CacheElementWTinylfu.js"],"names":[],"mappings":"AAGA;;IAEI;;;OAGG;IACH,QAFU,eAAe,CAEO;IAEhC;;;;OAIG;IACH,SAFU,MAAM,CAEJ;CACf;6BAjB0B,oBAAoB;gCACjB,sBAAsB"}
@@ -0,0 +1,18 @@
1
+ import {CacheElement} from "../CacheElement.js";
2
+ import {CacheRegionType} from "./CacheRegionType.js";
3
+
4
+ export class CacheElementWTinylfu extends CacheElement {
5
+
6
+ /**
7
+ *
8
+ * @type {CacheRegionType}
9
+ */
10
+ region = CacheRegionType.Window;
11
+
12
+ /**
13
+ * Cached key hash (keyHashFunction(key)), computed once at admission so the frequency-sketch paths
14
+ * (increment / frequency / admission duel) never recompute it.
15
+ * @type {number}
16
+ */
17
+ keyHash = 0;
18
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * *
3
+ */
4
+ export type CacheRegionType = number;
5
+ export namespace CacheRegionType {
6
+ let Window: number;
7
+ let Trial: number;
8
+ let Protected: number;
9
+ }
10
+ //# sourceMappingURL=CacheRegionType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheRegionType.d.ts","sourceRoot":"","sources":["../../../../../src/core/cache/wtinylfu/CacheRegionType.js"],"names":[],"mappings":";;;8BAEU,MAAM"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @enum {number}
4
+ * @private
5
+ */
6
+ export const CacheRegionType = {
7
+ Window: 0,
8
+ Trial: 1,
9
+ Protected: 2
10
+ };
@@ -0,0 +1,66 @@
1
+ export class CacheRegionWTinylfu {
2
+ /**
3
+ *
4
+ * @param {number} maxWeight
5
+ */
6
+ constructor({ maxWeight }?: number);
7
+ /**
8
+ * Add new element to this region
9
+ * @param {CacheElementWTinylfu} element
10
+ * @param {number} [weight=element.weight]
11
+ */
12
+ add(element: CacheElementWTinylfu, weight?: number): void;
13
+ /**
14
+ * Update to MRU
15
+ * @param {CacheElementWTinylfu} element
16
+ */
17
+ touch(element: CacheElementWTinylfu): void;
18
+ /**
19
+ *
20
+ * @returns {CacheElementWTinylfu<Key,Value>|null}
21
+ */
22
+ findEvictionVictim(): CacheElementWTinylfu<Key, Value> | null;
23
+ /**
24
+ *
25
+ * @param {CacheElementWTinylfu<Key,Value>} element
26
+ * @param {number} [weight=element.weight]
27
+ * @private
28
+ */
29
+ private __removeElement;
30
+ /**
31
+ *
32
+ * @param {CacheElementWTinylfu<Key,Value>} element
33
+ * @param {number} [weight=element.weight]
34
+ */
35
+ remove(element: any, weight?: number): void;
36
+ /**
37
+ * Total weight of all elements in this region.
38
+ *
39
+ * @returns {number}
40
+ */
41
+ get weight(): number;
42
+ /**
43
+ *
44
+ * @param {number} delta
45
+ */
46
+ adjustWeight(delta: number): void;
47
+ /**
48
+ *
49
+ * @returns {number}
50
+ */
51
+ get maxWeight(): number;
52
+ /**
53
+ * Would the region exceed its capacity if `extraWeight` were added?
54
+ * Pass 0 (default) to test the current state.
55
+ * @param {number} [extraWeight=0]
56
+ * @returns {boolean}
57
+ */
58
+ wouldExceedCapacity(extraWeight?: number): boolean;
59
+ /**
60
+ * Empty the region. Elements are abandoned (the cache drops them from its lookup map).
61
+ */
62
+ clear(): void;
63
+ #private;
64
+ }
65
+ import { CacheElementWTinylfu } from "./CacheElementWTinylfu.js";
66
+ //# sourceMappingURL=CacheRegionWTinylfu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheRegionWTinylfu.d.ts","sourceRoot":"","sources":["../../../../../src/core/cache/wtinylfu/CacheRegionWTinylfu.js"],"names":[],"mappings":"AAIA;IA8BI;;;OAGG;IACH,4BAFW,MAAM,EAWhB;IAED;;;;OAIG;IACH,aAHW,oBAAoB,WACpB,MAAM,QAmBhB;IAED;;;OAGG;IACH,eAFW,oBAAoB,QAoB9B;IAED;;;OAGG;IACH,sBAFa,gCAA+B,GAAC,IAAI,CAIhD;IAED;;;;;OAKG;IACH,wBAcC;IAED;;;;OAIG;IACH,8BAFW,MAAM,QAMhB;IAED;;;;OAIG;IACH,qBAEC;IAED;;;OAGG;IACH,oBAFW,MAAM,QAIhB;IAED;;;OAGG;IACH,wBAEC;IAED;;;;;OAKG;IACH,kCAHW,MAAM,GACJ,OAAO,CAInB;IAED;;OAEG;IACH,cAIC;;CAEJ;qCArLkC,2BAA2B"}
@@ -0,0 +1,183 @@
1
+ import {assert} from "../../assert.js";
2
+ import {CacheElementWTinylfu} from "./CacheElementWTinylfu.js";
3
+
4
+
5
+ export class CacheRegionWTinylfu {
6
+
7
+ /**
8
+ * How much "weight" the region can hold before it starts evicting elements
9
+ * @type {number}
10
+ * @private
11
+ */
12
+ #allowedMaxWeight = Number.POSITIVE_INFINITY;
13
+
14
+ /**
15
+ *
16
+ * @type {number}
17
+ * @private
18
+ */
19
+ #currentWeight = 0;
20
+
21
+ /**
22
+ * Head (next is LRU direction, previous is MRU direction)
23
+ * @type {CacheElementWTinylfu|null}
24
+ * @private
25
+ */
26
+ #first = null;
27
+
28
+ /**
29
+ * Tail (next is LRU direction, previous is MRU direction)
30
+ * @type {CacheElementWTinylfu|null}
31
+ * @private
32
+ */
33
+ #last = null;
34
+
35
+ /**
36
+ *
37
+ * @param {number} maxWeight
38
+ */
39
+ constructor({
40
+ maxWeight = Number.POSITIVE_INFINITY
41
+ } = {}) {
42
+
43
+ assert.isNumber(maxWeight, 'maxWeight');
44
+ assert.notNaN(maxWeight, 'maxWeight');
45
+ assert.greaterThanOrEqual(maxWeight, 0, 'maxWeight < 0');
46
+
47
+ this.#allowedMaxWeight = maxWeight;
48
+ }
49
+
50
+ /**
51
+ * Add new element to this region
52
+ * @param {CacheElementWTinylfu} element
53
+ * @param {number} [weight=element.weight]
54
+ */
55
+ add(element, weight = element.weight){
56
+ assert.ok(element instanceof CacheElementWTinylfu);
57
+
58
+ // patch the element in
59
+ element.next = this.#first;
60
+
61
+ if (this.#first !== null) {
62
+ this.#first.previous = element;
63
+ }
64
+ this.#first = element;
65
+
66
+ if (this.#last === null) {
67
+ this.#last = element;
68
+ }
69
+
70
+ //update weight
71
+ this.#currentWeight += weight;
72
+ }
73
+
74
+ /**
75
+ * Update to MRU
76
+ * @param {CacheElementWTinylfu} element
77
+ */
78
+ touch(element) {
79
+ if (element === this.#first) {
80
+ // already at the front
81
+ return;
82
+ }
83
+
84
+ // update end-pointers
85
+ if (element === this.#last) {
86
+ this.#last = element.previous;
87
+ }
88
+
89
+ element.unlink(); //detach from the list
90
+
91
+ if (this.#first !== null) {
92
+ element.next = this.#first;
93
+ this.#first.previous = element;
94
+ }
95
+ this.#first = element;
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @returns {CacheElementWTinylfu<Key,Value>|null}
101
+ */
102
+ findEvictionVictim() {
103
+ return this.#last;
104
+ }
105
+
106
+ /**
107
+ *
108
+ * @param {CacheElementWTinylfu<Key,Value>} element
109
+ * @param {number} [weight=element.weight]
110
+ * @private
111
+ */
112
+ __removeElement(element, weight = element.weight) {
113
+ // remove from the queue
114
+ if (element === this.#first) {
115
+ this.#first = element.next;
116
+ }
117
+
118
+ if (element === this.#last) {
119
+ this.#last = element.previous;
120
+ }
121
+
122
+ element.unlink();
123
+
124
+ //update weight
125
+ this.#currentWeight -= weight;
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @param {CacheElementWTinylfu<Key,Value>} element
131
+ * @param {number} [weight=element.weight]
132
+ */
133
+ remove(element, weight = element.weight) {
134
+ assert.ok(element != null, "Attempted to remove undefined element");
135
+
136
+ this.__removeElement(element, weight);
137
+ }
138
+
139
+ /**
140
+ * Total weight of all elements in this region.
141
+ *
142
+ * @returns {number}
143
+ */
144
+ get weight() {
145
+ return this.#currentWeight;
146
+ }
147
+
148
+ /**
149
+ *
150
+ * @param {number} delta
151
+ */
152
+ adjustWeight(delta) {
153
+ this.#currentWeight += delta;
154
+ }
155
+
156
+ /**
157
+ *
158
+ * @returns {number}
159
+ */
160
+ get maxWeight() {
161
+ return this.#allowedMaxWeight;
162
+ }
163
+
164
+ /**
165
+ * Would the region exceed its capacity if `extraWeight` were added?
166
+ * Pass 0 (default) to test the current state.
167
+ * @param {number} [extraWeight=0]
168
+ * @returns {boolean}
169
+ */
170
+ wouldExceedCapacity(extraWeight = 0) {
171
+ return this.#currentWeight + extraWeight > this.#allowedMaxWeight;
172
+ }
173
+
174
+ /**
175
+ * Empty the region. Elements are abandoned (the cache drops them from its lookup map).
176
+ */
177
+ clear() {
178
+ this.#first = null;
179
+ this.#last = null;
180
+ this.#currentWeight = 0;
181
+ }
182
+
183
+ }