Also for anyone else reading this, Frank Liang's thesis "Word Hy-phen-a-tion by Com-put-er" (https://tug.org/docs/liang/) is a great read, and the data structure it uses (packed tries) is clever too. The section of the TeX program that describes hyphenation is also an interesting read, and Knuth added a further twist (what we may call a hash-packed trie) in his frequent-words literate program for Bentley's column.