mirror of
git://jb55.com/damus
synced 2024-09-19 19:46:51 +00:00
Fix bug with Trie search
Exact matches were not being returned first in the array of results Signed-off-by: Terry Yiu <git@tyiu.xyz> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
7d49d3d9f1
commit
0c0c58c0cc
@ -50,18 +50,18 @@ extension Trie {
|
||||
}
|
||||
|
||||
// Perform breadth-first search from matching branch and collect values from all descendants.
|
||||
var exactMatches = Set<V>()
|
||||
var substringMatches = Set<V>()
|
||||
var queue = [currentNode]
|
||||
let exactMatches = Array(currentNode.exactMatchValues)
|
||||
var substringMatches = Set<V>(currentNode.substringMatchValues)
|
||||
var queue = Array(currentNode.children.values)
|
||||
|
||||
while !queue.isEmpty {
|
||||
let node = queue.removeFirst()
|
||||
exactMatches.formUnion(node.exactMatchValues)
|
||||
substringMatches.formUnion(node.exactMatchValues)
|
||||
substringMatches.formUnion(node.substringMatchValues)
|
||||
queue.append(contentsOf: node.children.values)
|
||||
}
|
||||
|
||||
return Array(exactMatches) + substringMatches
|
||||
return exactMatches + substringMatches
|
||||
}
|
||||
|
||||
/// Inserts value of type V into this trie for the specified key. This function stores all substring endings of the key, not only the key itself.
|
||||
|
Loading…
Reference in New Issue
Block a user