kmpSearch
Returns every zero-based byte offset where pattern occurs in text. An empty pattern matches at every boundary, so the result contains offsets from 0 through text.length.
tyrus
import { kmpSearch } from "tyrus:algorithm";
const matches: usize[] = kmpSearch("ababa", "aba");
print(matches[0], matches[1]); // 0 2Study result
tyrus
interface KmpSearchInfo {
text: string;
pattern: string;
matches: usize[];
comparisonCount: usize;
shiftCount: usize;
prefixTable: usize[];
prefixFallbackCount: usize;
}tyrus
import { KmpSearchInfo, StringSearchInfo, kmpSearchInfo } from "tyrus:algorithm";
const info: KmpSearchInfo = kmpSearchInfo("ababa", "aba");
print(info.text); // ababa
print(info.pattern); // aba
print(info.matches); // [0, 2]
print(info.comparisonCount); // 7
print(info.shiftCount); // 5
print(info.prefixTable); // [0, 0, 1]
print(info.prefixFallbackCount); // 0The algorithm runs in O(n + m) time and uses O(m) auxiliary space.
