Skip to content

New Set[Algebra] API #2002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions benchmark/single-source/SetTests.swift
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import TestsUtils import TestsUtils


@inline(never) @inline(never)
public func run_SetIsSubsetOf(N: Int) { public func run_SetIsSubset(of N: Int) {
let size = 200 let size = 200


SRand() SRand()
Expand All @@ -28,7 +28,7 @@ public func run_SetIsSubsetOf(N: Int) {


var isSubset = false; var isSubset = false;
for _ in 0 ..< N * 5000 { for _ in 0 ..< N * 5000 {
isSubset = set.isSubsetOf(otherSet) isSubset = set.isSubset(of: otherSet)
if isSubset { if isSubset {
break break
} }
Expand Down Expand Up @@ -57,7 +57,7 @@ public func run_SetExclusiveOr(N: Int) {


var xor = Set<Int>() var xor = Set<Int>()
for _ in 0 ..< N * 100 { for _ in 0 ..< N * 100 {
xor = set.exclusiveOr(otherSet) xor = set.symmetricDifference(otherSet)
} }
sink(&xor) sink(&xor)
} }
Expand Down Expand Up @@ -99,7 +99,7 @@ public func run_SetIntersect(N: Int) {


var and = Set<Int>() var and = Set<Int>()
for _ in 0 ..< N * 100 { for _ in 0 ..< N * 100 {
and = set.intersect(otherSet) and = set.intersection(otherSet)
} }
sink(&and) sink(&and)
} }
Expand Down Expand Up @@ -139,7 +139,7 @@ public func run_SetIsSubsetOf_OfObjects(N: Int) {


var isSubset = false; var isSubset = false;
for _ in 0 ..< N * 5000 { for _ in 0 ..< N * 5000 {
isSubset = set.isSubsetOf(otherSet) isSubset = set.isSubset(of: otherSet)
if isSubset { if isSubset {
break break
} }
Expand Down Expand Up @@ -168,7 +168,7 @@ public func run_SetExclusiveOr_OfObjects(N: Int) {


var xor = Set<Box<Int>>() var xor = Set<Box<Int>>()
for _ in 0 ..< N * 100 { for _ in 0 ..< N * 100 {
xor = set.exclusiveOr(otherSet) xor = set.symmetricDifference(otherSet)
} }
sink(&xor) sink(&xor)
} }
Expand Down Expand Up @@ -210,7 +210,7 @@ public func run_SetIntersect_OfObjects(N: Int) {


var and = Set<Box<Int>>() var and = Set<Box<Int>>()
for _ in 0 ..< N * 100 { for _ in 0 ..< N * 100 {
and = set.intersect(otherSet) and = set.intersection(otherSet)
} }
sink(&and) sink(&and)
} }
30 changes: 15 additions & 15 deletions stdlib/internal/SwiftExperimental/SwiftExperimental.swift
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ infix operator ⊉ { associativity left precedence 130 }
public func ∖ < public func ∖ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Set<T> { >(lhs: Set<T>, rhs: S) -> Set<T> {
return lhs.subtract(rhs) return lhs.subtracting(rhs)
} }


/// Assigns the relative complement between `lhs` and `rhs` to `lhs`. /// Assigns the relative complement between `lhs` and `rhs` to `lhs`.
public func ∖= < public func ∖= <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: inout Set<T>, rhs: S) { >(lhs: inout Set<T>, rhs: S) {
lhs.subtractInPlace(rhs) lhs.subtract(rhs)
} }


/// - Returns: The union of `lhs` and `rhs`. /// - Returns: The union of `lhs` and `rhs`.
Expand All @@ -87,35 +87,35 @@ public func ∪ <
public func ∪= < public func ∪= <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: inout Set<T>, rhs: S) { >(lhs: inout Set<T>, rhs: S) {
lhs.unionInPlace(rhs) lhs.formUnion(rhs)
} }


/// - Returns: The intersection of `lhs` and `rhs`. /// - Returns: The intersection of `lhs` and `rhs`.
public func ∩ < public func ∩ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Set<T> { >(lhs: Set<T>, rhs: S) -> Set<T> {
return lhs.intersect(rhs) return lhs.intersection(rhs)
} }


/// Assigns the intersection of `lhs` and `rhs` to `lhs`. /// Assigns the intersection of `lhs` and `rhs` to `lhs`.
public func ∩= < public func ∩= <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: inout Set<T>, rhs: S) { >(lhs: inout Set<T>, rhs: S) {
lhs.intersectInPlace(rhs) lhs.formIntersection(rhs)
} }


/// - Returns: A set with elements in `lhs` or `rhs` but not in both. /// - Returns: A set with elements in `lhs` or `rhs` but not in both.
public func ⨁ < public func ⨁ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Set<T> { >(lhs: Set<T>, rhs: S) -> Set<T> {
return lhs.exclusiveOr(rhs) return lhs.symmetricDifference(rhs)
} }


/// Assigns to `lhs` the set with elements in `lhs` or `rhs` but not in both. /// Assigns to `lhs` the set with elements in `lhs` or `rhs` but not in both.
public func ⨁= < public func ⨁= <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: inout Set<T>, rhs: S) { >(lhs: inout Set<T>, rhs: S) {
lhs.exclusiveOrInPlace(rhs) lhs.formSymmetricDifference(rhs)
} }


/// - Returns: True if `x` is in the set. /// - Returns: True if `x` is in the set.
Expand All @@ -132,54 +132,54 @@ public func ∉ <T>(x: T, rhs: Set<T>) -> Bool {
public func ⊂ < public func ⊂ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return lhs.isStrictSubsetOf(rhs) return lhs.isStrictSubset(of: rhs)
} }


/// - Returns: True if `lhs` is not a strict subset of `rhs`. /// - Returns: True if `lhs` is not a strict subset of `rhs`.
public func ⊄ < public func ⊄ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return !lhs.isStrictSubsetOf(rhs) return !lhs.isStrictSubset(of: rhs)
} }


/// - Returns: True if `lhs` is a subset of `rhs`. /// - Returns: True if `lhs` is a subset of `rhs`.
public func ⊆ < public func ⊆ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return lhs.isSubsetOf(rhs) return lhs.isSubset(of: rhs)
} }


/// - Returns: True if `lhs` is not a subset of `rhs`. /// - Returns: True if `lhs` is not a subset of `rhs`.
public func ⊈ < public func ⊈ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return !lhs.isSubsetOf(rhs) return !lhs.isSubset(of: rhs)
} }


/// - Returns: True if `lhs` is a strict superset of `rhs`. /// - Returns: True if `lhs` is a strict superset of `rhs`.
public func ⊃ < public func ⊃ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return lhs.isStrictSupersetOf(rhs) return lhs.isStrictSuperset(of: rhs)
} }


/// - Returns: True if `lhs` is not a strict superset of `rhs`. /// - Returns: True if `lhs` is not a strict superset of `rhs`.
public func ⊅ < public func ⊅ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return !lhs.isStrictSupersetOf(rhs) return !lhs.isStrictSuperset(of: rhs)
} }


/// - Returns: True if `lhs` is a superset of `rhs`. /// - Returns: True if `lhs` is a superset of `rhs`.
public func ⊇ < public func ⊇ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return lhs.isSupersetOf(rhs) return lhs.isSuperset(of: rhs)
} }


/// - Returns: True if `lhs` is not a superset of `rhs`. /// - Returns: True if `lhs` is not a superset of `rhs`.
public func ⊉ < public func ⊉ <
T, S: Sequence where S.Iterator.Element == T T, S: Sequence where S.Iterator.Element == T
>(lhs: Set<T>, rhs: S) -> Bool { >(lhs: Set<T>, rhs: S) -> Bool {
return !lhs.isSupersetOf(rhs) return !lhs.isSuperset(of: rhs)
} }
12 changes: 6 additions & 6 deletions stdlib/public/SDK/CoreGraphics/CoreGraphics.swift
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -245,25 +245,25 @@ public extension CGRect {
} }


@_transparent // @fragile @_transparent // @fragile
@warn_unused_result(mutable_variant: "unionInPlace") @warn_unused_result(mutable_variant: "formUnion")
func union(rect: CGRect) -> CGRect { func union(rect: CGRect) -> CGRect {
return CGRectUnion(self, rect) return CGRectUnion(self, rect)
} }


@_transparent // @fragile @_transparent // @fragile
mutating func unionInPlace(rect: CGRect) { mutating func formUnion(rect: CGRect) {
self = union(rect) self = union(rect)
} }


@_transparent // @fragile @_transparent // @fragile
@warn_unused_result(mutable_variant: "intersectInPlace") @warn_unused_result(mutable_variant: "formIntersection")
func intersect(rect: CGRect) -> CGRect { func intersection(rect: CGRect) -> CGRect {
return CGRectIntersection(self, rect) return CGRectIntersection(self, rect)
} }


@_transparent // @fragile @_transparent // @fragile
mutating func intersectInPlace(rect: CGRect) { mutating func formIntersection(rect: CGRect) {
self = intersect(rect) self = intersection(rect)
} }


@_transparent // @fragile @_transparent // @fragile
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/CoreMedia/CMTime.swift
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension CMTime {


public var isNumeric: Bool { public var isNumeric: Bool {
return return
self.flags.intersect([.valid, .impliedValueFlagsMask]) == .valid self.flags.intersection([.valid, .impliedValueFlagsMask]) == .valid
} }


public var hasBeenRounded: Bool { public var hasBeenRounded: Bool {
Expand Down
Loading