Case insensitive string set#658
Draft
CTMacUser wants to merge 4 commits into
Draft
Conversation
Add a type that can be a skeleton for a sorted-set. Useful for un-`Hashable` types or custom comparisons. Add protocol to define custom comparison semantics. Add functions (with helper types) that perform set operations and check for certain combinations of elements. Since the set must always be stored sorted, add conformance to Sequence and Comparable to take advantage.
Relax a method's visibility to be non-private, so it can be called from extension files. Improve the implementation of the self-mutating versions of set operations. Add a method to remove the first element of a set without comparing its value first.
Add _ensureUnique() calls to the element-level mutating set operations.
Introduce CaseInsensitiveStringSet as an internally-sorted list of strings, but any comparisons between strings are case-insensitive. This type conforms to Comparable, CustomDebugStringConvertible, CustomReflectable, CustomStringConvertible, Decodable, Encodable, Hashable, Sequence, and SetAlgebra. There are extra members that are a subset of RangeReplaceableCollection.
Contributor
Author
|
The inspiration came from the extension Then I realized that I had a different problem. The Standard library's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces
CaseInsensitiveStringSet, a sorted set ofStringthat uses case-insensitive comparisons for ordering and equivalence.The API is that
CaseInsensitiveStringSetconforms toComparable,CustomDebugStringConvertible,CustomReflectable,CustomStringConvertible,Decodable,Encodable,Hashable,Sequence, andSetAlgebra. A subset ofRangeReplaceableCollectionprovides common functionality that the previous protocols don't cover.The functions in "SortedSetMerge.swift" evaluate operations combining two sorted sets.
rawSortedMerge(of: and:)vends the merger of the sets, giving an also-sorted result. Those results are expressed as one or two values with their category. Categories are: values only from the first sequence, values only from the second sequence, and values that the two sequences share. A shared vended element gives out the element value from both sources. This function doesn't necessarily need to be used directly, but it implements the actual user-facing functions.sortedMerge(between: and: retaining:)vends a sorted sequence that applies the given set operation to combine the two given source sequences.doesSortedMerger(of: and: haveExclusivesToFirst: hasExclusivesToSecond: haveSharedElements:)checks the count of each result category, returning whether it matches the given pattern. A category can be checked for not being there, being there, or ignored.The
SortedSettype, in "SortedSetToo.swift", uses the above functions to implementSetAlgebrawith an internal skip-list structure.SortedSetis not templated onElementdirectly, but through the protocolOrderable(in "Orderable.swift").Orderabletypes specify theirElementtype and three functions that define ordering. You only have to implement the function that's an analogue to the less-than operation. The equal-to and greater-than operator analogues have default implementations that use the less-than function.CaseInsensitiveStringSetwraps aSortedSetimplementing anOrderableinstantiation that uses case-insensitive comparisons from the Foundation system library. (Thenillocale is used in `String.compare_: options: range: locale:)When being printed, the regular version will print out the canonized casing for each element. (The hash implementation uses this form.) The debug version will print out the string that is actually stored.
Checklist