mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
44 lines
1.1 KiB
Swift
44 lines
1.1 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 BitSet {
|
|
public __consuming func union(_ other: __owned Self) -> Self {
|
|
self._read { first in
|
|
other._read { second in
|
|
Self(
|
|
_combining: (first, second),
|
|
includingTail: true,
|
|
using: { $0.union($1) })
|
|
}
|
|
}
|
|
}
|
|
|
|
@inlinable
|
|
public __consuming func union<S: Sequence>(
|
|
_ other: __owned S
|
|
) -> Self
|
|
where S.Element == Int
|
|
{
|
|
if S.self == BitSet.self {
|
|
return union(other as! BitSet)
|
|
}
|
|
var result = self
|
|
result.formUnion(other)
|
|
return result
|
|
}
|
|
|
|
public __consuming func union(_ other: Range<Int>) -> Self {
|
|
var result = self
|
|
result.formUnion(other)
|
|
return result
|
|
}
|
|
}
|