Aho-Korasick algorithm implementation