about 15% faster trie building not much but eh

also stopped using a Task for searching
This commit is contained in:
Nihaal Sharma committed 2026-03-19 10:18:13 +00:00
1 parent 4bd3442cf4
commit d64ca5cd42
2 files changed
+9 -8

No files matched your search

+5 -5
View File
@@ -34,15 +34,15 @@ struct SearchView: View {
if currentSearch != nil { if currentSearch != nil {
withAnimation { currentSearch?.cancel() } withAnimation { currentSearch?.cancel() }
} }
currentSearch = Task { // currentSearch = Task {
let result = await hoarder.trie.search(for: searchTerm) let result = hoarder.trie.search(for: searchTerm)
guard !Task.isCancelled else { return } guard !Task.isCancelled else { return }
await MainActor.run { // await MainActor.run {
withAnimation(.snappy) { withAnimation(.snappy) {
searchResult = result searchResult = result
} }
} // }
} // }
} }
} }
} }
+4 -3
View File
@@ -18,11 +18,12 @@ class Trie: ObservableObject {
var root: TrieNode = TrieNode() var root: TrieNode = TrieNode()
var dict: [String:Emoji] = [:] var dict: [String:Emoji] = [:]
var wordlist: [String] = [] var wordlist: Set<String> = []
// var previousSearchTerm
func insert(word: String) { func insert(word: String) {
let word = word.lowercased() let word = word.lowercased()
wordlist.append(word) wordlist.insert(word)
var currentNode = root var currentNode = root
let indices = word.indices let indices = word.indices
let last = indices.last let last = indices.last
@@ -42,7 +43,7 @@ class Trie: ObservableObject {
} }
func search(for query: String) -> [String] { func search(for query: String) -> [String] {
var result: Set<String> = Set(wordlist) var result: Set<String> = wordlist
for word in query.split(separator: " ") { for word in query.split(separator: " ") {
result = result.filter { $0.localizedCaseInsensitiveContains(word) } result = result.filter { $0.localizedCaseInsensitiveContains(word) }
} }
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.