mirror of
https://github.com/apple/swift-collections
synced 2026-11-22 04:20:40 +00:00
DocC keeps changing its link syntax. The latest iteration appears to have trouble dealing with `Self`-taking or `Self`-returning methods, so change our API to replace `Self` with a direct mention of the concrete type. ¯\\\_(ツ)\_/¯ That said, the new compiler also found a large number of mismatching parameter names, and that was really helpful.
76 lines
2.2 KiB
Swift
76 lines
2.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2022 - 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 InternalCollectionsUtilities
|
|
#endif
|
|
|
|
extension TreeSet {
|
|
/// Creates an empty set.
|
|
///
|
|
/// This initializer is equivalent to initializing with an empty array
|
|
/// literal.
|
|
///
|
|
/// - Complexity: O(1)
|
|
@inlinable
|
|
public init() {
|
|
self.init(_new: ._emptyNode())
|
|
}
|
|
|
|
/// Creates a new set from a finite sequence of items.
|
|
///
|
|
/// - Parameter items: The elements to use as members of the new set.
|
|
/// The sequence is allowed to contain duplicate elements, but only
|
|
/// the first duplicate instance is preserved in the result.
|
|
///
|
|
/// - Complexity: This operation is expected to perform O(*n*)
|
|
/// hashing and equality comparisons on average (where *n*
|
|
/// is the number of elements in the sequence), provided that
|
|
/// `Element` properly implements hashing.
|
|
@inlinable
|
|
public init(_ items: __owned some Sequence<Element>) {
|
|
if let items = _specialize(items, for: Self.self) {
|
|
self = items
|
|
return
|
|
}
|
|
self.init()
|
|
for item in items {
|
|
self._insert(item)
|
|
}
|
|
}
|
|
|
|
/// Creates a new set from a an existing set. This is functionally the same as
|
|
/// copying the value of `items` into a new variable.
|
|
///
|
|
/// - Parameter items: The elements to use as members of the new set.
|
|
///
|
|
/// - Complexity: O(1)
|
|
@inlinable
|
|
public init(_ items: __owned TreeSet) {
|
|
self = items
|
|
}
|
|
|
|
/// Creates a new persistent set from the keys view of an existing persistent
|
|
/// dictionary.
|
|
///
|
|
/// - Parameter items: The elements to use as members of the new set.
|
|
///
|
|
/// - Complexity: O(*items.count*)
|
|
@inlinable
|
|
public init<Value>(
|
|
_ items: __owned TreeDictionary<Element, Value>.Keys
|
|
) {
|
|
self.init(_new: items._base._root.mapValues { _ in () })
|
|
}
|
|
}
|