From b61b59ea424abdfc3fc04e962f7b37fb0da0ab7c Mon Sep 17 00:00:00 2001 From: "Dr. Brandon Wiley" Date: Thu, 29 Feb 2024 11:40:29 -0600 Subject: [PATCH 1/5] Updated Abacus iOS version --- Package.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 26874ca..1629609 100644 --- a/Package.swift +++ b/Package.swift @@ -1,11 +1,14 @@ -// swift-tools-version:5.5 +// swift-tools-version:5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "Abacus", - platforms: [.macOS(.v12)], + platforms: [ + .iOS(.v16), + .macOS(.v12) + ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( From 8bb42503d42bdcd5be3347703139939ea937bb60 Mon Sep 17 00:00:00 2001 From: consuelita Date: Wed, 16 Oct 2024 16:46:29 -0500 Subject: [PATCH 2/5] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 70b0fbf..71920d3 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package( name: "Abacus", platforms: [ .iOS(.v16), - .macOS(.v13) + .macOS(.v14) ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. From 95b6740311434e684833382c6334e98d57bd61d5 Mon Sep 17 00:00:00 2001 From: "Dr. Brandon Wiley" Date: Sat, 19 Oct 2024 13:56:16 -0500 Subject: [PATCH 3/5] Equatable and Hashable for OrderedSet and OrderedDictionary --- Sources/Abacus/OrderedDictionary.swift | 35 +++++++++++++++++++++++++- Sources/Abacus/OrderedSet.swift | 8 ++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Sources/Abacus/OrderedDictionary.swift b/Sources/Abacus/OrderedDictionary.swift index 2da1795..c73678c 100644 --- a/Sources/Abacus/OrderedDictionary.swift +++ b/Sources/Abacus/OrderedDictionary.swift @@ -7,7 +7,7 @@ import Foundation -public class OrderedDictionary where Key: Hashable +public class OrderedDictionary where Key: Equatable, Key: Hashable, Value: Equatable, Value: Hashable { public typealias Key = Key public typealias Value = Value @@ -88,3 +88,36 @@ public class OrderedDictionary where Key: Hashable } } } + +extension OrderedDictionary: Equatable +{ + public static func ==(lhs: OrderedDictionary, rhs: OrderedDictionary) -> Bool + { + guard lhs.orderedKeys == rhs.orderedKeys else + { + return false + } + + for key in lhs.orderedKeys.array + { + let lvalue = lhs.dictionary[key] + let rvalue = rhs.dictionary[key] + + guard lvalue == rvalue else + { + return false + } + } + + return true + } +} + +extension OrderedDictionary: Hashable +{ + public func hash(into hasher: inout Hasher) + { + hasher.combine(self.dictionary) + hasher.combine(self.orderedKeys) + } +} diff --git a/Sources/Abacus/OrderedSet.swift b/Sources/Abacus/OrderedSet.swift index b5830a6..5018409 100644 --- a/Sources/Abacus/OrderedSet.swift +++ b/Sources/Abacus/OrderedSet.swift @@ -57,3 +57,11 @@ extension OrderedSet: Equatable return lhs.array == rhs.array } } + +extension OrderedSet: Hashable +{ + public func hash(into hasher: inout Hasher) + { + hasher.combine(self.array) + } +} From 845a8518b5d18df1046db578aed01f3409dcec27 Mon Sep 17 00:00:00 2001 From: "Dr. Brandon Wiley" Date: Sat, 19 Oct 2024 14:02:35 -0500 Subject: [PATCH 4/5] Made OrderedDictionary API public --- Sources/Abacus/OrderedDictionary.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Abacus/OrderedDictionary.swift b/Sources/Abacus/OrderedDictionary.swift index c73678c..020ceee 100644 --- a/Sources/Abacus/OrderedDictionary.swift +++ b/Sources/Abacus/OrderedDictionary.swift @@ -32,30 +32,30 @@ public class OrderedDictionary where Key: Equatable, Key: Hashable, V } } - func set(key: Key, value: Value) + public func set(key: Key, value: Value) { self.dictionary[key] = value self.orderedKeys.add(key) } - func get(key: Key) -> Value? + public func get(key: Key) -> Value? { return self.dictionary[key] } - func remove(key: Key) + public func remove(key: Key) { guard self.orderedKeys.contains(key) else {return} self.dictionary.removeValue(forKey: key) self.orderedKeys.remove(key) } - func keys() -> [Key] + public func keys() -> [Key] { return self.orderedKeys.array } - func set(index: Int, value: Value) -> Bool + public func set(index: Int, value: Value) -> Bool { guard let key = self.orderedKeys.get(index) else {return false} self.dictionary[key] = value @@ -63,13 +63,13 @@ public class OrderedDictionary where Key: Equatable, Key: Hashable, V return true } - func get(index: Int) -> Value? + public func get(index: Int) -> Value? { guard let key = self.orderedKeys.get(index) else {return nil} return self.dictionary[key] } - func remove(index: Int) -> Bool + public func remove(index: Int) -> Bool { guard let key = self.orderedKeys.get(index) else {return false} self.dictionary.removeValue(forKey: key) @@ -78,7 +78,7 @@ public class OrderedDictionary where Key: Equatable, Key: Hashable, V return true } - func values() -> [Value] + public func values() -> [Value] { return self.orderedKeys.array.compactMap { From 44ad10a576f92f82a9cdd6747e5937998964aad5 Mon Sep 17 00:00:00 2001 From: "Dr. Brandon Wiley" Date: Wed, 30 Oct 2024 16:42:53 -0500 Subject: [PATCH 5/5] public init on Bijection --- Sources/Abacus/Bijection.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/Abacus/Bijection.swift b/Sources/Abacus/Bijection.swift index f5a0aa2..ba0557d 100644 --- a/Sources/Abacus/Bijection.swift +++ b/Sources/Abacus/Bijection.swift @@ -12,6 +12,16 @@ public class Bijection where S: Hashable, T: Hashable var leftward: [T: S] = [:] var rightward: [S: T] = [:] + public init() + { + } + + public init(leftward: [T : S], rightward: [S : T]) + { + self.leftward = leftward + self.rightward = rightward + } + public func set(_ s: S, _ t: T) throws { guard !rightward.keys.contains(s) else