<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. I tried making sample implementations and a proposal, but it transitioned to adapting C++’s “is_permutation,” “next_permutation,” and “prev_permutation” instead. The sample implementation of “is_permutation” I saw at <<a href="http://en.cppreference.com/w/cpp/algorithm/is_permutation" class="">http://en.cppreference.com/w/cpp/algorithm/is_permutation</a>> involves the “mismatch” function, which we also don’t seem to have. Since that function seems like a small enough bite the chew, I finally made a proposal at <<a href="https://gist.github.com/CTMacUser/c1a0d7ac60cf827184c33e8768a23dfc" class="">https://gist.github.com/CTMacUser/c1a0d7ac60cf827184c33e8768a23dfc</a>>. (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. Unfortunately, I still on non-beta code, which means Swift 2.2. 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. 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. The last one inspired me to trim the fat and just use “diverge(from:)”. 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. 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. Since I used the “diverge” name for the forward search, I flipped it to “converge(with:)” for the reverse/suffix search. 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 (<<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>>). 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="">— </div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com </div></div>
</div>
<br class=""></body></html>