MCPcopy Create free account
hub / github.com/ChartGPU/ChartGPU / countExtremaRetainedWithinWindow

Function countExtremaRetainedWithinWindow

examples/acceptance/lttb-sample.ts:115–140  ·  view source on GitHub ↗
(
  extremaIndices: Int32Array,
  sampledIndices: Int32Array,
  windowHalfWidth: number,
)

Source from the content-addressed store, hash-verified

113}
114
115function countExtremaRetainedWithinWindow(
116 extremaIndices: Int32Array,
117 sampledIndices: Int32Array,
118 windowHalfWidth: number,
119): number {
120 let retained = 0;
121 for (let e = 0; e < extremaIndices.length; e++) {
122 const idx = extremaIndices[e]!;
123
124 // "Within window" definition:
125 // - exact retention passes
126 // - otherwise, allow the sampled point to land within +/- windowHalfWidth indices
127 // around the extremum (a "bucket-sized window" tolerance).
128 let ok = false;
129 for (let s = 0; s < sampledIndices.length; s++) {
130 const j = sampledIndices[s]!;
131 const d = j - idx;
132 if (d === 0 || (d <= windowHalfWidth && d >= -windowHalfWidth)) {
133 ok = true;
134 break;
135 }
136 }
137 if (ok) retained++;
138 }
139 return retained;
140}
141
142{
143 const N = 100_000;

Callers 1

lttb-sample.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected