I just wanted to share my implementation of the algorithm in zig. I tried moving things around to program without pointers but there are still some. I think if was fun and it had the unexpected advantage of using Node enum as a key for the words map where I store leaf nodes and the whole word.
There are speed and space optimization I could do but overall I am happy user.
There are also Guard and StateMachine structs that I added later but would have been more helpful had they were at the beginning. Guard is used to limit while loops and StateMachine is just all the printing options in one place so I don’t jump around switching flags. I thought of reading it from a file with reader.readStruct but don’t have experience with it so maybe for next time.
opinions about style and implementation are welcome.
Nice, Aho Corasick is really fun to learn about/implement.
I also did similar stuff backin in December/January for a (now abandoned) project.
After lots of time and based on this paper: https://arxiv.org/pdf/2207.13870 I eventually did end up with a more “Programmin without pointers” approach.
If you’re interested in some overly generic, undocumented code I put it here The Zig Pastebin (There are two implementations there BasicAhoCorasick which is more similar to yours and DoubleArrayAhoCorasick which follows the paper).