Merge pull request #263 from lorentey/bitcollections-finalization

BitArray API refinements & additions
This commit is contained in:
Karoy Lorentey authored and GitHub committed 2023-04-10 17:32:10 -07:00
commit 8ca5c0367f
24 files changed
+844 -92

No files matched your search

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
// Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@@ -83,6 +83,24 @@ extension BitArray._UnsafeHandle {
Int(_count)
}
internal var end: _BitPosition {
_BitPosition(_count)
}
internal func set(at position: Int) {
ensureMutable()
assert(position >= 0 && position < _count)
let (word, bit) = _BitPosition(UInt(position)).split
_mutableWords[word].insert(bit)
}
internal func clear(at position: Int) {
ensureMutable()
assert(position >= 0 && position < _count)
let (word, bit) = _BitPosition(UInt(position)).split
_mutableWords[word].remove(bit)
}
internal subscript(position: Int) -> Bool {
get {
assert(position >= 0 && position < _count)