//===----------------------------------------------------------------------===// // // This source file is part of the Swift Collections open source project // // Copyright (c) 2026 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 // // SPDX-License-Identifier: Apache-2.0 WITH Swift-exception // //===----------------------------------------------------------------------===// #if !COLLECTIONS_SINGLE_MODULE import ContainersPreview #endif #if compiler(>=6.4) && UnstableHashedContainers @available(SwiftStdlib 5.0, *) extension RigidSet where Element: ~Copyable { @inlinable @inline(__always) public init() { self.init(capacity: 0) } @inlinable public init(capacity: Int) { precondition(capacity >= 0, "Capacity must be nonnegative") self.init(_table: _HTable(capacity: capacity)) } @inlinable public init(consuming set: consuming UniqueSet) { self.init() // FIXME: Language limitation as of 6.3; this should not be needed here. // error: Conditional initialization or destruction of noncopyable types is // not supported; this variable must be consistently in an initialized or // uninitialized state through every code path self = set._storage } @inlinable public init( capacity: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { self.init(capacity: capacity) try self.insert(maximumCount: capacity, initializingWith: initializer) } #if UnstableContainersPreview @_alwaysEmitIntoClient public init< E: Error, P: Producer & ~Copyable & ~Escapable >( capacity: Int, from producer: inout P ) throws(E) where P.Element: ~Copyable { self.init(capacity: capacity) try self.insert(maximumCount: capacity, from: &producer) } #endif #if UnstableContainersPreview @_alwaysEmitIntoClient public init< D: Drain & ~Copyable & ~Escapable >( capacity: Int, from drain: inout D ) { self.init(capacity: capacity) self.insert(maximumCount: capacity, from: &drain) } #endif } @available(SwiftStdlib 5.0, *) extension RigidSet /* where Element: Copyable */ { #if UnstableContainersPreview @_alwaysEmitIntoClient @inline(__always) public init< S: Iterable_ & ~Copyable & ~Escapable >( capacity: Int, copying contents: borrowing S ) throws(S.Failure_) where S.Element_ == Element { self.init(capacity: capacity) try self._insert(copying: contents) } #endif @_alwaysEmitIntoClient @inline(__always) public init( capacity: Int, copying contents: some Sequence ) { self.init(capacity: capacity) self.insert(copying: contents) } @_alwaysEmitIntoClient @inline(__always) public init( capacity: Int? = nil, copying contents: some Collection ) { self.init(capacity: capacity ?? contents.count) self.insert(copying: contents) } #if UnstableContainersPreview @_alwaysEmitIntoClient @inline(__always) public init< S: Iterable_ & Sequence >( capacity: Int, copying contents: borrowing S ) throws(S.Failure_) where S.Element_ == Element { self.init(capacity: capacity) try self._insert(copying: contents) } @_alwaysEmitIntoClient @inline(__always) public init< S: Iterable_ & Collection >( capacity: Int? = nil, copying contents: S ) throws(S.Failure_) where S.Element_ == Element { self.init(capacity: capacity ?? contents.count) try self._insert(copying: contents) } #endif } #endif