damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 0c0c58c0ccf64008c6760f55812a5b7f94af16cc
parent 7d49d3d9f1ada695a6b11b0d3e0a53854f137f33
Author: Terry Yiu <git@tyiu.xyz>
Date:   Mon,  3 Jul 2023 16:32:18 -0400

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>

Diffstat:
Mdamus/Models/Trie.swift | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git 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<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.