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 {
withAnimation { currentSearch?.cancel() }
}
currentSearch = Task {
let result = await hoarder.trie.search(for: searchTerm)
// currentSearch = Task {
let result = hoarder.trie.search(for: searchTerm)
guard !Task.isCancelled else { return }
await MainActor.run {
// await MainActor.run {
withAnimation(.snappy) {
searchResult = result
}
}
}
// }
// }
}
}
}
+4 -3
View File
@@ -18,11 +18,12 @@ class Trie: ObservableObject {
var root: TrieNode = TrieNode()
var dict: [String:Emoji] = [:]
var wordlist: [String] = []
var wordlist: Set<String> = []
// var previousSearchTerm
func insert(word: String) {
let word = word.lowercased()
wordlist.append(word)
wordlist.insert(word)
var currentNode = root
let indices = word.indices
let last = indices.last
@@ -42,7 +43,7 @@ class Trie: ObservableObject {
}
func search(for query: String) -> [String] {
var result: Set<String> = Set(wordlist)
var result: Set<String> = wordlist
for word in query.split(separator: " ") {
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.