Aho_corasick.StreamScan input arriving in chunks (sockets, files) without concatenating: matches spanning chunk boundaries are found, and offsets are absolute across everything fed so far.
Always use the same automaton that created a state. Empty chunks are allowed. Returned states are immutable; keep the new state to advance the stream. Offsets must fit in an OCaml int.
Three match modes are available:
Stream.feed reports every match, overlapping included — find_all, chunked.Stream.feed_nonoverlapping reports non-overlapping matches with earliest-end selection and no input buffering.Stream.Leftmost_longest and Stream.Replace stream the find_leftmost_longest / replace_all selection, using lookahead bounded by the longest pattern.Immutable scanning position; keep the value returned by feed.
feed t st chunk scans chunk, returning the advanced state and the matches whose last byte lies in chunk (offsets are absolute). Every match is reported, overlapping ones included, as soon as its final byte is seen; there is never anything to flush.
Like feed, but non-overlapping, preferring the match that ends first: whenever one or more matches end, the longest of them is reported and scanning restarts immediately after it, so no later match overlaps it. Zero latency and nothing to flush, like feed. Equal-length ties use the lowest pattern index. With patterns ["Samwise"; "Sam"] and input "Samwise", the one match is Sam.
Feed any given stream exclusively with feed or exclusively with feed_nonoverlapping: both advance the same state type, but the restart-after-match discipline only makes sense applied to the whole stream.
val pos : state -> intTotal bytes fed so far.
module Leftmost_longest : sig ... endNon-overlapping leftmost-longest matches — the find_leftmost_longest selection, streamed.
module Replace : sig ... endreplace_all, streamed: each Leftmost_longest match m is replaced by f m, everything else passes through unchanged.