Commit Graph
63 Commits
Author SHA1 Message Date
Karoy Lorentey 18a01247a3 [PersistentDictionary] Add missing documentation comments 2022-10-27 18:08:27 -07:00
Karoy Lorentey 648aaa7f56 [PersistentSet] Review, test, fix, and document binary set operations 2022-10-21 18:24:08 -07:00
Karoy Lorentey 5783b82d72 [PersistentCollections] Fix building with library stability enabled
Building this package with library stability enabled
is entirely unsupported, but let’s add a few @frozen
attributes to fix such builds anyway.

This package is explicitly not ABI stable; the @frozen
attribute does not mean a guarantee to leave
layout unchanged in future revisions.
2022-10-19 19:33:33 -07:00
Karoy Lorentey bceadab267 [PersistentCollections] Reduce popcount usages where possible
# Conflicts:
#	Sources/PersistentCollections/Node/_Node+Primitive Removals.swift

(cherry picked from commit e153ebf798)
2022-10-19 17:58:46 -07:00
Karoy Lorentey 6b516b72fb [PersistentCollections] Slightly more readable index descriptions
(cherry picked from commit 785caa4a55)
2022-10-19 17:58:46 -07:00
Karoy Lorentey 2e276ba42b [PersistentCollections] Clean up _Node.Builder & removals
This sanitizes the semantics of _Node.Builder, removing
the (unneccessary) need to pass around hash paths.

It also slightly refactors removal operations, but stops short of
implementing node shrinking.

# Conflicts:
#	Sources/PersistentCollections/Node/_Node+Builder.swift
#	Sources/PersistentCollections/Node/_Node+Initializers.swift
#	Sources/PersistentCollections/Node/_Node+Structural intersection.swift
#	Sources/PersistentCollections/Node/_Node+Structural subtracting.swift
#	Sources/PersistentCollections/Node/_Node+Subtree Modify.swift
#	Sources/PersistentCollections/Node/_Node+Subtree Removals.swift
#	Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Initializers.swift
#	Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra Initializers.swift
#	Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra intersection.swift
#	Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtracting.swift

(cherry picked from commit c73a8caad1)
2022-10-19 17:58:46 -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 0b86bb11d2 [PersistentSet] Flesh out API surface
Add customary overloads for high-level Set operations.
2022-10-09 15:26:32 -07:00
Karoy Lorentey d7dbaee8b9 [PersistentCollections] Minor enhancements 2022-10-09 15:20:40 -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 6dfad714a1 [PersistentCollections] _Node.update → _Node.updateValue
To prevent confusion with the low-level _Node.update method.

This also switches PersistentSet.insert to use `_Node.insert` instead of `_Node.updateValue`, to fix its semantics. `insert` no longer invalidates indices when the new member already exists in the collection.
2022-09-30 12:19:40 -07:00
Karoy Lorentey 8e3e205954 [PersistentCollections] Add missing import 2022-09-29 17:54:08 -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 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 c7906d924e [PersistentSet] intersect, subtracting, filter: Preserve structure when possible 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 03c1bd958a [PersistentSet] Implement structural union operation (untested) 2022-09-27 14:18:39 -07:00
Karoy Lorentey c92b0fa99a [PersistentSet] Implement structural subtraction, intersection, filtering (untested) 2022-09-24 17:11:10 -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 d87f5fd1e1 [PersistentCollections] Optimize key-based lookup operations 2022-09-23 21:28:32 -07:00
Karoy Lorentey 92d1d1297e [PersistentDictionary] Add a quick&dirty memory benchmark
The new executable target `memory-benchmark` collects some memory usage statistics and outputs average memory efficiency for a range of sizes in CSV format.

Bump required toolchain version for benchmarks to Swift 5.5.
2022-09-23 16:47:30 -07:00
Karoy Lorentey 2193e7995d [PersistentCollections] Slightly optimize compressed path case in isSubset/isDisjoint 2022-09-23 11:15:56 -07:00
Karoy Lorentey 9150bbf06e [PersistentCollections] Cache the item hash within collision nodes
This will simplify merge operations as we no longer have to spend effort on preventing repeated rehashings of items within collision nodes.

Also, review and simplify node allocation and lookup code.
2022-09-23 11:15:56 -07:00
Karoy Lorentey 287c677482 [PersistentCollections] Fix indexing oversight when spawning a new child in a non-unique node
Oops, this did not account for reversed item order, so it was spawning the new child with the wrong item.
2022-09-23 11:15:56 -07:00
Karoy Lorentey 77f205f45e [PersistentCollections] Implement structural index(_:offsetBy:) & index(_:offsetBy:limitedBy:) 2022-09-23 11:15:46 -07:00
Karoy Lorentey eefef1e585 [PersistentCollections] Small path-related adjustments 2022-09-23 11:15:46 -07:00
Karoy Lorentey 8c9ae08abf [PersistentCollections] Remove dead code 2022-09-23 11:15:46 -07:00
Karoy Lorentey de136505c0 [PersistentCollections] _Node.isEqual: Don’t allow customizing key comparisons; add a fast path for collision nodes 2022-09-22 16:33:59 -07:00
Karoy Lorentey f79fd630bf [PersistentCollections] _Node.isDisjoint: Add new fast path 2022-09-22 16:33:55 -07:00
Karoy LorenteyandMichael Steindorfer f2539a4b21 Update Sources/PersistentCollections/Node/_Stack.swift
Co-authored-by: Michael Steindorfer <michael@steindorfer.name>
2022-09-22 16:31:21 -07:00
Karoy LorenteyandMichael Steindorfer 24619dfe31 Update Sources/PersistentCollections/Node/_Node+isDisjoint.swift
Co-authored-by: Michael Steindorfer <michael@steindorfer.name>
2022-09-22 11:31:11 -07:00
Karoy Lorentey 958fd47539 [PersistentSet] Start drafting the new type 2022-09-21 10:45:20 -07:00
Karoy Lorentey 04b134e9aa [PersistentCollections] Fix memory management for the hash tree iterator
This slows iteration down by about 37% percent but it now works within ManagedBuffer’s requirements.
2022-09-21 10:45:20 -07:00
Karoy Lorentey c355812e53 [PersistentDictionary] Small cleanups 2022-09-21 10:45:20 -07:00
Karoy Lorentey 8d7c777e47 [PersistentCollections] _children → children, itemEnd → itemsEndSlot, childEnd → childrenEndSlot 2022-09-19 21:25:07 -07:00
Karoy Lorentey 71c881cfdb [PersistentDictionary] mapValues, compactMapValues, filter 2022-09-19 21:25:07 -07:00
Karoy Lorentey 75edf6cd69 [PersistentDictionary] Add support for merging dictionaries & for in-place value mutations 2022-09-19 21:25:07 -07:00
Karoy Lorentey ea30715a6c [PersistentDictionary] Implement Keys and Values views 2022-09-19 21:25:07 -07:00
Karoy Lorentey 310f801deb [Utilities] Add UInt16 rank utilities 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 f7c419d7cf [PersistentDictionary] Rework allocations 2022-09-19 21:25:07 -07:00
Karoy Lorentey 53895c6537 [PersistentCollections] Split up node mutations into multiple files 2022-09-19 21:24:37 -07:00
Karoy Lorentey b263fb442e [Benchmarks] Move source files under Sources/
This eliminates the need to use path overrides.

Also, explicitly define a product for the “benchmark” executable.
2022-09-19 16:58:25 -07:00
Karoy Lorentey d45f264ef0 [PersistentDictionary] Fix index(forKey:) performance 2022-09-17 20:04:19 -07:00
Karoy Lorentey 5240bf6e0a [PersistentCollections] Reduce _Bucket’s storage size 2022-09-17 17:20:34 -07:00
Karoy Lorentey 2321b34d80 [PersistentCollections] Fix node sizing logic
Base the allocation request on the currently occupied space, not the
full capacity.

The original code tended to lead to unnecessary doubling of the node
size in each copy, until we exhaust the 32 bit capacity value. (Oops.)
2022-09-17 17:20:34 -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 1661bd431c [PersistentDictionary] Implement in-place mutations for defaulted subscript 2022-09-16 23:19:40 -07:00