mirror of
https://github.com/apple/swift-collections
synced 2026-11-22 04:20:40 +00:00
Run random sequences of operations on SortedDictionary and SortedSet and compare them against a standard Dictionary/Set model after each step: count, contents in sorted order (forward and backward), offset-based indexing, lookups for every key in the domain, and value semantics of earlier copies. SortedDictionary operations include subscript assignment, the `_modify` accessor (`take()`, optional chaining, inout), updateValue, removeValue, modifyValue(forKey:default:), the default subscript, remove(at:), removeFirst/removeLast(_:), popFirst/popLast, filter, mapValues, and rebuilding from a sequence. SortedSet operations include insert/update/remove with members that are equal but distinguishable (checking that insert keeps and update replaces the stored member), remove(at:), removeFirst/removeLast(_:), the form* set algebra operations, and the element range subscripts. In debug builds, nodes hold at most 4-5 keys, so even small key domains produce multi-level trees. Building with COLLECTIONS_INTERNAL_CHECKS also validates the B-tree after every mutation; with that, these tests catch the bugs fixed in93745231(remove(at:) not rebalancing) and3a80514a(empty root after removal through `_modify`).