mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 13:26:17 +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)
|
.buttonStyle(.borderedProminent)
|
||||||
|
|
||||||
TextField("", text: $searchTerm)
|
HStack {
|
||||||
.textFieldStyle(.roundedBorder)
|
TextField("", text: $searchTerm)
|
||||||
.border(.orange)
|
.textFieldStyle(.roundedBorder)
|
||||||
.onChange(of: searchTerm) { _ in
|
.border(.orange)
|
||||||
searchStatus = hoarder.trie.search(for: searchTerm)
|
.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)
|
HStack {
|
||||||
.textFieldStyle(.roundedBorder)
|
TextField("", text: $filterTerm)
|
||||||
.border(.orange)
|
.textFieldStyle(.roundedBorder)
|
||||||
.onChange(of: filterTerm) { _ in
|
.border(.orange)
|
||||||
withAnimation { filterResult = hoarder.trie.search(prefix: filterTerm) }
|
.onChange(of: filterTerm) { _ in
|
||||||
}
|
withAnimation { filterResult = hoarder.trie.search(prefix: filterTerm) }
|
||||||
Text("\(filterResult.count)")
|
}
|
||||||
.modifier(numericTextCompat())
|
Text("\(filterResult.count)")
|
||||||
|
.modifier(numericTextCompat())
|
||||||
|
}
|
||||||
|
|
||||||
if uikit {
|
if uikit {
|
||||||
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
EmojiCollectionView(hoarder: hoarder, items: filterResult)
|
||||||
.id(filterResult)
|
.id(filterResult)
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ class EmojiHoarder: ObservableObject {
|
|||||||
try! data.write(to: EmojiHoarder.localEmojiDB)
|
try! data.write(to: EmojiHoarder.localEmojiDB)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resetTrie() {
|
||||||
|
trie.root = TrieNode()
|
||||||
|
trie.dict = [:]
|
||||||
|
downloadedEmojis = []
|
||||||
|
filteredEmojis = []
|
||||||
|
}
|
||||||
|
|
||||||
func buildTrie() {
|
func buildTrie() {
|
||||||
let start = Date().timeIntervalSince1970
|
let start = Date().timeIntervalSince1970
|
||||||
trie.root = TrieNode()
|
trie.root = TrieNode()
|
||||||
|
|||||||
@@ -127,4 +127,17 @@ struct PerformanceTests {
|
|||||||
try! await fakeDownloadAllStickers()
|
try! await fakeDownloadAllStickers()
|
||||||
await hoarder.deleteAllStickers()
|
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