UnsafeCursor.removeElement(hasValueHole:) only collapsed an empty root
inside the loop that walks up the cursor's path, which never runs when
the removed key is in the root. Removing such a key with d[key].take()
could leave the root as an internal node with no keys and one child.
Collapse the root after the loop so every path depth is covered.
Fixes#811
remove(at:) recursed into the child holding the offset and returned
without balancing it, so repeated removals could empty a leaf. Iterating
then read a stale slot, which returned already-removed elements and read
released references in release builds, and trapped in debug builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_subSequence_Equatable only compared three single-leaf slices with
expectEqual and expectNotEqual. Also run checkHashable, adding empty
slices, equal slices cut from bulk-built and inserted dictionaries, and
ones that differ from them only in a value or only in their keys.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_values_Equatable only ran checkEquatable over single-leaf
dictionaries. Run checkHashable instead, and add a multi-level class
built in bulk and by insertion with different keys but the same values,
plus one that differs in a single value past the first leaf.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_keys_Equatable only ran checkEquatable over single-leaf
dictionaries. Run checkHashable instead, and add a multi-level class
built in bulk and by insertion with different values, plus one that
differs in a single key past the first leaf.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SortedDictionary conforms to Hashable but was never run through
checkHashable. The multi-level dictionary is built both in bulk and by
insertion, so equal dictionaries with different tree layouts must
compare and hash equal; the last two classes differ from it in one key
or one value past the first leaf.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Package traits already pass defines with their trait name when building. Instead of adding our own conditional defines based on the traits we can use the trait provided defines directly. I observed that various tooling behaves better with the trait provided defines.
This re-enables the SortedCollections for easi(er) experimentation.
The module remains source unstable — it may go away entirely or it may receive arbitrary source-breaking changes in any new swift-collections release, with no special pre-announcement.
When removing elements from a B-tree, the root node could become empty while still having children. The previous code incorrectly called drop() which deallocated all children, causing massive data loss during removal operations.
This fix implements proper root reduction by moving the single remaining child out of the empty root, then safely dropping the now-empty parent node and promoting the extracted child to become the new root.
This fixes `test_modifySubscriptRemoval` in `SortedDictionaryTests`, so we re-enable SortedDictionary tests which now all pass.
Key Changes:
- Add tests and benchmarks for SortedSet
- Fix bug during _Node.UnsafeHandle.popFirstElement() rebalancing
- Enable _Node.UnsafeHandle.subscript(elementAt:) to work on value-less nodes.
Minor Changes:
- Optimize Codable to use _BTree.Builder and forEach
- Codable now checks for order, not strictly uniqueness
- Add smaller node size for debug builds to easily catch errors
Key Changes:
- Implement Equatable, Hashable for SubSequences
- Implement SortedDictionary initializers
- init(keysWithValues:) and init(sortedKeysAndValues:) with named and unnamed variants.
- Expand benchmark suite for SortedDictionary
- Commit _BTree.Builder
Minor Changes:
- Update documentation
- Expand test suits
- Fix bug where SubSequences did not define subscript(bounds: Range<Index>)
- _Node
- Implement `depth` property for `_Node`
- Packs both `depth`, `count`, and `capacity` within a single UInt64.
- Implement `init(leftChild:seperator:rightChild:capacity:)` for `_Node`
- Implement `concatenateWith(node:seperatedBy:)` to `_Node.UnsafeHandle`
- Remove bad invariant check on `_Node.UnsafeHandle` deletion subroutines
- _BTree
- Add invariant checks as `_BTree.checkInvariants()`
- Separate `_BTree.*capacity` into `*size` and `*capacity`
- Make _FixedSizeArray top-level
- Remove deque behavior.
Documentation:
- Update complexity documentation style from 'n' to `self.count`
Testing:
- Expand tests for SortedDictionary
- Add tests for SortedDictionary.Keys
- Add tests for _Node.join(...) routines
- Add tests for _BTree.Builder
- Restore checkBidirectionalCollection tests for _BTree
Major Changes:
- Implement Sequence for SortedSet
Minor Changes:
- Fix bug within _Node.UnsafeHandle.pointerToChild(atSlot:)
- Cleanup cursor implementation and fix bugs.
- Fix various bugs in _BTree.FixedSizeArray