Repository navigation
SwiftCollections v9.0.0
This release adds dense ticket-based storage, native 2D spatial queries, and comparer-aware persistence, alongside correctness and allocation improvements throughout the library.
Build packed agent updates, attach optional component data to shared identities, and query planar worlds with matching Numerics and fixed-point APIs.
Breaking changes and upgrading
Comparers now persist with their collections
SwiftSortedList<T>, SwiftDictionary<TKey, TValue>, SwiftHashSet<T>, SwiftBiDictionary<T1, T2>, and SwiftObservableDictionary<TKey, TValue> now preserve supported comparison rules through JSON and Standard-package MemoryPack serialization.
These owners use a new, versioned serialization format. Previous state-only owner payloads are rejected by the new readers, and old readers cannot read the new format. Upgrade writers and readers together; no legacy reader or migration helper is provided.
- Supported built-in comparison rules require no host registration.
- Custom comparers—including comparisons backed by lambdas—require a registered typed codec and reconstruction factory. Delegates are not serialized automatically.
- Unsupported comparer persistence fails explicitly instead of silently restoring different comparison behavior.
- Lean packages support the same JSON contract without MemoryPack.
- Raw state DTOs and explicit trusted-state constructors remain separate APIs; they do not provide compatibility readers for old owner payloads.
See the serialization guide for registration and persistence contracts.
BVH insertion now enforces unique keys
BVH indexes now follow the same key-ownership model as spatial hashes and subdivision trees:
- Inserting a new key returns true.
- Reinserting an equal key updates its bounds and returns false, preserving the original stored key and count.
- Null keys are rejected before mutation.
Code that relied on duplicate leaves or an always-true insertion result must adapt. Use distinct keys for independently indexed entries.
FixedMathSharp companion dependencies
Review the v8 → v9 migration guide before upgrading persisted data or fixed-point consumers.
New features
Dense storage with explicit identity ownership
Two new collections combine packed live-value iteration with generation-checked tickets:
SwiftDenseTicketMap<T>owns ticket allocation and reusable slots. Removal uses swap-back storage while preserving surviving tickets. Exhausted generations retire instead of wrapping.SwiftTicketStore<T>attaches packed values to tickets issued by another owner. Multiple stores can share an agent identity while independently owning position, velocity, health, or other optional data.
Both provide writable live-value spans, reference access, state snapshots, JSON serialization, and Standard-package MemoryPack support. Dense ordering is deterministic for the same initial state and ordered mutations.
A ticket store owns local membership; the caller coordinates issuer lifetime and component teardown.
See the collection guide and examples for choosing between slots, ticket maps, dense maps, and external stores.
Native 2D spatial queries
New planar query families complement the existing 3D indexes:
SwiftBVH2D<TKey>SwiftSpatialHash2D<TKey>SwiftQuadtree<TKey>- Native
BoundVolume2Dbounds - Matching
SwiftFixedBVH2D<TKey>,SwiftFixedSpatialHash2D<TKey>,SwiftFixedQuadtree<TKey>, andFixedBoundVolume2Dcompanion types
The 2D implementations use native XY storage. Spatial hashes and subdivision trees share internal machinery with their 3D counterparts to keep behavior aligned.
See the spatial query guide.
More control over bounded work
- Added BVH
TryQuerywith caller-owned result capacity and traversal scratch. Insufficient capacity returns false before modifying either buffer. - Added
SwiftSortedList<T>.TryAddUnique, using the ordering comparer to determine uniqueness. - Added
SwiftDictionary<TKey, TValue>.LookupProbeLimitandSwiftHashSet<T>.EnumerationSlotCountfor explicit traversal-work accounting.
Correctness fixes
- Arrays: Validate dimensional shapes before mutation and use exact integer arithmetic for deterministic Int16 normalization.
- Queue and list: Correct full-capacity queue restoration and grow list-copy destinations to the required capacity.
- Dictionary views and inheritance: Keep retained key/value views connected to current storage after resizing, and preserve bidictionary invariants and observable notifications through base and interface indexer assignments.
- State restoration: Reject malformed packed-set state containing duplicate or null entries instead of publishing inconsistent membership.
- Slot maps: Preserve live-slot ownership during reinsertion while retaining constant-time reinsertion.
- Pools: Preserve outstanding-rental counts during clearing and consistently enforce terminal disposal across collection-pool wrappers.
- Observable dictionaries: Emit addition notifications only after successful insertion.
- Object adapters: Preserve exceptions from user comparers, equality methods, overrides, and event subscribers instead of misclassifying them as conversion failures.
- Spatial queries: Prevent overflowing or nonshrinking Numerics octree subdivisions.
- Utilities: Reject non-positive inputs in IsPowerOfTwo.
Performance and documentation
- Removed value-key boxing from the verified unchanged-bounds spatial-hash upsert paths.
- Reduced bidictionary restoration allocations.
- Removed discarded old-state snapshots when replacing dense ticket owners during MemoryPack deserialization.
- Improved sorted-list insertion, recentering, and reference cleanup.
- Consolidated shared collection-pool lifecycle and 2D/3D query machinery.
- Hardened public XML documentation, ownership contracts, collection-selection guidance, and generated API-reference coverage.
- Enforced 100% reported line, branch, and executable-method coverage for both runtime assemblies in Standard and Lean validation.
Packages and compatibility
All four package variants continue to target netstandard2.1 and net10.0:
- SwiftCollections
- SwiftCollections.Lean
- SwiftCollections.FixedMathSharp
- SwiftCollections.FixedMathSharp.Lean
Get started · Documentation · Migration guide
Full changelog: v8.0.0 → reviewed v9 revision