美文网首页
Swift_集合的count和underestimatedCou

Swift_集合的count和underestimatedCou

作者: Eyes_cc | 来源:发表于2020-03-18 11:08 被阅读0次

【使用】:集合的元素个数。
值得注意的是:字符串是字符的集合。
Count

/// The number of elements in the collection.
// : 元素个数
///
/// To check whether a collection is empty, use its `isEmpty` property
/// instead of comparing `count` to zero. Unless the collection guarantees
/// random-access performance, calculating `count` can be an O(*n*)
/// operation.
// :要检查集合是否是空的,请使用它的' isEmpty '属性,代替将' count '与0进行比较。除非集合保证了随机访问性能,否则计算“count”可以是O(*n*)操作。
///
/// - Complexity: O(1) if the collection conforms to
///   `RandomAccessCollection`; otherwise, O(*n*), where *n* is the length
///   of the collection.
    @inlinable public var count: Int { get }

underestimatedCount

/// A value less than or equal to the number of elements in the collection.
// :  一个值少于或等于元素的个数
///
/// - Complexity: O(1) if the collection conforms to
///   `RandomAccessCollection`; otherwise, O(*n*), where *n* is the length
///   of the collection.
    @inlinable public var underestimatedCount: Int { get }

相关文章

网友评论

      本文标题:Swift_集合的count和underestimatedCou

      本文链接:https://www.haomeiwen.com/subject/kmcqyhtx.html