mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
Fix {Rigid,Unique}{Set,Dictionary}
This commit is contained in:
14 files changed
+67
-52
No files matched your search
@@ -17,7 +17,7 @@ import ContainersPreview
|
||||
|
||||
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||
@frozen
|
||||
public struct Indices: ~Escapable {
|
||||
@@ -45,9 +45,10 @@ extension RigidDictionary.Indices: BorrowingSequence_
|
||||
where Key: ~Copyable, Value: ~Copyable
|
||||
{
|
||||
public typealias Element = RigidDictionary.Index
|
||||
|
||||
public typealias Element_ = Element
|
||||
|
||||
@frozen
|
||||
public struct BorrowingIterator: ~Escapable {
|
||||
public struct BorrowingIterator_: ~Escapable {
|
||||
public typealias Element = RigidDictionary.Index
|
||||
|
||||
@usableFromInline
|
||||
@@ -67,22 +68,24 @@ where Key: ~Copyable, Value: ~Copyable
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var underestimatedCount: Int { self._base.value.count }
|
||||
|
||||
public var underestimatedCount_: Int { self._base.value.count }
|
||||
|
||||
@_lifetime(copy self)
|
||||
public func makeBorrowingIterator() -> BorrowingIterator {
|
||||
public func makeBorrowingIterator_() -> BorrowingIterator_ {
|
||||
let bit = self._base.value.makeBucketIterator()
|
||||
// FIXME: This override really should not be necessary. Check if the real `struct Borrow` fixes it.
|
||||
let override = _overrideLifetime(bit, copying: self)
|
||||
return BorrowingIterator(_it: override)
|
||||
return BorrowingIterator_(_it: override)
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RigidDictionary.Indices.BorrowingIterator: BorrowingIteratorProtocol
|
||||
extension RigidDictionary.Indices.BorrowingIterator_: BorrowingIteratorProtocol_
|
||||
where Key: ~Copyable, Value: ~Copyable {
|
||||
public typealias Element_ = Element
|
||||
|
||||
@_lifetime(&self)
|
||||
public mutating func nextSpan(maximumCount: Int) -> Span<Element> {
|
||||
public mutating func nextSpan_(maximumCount: Int) -> Span<Element> {
|
||||
guard _it.advanceToOccupied() else { return .init() }
|
||||
_current[0] = Element(_bucket: _it.currentBucket)
|
||||
_it.advanceToNextBit()
|
||||
|
||||
@@ -19,8 +19,10 @@ import ContainersPreview
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
public typealias Element_ = Element
|
||||
|
||||
@inlinable
|
||||
public var underestimatedCount: Int { count }
|
||||
public var underestimatedCount_: Int { count }
|
||||
|
||||
@inlinable
|
||||
public func _customContainsEquatableElement_(
|
||||
@@ -31,18 +33,18 @@ extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
|
||||
@inlinable
|
||||
@_lifetime(borrow self)
|
||||
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
|
||||
BorrowingIterator(_set: self)
|
||||
public borrowing func makeBorrowingIterator_() -> BorrowingIterator_ {
|
||||
BorrowingIterator_(_set: self)
|
||||
}
|
||||
|
||||
@frozen
|
||||
public struct BorrowingIterator:
|
||||
BorrowingIteratorProtocol,
|
||||
public struct BorrowingIterator_:
|
||||
BorrowingIteratorProtocol_,
|
||||
~Copyable,
|
||||
~Escapable
|
||||
{
|
||||
@_alwaysEmitIntoClient
|
||||
internal var _baseAddress: UnsafePointer<Element>?
|
||||
internal var _baseAddress: UnsafePointer<Element_>?
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
internal var _bucketIterator: _HTable.BucketIterator
|
||||
@@ -50,7 +52,7 @@ extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(borrow _set)
|
||||
internal init(
|
||||
_set: borrowing RigidSet<Element>
|
||||
_set: borrowing RigidSet<Element_>
|
||||
) {
|
||||
self._baseAddress = .init(_set._members)
|
||||
self._bucketIterator = _set._table.makeBucketIterator()
|
||||
@@ -58,7 +60,7 @@ extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(copy self)
|
||||
internal func _span(over buckets: Range<_Bucket>) -> Span<Element> {
|
||||
internal func _span(over buckets: Range<_Bucket>) -> Span<Element_> {
|
||||
let items = UnsafeBufferPointer(
|
||||
start: _baseAddress.unsafelyUnwrapped + buckets.lowerBound.offset,
|
||||
count: buckets.upperBound.offset - buckets.lowerBound.offset)
|
||||
@@ -67,7 +69,7 @@ extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(copy self)
|
||||
public mutating func nextSpan(maximumCount: Int) -> Span<Element> {
|
||||
public mutating func nextSpan_(maximumCount: Int) -> Span<Element_> {
|
||||
precondition(maximumCount > 0, "maximumCount must be positive")
|
||||
guard
|
||||
let next = _bucketIterator.nextOccupiedRegion(maximumCount: maximumCount)
|
||||
|
||||
@@ -30,16 +30,19 @@ extension RigidSet {
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidSet: Equatable {
|
||||
extension RigidSet: Equatable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet {
|
||||
@inlinable
|
||||
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
|
||||
if left.isTriviallyIdentical(to: right) { return true }
|
||||
|
||||
guard left.count == right.count else { return false }
|
||||
|
||||
var lit = left.makeBorrowingIterator()
|
||||
var lit = left.makeBorrowingIterator_()
|
||||
while true {
|
||||
let l = lit.nextSpan()
|
||||
let l = lit.nextSpan_()
|
||||
if l.isEmpty { break }
|
||||
var i = 0
|
||||
while i < l.count {
|
||||
|
||||
@@ -19,7 +19,10 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidSet: Hashable {
|
||||
extension RigidSet: Hashable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidSet {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
// Generate a seed from a snapshot of the hasher. This makes members' hash
|
||||
@@ -34,9 +37,9 @@ extension RigidSet: Hashable {
|
||||
public func _rawHashValue(seed: Int) -> Int {
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
var hash = 0
|
||||
var it = self.makeBorrowingIterator()
|
||||
var it = self.makeBorrowingIterator_()
|
||||
while true {
|
||||
let next = it.nextSpan()
|
||||
let next = it.nextSpan_()
|
||||
var i = 0
|
||||
while i < next.count {
|
||||
hash ^= next[i]._rawHashValue(seed: seed)
|
||||
|
||||
@@ -227,9 +227,9 @@ extension RigidSet /* where Element: Copyable */ {
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
var it = items.makeBorrowingIterator()
|
||||
var it = items.makeBorrowingIterator_()
|
||||
while true {
|
||||
let span = it.nextSpan()
|
||||
let span = it.nextSpan_()
|
||||
guard !span.isEmpty else { break }
|
||||
self.insert(copying: span)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
|
||||
public typealias Indices = RigidDictionary<Key, Value>.Indices
|
||||
|
||||
|
||||
@@ -20,11 +20,12 @@ import ContainersPreview
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
public typealias BorrowingIterator = RigidSet<Element>.BorrowingIterator
|
||||
|
||||
public typealias Element_ = Element
|
||||
public typealias BorrowingIterator_ = RigidSet<Element>.BorrowingIterator_
|
||||
|
||||
@inlinable
|
||||
public var underestimatedCount: Int { count }
|
||||
|
||||
public var underestimatedCount_: Int { count }
|
||||
|
||||
@inlinable
|
||||
public func _customContainsEquatableElement_(
|
||||
_ element: borrowing Element
|
||||
@@ -34,8 +35,8 @@ extension UniqueSet: BorrowingSequence_ where Element: ~Copyable {
|
||||
|
||||
@inlinable
|
||||
@_lifetime(borrow self)
|
||||
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
|
||||
BorrowingIterator(_set: _storage)
|
||||
public borrowing func makeBorrowingIterator_() -> BorrowingIterator_ {
|
||||
BorrowingIterator_(_set: _storage)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -29,6 +29,9 @@ extension UniqueSet {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueSet: Equatable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet: Equatable {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
|
||||
@@ -19,7 +19,10 @@ import ContainersPreview
|
||||
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueSet: Hashable {
|
||||
extension UniqueSet: Hashable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueSet {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
_storage.hash(into: &hasher)
|
||||
|
||||
@@ -75,7 +75,6 @@ extension UniqueSet where Element: ~Copyable {
|
||||
extension UniqueSet where Element: Copyable {
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public init<
|
||||
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
|
||||
@@ -94,7 +93,6 @@ extension UniqueSet where Element: Copyable {
|
||||
}
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public init<
|
||||
S: BorrowingSequence_<Element> & Sequence<Element>
|
||||
|
||||
@@ -130,17 +130,16 @@ extension UniqueSet /* where Element: Copyable */ {
|
||||
}
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
package mutating func _insert<
|
||||
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
_ensureFreeCapacity(items.underestimatedCount)
|
||||
var it = items.makeBorrowingIterator()
|
||||
_ensureFreeCapacity(items.underestimatedCount_)
|
||||
var it = items.makeBorrowingIterator_()
|
||||
while true {
|
||||
let span = it.nextSpan()
|
||||
let span = it.nextSpan_()
|
||||
guard !span.isEmpty else { break }
|
||||
self.insert(copying: span)
|
||||
}
|
||||
@@ -148,7 +147,6 @@ extension UniqueSet /* where Element: Copyable */ {
|
||||
#endif
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
@@ -171,7 +169,6 @@ extension UniqueSet /* where Element: Copyable */ {
|
||||
}
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
|
||||
Reference in new issue
Block a user