mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
Key Changes: - Add duplicate handling functionality to _BTree.Builder - Remove transient allocation in SortedDictionary.values _modify - Add missing SortedDictionary.Values.subscript _modify - Add SortedSet(sortedElements:) - Add optimized SetAlgebra implementations - Remove remaining high-level offset APIs - Various optimizations - Expand internal documentation Minor Changes: - Add ability to create dummy node - _BTree.Builder.append(key: Key) for sets. - Fix bug where findAnyIndex(forKey:) didn't calculate the offset. - Remove old, unused files - findAnyCursor -> takeCursor (to emphasize consuming nature) - Add takeCursor(at: Index) - Optimize init(grouping:by:) to use modifyValue to reduce CoW Optimizations: - Use dummy node for transient _modify state rather than allocating new buffer
38 lines
1021 B
Swift
38 lines
1021 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2021 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// An sorted collection of unique elements.
|
|
public struct SortedSet<Element: Comparable> {
|
|
@usableFromInline
|
|
internal typealias _Tree = _BTree<Element, ()>
|
|
|
|
@usableFromInline
|
|
internal var _root: _Tree
|
|
|
|
//// Creates an empty set.
|
|
///
|
|
/// This initializer is equivalent to initializing with an empty array
|
|
/// literal.
|
|
///
|
|
/// - Complexity: O(1)
|
|
@inlinable
|
|
@inline(__always)
|
|
public init() {
|
|
self._root = _Tree()
|
|
}
|
|
|
|
/// Creates a set rooted at a given B-Tree.
|
|
@inlinable
|
|
internal init(_rootedAt tree: _Tree) {
|
|
self._root = tree
|
|
}
|
|
}
|