@@ -355,6 +355,33 @@ public protocol Sequence<Element> {
355
355
/// In this case, see the documentation of `Collection.underestimatedCount`.
356
356
var underestimatedCount : Int { get }
357
357
358
+ /// Sequences whose `Element` is `Equatable` and that are able to quickly
359
+ /// check if they contain a particular value can implement this requirement
360
+ /// to speed up the standard `contains` method.
361
+ ///
362
+ /// The default implementation returns nil, indicating that `contains` should
363
+ /// fall back to the standard linear search algorithm.
364
+ ///
365
+ /// `Sequence` and `Collection` algorithms other than `contains` itself may
366
+ /// adapt their behavior based on whether or not this function returns nil.
367
+ /// For example, a generic algorithm that needs to do containment checks for
368
+ /// many different values may decide not to copy items into a temporary `Set`
369
+ /// if it sees that the sequence implements this method. Therefore, sequences
370
+ /// should only implement this method if they can do it in better than linear
371
+ /// time.
372
+ ///
373
+ /// For sequences that are destructively consumed by iteration, calling this
374
+ /// method must not consume any elements. (Such sequences usually leave this
375
+ /// method with its default, `nil`-returning implementation, which trivially
376
+ /// satisfies this requirement.)
377
+ ///
378
+ /// - Returns: `nil` if containment cannot be verified in better than linear
379
+ /// time; otherwise, the method returns a boolean value indicating whether
380
+ /// or not the item is an element of this sequence.
381
+ ///
382
+ /// - Complexity: If this function returns `nil`, it must do so in constant
383
+ /// (O(1)) time. If this returns non-`nil`, then it must have better than linear
384
+ /// (O(*n*)) complexity.
358
385
func _customContainsEquatableElement(
359
386
_ element: Element
360
387
) -> Bool ?
0 commit comments