update trietestingview

made uikit list view have updated emojirow
made reindexing 5x faster by making it not recompute container location
This commit is contained in:
neon443 committed 2026-03-14 22:43:31 +00:00
1 parent 7d6bad2f69
commit de9fbf0b12
5 files changed
+88 -62

No files matched your search

+1
View File
@@ -12,6 +12,7 @@ import UniformTypeIdentifiers
import Haptics
class EmojiHoarder: Hoarder, ObservableObject {
static let container: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
nonisolated static let localEmojiDB: URL = EmojiHoarder.container.appendingPathComponent("_localEmojiDB.json", conformingTo: .fileURL)
nonisolated static let localTrie: URL = EmojiHoarder.container.appendingPathComponent("_localTrie.json", conformingTo: .fileURL)
nonisolated static let localTrieDict: URL = EmojiHoarder.container.appendingPathComponent("_localTrieDict.json", conformingTo: .fileURL)
+3
View File
@@ -7,9 +7,12 @@
import Foundation
import SwiftUI
import UniformTypeIdentifiers
import Combine
class GifHoarder: Hoarder, ObservableObject {
static let container: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
var endpoint: URL = URL(string: "api.giphy.com/v1/gifs/trending")!
var endpointSearch: URL = URL(string: "api.giphy.com/v1/gifs/search")!
-3
View File
@@ -22,9 +22,6 @@ protocol Hoarder {
}
extension Hoarder {
static var container: URL { FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
}
var encoder: JSONEncoder { JSONEncoder() }
var decoder: JSONDecoder { JSONDecoder() }
}
+82 -38
View File
@@ -10,67 +10,110 @@ import SwiftUI
struct TrieTestingView: View {
@ObservedObject var hoarder: EmojiHoarder
@State var searchTerm: String = ""
@State var searchStatus: Bool? = nil
@State var filterTerm: String = ""
@State var filterResult: [String] = []
@State var filterTerm2: String = ""
@State var uikit: Bool = false
@State private var searchType: SearchType = .contains
private enum SearchType: String, CaseIterable {
case trie = "trie"
case contains = "contains"
case exact = "exact"
}
private func runSearch() {
filterResult = []
searchStatus = nil
guard !filterTerm.isEmpty else { return }
switch searchType {
case .trie:
withAnimation(.snappy) {
filterResult = hoarder.trie.search(prefix: filterTerm)
}
print("testing: trie search")
case .contains:
withAnimation(.snappy) {
filterResult = hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(filterTerm) }).map({ $0.name })
}
print("testing: contains search")
case .exact:
withAnimation(.snappy) {
searchStatus = hoarder.trie.search(for: filterTerm)
}
print("testing: exact search")
}
}
var body: some View {
VStack {
Toggle("uikit!!", isOn: $uikit)
.foregroundStyle(.blue)
Button("reset", role: .destructive) {
hoarder.resetAllIndexes()
}
Button("add emojis!") {
hoarder.buildTrie()
}
.buttonStyle(.borderedProminent)
HStack {
TextField("", text: $searchTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
.onChange(of: searchTerm) { _ in
searchStatus = hoarder.trie.search(for: searchTerm)
Button("reset", role: .destructive) {
hoarder.resetAllIndexes()
}
Spacer()
Button("add emojis!") {
hoarder.buildTrie()
}
.buttonStyle(.borderedProminent)
}
Picker("", selection: $searchType) {
ForEach(SearchType.allCases, id: \.self) { typee in
Text(typee.rawValue).tag(typee)
}
}
.pickerStyle(.segmented)
.onChange(of: searchType) { _ in
runSearch()
}
.onChange(of: filterTerm) { _ in
runSearch()
}
if searchType == .exact {
HStack {
TextField("", text: $filterTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
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)
} else {
Text("?")
.frame(width: 20, height: 20)
}
}
HStack {
TextField("", text: $filterTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
.onChange(of: filterTerm) { _ in
withAnimation(.snappy) { filterResult = hoarder.trie.search(prefix: filterTerm) }
}
Text("\(filterResult.count)")
.modifier(numericTextCompat())
if searchType == .trie {
HStack {
TextField("", text: $filterTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
Text("\(filterResult.count)")
.modifier(numericTextCompat())
}
}
TextField("", text: $filterTerm2)
.textFieldStyle(.roundedBorder)
.border(.orange)
.onChange(of: filterTerm2) { _ in
withAnimation(.snappy) { filterResult = hoarder.emojis.filter({ $0.name.localizedCaseInsensitiveContains(filterTerm2) }).map({ $0.name }) }
if searchType == .contains {
HStack {
TextField("", text: $filterTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
Text("\(filterResult.count)")
.modifier(numericTextCompat())
}
}
if uikit {
EmojiCollectionView(hoarder: hoarder, items: filterResult)
.id(filterResult)
} else {
List(filterResult, id: \.self) { item in
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
@@ -79,6 +122,7 @@ struct TrieTestingView: View {
Text("\(hoarder.trie.root.children.count)")
}
.padding(.horizontal)
}
}
+2 -21
View File
@@ -50,27 +50,8 @@ struct EmojiCollectionView: UIViewRepresentable {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.contentConfiguration = UIHostingConfiguration {
HStack {
EmojiPreview(
hoarder: hoarder,
emoji: emoji
)
.frame(maxWidth: 100, maxHeight: 100)
Spacer()
if hoarder.downloadedEmojis.contains(emojiName) {
Button("", systemImage: "trash") {
fatalError()
}
.buttonStyle(.plain)
} else {
Button("", systemImage: "arrow.down.circle") {
Task {
await self.hoarder.download(emoji: emoji)
}
}
.buttonStyle(.plain)
}
}
EmojiRow(hoarder: hoarder, emoji: emoji)
.id(emoji)
}
return cell
}
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.