diff --git a/lib/util/trie.js b/lib/util/trie.js index a98f6b1..8bc5966 100644 --- a/lib/util/trie.js +++ b/lib/util/trie.js @@ -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 []; }