[BasicContainers] Fix insertion algorithm

Due to a number of cascading off-by-one errors, the maximum probe length could end up getting set lower than the actual value, _sometimes_ rendering some items unreachable.

Weirdly, the issue seems to be rare enough that it somehow never triggered in any of my previous test runs.
This commit is contained in:
Karoy Lorentey committed 2026-03-10 23:06:07 -07:00
1 parent ccf3d3a254
commit 2a53ad50b0
2 files changed
+3 -3

No files matched your search

@@ -49,9 +49,8 @@ extension _HTable {
return actual
#else
var b = idealBucket(forHashValue: hashValue)
var probeLength = 0
var probeLength = 1
while bitmap.isOccupied(b) {
probeLength &+= 1
let oldHashValue = hashGenerator(b)
let oldProbeLength = self.probeLength(
forHashValue: oldHashValue,
@@ -64,6 +63,7 @@ extension _HTable {
probeLength = oldProbeLength
}
self.wrapBucket(after: &b)
probeLength &+= 1
}
bitmap.setOccupied(b)
_count &+= 1
@@ -204,7 +204,7 @@ extension _HTable {
if start.offset <= end.offset {
return Int(end._offset &- start._offset &+ 1)
}
return Int(bucketCount &- start._offset &+ end._offset)
return Int(bucketCount &- start._offset &+ end._offset &+ 1)
}
@_transparent