[BasicContainers] Implement removals on RigidSet and UniqueSet

Dictionaries are still to be done.
This commit is contained in:
Karoy Lorentey committed 2026-02-20 18:19:51 -08:00
1 parent d318a65867
commit 3941dab5b0
23 files changed
+513 -104

No files matched your search

@@ -16,15 +16,17 @@ extension UniqueSet where Element: ~Copyable {
public func _describe(
bitmap: Bool = false,
chains: Bool = false,
buckets: Bool = false,
) -> String {
_storage._describe(bitmap: bitmap, chains: chains)
_storage._describe(bitmap: bitmap, chains: chains, buckets: buckets)
}
public func _dump(
bitmap: Bool = false,
chains: Bool = false,
buckets: Bool = false,
) {
_storage._dump(bitmap: bitmap, chains: chains)
_storage._dump(bitmap: bitmap, chains: chains, buckets: buckets)
}
}
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@inlinable
package mutating func _remove(at bucket: _Bucket) -> Element {
guard self.count == _HTable.minimumCapacity(forScale: self._scale) else {
return _storage._remove(at: bucket)
}
// Shrink storage.
let result = _storage._punchHole(at: bucket)
_resize(minimumCapacity: self.count)
return result
}
@inlinable
public mutating func remove(_ member: borrowing Element) -> Element? {
let r = _storage._find(member)
guard let bucket = r.bucket else { return nil }
return _remove(at: bucket)
}
}
#endif
@@ -19,6 +19,9 @@ import ContainersPreview
@available(SwiftStdlib 5.0, *)
@frozen
public struct UniqueSet<Element: GeneralizedHashable & ~Copyable>: ~Copyable {
@usableFromInline
package typealias _Bucket = _HTable.Bucket
@_alwaysEmitIntoClient
package var _storage: RigidSet<Element>