From 0dd4c019888a79ad735927dc4679b4930f62d92e Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 26 Apr 2022 09:45:32 +0800 Subject: [PATCH] Repo // +KeyValueStructs. --- .../LangModelRelated/KeyValueStructs.swift | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Source/Modules/LangModelRelated/KeyValueStructs.swift diff --git a/Source/Modules/LangModelRelated/KeyValueStructs.swift b/Source/Modules/LangModelRelated/KeyValueStructs.swift new file mode 100644 index 00000000..6897b960 --- /dev/null +++ b/Source/Modules/LangModelRelated/KeyValueStructs.swift @@ -0,0 +1,63 @@ +// Copyright (c) 2021 and onwards The vChewing Project (MIT-NTL License). +/* +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +1. The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +2. No trademark license is granted to use the trade names, trademarks, service +marks, or product names of Contributor, except as required to fulfill notice +requirements above. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +import Foundation + +extension vChewing { + @frozen public struct KeyValue: Equatable { + var key: String + var value: String + + public init(key: String = "", value: String = "") { + self.key = key + self.value = value + } + + public static func == (lhs: KeyValue, rhs: KeyValue) -> Bool { + lhs.key == rhs.key && lhs.value == rhs.value + } + } + + @frozen public struct KeyValueRate: Equatable { + var key: String + var value: String + var rate: Double + + public init(key: String = "", value: String = "", rate: Double = 0.0) { + self.key = key + self.value = value + self.rate = rate + } + + public init(keyValue: KeyValue = KeyValue(key: "", value: ""), rate: Double = 0.0) { + key = keyValue.key + value = keyValue.value + self.rate = rate + } + + public static func == (lhs: KeyValueRate, rhs: KeyValueRate) -> Bool { + lhs.key == rhs.key && lhs.value == rhs.value && lhs.rate == rhs.rate + } + } +}