<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=""><div class="">I mentioned in other messages about adding permutations and combinations (probably as generators/iterators) to the standard library. &nbsp;I tried making sample implementations and a proposal, but it transitioned to adapting C++’s “is_permutation,” “next_permutation,” and “prev_permutation” instead. &nbsp;The sample implementation of “is_permutation” I saw at &lt;<a href="http://en.cppreference.com/w/cpp/algorithm/is_permutation" class="">http://en.cppreference.com/w/cpp/algorithm/is_permutation</a>&gt; involves the “mismatch” function, which we also don’t seem to have. &nbsp;Since that function seems like a small enough bite the chew, I finally made a proposal at &lt;<a href="https://gist.github.com/CTMacUser/c1a0d7ac60cf827184c33e8768a23dfc" class="">https://gist.github.com/CTMacUser/c1a0d7ac60cf827184c33e8768a23dfc</a>&gt;. &nbsp;(The Gist is currently flagged as secret.)</div><div class=""><br class=""></div><div class="">Oh, it seems that everyone here has moved on to Swift 3, and so has my third-party documentation program. &nbsp;Unfortunately, I still on non-beta code, which means Swift 2.2. &nbsp;So I took some time having to translate concepts between the versions, including new names.</div><div class=""><br class=""></div><div class="">The name “mismatch” didn’t seem Swift-y enough since it doesn’t describe what’s happening from a Swift programming perspective. &nbsp;I tried:</div><div class=""><br class=""></div><div class="">* commonPrefixUntil / commonSuffixUntil</div><div class="">* elementsEqualUntil / elementsEqualSince</div><div class="">* elementsShared(until:) / elementsShared(since:)</div><div class="">* elementsDiverge / elementsConverge</div><div class=""><br class=""></div><div class="">No, those parameters on the third one don’t make sense. &nbsp;The last one inspired me to trim the fat and just use “diverge(from:)”. &nbsp;Since we use indexes here like C++’s iterators, that was the best choice for a return type that allows the users to take the results in an inspecting manner or mutating manner. &nbsp;But Swift’s model doesn’t handle reversed collections like C++ does, so I need a separate routine for mismatching with reverse iterators, i.e. searching backwards with indexes. &nbsp;Since I used the “diverge” name for the forward search, I flipped it to “converge(with:)” for the reverse/suffix search. &nbsp;The returns aren’t used in quite the same manner since I have to avoid needing a before-the-start index.</div><div class=""><br class=""></div><div class="">A lot of the format was badly copied from the rotate/reverse proposal (&lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0078-rotate-algorithm.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0078-rotate-algorithm.md</a>&gt;). &nbsp;Looking for opinions, mistakes/clean-up, anything major missing?...</div><div class=""><br class=""></div><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="">—&nbsp;</div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com&nbsp;</div></div>
</div>
<br class=""></body></html>