BidirectionalCollection has the connotation that the ordering
of elements is meaningful, which isn’t the case for PersistentSet
and PersistentDictionary.
These marker-like protocols will allow certain
generic operations to get a performance boost
if the passed-in value happens to be guaranteed
to contain unique elements or to be sorted.
Also, review API checker protocols for Sets and
sorted collections and adjust things as needed.
BitSet gains custom implementations for min()
and max() as part of these improvements.
This is mostly about adding more type declarations to deal with type checker limitations in the older compiler.
This also includes workarounds that allow better support for CodingKeyRepresentable in PersistentDictionary, and it fixes a couple of small oversights on various #else branches.
This is useful for validating the API surface of set-like types,
ensuring that we haven’t forgotten to implement members that
are part of users’ baseline expectations.
To ensure maximum utility, this protocol refines neither Collection
nor SetAlgebra.
Merging is best done in-place, as merging a non-empty dictionary will
always mutate the dictionary, so we don’t have to tiptoe around
uniqueness issues.
(The union operation on PersistentSet is vaguely similar, but not
quite — unlike with merge, union is able directly link shared subtrees
into the result. However, a similar optimization may be worthwhile for
symmetricDifference.)
`withHiddenCopies(if:of:)` is supposed to check for value semantic violations where mutations of one copy affect another -- however, it currently only checks that iteration returns the same items before/after the change, not that the old copy is still in a fully consistent state.
Add an extra parameter that can be set to a closure that performs stricter checks.
Use it to call `_checkInvariants()` in ordered collections tests, uncovering a missing uniqueness check in `OrderedSet._insertNew(_:at:in:)`.