So, I did a whole series on word search algorithms. Guess what turns out to work well enough? Just walking the entire list of words.
I put in a 500ms delay to debounce the input, and walking the entire list of words takes less time than that. I had wondered if this was the case so I tried it out before implementing a suffix tree lookup.
And I don't even think my Javascript code is all that efficient at doing the search, either.
vm.searchSync = function() {
var start = performance.now();
vm.words = [];
var searchLetters = Array.from( vm.searchCap );
var allWords = vm.dictionary['wordList'];
for (var w = 0; w < allWords.length; ++w) {
var word = allWords[w];
if ( searchLetters.length < word.length ) {
var letters = Array.from( word );
letters.sort();
var i = 0;
var j = 0;
var notPresent = false;
while ( i < searchLetters.length ) {
if ( j >= letters.length ) {
notPresent = true;
break;
}
if ( searchLetters[i] == letters[j] ) {
i += 1;
j += 1;
} else if ( searchLetters[i] > letters[j] ) {
j += 1;
} else {
notPresent = true;
break;
}
}
if (!notPresent) {
vm.words.push( word );
if ( vm.words.length > 100 ) {
break;
}
}
}
}
var end = performance.now();
vm.lastSearch = end - start;
}