mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
`RigidDictionary._insertNew` (and `RigidSet._insertNew`) returned the bucket reported by the hash table's `insertNew_Small`/`insertNew_Large`. That is where the *last displaced* item ends up, not the new item: small tables swap the new item into the middle and move the old middle item to the end, and hashed tables do Robin Hood swaps along the probe sequence. Whenever a swap happened, the returned bucket held some other entry. `memoizedValue(forKey:_:)` on `RigidDictionary` and `UniqueDictionary` returns a reference to the value at that bucket, so inserting a new key often returned the value of a different key. Track the first bucket the swapper writes the new item into, and return that (or the final bucket if nothing was swapped). The hash table's own return value is still used to initialize the displaced item, and its other user (rehashing in `migrateItems_Large`) is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>