new contains searching algo

also fix animations on list
This commit is contained in:
neon443 committed 2026-03-14 23:11:38 +00:00
1 parent de9fbf0b12
commit 02fe170563
1 file changed
+18 -7
+18 -7
View File
@@ -35,10 +35,22 @@ struct TrieTestingView: View {
} }
print("testing: trie search") print("testing: trie search")
case .contains: case .contains:
withAnimation(.snappy) { Task.detached {
filterResult = hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(filterTerm) }).map({ $0.name }) var results: [[Emoji]] = []
var result: [Emoji] = []
for word in filterTerm.split(separator: " ") {
results.append(hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(word) }))
}
result = results.reduce(results[0]) { partialResult, array in
partialResult.filter { array.contains($0) }
}
await MainActor.run {
withAnimation(.snappy) {
filterResult = result.map { $0.name }
}
print("testing: contains search")
}
} }
print("testing: contains search")
case .exact: case .exact:
withAnimation(.snappy) { withAnimation(.snappy) {
searchStatus = hoarder.trie.search(for: filterTerm) searchStatus = hoarder.trie.search(for: filterTerm)
@@ -69,10 +81,7 @@ struct TrieTestingView: View {
} }
} }
.pickerStyle(.segmented) .pickerStyle(.segmented)
.onChange(of: searchType) { _ in .onChange(of: searchType.rawValue+filterTerm) { _ in
runSearch()
}
.onChange(of: filterTerm) { _ in
runSearch() runSearch()
} }
@@ -114,10 +123,12 @@ struct TrieTestingView: View {
if uikit { if uikit {
EmojiCollectionView(hoarder: hoarder, items: filterResult) EmojiCollectionView(hoarder: hoarder, items: filterResult)
.animation(.snappy, value: filterResult)
} else { } else {
List(filterResult, id: \.self) { item in List(filterResult, id: \.self) { item in
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!) EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
} }
.animation(.snappy, value: filterResult)
} }
Text("\(hoarder.trie.root.children.count)") Text("\(hoarder.trie.root.children.count)")
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.