diff --git a/damus/Models/Trie.swift b/damus/Models/Trie.swift index 3da3e118..f681348b 100644 --- a/damus/Models/Trie.swift +++ b/damus/Models/Trie.swift @@ -50,18 +50,18 @@ extension Trie { } // Perform breadth-first search from matching branch and collect values from all descendants. - var exactMatches = Set() - var substringMatches = Set() - var queue = [currentNode] + let exactMatches = Array(currentNode.exactMatchValues) + var substringMatches = Set(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.