[swift-users] Time taken on Collection.underestimatedCount?
Daryle Walker
darylew at mac.com
Fri Dec 29 19:53:57 CST 2017
Sequence.underestimatedCount is supposed to work at O(1) time, according to the docs on Apple’s developer website. On the other hand, Collection.count works at O(n) time, except for RandomAccessCollection where it can work at O(1) time. I’ve been playing around with creating various Collection types, and it seem that their underestimatedCount has a default implementation that just dumps to count, even when the latter is O(n)!
I think that underestimatedCount should call count only for RandomAccessCollection, while Collection and BidirectionalCollection call isEmpty as needed. Is this a good idea? Should I post a bug report (somewhere)?
—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171229/1c31ddd8/attachment.html>
More information about the swift-users
mailing list