mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 05:19:13 +00:00
updating the ui
restTrie function build trie and searching trie tests
This commit is contained in:
@@ -35,27 +35,34 @@ struct TrieTestingView: View {
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
|
||||
TextField("", text: $searchTerm)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.border(.orange)
|
||||
.onChange(of: searchTerm) { _ in
|
||||
searchStatus = hoarder.trie.search(for: searchTerm)
|
||||
HStack {
|
||||
TextField("", text: $searchTerm)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.border(.orange)
|
||||
.onChange(of: searchTerm) { _ in
|
||||
searchStatus = hoarder.trie.search(for: searchTerm)
|
||||
}
|
||||
if let searchStatus {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(searchStatus ? .green : .red)
|
||||
} else {
|
||||
Text("?")
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
if let searchStatus {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(searchStatus ? .green : .red)
|
||||
}
|
||||
|
||||
TextField("", text: $filterTerm)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.border(.orange)
|
||||
.onChange(of: filterTerm) { _ in
|
||||
withAnimation { filterResult = hoarder.trie.search(prefix: filterTerm) }
|
||||
}
|
||||
Text("\(filterResult.count)")
|
||||
.modifier(numericTextCompat())
|
||||
|
||||
HStack {
|
||||
TextField("", text: $filterTerm)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.border(.orange)
|
||||
.onChange(of: filterTerm) { _ in
|
||||
withAnimation { filterResult = hoarder.trie.search(prefix: filterTerm) }
|
||||
}
|
||||
Text("\(filterResult.count)")
|
||||
.modifier(numericTextCompat())
|
||||
}
|
||||
|
||||
if uikit {
|
||||
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
||||
.id(filterResult)
|
||||
|
||||
@@ -67,6 +67,13 @@ class EmojiHoarder: ObservableObject {
|
||||
try! data.write(to: EmojiHoarder.localEmojiDB)
|
||||
}
|
||||
|
||||
func resetTrie() {
|
||||
trie.root = TrieNode()
|
||||
trie.dict = [:]
|
||||
downloadedEmojis = []
|
||||
filteredEmojis = []
|
||||
}
|
||||
|
||||
func buildTrie() {
|
||||
let start = Date().timeIntervalSince1970
|
||||
trie.root = TrieNode()
|
||||
|
||||
@@ -127,4 +127,17 @@ struct PerformanceTests {
|
||||
try! await fakeDownloadAllStickers()
|
||||
await hoarder.deleteAllStickers()
|
||||
}
|
||||
|
||||
@Test func buildTrie() async throws {
|
||||
hoarder.resetTrie()
|
||||
hoarder.buildTrie()
|
||||
}
|
||||
|
||||
@Test func testSearching() async throws {
|
||||
try! await buildTrie()
|
||||
let terms = ["h", "j", "s", "2", "heavysob", "hs", "asjasdklf", "a", "w", "t", "h", "z", "b", "c", "m", "n"]
|
||||
for term in terms {
|
||||
let _ = hoarder.trie.search(prefix: term)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user