[BasicContainers] Fix incorrect wraparound implementation in hashed container insertions with NO_ROBIN_HOOD_HASHING

This commit is contained in:
Karoy Lorentey committed 2026-03-05 15:30:10 -08:00
1 parent ae4e6f850e
commit cef50eee26
2 files changed
+7 -2

No files matched your search

@@ -86,8 +86,10 @@ extension _HTable.Bitmap {
}
}
/// Note: If the bitmap has fewer than Word.capacity bits, then this may
/// report an unoccupied bit beyond the end of its actual size.
@inlinable
package func firstUnoccupiedBucket(wrappingFrom start: Bucket) -> Bucket {
package func firstUnoccupiedBucket(from start: Bucket) -> Bucket {
assert(isValid(start))
var word = start.word
var bits = _words[word]
@@ -36,7 +36,10 @@ extension _HTable {
#if COLLECTIONS_NO_ROBIN_HOOD_HASHING
let ideal = idealBucket(forHashValue: hashValue)
let bitmap = self.bitmap
let actual = bitmap.nextUnoccupiedBucket(wrappingFrom: ideal)
var actual = bitmap.firstUnoccupiedBucket(from: ideal)
if actual._offset >= self.bucketCount {
actual = bitmap.firstUnoccupiedBucket(from: Bucket(offset: 0))
}
bitmap.setOccupied(actual)
let probeLength = self.probeLength(from: ideal, to: actual)
_maxProbeLength = Swift.max(_maxProbeLength, probeLength)