Files
swift-collections/Sources/_CollectionsTestSupport/Utilities/SetAPIChecker.swift
T
Karoy Lorentey 51a1554f89 Introduce _UniqueCollection & _SortedCollection
These marker-like protocols will allow certain
generic operations to get a performance boost
if the passed-in value happens to be guaranteed
to contain unique elements or to be sorted.

Also, review API checker protocols for Sets and
sorted collections and adjust things as needed.

BitSet gains custom implementations for min()
and max() as part of these improvements.
2022-10-19 01:40:06 -07:00

83 lines
2.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2022 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
//
//===----------------------------------------------------------------------===//
/// 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.
public 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<S: Sequence>(of other: S) -> Bool
where S.Element == Element
func isSuperset<S: Sequence>(of other: S) -> Bool
where S.Element == Element
func isStrictSubset<S: Sequence>(of other: S) -> Bool
where S.Element == Element
func isStrictSuperset<S: Sequence>(of other: S) -> Bool
where S.Element == Element
func isDisjoint<S: Sequence>(with other: S) -> Bool
where S.Element == Element
func intersection<S: Sequence>(_ other: S) -> Self
where S.Element == Element
func union<S: Sequence>(_ other: __owned S) -> Self
where S.Element == Element
__consuming func subtracting<S: Sequence>(_ other: S) -> Self
where S.Element == Element
func symmetricDifference<S: Sequence>(_ other: __owned S) -> Self
where S.Element == Element
mutating func formIntersection<S: Sequence>(_ other: S)
where S.Element == Element
mutating func formUnion<S: Sequence>(_ other: __owned S)
where S.Element == Element
mutating func subtract<S: Sequence>(_ other: S)
where S.Element == Element
mutating func formSymmetricDifference<S: Sequence>(_ other: __owned S)
where S.Element == Element
}
extension Set: SetAPIChecker {}
public protocol SetAPIExtras: SetAPIChecker {
// Non-standard extensions
mutating func update(_ member: Element, at index: Index) -> Element
func isEqual(to other: Self) -> Bool
func isEqual<S: Sequence>(to other: S) -> Bool
where S.Element == Element
}