kmpSearch
Retorna todos os offsets byte zero-based onde pattern ocorre em text. Um padrão vazio ocorre em cada limite, então o resultado contém offsets de 0 até text.length.
tyrus
import { kmpSearch } from "tyrus:algorithm";
const matches: usize[] = kmpSearch("ababa", "aba");
print(matches[0], matches[1]); // 0 2Resultado para estudo
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); // 0O algoritmo executa em O(n + m) e usa espaço auxiliar O(m).
