Does `Dictionary.Keys.contains(_:)` have `O(1)` time complexity?

Dictionary.Keys implements _customContainsEquatableElement, which is a customisation point of Sequence that's called from contains(_ element:).

Dictionary.Key's implementation of this customisation point forwards the call onto the underlying variant buffer which indeed performs the lookup in O(1) time. So yes, dict.key.contains(key) is an O(1) operation.

3 Likes