Commit Graph
40 Commits
Author SHA1 Message Date
Karoy Lorentey 893e0ff79e [PersistentCollections] Convert _Node to a wrapper around _RawNode
This makes it more explicit that they are assumed to be layout-compatible.
2022-09-14 14:27:26 -07:00
Karoy Lorentey 8a789c2d6f [PersistentCollections] _Node._FindResult: Add docs, rename newSplit to expansion 2022-09-14 13:40:16 -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 e05f4042ed [PersistentCollections] Remove unused code 2022-09-13 23:48:54 -07:00
Karoy Lorentey da0ee9bf79 [PersistentCollections] Remove node protocols 2022-09-13 23:48:54 -07:00
Karoy Lorentey 77edbef16d [_CollectionsUtilities] Restore original debug descriptions 2022-09-13 23:45:22 -07:00
Karoy Lorentey b1cf1eedde [PersistentCollections] Start splitting up _HashPath into _HashValue & _Level
The original approach was a good one — gluing the level (aka shift) onto the hash value isn’t helpful when we’re passing around multiple hashes. The current level also seems like an important enough concept to keep as a standalone parameter.
2022-09-12 12:47:04 -07:00
Karoy Lorentey 4aff69e63c [_CollectionUtilities] More additions 2022-09-12 12:47:04 -07:00
Karoy Lorentey 1e41efa3f0 [PersistentCollections] Slap @inlinable on everything 2022-09-12 12:47:04 -07:00
Karoy Lorentey dd76591970 [_CollectionsUtilities] New module. Use it to unify description/debugDescription implementations 2022-09-12 12:47:04 -07:00
Karoy Lorentey 493aa911ff [PersistentDictionary] Conform to Codable 2022-09-12 12:47:04 -07:00
Karoy Lorentey 65bf47816a [PersistentDictionary] Remove capacity property 2022-09-12 12:47:04 -07:00
Karoy Lorentey 92f3d66996 [PersistentDictionary] Move members to corresponding protocol conformance 2022-09-12 12:47:04 -07:00
Karoy Lorentey f36649d615 [PersistentDictionary] Review Iterator
- Adjust terminology
- Add a reference to the root node — the iterator must have a copy of the underlying collection.
2022-09-12 12:47:04 -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 Lorentey 8429144ae7 [PersistentDictionary] Remove CVarArg placeholder 2022-09-09 00:47:10 -07:00
Karoy Lorentey 7d6d779377 [PersistentCollections] Convert global lets to computed properties
This is just to prevent these from getting turned into global variables that are initialized on first access, especially once we make things inlinable.
(I expect these will all get moved under some type eventually.)
2022-09-09 00:47:10 -07:00
Karoy Lorentey 8d96e3d847 [PersistentCollections] DataBufferElement → Element, ReturnPayload → Element
`Payload` wouldn’t be a bad term for this, though, and we may return to it when we start thinking about PersistentSet.
2022-09-09 00:47:10 -07:00
Karoy Lorentey 36c7f9270c [PersistentCollections] TrieBufferElement → _Node 2022-09-09 00:47:10 -07:00
Karoy Lorentey 5d8bb68209 [PersistentCollections] ReturnBitmapIndexedNode → _Node/Self 2022-09-09 00:47:10 -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
Karoy Lorentey 2597ff23cd [PersistentDictionary] Apply leading underscore rule to common functions 2022-09-07 21:06:19 -07:00
Karoy Lorentey 1f7eb2f95d [PersistentDictionary] Remove unused utility functions 2022-09-07 21:06:19 -07:00
Karoy Lorentey 978a833756 [PersistentDictionary] Clean up Iterator types
- DictionaryKeyValueTupleIterator → PersistentDictionary.Iterator
- DictionaryKeyValueTupleReverseIterator → PersistentDictionary.ReverseIterator

The latter type is unused. Moved under the Unused folder for now.
2022-09-07 21:06:19 -07:00
Karoy Lorentey 8e19b80a23 [PersistentCollections] Apply the leading underscore rule
Also, move types into their own files.
2022-09-07 21:06:19 -07:00
Karoy Lorentey b2d6d98edb [PersistentCollections] NonzeroBits → _NonzeroBits
This doesn’t need to be public API.
2022-09-07 19:38:55 -07:00
Karoy Lorentey 1a4993dfda [PersistentCollections] Reformat
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
2022-09-07 19:16:41 -07:00
Michael Steindorfer ccd11e55dd [Capsule] Clean-up annotations 2022-09-06 21:20:41 +02:00
Michael Steindorfer e2f53441d6 [Capsule] Add subscript(position:) benchmarks 2022-09-06 20:39:38 +02:00
Michael Steindorfer 868eb2fdcc [Capsule] Remove comment after check 2022-09-06 16:43:19 +02:00
Michael Steindorfer 49283d3251 [Capsule] Remove unchecked variant of initializer 2022-09-06 16:37:23 +02:00
Michael Steindorfer 26b97f95d2 [Capsule] Unify insertion/deletion methods
Note, always tracking discardable result negatively impacts batch
use cases.
2022-09-06 16:11:17 +02:00
Michael Steindorfer 7ea47d711f [Capsule] Simplify deletion methods 2022-09-06 14:02:54 +02:00
Michael Steindorfer 4e213be00a [Capsule] Simplify insertion methods 2022-09-06 13:53:58 +02:00
Michael Steindorfer 5bc17ffe84 [Capsule] Rename package to PersistentCollections 2022-09-06 13:22:10 +02:00