fix Trie.suggest (for real this time?)
This commit is contained in:
parent
660512cc19
commit
075cc1244f
1 changed files with 7 additions and 3 deletions
|
|
@ -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 [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue