//===----------------------------------------------------------------------===// // // This source file is part of the Swift Collections open source project // // Copyright (c) 2022 - 2026 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // // SPDX-License-Identifier: Apache-2.0 WITH Swift-exception // //===----------------------------------------------------------------------===// /// A test protocol for validating that set-like types implement users' /// baseline expectations. /// /// To ensure maximum utility, this protocol refines neither `Collection` nor /// `SetAlgebra` although it does share some of the same requirements. package protocol SetAPIChecker { associatedtype Element associatedtype Index var isEmpty: Bool { get } var count: Int { get } init() mutating func remove(at index: Index) -> Element func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> Self func isSubset(of other: S) -> Bool where S.Element == Element func isSuperset(of other: S) -> Bool where S.Element == Element func isStrictSubset(of other: S) -> Bool where S.Element == Element func isStrictSuperset(of other: S) -> Bool where S.Element == Element func isDisjoint(with other: S) -> Bool where S.Element == Element func intersection(_ other: S) -> Self where S.Element == Element func union(_ other: __owned S) -> Self where S.Element == Element __consuming func subtracting(_ other: S) -> Self where S.Element == Element func symmetricDifference(_ other: __owned S) -> Self where S.Element == Element mutating func formIntersection(_ other: S) where S.Element == Element mutating func formUnion(_ other: __owned S) where S.Element == Element mutating func subtract(_ other: S) where S.Element == Element mutating func formSymmetricDifference(_ other: __owned S) where S.Element == Element } extension Set: SetAPIChecker {} package protocol SetAPIExtras: SetAPIChecker { // Non-standard extensions mutating func update(_ member: Element, at index: Index) -> Element func isEqualSet(to other: Self) -> Bool func isEqualSet(to other: S) -> Bool where S.Element == Element }