fix Trie.suggest (for real this time?)

This commit is contained in:
Joeri Exelmans 2025-05-10 19:51:00 +02:00
parent 660512cc19
commit 075cc1244f

View file

@ -136,7 +136,8 @@ const __suggest = (trie, path, remaining, maxSuggestions) => {
if (maxSuggestions === 0) {
return [];
}
if (remaining === "") {
if (remaining === '') {
const results = [];
if (trie.value !== undefined) {
results.push([path, trie.value]);
@ -152,9 +153,12 @@ const __suggest = (trie, path, remaining, maxSuggestions) => {
}
return results;
}
const [pos, prefix] = binarySearch(trie.children, remaining);
if (prefix.length === haveKey.length) {
return __suggest(haveChildNode, path+haveKey, remaining.slice(haveKey.length), maxSuggestions)
if (pos < trie.children.length) {
const [haveKey, haveChildNode] = trie.children[pos];
return __suggest(haveChildNode, path+haveKey, remaining.slice(haveKey.length), maxSuggestions);
}
return [];
}