Files
swift-collections/Sources/BitCollections/BitArray/BitArray+Initializers.swift
T
Károly Lőrentey 1d1fbc82d4 [BitSet] Make BitSet generic over its Element
This gets rid of the weird asymmetry between reading the contents of a BitSet (where we used to always get Int values) and mutating it (where we used to be able to give it values fo any fixed-width integer type).
2022-07-30 23:25:53 -07:00

24 lines
809 B
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 BitArray {
public init(_ set: BitSet<Index>) {
guard let l = set.last else { self.init(); return }
self.init(_storage: set._core._storage, count: l + 1)
}
public init<I: BinaryInteger>(bitPattern value: I) {
let words = value.words.map { _Word($0) }
let count = value.bitWidth
self.init(_storage: words, count: count)
}
}