@@ -355,6 +355,31 @@ 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
+ /// This method must not return non-nil on sequences that are destructively
374
+ /// consumed by iteration.
375
+ ///
376
+ /// - Returns: `nil` if containment cannot be verified in better than linear
377
+ /// time; otherwise, the method returns a boolean value indicating whether
378
+ /// or not the item is an element of this sequence.
379
+ ///
380
+ /// - Complexity: If this function returns `nil`, it must do so in constant
381
+ /// time. If this returns non-`nil`, then it must have better than linear
382
+ /// complexity.
358
383
func _customContainsEquatableElement(
359
384
_ element: Element
360
385
) -> Bool ?
0 commit comments