Files
swift-collections/Sources/BitCollections/BitSet/UnsafeMutableBufferPointer+Utilities.swift
T
Károly Lőrentey 8f2e0c79c3 Review & update BitSet
This is a work in progress; in particular, it adds a cached `count` to BitSet, which may turn out to be a bad idea. (It generates extra work for bulk operations even if the count is never needed.) I think replacing this with a cached `startIndex` might be more useful in practice.

The `_UnsafeBitset` type from the OrderedCollections module is brought over as `BitSet._UnsafeHandle`. This implements an (internal-only) fixed-size bitset.

`BitSet` now conforms to `SetAlgebra`. We decided against this in the initial implementation, but on reflection, it seems like the right move. (The somewhat nonsensical `insert` and `update` methods are unfortunate, but consistency is valuable.)
2022-01-10 23:35:33 -08:00

46 lines
1.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021-2022 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
//
//===----------------------------------------------------------------------===//
extension Collection {
@inlinable
@inline(__always)
internal func _rebased<Element>() -> UnsafeBufferPointer<Element>
where Self == UnsafeBufferPointer<Element>.SubSequence {
.init(rebasing: self)
}
}
extension Collection {
@inlinable
@inline(__always)
internal func _rebased<Element>() -> UnsafeMutableBufferPointer<Element>
where Self == UnsafeMutableBufferPointer<Element>.SubSequence {
.init(rebasing: self)
}
}
extension UnsafeMutableBufferPointer {
@inlinable
@inline(__always)
internal func _assign(from source: Self) {
assert(source.count == self.count)
if count > 0 {
baseAddress!.assign(from: source.baseAddress!, count: count)
}
}
@inlinable
@inline(__always)
internal func _initialize(at index: Int, to value: Element) {
(baseAddress.unsafelyUnwrapped + index).initialize(to: value)
}
}