Merge pull request #195 from lorentey/fix-bitset-shrinking-issue

[BitSet] Fix invariant violation in member subscript
This commit is contained in:
Karoy Lorentey authored and GitHub committed 2022-10-09 16:41:50 -07:00
commit d05cba098a
2 files changed
+8 -8

No files matched your search

@@ -70,7 +70,9 @@ extension BitSet {
} else if member > _capacity {
return
}
_update { handle in handle[member: member] = newValue }
_updateThenShrink { handle, shrink in
shrink = handle.update(member, to: newValue)
}
}
}
@@ -189,13 +189,11 @@ extension BitSet._UnsafeHandle {
return _mutableWords[index.word].remove(index.bit)
}
subscript(member member: UInt) -> Bool {
get { contains(member) }
set {
ensureMutable()
let (w, b) = _BitPosition(member).split
_mutableWords[w].update(b, to: newValue)
}
internal mutating func update(_ member: UInt, to newValue: Bool) -> Bool {
ensureMutable()
let (w, b) = _BitPosition(member).split
_mutableWords[w].update(b, to: newValue)
return w == _words.count &- 1
}
}