kmpSearch
Devuelve todos los offsets de byte zero-based donde pattern aparece en text. Un patrón vacío coincide en cada límite, por lo que el resultado contiene offsets de 0 a text.length.
tyrus
import { kmpSearch } from "tyrus:algorithm";
const matches: usize[] = kmpSearch("ababa", "aba");
print(matches[0], matches[1]); // 0 2Resultado para estudio
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); // 0El algoritmo se ejecuta en O(n + m) y usa espacio auxiliar O(m).
