码迷,mamicode.com
首页 > 编程语言 > 详细

Swift 里 Set(四)Testing for Membership

时间:2019-03-24 13:50:50      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:set   test   not   lang   soc   img   htable   nal   present   

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 里 Set(四)Testing for Membership

标签:set   test   not   lang   soc   img   htable   nal   present   

原文地址:https://www.cnblogs.com/huahuahu/p/Swift-li-Set-siTesting-for-Membership.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!