"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PatternScanner = void 0;
/**
 * Stateful helper for incremental pattern scanning in growing buffers.
 *
 * The scanner tracks a `searchFrom` cursor and an `overlap` region so callers
 * can avoid rescanning bytes that cannot start a match.
 */
class PatternScanner {
    constructor(pattern) {
        this.searchFrom = 0;
        this.pattern = pattern;
        this.overlap = Math.max(0, pattern.length - 1);
    }
    /** Find the next match index starting at the current `searchFrom`. */
    find(target) {
        return target.indexOfPattern(this.pattern, this.searchFrom);
    }
    /** Update `searchFrom` after consuming `consumed` bytes from the front. */
    onConsume(consumed) {
        if (consumed > 0) {
            this.searchFrom = Math.max(0, this.searchFrom - consumed);
        }
    }
    /** Update `searchFrom` after a no-match scan on a buffer of length `bufferLength`. */
    onNoMatch(bufferLength) {
        this.searchFrom = Math.max(this.searchFrom, Math.max(0, bufferLength - this.overlap));
    }
}
exports.PatternScanner = PatternScanner;
