A fairly roundabout method for SO for crosswords was proposed.
It can be adapted here quite easily :)
The idea is simple, but quite effective: it consists in indexing words, building one index per letter position. It should be noted that after 4/5 letters, the subset of available words is so small that brute force is probably best ... this, of course, needs to be measured.
As for the idea, there is a Python way here:
class AutoCompleter: def __init__(self, words): self.words = words self.map = defaultdict(set) self._map() def _map(self): for w in words: for i in range(0,len(w)): self.map[(i,w[i])].insert(w) def words(self, firstLetters):
The memory requirement is quite strict: one entry for each letter in each position. However, the entry means that the word exists with a letter in this position, which does not apply to everyone.
The speed seems to be good if you want to automatically fill in a 3-letter word (the classic threshold for starting autocompletion):
- 3 hash search
- 2 intersections of sets (definitely one spot), but ordered as efficient as possible.
I would definitely need to try this against the triple tree and approach to see how it works.
source share