/** * SpeculativeEvaluator -- threshold proximity prefetching. * * When a boundary signal is near a threshold, pre-compute the next state. * Uses hysteresis dead zone as the prefetch window and linear extrapolation * from velocity (last 3-4 signal values) to predict crossings. * * Wrong prediction cost: ~80ns to recompute (negligible). * * @module */ import { Boundary } from './boundary.js'; import type { StateUnion } from './type-utils.js'; import { type Clock } from './clock.js'; interface SpeculativeResult { readonly current: StateUnion; readonly prefetched?: StateUnion; readonly confidence: number; } interface SpeculativeEvaluatorShape { evaluate(value: number, velocity?: number): SpeculativeResult; } /** * Creates a speculative evaluator for a boundary that prefetches the next state * when the signal value is near a threshold and moving toward it. * * @example * ```ts * const boundary = Boundary.make({ * thresholds: [768, 1024], * states: ['mobile', 'tablet', 'desktop'] as const, * hysteresis: 20, * }); * const spec = SpeculativeEvaluator.make(boundary); * const result = spec.evaluate(760, 2.0); // approaching 768 threshold * result.current; // 'mobile' * result.prefetched; // 'tablet' (pre-computed) * result.confidence; // 0.0-1.0 likelihood of crossing * ``` */ declare function _make(boundary: B, clock?: Clock): SpeculativeEvaluatorShape; /** * SpeculativeEvaluator -- threshold proximity prefetching for boundaries. * Pre-computes the next discrete state when a signal is near a threshold, * using velocity estimation and hysteresis-based prefetch windows. * * @example * ```ts * const boundary = Boundary.make({ * thresholds: [600], * states: ['small', 'large'] as const, * }); * const spec = SpeculativeEvaluator.make(boundary); * const { current, prefetched, confidence } = spec.evaluate(595, 1.5); * // current='small', prefetched='large', confidence ~0.85 * ``` */ export declare const SpeculativeEvaluator: { make: typeof _make; }; export declare namespace SpeculativeEvaluator { /** Structural shape of an evaluator bound to a specific {@link Boundary}. */ type Shape = SpeculativeEvaluatorShape; /** Prediction result from `evaluate()` — current state, optional prefetched next state, and confidence. */ type Result = SpeculativeResult; } export {}; //# sourceMappingURL=speculative.d.ts.map