UOM // Use class in lieu of struct in certain types.

This commit is contained in:
ShikiSuen 2022-06-14 18:38:51 +08:00
parent 4f205f35f0
commit d768c12d5a
1 changed files with 14 additions and 7 deletions

View File

@ -28,28 +28,35 @@ import Foundation
extension vChewing {
public class LMUserOverride {
// MARK: - Private Structures
// class
struct Override {
class Override {
var count: Int = 0
var timestamp: Double = 0.0
}
struct Observation {
class Observation {
var count: Int = 0
var overrides: [String: Override] = [:]
mutating func update(candidate: String, timestamp: Double) {
func update(candidate: String, timestamp: Double) {
count += 1
if var neta = overrides[candidate] {
if let neta = overrides[candidate] {
neta.timestamp = timestamp
neta.count += 1
overrides[candidate] = neta
}
}
}
struct KeyObservationPair {
class KeyObservationPair {
var key: String
var observation: Observation
init(key: String, observation: Observation) {
self.key = key
self.observation = observation
}
}
// MARK: - Main
@ -74,7 +81,7 @@ extension vChewing {
let key = convertKeyFrom(walkedNodes: walkedNodes, cursorIndex: cursorIndex)
guard mutLRUMap[key] != nil else {
var observation: Observation = .init()
let observation: Observation = .init()
observation.update(candidate: candidate, timestamp: timestamp)
let koPair = KeyObservationPair(key: key, observation: observation)
mutLRUMap[key] = koPair
@ -87,7 +94,7 @@ extension vChewing {
IME.prtDebugIntel("UOM: Observation finished with new observation: \(key)")
return
}
if var theNeta = mutLRUMap[key] {
if let theNeta = mutLRUMap[key] {
theNeta.observation.update(candidate: candidate, timestamp: timestamp)
mutLRUList.insert(theNeta, at: 0)
mutLRUMap[key] = theNeta