From 8f7d5fd50532e883a3d59e050a17ec992827fef8 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 31 Oct 2022 15:05:12 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[SetAlgebra=20types]=20isEqual(to:)=20?= =?UTF-8?q?=E2=86=92=20isEqualSet(to:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `isEqual(to:)` methods are a bit too confusing — they implement mathematical set comparisons (ignoring element ordering and, in the case of the Sequence variant, even element multiplicities), so it seems better to highlight this by putting a `Set` in the name. --- .../Extensions/BitArray.md | 8 ++--- .../Extensions/BitSet.Counted.md | 8 ++--- .../BitCollections.docc/Extensions/BitSet.md | 8 ++--- .../BitSet/BitSet+Equatable.swift | 4 +-- ...ift => BitSet+SetAlgebra isEqualSet.swift} | 20 ++++++------- .../BitSet/BitSet.Counted.swift | 18 +++++------ .../BitSet/BitSet._UnsafeHandle.swift | 2 +- .../Collections.docc/Extensions/BitArray.md | 8 ++--- .../Extensions/BitSet.Counted.md | 8 ++--- .../Collections.docc/Extensions/BitSet.md | 8 ++--- .../Extensions/OrderedSet.UnorderedView.md | 7 ++--- .../Collections.docc/Extensions/OrderedSet.md | 8 ++--- .../Extensions/PersistentSet.md | 6 ++-- .../Extensions/OrderedSet.UnorderedView.md | 7 ++--- .../Extensions/OrderedSet.md | 8 ++--- .../OrderedSet/OrderedSet+Equatable.swift | 2 +- ...edSet+Partial SetAlgebra isEqualSet.swift} | 8 ++--- .../OrderedSet/OrderedSet+UnorderedView.swift | 30 +++++++++++++++++++ ...wift => _Node+Structural isEqualSet.swift} | 4 +-- .../Extensions/PersistentSet.md | 6 ++-- .../PersistentDictionary+Equatable.swift | 2 +- .../PersistentSet+Equatable.swift | 4 +-- ...PersistentSet+SetAlgebra isEqualSet.swift} | 14 ++++----- .../Utilities/SetAPIChecker.swift | 4 +-- .../BitSet.Counted Tests.swift | 16 +++++----- Tests/BitCollectionsTests/BitSetTests.swift | 22 +++++++------- .../OrderedSet/OrderedSetTests.swift | 14 ++++----- .../PersistentSet Tests.swift | 14 ++++----- 28 files changed, 146 insertions(+), 122 deletions(-) rename Sources/BitCollections/BitSet/{BitSet+SetAlgebra isEqual.swift => BitSet+SetAlgebra isEqualSet.swift} (86%) rename Sources/OrderedCollections/OrderedSet/{OrderedSet+Partial SetAlgebra isEqual.swift => OrderedSet+Partial SetAlgebra isEqualSet.swift} (92%) rename Sources/PersistentCollections/Node/{_Node+Structural isEqual.swift => _Node+Structural isEqualSet.swift} (95%) rename Sources/PersistentCollections/PersistentSet/{PersistentSet+SetAlgebra isEqual.swift => PersistentSet+SetAlgebra isEqualSet.swift} (92%) diff --git a/Sources/BitCollections/BitCollections.docc/Extensions/BitArray.md b/Sources/BitCollections/BitCollections.docc/Extensions/BitArray.md index 5fa6a8e4..14137001 100644 --- a/Sources/BitCollections/BitCollections.docc/Extensions/BitArray.md +++ b/Sources/BitCollections/BitCollections.docc/Extensions/BitArray.md @@ -27,11 +27,11 @@ ### Adding Elements -- ``append(_:)`` +- ``append(_:)-8dqhn`` - ``append(contentsOf:)-18dwf`` - ``append(contentsOf:)-576q4`` - ``append(contentsOf:)-8xkr8`` -- ``insert(_:at:)`` +- ``insert(_:at:)-9t4hf`` - ``insert(contentsOf:at:)-7e1xn`` - ``insert(contentsOf:at:)-35dp3`` - ``insert(contentsOf:at:)-1wsgw`` @@ -46,8 +46,8 @@ - ``removeSubrange(_:)-18qe7`` - ``removeLast()`` - ``removeLast(_:)`` -- ``removeFirst()`` -- ``removeFirst(_:)`` +- ``removeFirst()-dcsp`` +- ``removeFirst(_:)-9nqlo`` - ``popLast()`` ### Replacing Elements diff --git a/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.Counted.md b/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.Counted.md index ae58fdf3..f7d6a6ba 100644 --- a/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.Counted.md +++ b/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.Counted.md @@ -94,10 +94,10 @@ ### Binary Set Predicates - ``==(_:_:)`` -- ``isEqual(to:)-5bw9h`` -- ``isEqual(to:)-8jxq5`` -- ``isEqual(to:)-7w9qy`` -- ``isEqual(to:)-9tnfo`` +- ``isEqualSet(to:)-11031`` +- ``isEqualSet(to:)-1hvpp`` +- ``isEqualSet(to:)-1mvpq`` +- ``isEqualSet(to:)-878x1`` - ``isSubset(of:)-8iy8c`` - ``isSubset(of:)-1r41b`` diff --git a/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.md b/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.md index 6f6edce8..6da45f00 100644 --- a/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.md +++ b/Sources/BitCollections/BitCollections.docc/Extensions/BitSet.md @@ -95,10 +95,10 @@ ### Comparing Sets - ``==(_:_:)`` -- ``isEqual(to:)-5zfpo`` -- ``isEqual(to:)-93d52`` -- ``isEqual(to:)-542zl`` -- ``isEqual(to:)-1d66i`` +- ``isEqualSet(to:)-4xfa9`` +- ``isEqualSet(to:)-359ao`` +- ``isEqualSet(to:)-5ap6y`` +- ``isEqualSet(to:)-2dezf`` - ``isSubset(of:)-73apg`` - ``isSubset(of:)-14xt1`` diff --git a/Sources/BitCollections/BitSet/BitSet+Equatable.swift b/Sources/BitCollections/BitSet/BitSet+Equatable.swift index ce81333f..2a096b66 100644 --- a/Sources/BitCollections/BitSet/BitSet+Equatable.swift +++ b/Sources/BitCollections/BitSet/BitSet+Equatable.swift @@ -13,13 +13,13 @@ extension BitSet: Equatable { /// Returns a Boolean value indicating whether two values are equal. Two /// bit sets are considered equal if they contain the same elements. /// - /// - Note: This simply forwards to the ``isEqual(to:)-5zfpo`` method. + /// - Note: This simply forwards to the ``isEqualSet(to:)-4xfa9`` method. /// That method has additional overloads that can be used to compare /// bit sets with additional types. /// /// - Complexity: O(*max*), where *max* is value of the largest member of /// either set. public static func ==(left: Self, right: Self) -> Bool { - left.isEqual(to: right) + left.isEqualSet(to: right) } } diff --git a/Sources/BitCollections/BitSet/BitSet+SetAlgebra isEqual.swift b/Sources/BitCollections/BitSet/BitSet+SetAlgebra isEqualSet.swift similarity index 86% rename from Sources/BitCollections/BitSet/BitSet+SetAlgebra isEqual.swift rename to Sources/BitCollections/BitSet/BitSet+SetAlgebra isEqualSet.swift index 2e3d1dbb..3c85b2c2 100644 --- a/Sources/BitCollections/BitSet/BitSet+SetAlgebra isEqual.swift +++ b/Sources/BitCollections/BitSet/BitSet+SetAlgebra isEqualSet.swift @@ -18,7 +18,7 @@ extension BitSet { /// /// - Complexity: O(*max*), where *max* is value of the largest member of /// either set. - public func isEqual(to other: Self) -> Bool { + public func isEqualSet(to other: Self) -> Bool { self._storage == other._storage } @@ -27,8 +27,8 @@ extension BitSet { /// /// - Complexity: O(*max*), where *max* is value of the largest member of /// either set. - public func isEqual(to other: BitSet.Counted) -> Bool { - self.isEqual(to: other._bits) + public func isEqualSet(to other: BitSet.Counted) -> Bool { + self.isEqualSet(to: other._bits) } /// Returns a Boolean value indicating whether a bit set is equal to a range @@ -36,9 +36,9 @@ extension BitSet { /// /// - Complexity: O(min(*max*, `other.upperBound`), where *max* is the largest /// member of `self`. - public func isEqual(to other: Range) -> Bool { + public func isEqualSet(to other: Range) -> Bool { guard let other = other._toUInt() else { return false } - return _read { $0.isEqual(to: other) } + return _read { $0.isEqualSet(to: other) } } /// Returns a Boolean value indicating whether this bit set contains the same @@ -50,18 +50,18 @@ extension BitSet { /// let bits: BitSet = [0, 1, 5, 6] /// let other = [5, 5, 0, 1, 1, 6, 5, 0, 1, 6, 6, 5] /// - /// bits.isEqual(to: other) // true + /// bits.isEqualSet(to: other) // true /// /// - Complexity: O(*n*), where *n* is the number of items in `other`. - public func isEqual(to other: S) -> Bool where S.Element == Int { + public func isEqualSet(to other: S) -> Bool where S.Element == Int { if S.self == Self.self { - return isEqual(to: other as! Self) + return isEqualSet(to: other as! Self) } if S.self == BitSet.Counted.self { - return isEqual(to: other as! BitSet.Counted) + return isEqualSet(to: other as! BitSet.Counted) } if S.self == Range.self { - return isEqual(to: other as! Range) + return isEqualSet(to: other as! Range) } if self.isEmpty { diff --git a/Sources/BitCollections/BitSet/BitSet.Counted.swift b/Sources/BitCollections/BitSet/BitSet.Counted.swift index aa0d2f7e..061e0e95 100644 --- a/Sources/BitCollections/BitSet/BitSet.Counted.swift +++ b/Sources/BitCollections/BitSet/BitSet.Counted.swift @@ -902,9 +902,9 @@ extension BitSet.Counted { /// /// - Complexity: O(*max*), where *max* is value of the largest member of /// either set. - public func isEqual(to other: Self) -> Bool { + public func isEqualSet(to other: Self) -> Bool { guard self.count == other.count else { return false } - return self._bits.isEqual(to: other._bits) + return self._bits.isEqualSet(to: other._bits) } /// Returns a Boolean value indicating whether a bit set is equal to a counted @@ -912,8 +912,8 @@ extension BitSet.Counted { /// /// - Complexity: O(*max*), where *max* is value of the largest member of /// either set. - public func isEqual(to other: BitSet) -> Bool { - self._bits.isEqual(to: other) + public func isEqualSet(to other: BitSet) -> Bool { + self._bits.isEqualSet(to: other) } /// Returns a Boolean value indicating whether a bit set is equal to a range @@ -921,9 +921,9 @@ extension BitSet.Counted { /// /// - Complexity: O(min(*max*, `other.upperBound`), where *max* is the largest /// member of `self`. - public func isEqual(to other: Range) -> Bool { + public func isEqualSet(to other: Range) -> Bool { guard self.count == other.count else { return false } - return _bits.isEqual(to: other) + return _bits.isEqualSet(to: other) } /// Returns a Boolean value indicating whether this bit set contains the same @@ -935,15 +935,15 @@ extension BitSet.Counted { /// let bits: BitSet = [0, 1, 5, 6] /// let other = [5, 5, 0, 1, 1, 6, 5, 0, 1, 6, 6, 5] /// - /// bits.isEqual(to: other) // true + /// bits.isEqualSet(to: other) // true /// /// - Complexity: O(*n*), where *n* is the number of items in `other`. @inlinable - public func isEqual(to other: S) -> Bool + public func isEqualSet(to other: S) -> Bool where S.Element == Int { guard self.count >= other.underestimatedCount else { return false } - return _bits.isEqual(to: other) + return _bits.isEqualSet(to: other) } } diff --git a/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift b/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift index a73a72a4..362814a8 100644 --- a/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift +++ b/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift @@ -624,7 +624,7 @@ extension BitSet._UnsafeHandle { return _words[upper.word].intersection(uw) == uw } - internal func isEqual(to range: Range) -> Bool { + internal func isEqualSet(to range: Range) -> Bool { if range.isEmpty { return self.isEmpty } let r = range.clamped(to: 0 ..< UInt(capacity)) guard r == range else { return false } diff --git a/Sources/Collections/Collections.docc/Extensions/BitArray.md b/Sources/Collections/Collections.docc/Extensions/BitArray.md index 7afab2f5..539c90f5 100644 --- a/Sources/Collections/Collections.docc/Extensions/BitArray.md +++ b/Sources/Collections/Collections.docc/Extensions/BitArray.md @@ -30,11 +30,11 @@ ### Adding Elements -- ``append(_:)`` +- ``append(_:)-8dqhn`` - ``append(contentsOf:)-18dwf`` - ``append(contentsOf:)-576q4`` - ``append(contentsOf:)-8xkr8`` -- ``insert(_:at:)`` +- ``insert(_:at:)-9t4hf`` - ``insert(contentsOf:at:)-7e1xn`` - ``insert(contentsOf:at:)-35dp3`` - ``insert(contentsOf:at:)-1wsgw`` @@ -49,8 +49,8 @@ - ``removeSubrange(_:)-18qe7`` - ``removeLast()`` - ``removeLast(_:)`` -- ``removeFirst()`` -- ``removeFirst(_:)`` +- ``removeFirst()-dcsp`` +- ``removeFirst(_:)-9nqlo`` - ``popLast()`` ### Replacing Elements diff --git a/Sources/Collections/Collections.docc/Extensions/BitSet.Counted.md b/Sources/Collections/Collections.docc/Extensions/BitSet.Counted.md index 93aeebc9..d5b23ba9 100644 --- a/Sources/Collections/Collections.docc/Extensions/BitSet.Counted.md +++ b/Sources/Collections/Collections.docc/Extensions/BitSet.Counted.md @@ -97,10 +97,10 @@ ### Binary Set Predicates - ``==(_:_:)`` -- ``isEqual(to:)-5bw9h`` -- ``isEqual(to:)-8jxq5`` -- ``isEqual(to:)-7w9qy`` -- ``isEqual(to:)-9tnfo`` +- ``isEqualSet(to:)-11031`` +- ``isEqualSet(to:)-1hvpp`` +- ``isEqualSet(to:)-1mvpq`` +- ``isEqualSet(to:)-878x1`` - ``isSubset(of:)-8iy8c`` - ``isSubset(of:)-1r41b`` diff --git a/Sources/Collections/Collections.docc/Extensions/BitSet.md b/Sources/Collections/Collections.docc/Extensions/BitSet.md index 790c8f33..122abadf 100644 --- a/Sources/Collections/Collections.docc/Extensions/BitSet.md +++ b/Sources/Collections/Collections.docc/Extensions/BitSet.md @@ -98,10 +98,10 @@ ### Comparing Sets - ``==(_:_:)`` -- ``isEqual(to:)-5zfpo`` -- ``isEqual(to:)-93d52`` -- ``isEqual(to:)-542zl`` -- ``isEqual(to:)-1d66i`` +- ``isEqualSet(to:)-4xfa9`` +- ``isEqualSet(to:)-359ao`` +- ``isEqualSet(to:)-5ap6y`` +- ``isEqualSet(to:)-2dezf`` - ``isSubset(of:)-73apg`` - ``isSubset(of:)-14xt1`` diff --git a/Sources/Collections/Collections.docc/Extensions/OrderedSet.UnorderedView.md b/Sources/Collections/Collections.docc/Extensions/OrderedSet.UnorderedView.md index f3f89bfc..13404810 100644 --- a/Sources/Collections/Collections.docc/Extensions/OrderedSet.UnorderedView.md +++ b/Sources/Collections/Collections.docc/Extensions/OrderedSet.UnorderedView.md @@ -38,28 +38,25 @@ ### Binary Set Predicates - ``==(_:_:)`` +- ``isEqualSet(to:)-1szq`` +- ``isEqualSet(to:)-9djqq`` -- ``isSubset(of:)-n4t7`` - ``isSubset(of:)-2dx31`` - ``isSubset(of:)-801lo`` - ``isSubset(of:)-952h5`` -- ``isSuperset(of:)-4ea6h`` - ``isSuperset(of:)-9t33p`` - ``isSuperset(of:)-2vtig`` - ``isSuperset(of:)-9krpz`` -- ``isStrictSubset(of:)-33z0l`` - ``isStrictSubset(of:)-9o6mg`` - ``isStrictSubset(of:)-91par`` - ``isStrictSubset(of:)-7n66e`` -- ``isStrictSuperset(of:)-8pbce`` - ``isStrictSuperset(of:)-89ig3`` - ``isStrictSuperset(of:)-1e0xt`` - ``isStrictSuperset(of:)-5dsfd`` -- ``isDisjoint(with:)-7sbsg`` - ``isDisjoint(with:)-3wuso`` - ``isDisjoint(with:)-25vmx`` - ``isDisjoint(with:)-8nfqs`` diff --git a/Sources/Collections/Collections.docc/Extensions/OrderedSet.md b/Sources/Collections/Collections.docc/Extensions/OrderedSet.md index b4e7087a..a6ce7002 100644 --- a/Sources/Collections/Collections.docc/Extensions/OrderedSet.md +++ b/Sources/Collections/Collections.docc/Extensions/OrderedSet.md @@ -94,9 +94,9 @@ ### Comparing Sets - ``==(_:_:)`` -- ``isEqual(to:)-69p52`` -- ``isEqual(to:)-1xzfo`` -- ``isEqual(to:)-3ab2q`` +- ``isEqualSet(to:)-6zqj7`` +- ``isEqualSet(to:)-34yz0`` +- ``isEqualSet(to:)-2bhxr`` - ``isSubset(of:)-ptij`` - ``isSubset(of:)-3mw6r`` @@ -135,7 +135,7 @@ ### Creating and Applying Differences -- ``difference(from:)`` +- ``difference(from:)-30bkk`` - ``applying(_:)`` ### Memory Management diff --git a/Sources/Collections/Collections.docc/Extensions/PersistentSet.md b/Sources/Collections/Collections.docc/Extensions/PersistentSet.md index 09b23d5b..874bf7c5 100644 --- a/Sources/Collections/Collections.docc/Extensions/PersistentSet.md +++ b/Sources/Collections/Collections.docc/Extensions/PersistentSet.md @@ -141,9 +141,9 @@ average -- typically they will need to compare against just one member. ### Comparing Sets - ``==(_:_:)`` -- ``isEqual(to:)-3m3in`` -- ``isEqual(to:)-7mkn1`` -- ``isEqual(to:)-5px5r`` +- ``isEqualSet(to:)-7egih`` +- ``isEqualSet(to:)-4t0k5`` +- ``isEqualSet(to:)-7s0cu`` - ``isSubset(of:)-9mp7l`` - ``isSubset(of:)-2jlh`` diff --git a/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.UnorderedView.md b/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.UnorderedView.md index b8ef33ba..659d1eb6 100644 --- a/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.UnorderedView.md +++ b/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.UnorderedView.md @@ -35,28 +35,25 @@ ### Binary Set Predicates - ``==(_:_:)`` +- ``isEqualSet(to:)-1szq`` +- ``isEqualSet(to:)-9djqq`` -- ``isSubset(of:)-n4t7`` - ``isSubset(of:)-2dx31`` - ``isSubset(of:)-801lo`` - ``isSubset(of:)-952h5`` -- ``isSuperset(of:)-4ea6h`` - ``isSuperset(of:)-9t33p`` - ``isSuperset(of:)-2vtig`` - ``isSuperset(of:)-9krpz`` -- ``isStrictSubset(of:)-33z0l`` - ``isStrictSubset(of:)-9o6mg`` - ``isStrictSubset(of:)-91par`` - ``isStrictSubset(of:)-7n66e`` -- ``isStrictSuperset(of:)-8pbce`` - ``isStrictSuperset(of:)-89ig3`` - ``isStrictSuperset(of:)-1e0xt`` - ``isStrictSuperset(of:)-5dsfd`` -- ``isDisjoint(with:)-7sbsg`` - ``isDisjoint(with:)-3wuso`` - ``isDisjoint(with:)-25vmx`` - ``isDisjoint(with:)-8nfqs`` diff --git a/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.md b/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.md index ed5d75c5..a7d38994 100644 --- a/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.md +++ b/Sources/OrderedCollections/OrderedCollections.docc/Extensions/OrderedSet.md @@ -91,9 +91,9 @@ ### Comparing Sets - ``==(_:_:)`` -- ``isEqual(to:)-69p52`` -- ``isEqual(to:)-1xzfo`` -- ``isEqual(to:)-3ab2q`` +- ``isEqualSet(to:)-6zqj7`` +- ``isEqualSet(to:)-34yz0`` +- ``isEqualSet(to:)-2bhxr`` - ``isSubset(of:)-ptij`` - ``isSubset(of:)-3mw6r`` @@ -132,7 +132,7 @@ ### Creating and Applying Differences -- ``difference(from:)`` +- ``difference(from:)-30bkk`` - ``applying(_:)`` ### Memory Management diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+Equatable.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+Equatable.swift index 2c6dee53..507eeef9 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+Equatable.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+Equatable.swift @@ -16,7 +16,7 @@ extension OrderedSet: Equatable { /// elements in the same order. /// /// - Note: This operator implements different behavior than the - /// `isEqual(to:)` method -- the latter implements an unordered + /// `isEqualSet(to:)` method -- the latter implements an unordered /// comparison, to match the behavior of members like `isSubset(of:)`, /// `isStrictSuperset(of:)` etc. /// diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra isEqual.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra isEqualSet.swift similarity index 92% rename from Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra isEqual.swift rename to Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra isEqualSet.swift index 8f63fe72..8c407db6 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra isEqual.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra isEqualSet.swift @@ -22,7 +22,7 @@ extension OrderedSet { /// /// - Complexity: O(`min(left.count, right.count)`), as long as`Element` /// properly implements hashing. - public func isEqual(to other: Self) -> Bool { + public func isEqualSet(to other: Self) -> Bool { self.unordered == other.unordered } @@ -31,7 +31,7 @@ extension OrderedSet { /// /// - Complexity: O(`min(left.count, right.count)`), as long as`Element` /// properly implements hashing. - public func isEqual(to other: UnorderedView) -> Bool { + public func isEqualSet(to other: UnorderedView) -> Bool { self.unordered == other } @@ -44,10 +44,10 @@ extension OrderedSet { /// /// - Complexity: O(*n*), where *n* is the number of items in /// `other`, as long as`Element` properly implements hashing. - public func isEqual(to other: S) -> Bool + public func isEqualSet(to other: S) -> Bool where S.Element == Element { if S.self == Self.self { - return isEqual(to: other as! Self) + return isEqualSet(to: other as! Self) } if self.isEmpty { diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+UnorderedView.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+UnorderedView.swift index 02c980ee..0611718d 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+UnorderedView.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+UnorderedView.swift @@ -641,6 +641,36 @@ extension OrderedSet.UnorderedView { } } +extension OrderedSet.UnorderedView { + /// Returns a Boolean value indicating whether two set values contain the + /// same elements, but not necessarily in the same order. + /// + /// - Note: This member implements different behavior than the `==(_:_:)` + /// operator -- the latter implements an ordered comparison, matching + /// the stricter concept of equality expected of an ordered collection + /// type. + /// + /// - Complexity: O(`min(left.count, right.count)`), as long as`Element` + /// properly implements hashing. + public func isEqualSet(to other: Self) -> Bool { + self == other + } + + /// Returns a Boolean value indicating whether an ordered set contains the + /// same values as a given sequence, but not necessarily in the same + /// order. + /// + /// Duplicate items in `other` do not prevent it from comparing equal to + /// `self`. + /// + /// - Complexity: O(*n*), where *n* is the number of items in + /// `other`, as long as`Element` properly implements hashing. + public func isEqualSet(to other: S) -> Bool + where S.Element == Element { + self._base.isEqualSet(to: other) + } +} + extension OrderedSet.UnorderedView { /// Returns a Boolean value that indicates whether this set is a subset of /// the given set. diff --git a/Sources/PersistentCollections/Node/_Node+Structural isEqual.swift b/Sources/PersistentCollections/Node/_Node+Structural isEqualSet.swift similarity index 95% rename from Sources/PersistentCollections/Node/_Node+Structural isEqual.swift rename to Sources/PersistentCollections/Node/_Node+Structural isEqualSet.swift index c45a8899..530d417e 100644 --- a/Sources/PersistentCollections/Node/_Node+Structural isEqual.swift +++ b/Sources/PersistentCollections/Node/_Node+Structural isEqualSet.swift @@ -12,7 +12,7 @@ // TODO: `Equatable` needs more test coverage, apart from hash-collision smoke test extension _Node { @inlinable - internal func isEqual( + internal func isEqualSet( to other: _Node, by areEquivalent: (Value, Value2) -> Bool ) -> Bool { @@ -54,7 +54,7 @@ extension _Node { let rc = r.children return lc.elementsEqual( rc, - by: { $0.isEqual(to: $1, by: areEquivalent) }) + by: { $0.isEqualSet(to: $1, by: areEquivalent) }) } } } diff --git a/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md b/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md index d0c03d00..a8864213 100644 --- a/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md +++ b/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md @@ -138,9 +138,9 @@ average -- typically they will need to compare against just one member. ### Comparing Sets - ``==(_:_:)`` -- ``isEqual(to:)-3m3in`` -- ``isEqual(to:)-7mkn1`` -- ``isEqual(to:)-5px5r`` +- ``isEqualSet(to:)-7egih`` +- ``isEqualSet(to:)-4t0k5`` +- ``isEqualSet(to:)-7s0cu`` - ``isSubset(of:)-9mp7l`` - ``isSubset(of:)-2jlh`` diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift index 55205e7f..e2c01e0b 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift +++ b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift @@ -18,6 +18,6 @@ extension PersistentDictionary: Equatable where Value: Equatable { /// - Complexity: O(`min(left.count, right.count)`) @inlinable public static func == (left: Self, right: Self) -> Bool { - left._root.isEqual(to: right._root, by: { $0 == $1 }) + left._root.isEqualSet(to: right._root, by: { $0 == $1 }) } } diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift b/Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift index 82614846..56d51a70 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift +++ b/Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift @@ -17,13 +17,13 @@ extension PersistentSet: Equatable { /// Two persistent sets are considered equal if they contain the same /// elements, but not necessarily in the same order. /// - /// - Note: This simply forwards to the ``isEqual(to:)-3m3in`` method. + /// - Note: This simply forwards to the ``isEqualSet(to:)-7egih`` method. /// That method has additional overloads that can be used to compare /// persistent sets with additional types. /// /// - Complexity: O(`min(left.count, right.count)`) @inlinable @inline(__always) public static func == (left: Self, right: Self) -> Bool { - left.isEqual(to: right) + left.isEqualSet(to: right) } } diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqual.swift b/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift similarity index 92% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqual.swift rename to Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift index fa2941bd..5409dbe7 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqual.swift +++ b/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift @@ -26,8 +26,8 @@ extension PersistentSet { /// every available shortcut to reduce complexity, e.g. by skipping /// comparing elements in shared subtrees. @inlinable - public func isEqual(to other: Self) -> Bool { - _root.isEqual(to: other._root, by: { _, _ in true }) + public func isEqualSet(to other: Self) -> Bool { + _root.isEqualSet(to: other._root, by: { _, _ in true }) } /// Returns a Boolean value indicating whether a persistent set compares equal @@ -45,10 +45,10 @@ extension PersistentSet { /// every available shortcut to reduce complexity, e.g. by skipping /// comparing elements in shared subtrees. @inlinable - public func isEqual( + public func isEqualSet( to other: PersistentDictionary.Keys ) -> Bool { - _root.isEqual(to: other._base._root, by: { _, _ in true }) + _root.isEqualSet(to: other._base._root, by: { _, _ in true }) } /// Returns a Boolean value indicating whether this persistent set contains @@ -61,7 +61,7 @@ extension PersistentSet { /// let this: PersistentSet = [0, 1, 5, 6] /// let that = [5, 5, 0, 1, 1, 6, 5, 0, 1, 6, 6, 5] /// - /// this.isEqual(to: that) // true + /// this.isEqualSet(to: that) // true /// /// - Parameter other: The keys view of a persistent dictionary. /// @@ -75,11 +75,11 @@ extension PersistentSet { /// every available shortcut to reduce complexity, e.g. by skipping /// comparing elements in shared subtrees. @inlinable - public func isEqual(to other: S) -> Bool + public func isEqualSet(to other: S) -> Bool where S.Element == Element { if S.self == Self.self { - return isEqual(to: other as! Self) + return isEqualSet(to: other as! Self) } if self.isEmpty { diff --git a/Sources/_CollectionsTestSupport/Utilities/SetAPIChecker.swift b/Sources/_CollectionsTestSupport/Utilities/SetAPIChecker.swift index ef65f56f..1f7d01cf 100644 --- a/Sources/_CollectionsTestSupport/Utilities/SetAPIChecker.swift +++ b/Sources/_CollectionsTestSupport/Utilities/SetAPIChecker.swift @@ -75,7 +75,7 @@ public protocol SetAPIExtras: SetAPIChecker { mutating func update(_ member: Element, at index: Index) -> Element - func isEqual(to other: Self) -> Bool - func isEqual(to other: S) -> Bool + func isEqualSet(to other: Self) -> Bool + func isEqualSet(to other: S) -> Bool where S.Element == Element } diff --git a/Tests/BitCollectionsTests/BitSet.Counted Tests.swift b/Tests/BitCollectionsTests/BitSet.Counted Tests.swift index a68e511e..bb7d86d7 100644 --- a/Tests/BitCollectionsTests/BitSet.Counted Tests.swift +++ b/Tests/BitCollectionsTests/BitSet.Counted Tests.swift @@ -155,16 +155,16 @@ final class BitSetCountedTests: CollectionTestCase { let a: BitSet.Counted = [1, 2, 3, 4] let b = 1 ..< 5 - expectTrue(a.isEqual(to: BitSet.Counted(b))) - expectTrue(a.isEqual(to: BitSet(b))) - expectTrue(a.isEqual(to: b)) - expectTrue(a.isEqual(to: Set(b))) + expectTrue(a.isEqualSet(to: BitSet.Counted(b))) + expectTrue(a.isEqualSet(to: BitSet(b))) + expectTrue(a.isEqualSet(to: b)) + expectTrue(a.isEqualSet(to: Set(b))) let c = 2 ..< 7 - expectFalse(a.isEqual(to: BitSet.Counted(c))) - expectFalse(a.isEqual(to: BitSet(c))) - expectFalse(a.isEqual(to: c)) - expectFalse(a.isEqual(to: Set(c))) + expectFalse(a.isEqualSet(to: BitSet.Counted(c))) + expectFalse(a.isEqualSet(to: BitSet(c))) + expectFalse(a.isEqualSet(to: c)) + expectFalse(a.isEqualSet(to: Set(c))) } func test_isSubset() { diff --git a/Tests/BitCollectionsTests/BitSetTests.swift b/Tests/BitCollectionsTests/BitSetTests.swift index b2ac7632..5a9becf2 100644 --- a/Tests/BitCollectionsTests/BitSetTests.swift +++ b/Tests/BitCollectionsTests/BitSetTests.swift @@ -1091,25 +1091,25 @@ final class BitSetTest: CollectionTestCase { func test_isEqual_to_integer_range() { let a = BitSet(200 ..< 400) - expectTrue(a.isEqual(to: 200 ..< 400)) - expectFalse(a.isEqual(to: 201 ..< 401)) - expectFalse(a.isEqual(to: -1 ..< 200)) - expectFalse(a.isEqual(to: 0 ..< 0)) - expectFalse(a.isEqual(to: 0 ..< 1000)) - expectFalse(a.isEqual(to: 0 ..< 250)) - expectFalse(a.isEqual(to: 270 ..< 400)) + expectTrue(a.isEqualSet(to: 200 ..< 400)) + expectFalse(a.isEqualSet(to: 201 ..< 401)) + expectFalse(a.isEqualSet(to: -1 ..< 200)) + expectFalse(a.isEqualSet(to: 0 ..< 0)) + expectFalse(a.isEqualSet(to: 0 ..< 1000)) + expectFalse(a.isEqualSet(to: 0 ..< 250)) + expectFalse(a.isEqualSet(to: 270 ..< 400)) var b = a b.remove(300) - expectFalse(b.isEqual(to: 200 ..< 400)) + expectFalse(b.isEqualSet(to: 200 ..< 400)) let c = BitSet(130 ..< 160) - expectTrue(c.isEqual(to: 130 ..< 160)) + expectTrue(c.isEqualSet(to: 130 ..< 160)) } func test_isEqual_to_counted_BitSet() { let a = BitSet(200 ..< 400) - expectTrue(a.isEqual(to: a.counted)) + expectTrue(a.isEqualSet(to: a.counted)) } func test_isEqual_to_Sequence() { @@ -1117,7 +1117,7 @@ final class BitSetTest: CollectionTestCase { _ bits: BitSet, _ items: S ) -> Bool where S.Element == Int { - bits.isEqual(to: items) + bits.isEqualSet(to: items) } let bits: BitSet = [3, 6, 8, 11] diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift index e44f2918..361078c1 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift @@ -1333,18 +1333,18 @@ class OrderedSetTests: CollectionTestCase { _ set: OrderedSet, _ other: S ) -> Bool where S.Element == Int { - set.isEqual(to: other) + set.isEqualSet(to: other) } - expectEqual(a.isEqual(to: b), expected) - expectEqual(a.isEqual(to: b.unordered), expected) - expectEqual(a.isEqual(to: c), expected) + expectEqual(a.isEqualSet(to: b), expected) + expectEqual(a.isEqualSet(to: b.unordered), expected) + expectEqual(a.isEqualSet(to: c), expected) expectEqual(checkSequence(a, b), expected) expectEqual(checkSequence(a, c), expected) - expectEqual(a.isEqual(to: d), expected) - expectEqual(a.isEqual(to: d + d), expected) - expectEqual(a.isEqual(to: r2), expected) + expectEqual(a.isEqualSet(to: d), expected) + expectEqual(a.isEqualSet(to: d + d), expected) + expectEqual(a.isEqualSet(to: r2), expected) } } } diff --git a/Tests/PersistentCollectionsTests/PersistentSet Tests.swift b/Tests/PersistentCollectionsTests/PersistentSet Tests.swift index f2552165..68930a36 100644 --- a/Tests/PersistentCollectionsTests/PersistentSet Tests.swift +++ b/Tests/PersistentCollectionsTests/PersistentSet Tests.swift @@ -264,7 +264,7 @@ class PersistentSetTests: CollectionTestCase { withEverySubset("a", of: testItems) { a in let x = PersistentSet(a) let u = Set(a) - expectTrue(x.isEqual(to: x)) + expectTrue(x.isEqualSet(to: x)) withEverySubset("b", of: testItems) { b in let y = PersistentSet(b) let v = Set(b) @@ -277,15 +277,15 @@ class PersistentSetTests: CollectionTestCase { _ b: S ) -> Bool where S.Element == RawCollider { - a.isEqual(to: b) + a.isEqualSet(to: b) } - expectEqual(x.isEqual(to: y), reference) - expectEqual(x.isEqual(to: z.keys), reference) + expectEqual(x.isEqualSet(to: y), reference) + expectEqual(x.isEqualSet(to: z.keys), reference) expectEqual(checkSequence(x, y), reference) - expectEqual(x.isEqual(to: v), reference) - expectEqual(x.isEqual(to: b), reference) - expectEqual(x.isEqual(to: b + b), reference) + expectEqual(x.isEqualSet(to: v), reference) + expectEqual(x.isEqualSet(to: b), reference) + expectEqual(x.isEqualSet(to: b + b), reference) } } } From 581490a7351be07e465100628ded472aaa137a99 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 31 Oct 2022 15:10:11 -0700 Subject: [PATCH 2/2] [CMake] Update CMakeLists.txts --- Sources/BitCollections/CMakeLists.txt | 2 +- Sources/OrderedCollections/CMakeLists.txt | 2 +- Sources/PersistentCollections/CMakeLists.txt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/BitCollections/CMakeLists.txt b/Sources/BitCollections/CMakeLists.txt index 06a2e744..49de8894 100644 --- a/Sources/BitCollections/CMakeLists.txt +++ b/Sources/BitCollections/CMakeLists.txt @@ -47,7 +47,7 @@ add_library(BitCollections "BitSet/BitSet+SetAlgebra formUnion.swift" "BitSet/BitSet+SetAlgebra intersection.swift" "BitSet/BitSet+SetAlgebra isDisjoint.swift" - "BitSet/BitSet+SetAlgebra isEqual.swift" + "BitSet/BitSet+SetAlgebra isEqualSet.swift" "BitSet/BitSet+SetAlgebra isStrictSubset.swift" "BitSet/BitSet+SetAlgebra isStrictSuperset.swift" "BitSet/BitSet+SetAlgebra isSubset.swift" diff --git a/Sources/OrderedCollections/CMakeLists.txt b/Sources/OrderedCollections/CMakeLists.txt index 5bae3f6b..2bbb9b7c 100644 --- a/Sources/OrderedCollections/CMakeLists.txt +++ b/Sources/OrderedCollections/CMakeLists.txt @@ -50,7 +50,7 @@ add_library(OrderedCollections "OrderedSet/OrderedSet+Partial SetAlgebra formUnion.swift" "OrderedSet/OrderedSet+Partial SetAlgebra intersection.swift" "OrderedSet/OrderedSet+Partial SetAlgebra isDisjoint.swift" - "OrderedSet/OrderedSet+Partial SetAlgebra isEqual.swift" + "OrderedSet/OrderedSet+Partial SetAlgebra isEqualSet.swift" "OrderedSet/OrderedSet+Partial SetAlgebra isStrictSubset.swift" "OrderedSet/OrderedSet+Partial SetAlgebra isStrictSuperset.swift" "OrderedSet/OrderedSet+Partial SetAlgebra isSubset.swift" diff --git a/Sources/PersistentCollections/CMakeLists.txt b/Sources/PersistentCollections/CMakeLists.txt index 121e50fb..544cd601 100644 --- a/Sources/PersistentCollections/CMakeLists.txt +++ b/Sources/PersistentCollections/CMakeLists.txt @@ -28,7 +28,7 @@ add_library(PersistentCollections "Node/_Node+Structural filter.swift" "Node/_Node+Structural intersection.swift" "Node/_Node+Structural isDisjoint.swift" - "Node/_Node+Structural isEqual.swift" + "Node/_Node+Structural isEqualSet.swift" "Node/_Node+Structural isSubset.swift" "Node/_Node+Structural mapValues.swift" "Node/_Node+Structural merge.swift" @@ -85,7 +85,7 @@ add_library(PersistentCollections "PersistentSet/PersistentSet+SetAlgebra formUnion.swift" "PersistentSet/PersistentSet+SetAlgebra intersection.swift" "PersistentSet/PersistentSet+SetAlgebra isDisjoint.swift" - "PersistentSet/PersistentSet+SetAlgebra isEqual.swift" + "PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift" "PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift" "PersistentSet/PersistentSet+SetAlgebra isStrictSuperset.swift" "PersistentSet/PersistentSet+SetAlgebra isSubset.swift"