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.)
The new fixtures provide an easier way to construct sample
hash trees with specific structure, to run tests on them.
Fixtures are able to determine the expected ordering for each
sample tree, which comes super useful for verifying collection
conformances.
If the key implements hashing properly, then this would be a clever
way to try another hash seed to differentiate between colliding keys.
However, if Key has proper hashing, then collision nodes are expected
to be tiny, so it’s better to simply do naive comparisons. If the Key
type has broken (i.e., partial) hashing, then loading colliding items
into a dictionary would just make == even slower.
So we’re better off comparing collidingh items via nested loops — so
let’s just unconditionally do that.
- Switch to using `ManagedBuffer` to represent node storage. This has
useful performance benefits, but it significantly complicates access
to node data. We no longer have direct access to the underlying raw
storage: everything needs to go through closures passed to
`ManagedBuffer.withUnsafeMutablePointers`.
- Introduce `struct _Node` and `struct _Node.UnsafeHandle` to
represent a (strong) reference to a hash tree node, and a
convenient handle for node storage, respectively. Use these instead
of directly accessing the ManagedBuffer object, whenever feasible.
- Implement separate paths for in-place mutations vs copy-on-write
operation, optimizing both flavors.
- Go to great lengths to eliminate unnecessary retain-release traffic,
whenever possible.
- Push subtree counts into parent nodes by moving the corresponding
field from the node header into the `_Node` struct. (This results in
a cool ~20x speedup for jumping around in the tree by integer
offsets.)
- Implement a type-punned empty root singleton, to allow creating
empty trees without allocating anything.
These provide nicer tools for slicing up hash values and dealing with node bitmaps.
_Bucket is a logical entry in the hash table inside a node.
_Bitmap is a set of bucket values, represented by a bitset.
_HashPath facilitates slicing up a hash value into a series of bucket values.
_HashValue represents a hash value.
This is still just mostly superficial refactoring, with little to no functional changes.
Follow the Standard Library coding style:
- Hard 80 character line limit
- Use two spaces as the indentation unit
- Overlong lines broken up by adding line breaks at the following places
1. After opening delimiters & before closing delimiters
2. Between each item in a list
3. Extracting subexpressions etc as needed