[BitArray] Add BitArray → BinaryInteger conversion initializers

extension BinaryInteger {
  public init(truncatingIfNeeded source: BitArray)
  public init?(exactly source: BitArray)
  public init(_ source: BitArray)
}
This commit is contained in:
Karoy Lorentey committed 2023-01-31 17:59:24 -08:00
1 parent c15e484f5a
commit c15b0d9889
2 files changed
+253 -1

No files matched your search

@@ -81,6 +81,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)