mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
[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:
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
|
||||
|
||||
Reference in new issue
Block a user