Hi Igor,<br><br>Since your proposal would be additive, it probably wouldn't be considered for review until the next phase of Swift evolution.<br><br>My read of the core team's feedback is that some binary search functionality is welcome, but it's a question of *how* it's designed. When purely additive changes are in scope, a successful proposal will likely address the weaknesses of the previous proposal. Since that proposal considered as an alternative a design such as yours, but it concluded that a different design was better, you'll probably want to address why you think this API design is best, or alternatively, you may want to study the alternatives presented in that proposal and refine them to be better.<br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 7, 2016 at 05:16 Igor Vasilenko via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)">do you mean this?</pre><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)">public func binarySearch<T: Comparable>(array: [T], key: T, range: Range<Int>, sorted: Bool) -> Int?</pre><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"></div></div></div></div></div></div></div></div></div><div style="word-wrap:break-word"><div><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><p dir="ltr" style="color:rgb(96,96,96);font-size:15px;line-height:22.5px;margin:1em 0px;padding:0px">Best regards, Igor Vasilenko <br></p><p dir="ltr" style="color:rgb(96,96,96);font-size:15px;line-height:22.5px;margin:1em 0px;padding:0px">iOS Developer at Yota</p></div></div></div></div></div></div></div></div></div><div style="word-wrap:break-word"><div><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><p dir="ltr" style="color:rgb(96,96,96);font-size:15px;line-height:22.5px;margin:1em 0px;padding:0px">+7 (999) 527 - 07 - 59<br><span style="line-height:1.6em"><a href="mailto:name.surname@e-legion.com" target="_blank">spb.vasilenko@gmail.com</a></span><br><a href="http://www.e-legion.com/" style="line-height:1.6em;word-wrap:break-word;color:rgb(109,198,221)" target="_blank">www.spbvasilenko.github.io</a></p></div></div><br></div><br></div><br></div><br></div><br></div><br><br>
</div></div><div style="word-wrap:break-word">
<br><div><blockquote type="cite"><div>On 07 Sep 2016, at 13:08, Guillaume DIDIER <<a href="mailto:guillaume.didier.2014@polytechnique.org" target="_blank">guillaume.didier.2014@polytechnique.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div>Basically for a binary search to work it needs to operate on a sorted array (it is a necessary invariant).</div><div><br></div><div>It is really interesting when you make a lot of search in the same sorted array, hence I would +1 the sorted array, with initializer from an array.</div><div><br></div><br><div>
<div style="text-align:start;text-indent:0px;word-wrap:break-word"><div style="text-align:start;text-indent:0px;word-wrap:break-word"><div style="text-align:start;text-indent:0px;word-wrap:break-word"><div style="text-align:start;text-indent:0px;word-wrap:break-word"><div style="text-align:start;text-indent:0px;word-wrap:break-word"><div style="margin:0px;line-height:normal"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px;line-height:normal"><font face="Georgia" size="2" color="#073763"><b><span>Guillaume </span><span> DIDIER</span></b></font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px;line-height:normal"><span style="color:rgb(7,55,99);font-family:'Century Gothic';font-size:13px">—</span></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;color:rgb(7,55,99)"><span><span><span><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;color:rgb(7,55,99);margin:0px;line-height:normal;font-family:'Lucida Sans';min-height:15px"><b style="font-family:'Century Gothic';font-size:11px">ÉCOLE POLYTECHNIQUE</b><i></i></div><div style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;color:rgb(7,55,99);margin:0px;font-size:11px;line-height:normal;font-family:'Century Gothic'">91128 PALAISEAU CEDEX<br><span style="color:rgb(30,73,125)">M.</span> <span style="color:rgb(30,73,125)">+33 (</span>0<span style="color:rgb(30,73,125)">)7</span> 70 43 18 40<br><a href="mailto:guillaume.didier@polytechnique.edu?subject=" target="_blank"><span style="line-height:normal">guillaume.didier@polytechnique.edu</span></a></div><div style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;color:rgb(71,135,255);margin:0px;font-size:11px;line-height:normal;font-family:'Century Gothic'"><span style="text-decoration:underline"><a href="http://www.polytechnique.edu/" target="_blank">www.polytechnique.edu</a></span></div><div style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;color:rgb(7,55,99);font-size:13px;margin:0px;line-height:normal;font-family:'Century Gothic'">—</div></span></span></span></span></span></div></div></div></div></div></div>
</div>
<br><div><blockquote type="cite"><div>Le 7 sept. 2016 à 12:04, Haravikk via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br><div><div><br><blockquote type="cite">On 7 Sep 2016, at 10:08, Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br>Aside from this being additive (i.e. out of scope for Swift 4), this requires the array to be sorted in order for the search to work - who will guarantee this? The caller? What happens when this is called on an array that is not sorted? You likely get nil, while the item is in the array (false negative).<br><br>This would probably make sense by not extending Array itself, but introducing SortedArray which would automatically keep its members sorted instead - this way there would be a guarantee that the array is sorted and the user won't have to deal with sorting the array. It would however be at the cost of O(log N) for insertion…<br></blockquote><br>I don't think this is really a problem, just needs to be clear that behaviour is undefined if the array wasn't previously sorted (or not in the same order).<br><br>On this topic there was a previous proposal that was undergoing refinements after being initially rejected, you can find it here:<br><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0074-binary-search.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0074-binary-search.md</a><br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></blockquote></div><br></div></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>