Commit Graph
167 Commits
Author SHA1 Message Date
Karoy Lorentey d3987c79a1 Merge branch 'release/1.1'
# Conflicts:
#	Package.swift
#	Sources/PersistentCollections/PersistentSet/PersistentSet+Extras.swift
#	Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqual.swift
#	Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift
2022-10-19 18:25:48 -07:00
Karoy Lorentey 5dfd51238c [OrderedSet] Review, test, fix, and document set relation predicates 2022-10-19 15:20:30 -07:00
Karoy Lorentey 8ce8a6bc86 [PersistentSet] Review, test, fix, and document set relation predicates 2022-10-19 15:20:17 -07:00
Karoy Lorentey f843bd40bf [PersistentSet] Add update(_:at:) 2022-10-19 15:20:17 -07:00
Karoy Lorentey 001df8e325 [BitSet] Review, test, fix, and document set relation predicates
- Update documentation
- Improve performance where possible
- Add missing test coverage where needed
2022-10-19 15:20:17 -07:00
Karoy Lorentey 291623d391 [BitSet] Implement isEqual(to:) family of functions 2022-10-19 01:40:06 -07:00
Karoy Lorentey 51a1554f89 Introduce _UniqueCollection & _SortedCollection
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.
2022-10-19 01:40:06 -07:00
Karoy Lorentey 2e9447fb1c [_CollectionsTestSupport] Richer support for combinatorial testing 2022-10-13 15:45:08 -07:00
Karoy Lorentey 098495b4ab [Heap] Add more exhaustive tests for some critical paths 2022-10-13 14:52:06 -07:00
Karoy Lorentey 5f70117c55 [Heap] Start using _CollectionsTestSupport for testing 2022-10-12 16:30:52 -07:00
Karoy Lorentey 5a712f4cfc Merge pull request #208 from lorentey/heap-replace-min-max
[Heap] Add methods to replace minimum/maximum (redux)
2022-10-12 16:25:20 -07:00
Karoy Lorentey 7138144f37 [Heap] Remove unnecessary testing APIs
We do not need a _raw initializer in the Heap implementation. The
heapify algorithm will not modify storage if it’s already in the
expected shape, so we can simply define one locally that double checks
that the order remains unchanged.
2022-10-12 16:01:23 -07:00
Karoy Lorentey 92d808d179 Merge branch 'heap-replace-extrema' into release/1.1 2022-10-12 15:23:17 -07:00
Karoy Lorentey b1506b6225 [SortedCollections] Remove for now
These are still on track for 1.2.0, but I’ll need to bump them from
the release/1.1 branch.
2022-10-11 17:55:35 -07:00
Karoy Lorentey 6286cd0b99 Restore support for building with Swift 5.5
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.
2022-10-10 18:07:49 -07:00
Karoy Lorentey 33b759b842 [Heap] PriorityQueueModule → HeapModule 2022-10-09 15:44:44 -07:00
Karoy Lorentey 0b86bb11d2 [PersistentSet] Flesh out API surface
Add customary overloads for high-level Set operations.
2022-10-09 15:26:32 -07:00
Karoy Lorentey 4604c1bc38 [test] Add SetAPIChecker protocol
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.
2022-10-09 13:33:23 -07:00
Karoy Lorentey 78ac2eaed7 [BitSet] Add remove(at:) implementation 2022-10-09 13:20:12 -07:00
Karoy Lorentey f71ebd9494 [PersistentDictionary] Implement structural merge operations
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.)
2022-09-30 19:55:04 -07:00
Karoy Lorentey 81acdb7f8d [PersistentSet] Implement structural symmetricDifference
I think this may be the last missing non-trivial algorithm for this module.
2022-09-29 17:33:10 -07:00
Karoy Lorentey 876177dbb5 [PersistentSet] Test & fix symmetricDifference 2022-09-28 18:38:14 -07:00
Karoy Lorentey 562b21e70f [PersistentCollections] filter, intersection, subtracting: Don’t build a result node until we know for sure we won’t just clone self 2022-09-28 14:45:44 -07:00
Karoy Lorentey 4a4c4a75fd [PersistentSet] Add tests for union; fix issues 2022-09-27 23:02:40 -07:00
Karoy Lorentey 03a4791766 [PersistentSet] Add tests for set predicates; fix issues 2022-09-27 14:18:40 -07:00
Karoy Lorentey a887a77ef5 [PersistentSet] Add tests for intersection & subtracting; fix issues 2022-09-27 14:18:40 -07:00
Karoy Lorentey 6437aea75a [PersistentCollections] Improve test coverage & fixtures 2022-09-27 14:18:40 -07:00
Karoy Lorentey 826e22c91e [PersistentDictionary] Implement structural filter & compactMapValues
Plus add tests covering these as well and mapValues.
2022-09-24 17:09:36 -07:00
Karoy Lorentey 958fd47539 [PersistentSet] Start drafting the new type 2022-09-21 10:45:20 -07:00
Karoy Lorentey c355812e53 [PersistentDictionary] Small cleanups 2022-09-21 10:45:20 -07:00
Karoy Lorentey b7bfc52664 [test] Add Dictionary API checker protocol
This can be used to verify that a new dictionary implementation
provides all expected members.
2022-09-19 21:25:07 -07:00
Karoy Lorentey a2491aac45 [PersistentDictionary] Improved copy & resize operations
Don’t copy the current node and then insert a new item into it.
Instead, create the copy with the new item already inserted.

Ditto for new collisions.
2022-09-19 21:25:07 -07:00
Karoy Lorentey d9cff57f0c [test][PersistentDictionary] Clean up fixture initialization 2022-09-19 21:25:07 -07:00
Karoy Lorentey 9da672fdf8 [PersistentDictionary] Fix index(forKey:) test 2022-09-19 21:25:07 -07:00
Karoy Lorentey 4c4154ca23 [SortedCollections] Just disable SortedDictionary tests for now 2022-09-19 21:10:36 -07:00
Karoy Lorentey f4dc3aa4a9 Merge branch 'feature/SortedCollections' into release/1.1
# Conflicts:
#	Package.swift
#	Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/SortedCollections.xcscheme
2022-09-19 16:06:24 -07:00
Karoy Lorentey de31437ee5 Merge branch 'feature/PersistentCollections' into release/1.1 2022-09-19 16:02:51 -07:00
Karoy Lorentey 31eca4a02c Merge branch 'feature/BitSet' into release/1.1
# Conflicts:
#	Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/Collections.xcscheme
2022-09-19 16:00:20 -07:00
Karoy Lorentey 57deed5f0f [PersistentDictionary] Implement in-place mutations
# Conflicts:
#	Tests/PersistentCollections2Tests/PersistentMap Fixtures.swift
2022-09-17 17:20:34 -07:00
Karoy Lorentey bf3617e379 [PersistentCollections] Work on testing a bit; add fixtures
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.
2022-09-15 20:56:50 -07:00
Karoy Lorentey 3e38184f2a [PersistentCollections] Optimize _Node.==
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.
2022-09-15 20:56:50 -07:00
Karoy Lorentey c9ca59fbb9 [PersistentCollections] Improved storage representation
- 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.
2022-09-13 23:48:54 -07:00
Karoy Lorentey 3441a48045 [PersistentDictionary] rootNode → root 2022-09-12 12:47:04 -07:00
Karoy Lorentey 3bc9b42739 [PersistentCollections] Standard invariant checks 2022-09-12 12:47:04 -07:00
Karoy Lorentey ca19ecb5b3 [PersistentDictionary] Don’t copy collision node contents into arrays 2022-09-12 12:47:04 -07:00
Karoy Lorentey afdb471af7 [PersistentCollections] “trie”, “subNode” → “child”, “data” → “item”
Also, replace the use of the word “trie” with “prefix trie” (or “hash tree”) throughout the documentation & comments.
2022-09-12 12:47:04 -07:00
Karoy Lorentey 14f90620c8 [PersistentCollections] Introduce _Bucket, _Bitmap, _HashPath, and _HashValue
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.
2022-09-09 00:47:10 -07:00
Karoy LorenteyandMichael Steindorfer aa428d0489 Update spelling of publication dates
Co-authored-by: Michael Steindorfer <michael@steindorfer.name>
2022-09-08 16:04:18 -07:00
Karoy Lorentey 750559ea9e [PersistentDictionary] PersistentDictionaryIndex → PersistentDictionary.Index 2022-09-08 00:55:48 -07:00
Karoy Lorentey 6f93a628e8 [PersistentDictionary] BitmapIndexedDictionaryNode → PersistentDictionary._ Node, Header → _NodeHeader
Also move Capacity, Bitmap under _NodeHeader.

Start thematically organizing _Node members.
2022-09-07 21:06:19 -07:00