<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><span style="font-family: Helvetica; font-size: 12px;">Hi guys, I know this
topic is probably out of scope for Swift 4 and a proposal was
already rejected for Swift 3, but I’d like to share my two cents on
this as I just wrote a SortedArray class with support for binary
search in my open source library HandySwift.</span></div><font color="#0a51a1" face="Helvetica"><span style="font-size: 12px;"><br></span></font><span style="font-size: 12px; font-family: Helvetica;">You can see my classes
current implementation here:</span><br><a href="https://github.com/Flinesoft/HandySwift/blob/cd7ae7041c8174cd655f24eae653f76697875a48/Sources/Structs/SortedArray.swift#L57">https://github.com/Flinesoft/HandySwift/blob/cd7ae7041c8174cd655f24eae653f76697875a48/Sources/Structs/SortedArray.swift</a><br><font color="#0a51a1"><br></font>My goal was to
provide only what is commonly needed when working with big arrays
in algorithms. For me this included:<br>- having a type
that keeps a sorted array to prevent re-sorting (solution: the
SortedArray class)<br>- have a method
that can find an object using binary search (solution: the index
method)<br>- allow
partitioning the array into smaller parts (solution: subscript,
prefix & suffix methods)<br>- prevent
re-implementing the Array class (solution: a getter to the stored
internal array)<br><font color="#0a51a1"><br></font>Also note that the
SortedArray in my approach allows all types that conform to
`Sequence` as input with `Comparable` elements and saves them into
a sorted array on initialization. That array is also publicly
read-accessible. Inserting and deleting objects from the
SortedArray are possible, too, but that’s just few of the
MutableCollection methods. I didn’t want the SortedArray to conform
to MutableCollection or even RandomAccessCollection as I felt
it was not needed just to support binary search and prevent
re-sorting.<br><font color="#0a51a1"><br></font>Maybe my approach
can somehow help forming the final solution to be included into
Swift once this features is tackled again.<br><font color="#0a51a1"><br></font>Best regards,<br>Cihat<br><blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div></div></span></blockquote></body></html>