<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""></div><div class="">It’s SR-6693 <<a href="https://bugs.swift.org/browse/SR-6693" class="">https://bugs.swift.org/browse/SR-6693</a>> (“Collection.underestimatedCount shouldn't call .count when the latter isn't O(1).").</div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">— </div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com </div></div>
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Jan 2, 2018, at 11:29 PM, Ben Cohen <<a href="mailto:ben_cohen@apple.com" class="">ben_cohen@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Daryle,<div class=""><br class=""></div><div class="">Good spot! This is definitely a bug. The documentation on Sequence should read something different (though what it ought to say is somewhat debatable…).</div><div class=""><br class=""></div><div class="">Could you file a bug on <a href="http://bugs.swift.org/" class="">bugs.swift.org</a>?</div><div class=""><br class=""></div><div class="">Thanks!<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Dec 29, 2017, at 17:54, Daryle Walker via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">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)!</div><div class=""><br class=""></div><div class="">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)?</div></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></body></html>