pub fn prefix_table(needle: &[u8]) -> Vec<usize> {
let mut table = vec![0; needle.len()];
let mut matched = 0usize;
for index in 1..needle.len() {
while matched > 0 && needle[index] != needle[matched] {
matched = table[matched - 1];
}
if needle[index] == needle[matched] {
matched += 1;
table[index] = matched;
}
}
table
}