Swift 里 SetTesting for Membership
Posted huahuahu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Swift 里 SetTesting for Membership相关的知识,希望对你有一定的参考价值。
即contains
操作
/// - Parameter member: An element to look for in the set.
/// - Returns: `true` if `member` exists in the set; otherwise, `false`.
///
/// - Complexity: O(1)
@inlinable
public func contains(_ member: Element) -> Bool {
return _variant.contains(member)
}
最终走到了 _NativeSet
的逻辑。
?
/// Search for a given element, assuming it has the specified hash value.
///
/// If the element is not present in this set, return the position where it
/// could be inserted.
@inlinable
@inline(__always)
internal func find(
_ element: Element,
hashValue: Int
) -> (bucket: Bucket, found: Bool) {
let hashTable = self.hashTable
var bucket = hashTable.idealBucket(forHashValue: hashValue)
while hashTable._isOccupied(bucket) {
if uncheckedElement(at: bucket) == element {
return (bucket, true)
}
bucket = hashTable.bucket(wrappedAfter: bucket)
}
return (bucket, false)
}
以上是关于Swift 里 SetTesting for Membership的主要内容,如果未能解决你的问题,请参考以下文章
经典英文情歌Taylor Swift《You Belong with Me》致最爱的你!
swift 在blog.chrishannah.me上发布“在UITableView上隐藏额外分隔符”的示例代码