<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 20, 2016, at 12:28 PM, Dave Abrahams 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=""><div class=""><blockquote type="cite" style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;" class="">"But what about dictionaries?" Ah, but a dictionary key is not an<br class="">Index (note the capital). The relation between a Collection and an<br class="">Index is that there must be a constant-time operation to get to a<br class="">value from an Index.<span class="Apple-converted-space"> </span><br class=""></blockquote><br style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;" class=""><span style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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; float: none; display: inline !important;" class="">Well, but that also applies to dictionary keys. </span></div></div></blockquote><br class=""></div><div>Not necessarily. It does if the dictionary is based on a [well-implemented] hash table. But if it’s implemented as a search tree (as C++’s std::map is), it’s not — lookup time is O(log n).</div><br class=""><div class="">Quibbling aside, there are significant differences between looking up array items and lookup up dictionary keys. It’s extremely common to look up a key that might validly not exist in the dictionary, but it’s pretty rare to do the same with an array — usually if the array index is out of bounds it’s a programmer error.</div><div class=""><br class=""></div><div class="">—Jens</div></body></html>