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) {
|
if (maxSuggestions === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (remaining === "") {
|
|
||||||
|
if (remaining === '') {
|
||||||
const results = [];
|
const results = [];
|
||||||
if (trie.value !== undefined) {
|
if (trie.value !== undefined) {
|
||||||
results.push([path, trie.value]);
|
results.push([path, trie.value]);
|
||||||
|
|
@ -152,9 +153,12 @@ const __suggest = (trie, path, remaining, maxSuggestions) => {
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [pos, prefix] = binarySearch(trie.children, remaining);
|
const [pos, prefix] = binarySearch(trie.children, remaining);
|
||||||
if (prefix.length === haveKey.length) {
|
if (pos < trie.children.length) {
|
||||||
return __suggest(haveChildNode, path+haveKey, remaining.slice(haveKey.length), maxSuggestions)
|
const [haveKey, haveChildNode] = trie.children[pos];
|
||||||
|
return __suggest(haveChildNode, path+haveKey, remaining.slice(haveKey.length), maxSuggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue