fix bug in trie
This commit is contained in:
parent
3b8548e9af
commit
29c7b6af61
2 changed files with 9 additions and 4 deletions
|
|
@ -182,12 +182,12 @@ const __suggest = (trie, path, remaining, maxSuggestions) => {
|
|||
return results;
|
||||
}
|
||||
|
||||
const [pos, prefix] = binarySearch(trie.children, remaining);
|
||||
if (prefix.length === 0) {
|
||||
return []; // nothing in common
|
||||
}
|
||||
const [pos] = binarySearch(trie.children, remaining);
|
||||
if (pos < trie.children.length) {
|
||||
const [haveKey, haveChildNode] = trie.children[pos];
|
||||
if (!remaining.startsWith(haveKey) && !haveKey.startsWith(remaining)) {
|
||||
return [];
|
||||
}
|
||||
return __suggest(haveChildNode, path+haveKey, remaining.slice(haveKey.length), maxSuggestions);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,3 +100,8 @@ assert.deepEqual(
|
|||
suggest(bigTrie)("ooo")(2),
|
||||
[]
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
suggest(bigTrie)("df")(2),
|
||||
[]
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue