Files
swift-collections/Sources/_CollectionsUtilities/_FastMembershipCheckable.swift
T
Karoy Lorentey 3d10964905 [PersistentSet] Flesh out isSubset/iSuperset/isDisjoint/etc overloads (untested)
This adds an experimental _FastMembershipCheckable protocol to speed
up these relationship predicates when possible — having separate
overloads for each known collection with a fast containment check
is not going to scale for long.

This commit also introduces a set of isEqual(to:) methods that
generalize ==.
2022-09-24 17:02:16 -07:00

28 lines
1.1 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 utility protocol for marking container types (not necessarily
/// conforming to `Sequence` or `Collection`) that provide a
/// fast `contains` operation.
public protocol _FastMembershipCheckable {
// FIXME: Add as primary associated type on >=5.7
associatedtype Element: Equatable
/// Returns a Boolean value that indicates whether the given element exists in `self`.
///
/// - Performance: O(log(*n*)) or better, where *n* is the size
/// of `self` (for some definition of "size").
func contains(_ item: Element) -> Bool
}
extension Set: _FastMembershipCheckable {}
extension Dictionary.Keys: _FastMembershipCheckable {}