diff --git a/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift index 4ba216fd..908fb494 100644 --- a/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// import CollectionsBenchmark -@_spi(Testing) import DequeModule +import DequeModule extension Deque { @inline(__always) diff --git a/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift index bfedda22..09cc539c 100644 --- a/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/RigidDequeBenchmarks.swift @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// import CollectionsBenchmark -@_spi(Testing) import DequeModule +import DequeModule /// Do nothing and immediately return. /// diff --git a/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift index 59c54b39..7a5c80b4 100644 --- a/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/UniqueDequeBenchmarks.swift @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// import CollectionsBenchmark -@_spi(Testing) import DequeModule +import DequeModule @inline(never) @_optimize(none) diff --git a/Sources/BitCollections/BitArray/BitArray+Testing.swift b/Sources/BitCollections/BitArray/BitArray+Testing.swift index d62c631b..c7421f7d 100644 --- a/Sources/BitCollections/BitArray/BitArray+Testing.swift +++ b/Sources/BitCollections/BitArray/BitArray+Testing.swift @@ -16,8 +16,7 @@ import InternalCollectionsUtilities #endif extension BitArray { - @_spi(Testing) - public var _capacity: Int { + package var _capacity: Int { _storage.capacity * _Word.capacity } } diff --git a/Sources/OrderedCollections/HashTable/_HashTable+Bucket.swift b/Sources/OrderedCollections/HashTable/_HashTable+Bucket.swift index 9d9f81df..4433f9ca 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+Bucket.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+Bucket.swift @@ -17,14 +17,14 @@ extension _HashTable { /// to a function that expects a word index, or vice versa. @usableFromInline @frozen - internal struct Bucket { + package struct Bucket { /// The distance of this bucket from the first bucket in the hash table. @usableFromInline - internal var offset: Int + package var offset: Int @inlinable @inline(__always) - internal init(offset: Int) { + package init(offset: Int) { assert(offset >= 0) self.offset = offset } @@ -33,7 +33,8 @@ extension _HashTable { extension _HashTable.Bucket: Equatable { @_transparent - public static func == (left: Self, right: Self) -> Bool { + @usableFromInline + package static func == (left: Self, right: Self) -> Bool { left.offset == right.offset } } diff --git a/Sources/OrderedCollections/HashTable/_HashTable+BucketIterator.swift b/Sources/OrderedCollections/HashTable/_HashTable+BucketIterator.swift index 743d24d2..9b6e7631 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+BucketIterator.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+BucketIterator.swift @@ -29,16 +29,16 @@ extension _HashTable { /// iterator values outside the closure call that produced the original /// hash table. @usableFromInline - internal struct BucketIterator { + package struct BucketIterator { @usableFromInline - internal typealias Bucket = _HashTable.Bucket + package typealias Bucket = _HashTable.Bucket /// The hash table we are iterating over. internal let _hashTable: _UnsafeHashTable /// The current position within the hash table. @usableFromInline - internal var _currentBucket: Bucket + package var _currentBucket: Bucket /// The raw bucket value corresponding to `_currentBucket`. internal var _currentRawValue: UInt64 @@ -54,7 +54,7 @@ extension _HashTable { /// Create a new iterator starting at the specified bucket. @_effects(releasenone) @usableFromInline - internal init(hashTable: _UnsafeHashTable, startingAt bucket: Bucket) { + package init(hashTable: _UnsafeHashTable, startingAt bucket: Bucket) { assert(hashTable.scale >= _HashTable.minimumScale) assert(bucket.offset >= 0 && bucket.offset < hashTable.bucketCount) self._hashTable = hashTable @@ -67,18 +67,18 @@ extension _HashTable { extension _HashTable.UnsafeHandle { @usableFromInline - internal typealias BucketIterator = _HashTable.BucketIterator + package typealias BucketIterator = _HashTable.BucketIterator @_effects(releasenone) @inlinable @inline(__always) - internal func idealBucket(forHashValue hashValue: Int) -> Bucket { + package func idealBucket(forHashValue hashValue: Int) -> Bucket { return Bucket(offset: hashValue & (bucketCount - 1)) } @inlinable @inline(__always) - internal func idealBucket(for element: Element) -> Bucket { + package func idealBucket(for element: Element) -> Bucket { let hashValue = element._rawHashValue(seed: seed) return idealBucket(forHashValue: hashValue) } @@ -87,7 +87,7 @@ extension _HashTable.UnsafeHandle { /// to the specified value. @inlinable @inline(__always) - internal func bucketIterator(for element: Element) -> BucketIterator { + package func bucketIterator(for element: Element) -> BucketIterator { let bucket = idealBucket(for: element) return bucketIterator(startingAt: bucket) } @@ -95,13 +95,13 @@ extension _HashTable.UnsafeHandle { /// Return a bucket iterator for the chain starting at the specified bucket. @inlinable @inline(__always) - internal func bucketIterator(startingAt bucket: Bucket) -> BucketIterator { + package func bucketIterator(startingAt bucket: Bucket) -> BucketIterator { BucketIterator(hashTable: self, startingAt: bucket) } @usableFromInline @_effects(releasenone) - internal func startFind( + package func startFind( _ startBucket: Bucket ) -> (iterator: BucketIterator, currentValue: Int?) { let iterator = bucketIterator(startingAt: startBucket) @@ -110,7 +110,7 @@ extension _HashTable.UnsafeHandle { @_effects(readonly) @usableFromInline - internal func _startIterator( + package func _startIterator( bucket: Bucket ) -> (currentBits: UInt64, nextBits: UInt64, remainingBitCount: Int) { // The `scale == 5` case is special because the last word is only half filled there, @@ -154,10 +154,22 @@ extension _HashTable.BucketIterator { /// The current position within the hash table. @inlinable @inline(__always) - internal var currentBucket: Bucket { _currentBucket } + package var currentBucket: Bucket { _currentBucket } + + // For testing + @usableFromInline + package func isIdentical(to other: Self) -> Bool { + self._hashTable.isIdentical(to: other._hashTable) + && self.currentBucket == other.currentBucket + && self._currentRawValue == other._currentRawValue + && self.currentValue == other.currentValue + && self._nextBits == other._nextBits + && self._remainingBitCount == other._remainingBitCount + && self._wrappedAround == other._wrappedAround + } @usableFromInline - internal var isOccupied: Bool { + package var isOccupied: Bool { @_effects(readonly) @inline(__always) get { @@ -170,7 +182,7 @@ extension _HashTable.BucketIterator { /// /// A nil value indicates an empty bucket. @usableFromInline - internal var currentValue: Int? { + package var currentValue: Int? { @inline(__always) @_effects(readonly) get { _hashTable._value(forBucketContents: _currentRawValue) } @@ -205,7 +217,7 @@ extension _HashTable.BucketIterator { /// time it needs to wrap around to the beginning of the table. @usableFromInline @_effects(releasenone) - internal mutating func advance() { + package mutating func advance() { // Advance to next bucket, checking for wraparound condition. _currentBucket.offset &+= 1 if _currentBucket.offset == _hashTable.bucketCount { @@ -240,7 +252,7 @@ extension _HashTable.BucketIterator { @usableFromInline @_effects(releasenone) - internal mutating func findNext() -> Int? { + package mutating func findNext() -> Int? { advance() return currentValue } @@ -249,7 +261,7 @@ extension _HashTable.BucketIterator { /// specified value, or an unoccupied bucket -- whichever comes first. @inlinable @_effects(releasenone) - internal mutating func advance(until expected: Int) { + package mutating func advance(until expected: Int) { while isOccupied && currentValue != expected { advance() } @@ -259,7 +271,7 @@ extension _HashTable.BucketIterator { /// Useful when inserting an element that we know isn't already in the table. @inlinable @_effects(releasenone) - internal mutating func advanceToNextUnoccupiedBucket() { + package mutating func advanceToNextUnoccupiedBucket() { while isOccupied { advance() } diff --git a/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift b/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift index d3682132..fc058610 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+Constants.swift @@ -15,7 +15,7 @@ extension _HashTable { /// The minimum hash table scale. @usableFromInline @inline(__always) - internal static var minimumScale: Int { + package static var minimumScale: Int { @_effects(readnone) get { 5 @@ -25,7 +25,7 @@ extension _HashTable { /// The maximum hash table scale. @usableFromInline @inline(__always) - internal static var maximumScale: Int { + package static var maximumScale: Int { @_effects(readnone) get { Swift.min(Int.bitWidth, 56) @@ -35,7 +35,7 @@ extension _HashTable { /// The maximum number of items for which we do not create a hash table. @usableFromInline @inline(__always) - internal static var maximumUnhashedCount: Int { + package static var maximumUnhashedCount: Int { @_effects(readnone) get { (1 &<< (minimumScale - 1)) - 1 @@ -45,17 +45,17 @@ extension _HashTable { /// The maximum hash table load factor. This is a rational number /// represented by a (numerator, denominator) tuple. @_transparent - internal static var maximumLoadFactor: (Int, Int) { (3, 4) } + package static var maximumLoadFactor: (Int, Int) { (3, 4) } /// The minimum hash table load factor. This is a rational number /// represented by a (numerator, denominator) tuple. @_transparent - internal static var minimumLoadFactor: (Int, Int) { (1, 4) } + package static var minimumLoadFactor: (Int, Int) { (1, 4) } /// The minimum number of items that can be held in a hash table of the given scale. @usableFromInline @_effects(readnone) - internal static func minimumCapacity(forScale scale: Int) -> Int { + package static func minimumCapacity(forScale scale: Int) -> Int { guard scale >= minimumScale else { return 0 } let bucketCount = 1 &<< scale return (bucketCount * minimumLoadFactor.0) / minimumLoadFactor.1 @@ -64,7 +64,7 @@ extension _HashTable { /// The maximum number of items that can be held in a hash table of the given scale. @usableFromInline @_effects(readnone) - internal static func maximumCapacity(forScale scale: Int) -> Int { + package static func maximumCapacity(forScale scale: Int) -> Int { guard scale >= minimumScale else { return maximumUnhashedCount } let bucketCount = 1 &<< scale return (bucketCount * maximumLoadFactor.0) / maximumLoadFactor.1 @@ -73,7 +73,7 @@ extension _HashTable { /// The minimum hash table scale that can hold the specified number of elements. @usableFromInline @_effects(readnone) - internal static func scale(forCapacity capacity: Int) -> Int { + package static func scale(forCapacity capacity: Int) -> Int { guard capacity > maximumUnhashedCount else { return 0 } let capacity = Swift.max(capacity, 1) // Calculate the minimum number of entries we need to allocate to satisfy @@ -94,7 +94,7 @@ extension _HashTable { /// The count of 64-bit words that a hash table of the specified scale /// will need to have in its storage. - internal static func wordCount(forScale scale: Int) -> Int { + package static func wordCount(forScale scale: Int) -> Int { ((scale &<< scale) + 63) / 64 } } diff --git a/Sources/OrderedCollections/HashTable/_HashTable+CustomStringConvertible.swift b/Sources/OrderedCollections/HashTable/_HashTable+CustomStringConvertible.swift index 1c46ce86..cd801a93 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+CustomStringConvertible.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+CustomStringConvertible.swift @@ -15,18 +15,18 @@ extension _HashTable.Header: CustomStringConvertible { @usableFromInline - internal var _description: String { + package var _description: String { "(scale: \(scale), reservedScale: \(reservedScale), bias: \(bias), seed: \(String(seed, radix: 16)))" } @usableFromInline - internal var description: String { + package var description: String { "_HashTable.Header\(_description)" } } extension _HashTable.UnsafeHandle: CustomStringConvertible { - internal func _description(type: String) -> String { + package func _description(type: String) -> String { var d = """ \(type)\(_header.pointee._description) load factor: \(debugLoadFactor()) @@ -42,21 +42,21 @@ extension _HashTable.UnsafeHandle: CustomStringConvertible { } @usableFromInline - internal var description: String { + package var description: String { _description(type: "_HashTable.UnsafeHandle") } } extension _HashTable: CustomStringConvertible { @usableFromInline - internal var description: String { + package var description: String { self.read { $0._description(type: "_HashTable") } } } extension _HashTable.Storage: CustomStringConvertible { @usableFromInline - internal var description: String { + package var description: String { _HashTable(self).read { $0._description(type: "_HashTable.Storage") } } } diff --git a/Sources/OrderedCollections/HashTable/_HashTable+Testing.swift b/Sources/OrderedCollections/HashTable/_HashTable+Testing.swift index 0ea51d17..2a4ae77a 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+Testing.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+Testing.swift @@ -17,7 +17,7 @@ extension _HashTable.Bucket: CustomStringConvertible { } extension _UnsafeHashTable { - internal func debugOccupiedCount() -> Int { + package func debugOccupiedCount() -> Int { var count = 0 var it = bucketIterator(startingAt: Bucket(offset: 0)) repeat { @@ -29,11 +29,11 @@ extension _UnsafeHashTable { return count } - internal func debugLoadFactor() -> Double { + package func debugLoadFactor() -> Double { return Double(debugOccupiedCount()) / Double(bucketCount) } - internal func debugContents() -> [Int?] { + package func debugContents() -> [Int?] { var result: [Int?] = [] result.reserveCapacity(bucketCount) var it = bucketIterator(startingAt: Bucket(offset: 0)) @@ -47,7 +47,7 @@ extension _UnsafeHashTable { extension _UnsafeHashTable.BucketIterator: CustomStringConvertible { @usableFromInline - var description: String { + package var description: String { func pad(_ s: String, to length: Int, by padding: Character = " ") -> String { let c = s.count guard c < length else { return s } diff --git a/Sources/OrderedCollections/HashTable/_HashTable+UnsafeHandle.swift b/Sources/OrderedCollections/HashTable/_HashTable+UnsafeHandle.swift index 7e594351..01d14c55 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable+UnsafeHandle.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable+UnsafeHandle.swift @@ -16,7 +16,7 @@ import InternalCollectionsUtilities #endif @usableFromInline -internal typealias _UnsafeHashTable = _HashTable.UnsafeHandle +package typealias _UnsafeHashTable = _HashTable.UnsafeHandle extension _HashTable { /// A non-owning handle to hash table storage, implementing higher-level @@ -27,29 +27,29 @@ extension _HashTable { /// the closure call that produced them. @usableFromInline @frozen - internal struct UnsafeHandle { + package struct UnsafeHandle { @usableFromInline - internal typealias Bucket = _HashTable.Bucket + package typealias Bucket = _HashTable.Bucket /// A pointer to the table header. @usableFromInline - internal var _header: UnsafeMutablePointer
+ package var _header: UnsafeMutablePointer
/// A pointer to bucket storage. @usableFromInline - internal var _buckets: UnsafeMutablePointer + package var _buckets: UnsafeMutablePointer #if DEBUG /// True when this handle does not support table mutations. /// (This is only checked in debug builds.) @usableFromInline - internal let _readonly: Bool + package let _readonly: Bool #endif /// Initialize a new hash table handle for storage at the supplied locations. @inlinable @inline(__always) - internal init( + package init( header: UnsafeMutablePointer
, buckets: UnsafeMutablePointer, readonly: Bool @@ -68,7 +68,7 @@ extension _HashTable { /// Note that this is a noop in release builds. @inlinable @inline(__always) - func assertMutable() { + package func assertMutable() { #if DEBUG assert(!_readonly, "Attempt to mutate a hash table through a read-only handle") #endif @@ -77,29 +77,41 @@ extension _HashTable { } extension _HashTable.UnsafeHandle { + @inlinable + package func isIdentical(to other: Self) -> Bool { + guard + self._header == other._header, + self._buckets == other._buckets + else { return false } +#if DEBUG + guard self._readonly == other._readonly else { return false } +#endif + return true + } + /// The scale of the hash table. A table of scale *n* holds 2^*n* buckets, /// each of which contain an *n*-bit value. @inlinable @inline(__always) - internal var scale: Int { _header.pointee.scale } + package var scale: Int { _header.pointee.scale } /// The scale corresponding to the last call to `reserveCapacity`. /// We store this to make sure we don't shrink the table below its reserved size. @inlinable @inline(__always) - internal var reservedScale: Int { _header.pointee.reservedScale } + package var reservedScale: Int { _header.pointee.reservedScale } /// The hasher seed to use within this hash table. @inlinable @inline(__always) - internal var seed: Int { _header.pointee.seed } + package var seed: Int { _header.pointee.seed } /// A bias value that needs to be added to buckets to convert them into offsets /// into element storage. (This allows O(1) insertions at the front when the /// underlying storage supports it.) @inlinable @inline(__always) - internal var bias: Int { + package var bias: Int { get { _header.pointee.bias } nonmutating set { _header.pointee.bias = newValue } } @@ -107,34 +119,34 @@ extension _HashTable.UnsafeHandle { /// The number of buckets within this hash table. This is always a power of two. @inlinable @inline(__always) - internal var bucketCount: Int { 1 &<< scale } + package var bucketCount: Int { 1 &<< scale } @inlinable @inline(__always) - internal var bucketMask: UInt64 { UInt64(truncatingIfNeeded: bucketCount) - 1 } + package var bucketMask: UInt64 { UInt64(truncatingIfNeeded: bucketCount) - 1 } /// The number of bits used to store all the buckets in this hash table. /// Each bucket holds a value that is `scale` bits wide. @inlinable @inline(__always) - internal var bitCount: Int { scale &<< scale } + package var bitCount: Int { scale &<< scale } /// The number of 64-bit words that are available in the storage buffer, /// rounded up to the nearest whole number if necessary. @inlinable @inline(__always) - internal var wordCount: Int { (bitCount + UInt64.bitWidth - 1) / UInt64.bitWidth } + package var wordCount: Int { (bitCount + UInt64.bitWidth - 1) / UInt64.bitWidth } /// The maximum number of items that can fit into this table. @inlinable @inline(__always) - internal var capacity: Int { _HashTable.maximumCapacity(forScale: scale) } + package var capacity: Int { _HashTable.maximumCapacity(forScale: scale) } /// Return the bucket logically following `bucket` in this hash table. /// The buckets form a cycle, so the last bucket is logically followed by the first. @inlinable @inline(__always) - func bucket(after bucket: Bucket) -> Bucket { + package func bucket(after bucket: Bucket) -> Bucket { var offset = bucket.offset + 1 if offset == bucketCount { offset = 0 @@ -146,7 +158,7 @@ extension _HashTable.UnsafeHandle { /// The buckets form a cycle, so the first bucket is logically preceded by the last. @inlinable @inline(__always) - func bucket(before bucket: Bucket) -> Bucket { + package func bucket(before bucket: Bucket) -> Bucket { let offset = (bucket.offset == 0 ? bucketCount : bucket.offset) - 1 return Bucket(offset: offset) } @@ -157,7 +169,7 @@ extension _HashTable.UnsafeHandle { /// Note that the last word may be only partially filled if `scale` is less than 6. @inlinable @inline(__always) - func word(after word: Int) -> Int { + package func word(after word: Int) -> Int { var result = word + 1 if result == wordCount { result = 0 @@ -171,7 +183,7 @@ extension _HashTable.UnsafeHandle { /// Note that the last word may be only partially filled if `scale` is less than 6. @inlinable @inline(__always) - func word(before word: Int) -> Int { + package func word(before word: Int) -> Int { if word == 0 { return wordCount - 1 } @@ -181,7 +193,7 @@ extension _HashTable.UnsafeHandle { /// Return the index of the 64-bit storage word that holds the first bit /// corresponding to `bucket`, along with its bit position within the word. @inlinable - internal func position(of bucket: Bucket) -> (word: Int, bit: Int) { + package func position(of bucket: Bucket) -> (word: Int, bit: Int) { let start = bucket.offset &* scale return (start &>> 6, start & 0x3F) } @@ -198,7 +210,7 @@ extension _HashTable.UnsafeHandle { /// encoding is used for `nil`. This isn't an issue, because the maximum load /// factor guarantees that the hash table will never be completely full.) @inlinable - func _value(forBucketContents bucketContents: UInt64) -> Int? { + package func _value(forBucketContents bucketContents: UInt64) -> Int? { let mask = bucketMask assert(bucketContents <= mask) guard bucketContents != 0 else { return nil } @@ -216,7 +228,7 @@ extension _HashTable.UnsafeHandle { /// its encoding is used for `nil`. This isn't an issue, because the maximum /// load factor guarantees that the hash table will never be completely full.) @inlinable - func _bucketContents(for value: Int?) -> UInt64 { + package func _bucketContents(for value: Int?) -> UInt64 { guard var value = value else { return 0 } let mask = Int(truncatingIfNeeded: bucketMask) assert(value >= 0 && value < mask) @@ -227,7 +239,7 @@ extension _HashTable.UnsafeHandle { } @inlinable - subscript(word word: Int) -> UInt64 { + package subscript(word word: Int) -> UInt64 { @inline(__always) get { assert(word >= 0 && word < wordCount) return _buckets[word] @@ -240,7 +252,7 @@ extension _HashTable.UnsafeHandle { } @inlinable - subscript(raw bucket: Bucket) -> UInt64 { + package subscript(raw bucket: Bucket) -> UInt64 { get { assert(bucket.offset < bucketCount) let (word, bit) = position(of: bucket) @@ -272,14 +284,14 @@ extension _HashTable.UnsafeHandle { @inlinable @inline(__always) - func isOccupied(_ bucket: Bucket) -> Bool { + package func isOccupied(_ bucket: Bucket) -> Bool { self[raw: bucket] != 0 } /// Return or update the current value stored in the specified bucket. /// A nil value indicates that the bucket is empty. @inlinable - internal subscript(bucket: Bucket) -> Int? { + package subscript(bucket: Bucket) -> Int? { get { let contents = self[raw: bucket] return _value(forBucketContents: contents) @@ -294,7 +306,7 @@ extension _HashTable.UnsafeHandle { extension _UnsafeHashTable { @inlinable - internal func _find( + package func _find( _ item: Element, in elements: ContiguousArray ) -> (index: Int?, bucket: Bucket) { @@ -304,7 +316,7 @@ extension _UnsafeHashTable { } @inlinable - internal func _find( + package func _find( _ item: Element, in elements: UnsafeBufferPointer ) -> (index: Int?, bucket: Bucket) { @@ -322,7 +334,7 @@ extension _UnsafeHashTable { extension _UnsafeHashTable { @usableFromInline - internal func firstOccupiedBucketInChain(with bucket: Bucket) -> Bucket { + package func firstOccupiedBucketInChain(with bucket: Bucket) -> Bucket { var bucket = bucket repeat { bucket = self.bucket(before: bucket) @@ -331,7 +343,7 @@ extension _UnsafeHashTable { } @inlinable - internal func delete( + package func delete( bucket: Bucket, hashValueGenerator: (Int, Int) -> Int // (offset, seed) -> hashValue ) { @@ -375,7 +387,7 @@ extension _UnsafeHashTable { extension _UnsafeHashTable { @inlinable - internal func adjustContents( + package func adjustContents( preparingForInsertionOfElementAtOffset offset: Int, in elements: Base ) where Base.Element: Hashable { @@ -425,7 +437,7 @@ extension _UnsafeHashTable { extension _UnsafeHashTable { @inlinable @inline(__always) - internal func adjustContents( + package func adjustContents( preparingForRemovalOf index: Base.Index, in elements: Base ) where Base.Element: Hashable { @@ -434,7 +446,7 @@ extension _UnsafeHashTable { } @inlinable - internal func adjustContents( + package func adjustContents( preparingForRemovalOf bounds: Range, in elements: Base ) where Base.Element: Hashable { @@ -497,7 +509,7 @@ extension _UnsafeHashTable { extension _UnsafeHashTable { @inlinable - internal func reverse(count: Int) { + package func reverse(count: Int) { assertMutable() var it = bucketIterator(startingAt: Bucket(offset: 0)) repeat { @@ -511,7 +523,7 @@ extension _UnsafeHashTable { extension _UnsafeHashTable { @usableFromInline - internal func clear() { + package func clear() { assertMutable() _buckets.update(repeating: 0, count: wordCount) } @@ -522,7 +534,7 @@ extension _UnsafeHashTable { /// /// - Parameter elements: A random-access collection for which this table is being generated. @inlinable - internal func fill( + package func fill( uncheckedUniqueElements elements: C ) where C.Element: Hashable { assertMutable() @@ -562,7 +574,7 @@ extension _UnsafeHashTable { /// - Parameter elements: A random-access collection for which this table is being generated. /// - Returns: `(success, index)` where `success` is a boolean value indicating that every value in `elements` was successfully inserted. A false success indicates that duplicate elements have been found; in this case `index` points to the first duplicate value; otherwise `index` is set to `elements.endIndex`. @inlinable - internal func fill( + package func fill( untilFirstDuplicateIn elements: C ) -> (success: Bool, end: C.Index) where C.Element: Hashable { diff --git a/Sources/OrderedCollections/HashTable/_HashTable.swift b/Sources/OrderedCollections/HashTable/_HashTable.swift index d8686f2f..21221ce1 100644 --- a/Sources/OrderedCollections/HashTable/_HashTable.swift +++ b/Sources/OrderedCollections/HashTable/_HashTable.swift @@ -13,13 +13,13 @@ @usableFromInline @frozen -internal struct _HashTable { +package struct _HashTable { @usableFromInline - internal var _storage: Storage + package var _storage: Storage @inlinable @inline(__always) - internal init(_ storage: Storage) { + package init(_ storage: Storage) { _storage = storage } } @@ -29,7 +29,7 @@ extension _HashTable { /// Values in the hash table are offsets into separate element storage, so /// this class doesn't need to be generic over `OrderedSet`'s `Element` type. @usableFromInline - internal final class Storage + package final class Storage : ManagedBuffer {} } @@ -38,7 +38,7 @@ extension _HashTable { /// Allocate a new empty hash table buffer of the specified scale. @usableFromInline @_effects(releasenone) - internal init(scale: Int, reservedScale: Int = 0) { + package init(scale: Int, reservedScale: Int = 0) { assert(scale >= Self.minimumScale && scale <= Self.maximumScale) let wordCount = Self.wordCount(forScale: scale) let storage = Storage.create( @@ -65,7 +65,7 @@ extension _HashTable { @inlinable @inline(never) @_effects(releasenone) - static func create( + package static func create( uncheckedUniqueElements elements: C, scale: Int? = nil, reservedScale: Int = 0 @@ -90,7 +90,7 @@ extension _HashTable { @inlinable @inline(never) @_effects(releasenone) - static func create( + package static func create( untilFirstDuplicateIn elements: C, scale: Int? = nil, reservedScale: Int = 0 @@ -139,7 +139,7 @@ extension _HashTable { /// scale and seed, and contains the exact same bucket data as the original instance. @usableFromInline @_effects(releasenone) - internal func copy() -> _HashTable { + package func copy() -> _HashTable { self.read { handle in let wordCount = handle.wordCount let new = Storage.create( @@ -158,7 +158,7 @@ extension _HashTable { /// also some modification to remove some more generic overhead. extension ContiguousArray where Element: Equatable { @inlinable - func _contains(_ element: Element) -> Bool { + internal func _contains(_ element: Element) -> Bool { for index in 0..(_ body: (_UnsafeHashTable) throws -> R) rethrows -> R { + package func read(_ body: (_UnsafeHashTable) throws -> R) rethrows -> R { try _storage.withUnsafeMutablePointers { header, elements in let handle = _UnsafeHashTable(header: header, buckets: elements, readonly: true) return try body(handle) @@ -190,7 +190,7 @@ extension _HashTable { /// the closure call. The closure must not escape it outside the call. @inlinable @inline(__always) - internal func update(_ body: (_UnsafeHashTable) throws -> R) rethrows -> R { + package func update(_ body: (_UnsafeHashTable) throws -> R) rethrows -> R { try _storage.withUnsafeMutablePointers { header, elements in let handle = _UnsafeHashTable(header: header, buckets: elements, readonly: false) return try body(handle) @@ -200,35 +200,35 @@ extension _HashTable { extension _HashTable { @inlinable - internal var header: Header { + package var header: Header { get { _storage.header } @inline(__always) // https://github.com/apple/swift-collections/issues/164 nonmutating _modify { yield &_storage.header } } @inlinable - internal var capacity: Int { + package var capacity: Int { _storage.header.capacity } @inlinable - internal var minimumCapacity: Int { + package var minimumCapacity: Int { if scale == reservedScale { return 0 } return Self.minimumCapacity(forScale: scale) } @inlinable - internal var scale: Int { + package var scale: Int { _storage.header.scale } @inlinable - internal var reservedScale: Int { + package var reservedScale: Int { _storage.header.reservedScale } @inlinable - internal var bias: Int { + package var bias: Int { _storage.header.bias } } diff --git a/Sources/OrderedCollections/HashTable/_Hashtable+Header.swift b/Sources/OrderedCollections/HashTable/_Hashtable+Header.swift index e7cd6598..bc56c4fb 100644 --- a/Sources/OrderedCollections/HashTable/_Hashtable+Header.swift +++ b/Sources/OrderedCollections/HashTable/_Hashtable+Header.swift @@ -17,7 +17,7 @@ extension _HashTable { /// Note that we don't store the number of items currently in the table; /// that information can be easily retrieved from the element storage. @usableFromInline - internal struct Header { + package struct Header { /// We are packing the scale data into the lower bits of the seed & bias /// to save a bit of space that would be otherwise taken up by padding. /// @@ -32,11 +32,11 @@ extension _HashTable { /// │ bias │ rsvd │ /// └──────────────────────────────────────────────┴────────┘ @usableFromInline - var _scaleAndSeed: UInt64 + package var _scaleAndSeed: UInt64 @usableFromInline - var _reservedScaleAndBias: UInt64 + package var _reservedScaleAndBias: UInt64 - init(scale: Int, reservedScale: Int, seed: Int) { + package init(scale: Int, reservedScale: Int, seed: Int) { assert(scale >= _HashTable.minimumScale && scale <= _HashTable.maximumScale) assert(reservedScale >= 0 && reservedScale <= _HashTable.maximumScale) _scaleAndSeed = UInt64(truncatingIfNeeded: seed) << (Swift.max(UInt64.bitWidth - Int.bitWidth, 6)) @@ -52,12 +52,12 @@ extension _HashTable { /// each of which contain an *n*-bit value. @inlinable @inline(__always) - var scale: Int { Int(_scaleAndSeed & 0x3F) } + package var scale: Int { Int(_scaleAndSeed & 0x3F) } /// The scale corresponding to the last call to `reserveCapacity`. /// We remember this here to make sure we don't shrink the table below its reserved size. @inlinable - var reservedScale: Int { + package var reservedScale: Int { @inline(__always) get { Int(_reservedScaleAndBias & 0x3F) } set { @@ -70,7 +70,7 @@ extension _HashTable { /// The hasher seed to use within this hash table. @inlinable @inline(__always) - var seed: Int { + package var seed: Int { Int(truncatingIfNeeded: _scaleAndSeed) } @@ -78,7 +78,7 @@ extension _HashTable { /// into element storage. (This allows O(1) insertions at the front when the /// underlying storage supports it.) @inlinable - var bias: Int { + package var bias: Int { @inline(__always) get { Int(truncatingIfNeeded: _reservedScaleAndBias) &>> 6 } set { @@ -96,6 +96,6 @@ extension _HashTable { /// The maximum number of items that can fit into this table. @inlinable @inline(__always) - var capacity: Int { _HashTable.maximumCapacity(forScale: scale) } + package var capacity: Int { _HashTable.maximumCapacity(forScale: scale) } } } diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+Testing.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+Testing.swift index 6c71f50a..fe496e7c 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+Testing.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+Testing.swift @@ -16,11 +16,11 @@ import InternalCollectionsUtilities #endif extension OrderedSet._UnstableInternals { - @_spi(Testing) public var capacity: Int { base._capacity } - @_spi(Testing) public var minimumCapacity: Int { base._minimumCapacity } - @_spi(Testing) public var scale: Int { base._scale } - @_spi(Testing) public var reservedScale: Int { base._reservedScale } - @_spi(Testing) public var bias: Int { base._bias } + package var capacity: Int { base._capacity } + package var minimumCapacity: Int { base._minimumCapacity } + package var scale: Int { base._scale } + package var reservedScale: Int { base._reservedScale } + package var bias: Int { base._bias } public static var isConsistencyCheckingEnabled: Bool { _isCollectionsInternalCheckingEnabled @@ -28,61 +28,52 @@ extension OrderedSet._UnstableInternals { } extension OrderedSet { - @_spi(Testing) @_alwaysEmitIntoClient - public static var _minimumScale: Int { + package static var _minimumScale: Int { _HashTable.minimumScale } - @_spi(Testing) @_alwaysEmitIntoClient - public static func _minimumCapacity(forScale scale: Int) -> Int { + package static func _minimumCapacity(forScale scale: Int) -> Int { _HashTable.minimumCapacity(forScale: scale) } - @_spi(Testing) @_alwaysEmitIntoClient - public static func _maximumCapacity(forScale scale: Int) -> Int { + package static func _maximumCapacity(forScale scale: Int) -> Int { _HashTable.maximumCapacity(forScale: scale) } - @_spi(Testing) @_alwaysEmitIntoClient - public static func _scale(forCapacity capacity: Int) -> Int { + package static func _scale(forCapacity capacity: Int) -> Int { _HashTable.scale(forCapacity: capacity) } - @_spi(Testing) @_alwaysEmitIntoClient - public static func _biasRange(scale: Int) -> Range { + package static func _biasRange(scale: Int) -> Range { guard scale != 0 else { return Range(uncheckedBounds: (0, 1)) } return Range(uncheckedBounds: (0, (1 &<< scale) - 1)) } } extension OrderedSet._UnstableInternals { - @_spi(Testing) @_alwaysEmitIntoClient - public var hasHashTable: Bool { base._table != nil } + package var hasHashTable: Bool { base._table != nil } - @_spi(Testing) @_alwaysEmitIntoClient - public var hashTableIdentity: ObjectIdentifier? { + package var hashTableIdentity: ObjectIdentifier? { guard let storage = base.__storage else { return nil } return ObjectIdentifier(storage) } - @_spi(Testing) - public var hashTableContents: [Int?] { + package var hashTableContents: [Int?] { guard let table = base._table else { return [] } return table.read { hashTable in hashTable.debugContents() } } - @_spi(Testing) @_alwaysEmitIntoClient - mutating public func _regenerateHashTable(bias: Int) { + package mutating func _regenerateHashTable(bias: Int) { base._ensureUnique() let new = base._table!.copy() base._table!.read { source in @@ -99,9 +90,8 @@ extension OrderedSet._UnstableInternals { base._checkInvariants() } - @_spi(Testing) @_alwaysEmitIntoClient - public mutating func reserveCapacity( + package mutating func reserveCapacity( _ minimumCapacity: Int, persistent: Bool ) { @@ -111,8 +101,7 @@ extension OrderedSet._UnstableInternals { } extension OrderedSet { - @_spi(Testing) - public init( + package init( _scale scale: Int, bias: Int, contents: some Sequence diff --git a/Sources/SortedCollections/BTree/_Node+Testing.swift b/Sources/SortedCollections/BTree/_Node+Testing.swift index fa49e231..b4dd5d06 100644 --- a/Sources/SortedCollections/BTree/_Node+Testing.swift +++ b/Sources/SortedCollections/BTree/_Node+Testing.swift @@ -15,42 +15,40 @@ extension _Node { /// Initialize a node from a list of key-value tuples. - @_spi(Testing) - public init( + package init( _keyValuePairs keyValuePairs: C, children: [_Node]? = nil, capacity: Int ) where C.Element == Element { precondition(keyValuePairs.count <= capacity, "Too many key-value pairs.") self.init(withCapacity: capacity, isLeaf: children == nil) - + self.update { handle in let sortedKeyValuePairs = keyValuePairs.sorted(by: { $0.key < $1.key }) - + for (index, pair) in sortedKeyValuePairs.enumerated() { let (key, value) = pair handle.keys.advanced(by: index).initialize(to: key) handle.values?.advanced(by: index).initialize(to: value) } - + if let children = children { for (index, child) in children.enumerated() { handle.children!.advanced(by: index).initialize(to: child) } - + handle.depth = handle[childAt: 0].storage.header.depth + 1 } - + let totalChildElements = children?.reduce(0, { $0 + $1.read({ $0.subtreeCount }) }) - + handle.elementCount = keyValuePairs.count handle.subtreeCount = keyValuePairs.count + (totalChildElements ?? 0) } } - + /// Converts a node to a single array. - @_spi(Testing) - public func toArray() -> [Element] { + package func toArray() -> [Element] { self.read { handle in if handle.isLeaf { return Array((0..(_ addition: S) where S.Element == Bool { var ref = reference var actual = value - + ref.append(contentsOf: addition) actual.append(contentsOf: addition) expectEqualElements(actual, ref) @@ -636,7 +636,7 @@ final class BitArrayTests: CollectionTestCase { withSome("length", in: 0 ..< 256, maxSamples: 50) { length in var reference = randomBoolArray(count: count) let addition = randomBoolArray(count: length) - + var actual = BitArray(reference) reference.append(contentsOf: addition) @@ -652,7 +652,7 @@ final class BitArrayTests: CollectionTestCase { withSomeRanges("range", in: 0 ..< 512, maxSamples: 50) { range in var reference = randomBoolArray(count: count) let addition = randomBoolArray(count: 512) - + var actual = BitArray(reference) reference.append(contentsOf: addition[range]) @@ -661,7 +661,7 @@ final class BitArrayTests: CollectionTestCase { } } } - + func test_insert() { withEvery("count", in: 0 ..< 129) { count in withSome("i", in: 0 ..< count + 1, maxSamples: 20) { i in @@ -675,7 +675,7 @@ final class BitArrayTests: CollectionTestCase { } } } - + func test_insert_contentsOf_Sequence() { withSome("count", in: 0 ..< 512, maxSamples: 10) { count in print(count) @@ -683,13 +683,13 @@ final class BitArrayTests: CollectionTestCase { withSome("i", in: 0 ..< count + 1, maxSamples: 10) { i in let reference = randomBoolArray(count: count) let addition = randomBoolArray(count: length) - + let value = BitArray(reference) - + func check(_ addition: C) where C.Element == Bool { var ref = reference var actual = value - + ref.insert(contentsOf: addition, at: i) actual.insert(contentsOf: addition, at: i) expectEqualElements(actual, ref) @@ -709,12 +709,12 @@ final class BitArrayTests: CollectionTestCase { withSome("i", in: 0 ..< count + 1, maxSamples: 10) { i in let reference = randomBoolArray(count: count) let addition = randomBoolArray(count: length) - + let value = BitArray(reference) - + var ref = reference var actual = value - + ref.insert(contentsOf: addition, at: i) actual.insert(contentsOf: BitArray(addition), at: i) expectEqualElements(actual, ref) @@ -722,13 +722,13 @@ final class BitArrayTests: CollectionTestCase { } } } - + func test_remove() { withSome("count", in: 0 ..< 512, maxSamples: 50) { count in withSome("i", in: 0 ..< count, maxSamples: 30) { i in var reference = randomBoolArray(count: count) var actual = BitArray(reference) - + let v1 = reference.remove(at: i) let v2 = actual.remove(at: i) expectEqual(v2, v1) @@ -736,7 +736,7 @@ final class BitArrayTests: CollectionTestCase { } } } - + func test_removeSubrange() { withSome("count", in: 0 ..< 512, maxSamples: 50) { count in withSomeRanges("range", in: 0 ..< count, maxSamples: 50) { range in @@ -759,7 +759,7 @@ final class BitArrayTests: CollectionTestCase { expectEqualElements(actual, reference) } } - + func test_removeFirst() { withEvery("count", in: 1 ..< 512) { count in var reference = randomBoolArray(count: count) @@ -770,13 +770,13 @@ final class BitArrayTests: CollectionTestCase { expectEqualElements(actual, reference) } } - + func test_removeFirst_n() { withSome("count", in: 0 ..< 512, maxSamples: 50) { count in withSome("n", in: 0 ... count, maxSamples: 30) { n in var reference = randomBoolArray(count: count) var actual = BitArray(reference) - + reference.removeFirst(n) actual.removeFirst(n) expectEqualElements(actual, reference) @@ -789,14 +789,14 @@ final class BitArrayTests: CollectionTestCase { withSome("n", in: 0 ... count, maxSamples: 30) { n in var reference = randomBoolArray(count: count) var actual = BitArray(reference) - + reference.removeLast(n) actual.removeLast(n) expectEqualElements(actual, reference) } } } - + func test_removeAll() { withSome("count", in: 0 ..< 512, maxSamples: 50) { count in withEvery("keep", in: [false, true]) { keep in @@ -812,7 +812,7 @@ final class BitArrayTests: CollectionTestCase { } } } - + func test_reserveCapacity() { var bits = BitArray() expectEqual(bits._capacity, 0) @@ -848,13 +848,13 @@ final class BitArrayTests: CollectionTestCase { withEvery("i", in: 0 ..< 10) { i in let a = randomBoolArray(count: count) let b = randomBoolArray(count: count) - + let c = BitArray(a) let d = BitArray(b) - + let expected = zip(a, b).map { $0 || $1 } let actual = c | d - + expectEqualElements(actual, expected) } } @@ -865,13 +865,13 @@ final class BitArrayTests: CollectionTestCase { withEvery("i", in: 0 ..< 10) { i in let a = randomBoolArray(count: count) let b = randomBoolArray(count: count) - + let c = BitArray(a) let d = BitArray(b) - + let expected = zip(a, b).map { $0 && $1 } let actual = c & d - + expectEqualElements(actual, expected) } } @@ -882,13 +882,13 @@ final class BitArrayTests: CollectionTestCase { withEvery("i", in: 0 ..< 10) { i in let a = randomBoolArray(count: count) let b = randomBoolArray(count: count) - + let c = BitArray(a) let d = BitArray(b) - + let expected = zip(a, b).map { $0 != $1 } let actual = c ^ d - + expectEqualElements(actual, expected) } } @@ -898,12 +898,12 @@ final class BitArrayTests: CollectionTestCase { withSome("count", in: 0 ..< 512, maxSamples: 100) { count in withEvery("i", in: 0 ..< 10) { i in let a = randomBoolArray(count: count) - + let b = BitArray(a) let expected = a.map { !$0 } let actual = ~b - + expectEqualElements(actual, expected) } } @@ -949,10 +949,10 @@ final class BitArrayTests: CollectionTestCase { withSome("newCount", in: 0 ... 1024, maxSamples: 30) { newCount in withEvery("padding", in: [false, true]) { padding in let array = randomBoolArray(count: oldCount) - + var bits = BitArray(array) bits.truncateOrExtend(toCount: newCount, with: padding) - + let delta = newCount - oldCount if delta >= 0 { let expected = array + repeatElement(padding, count: delta) diff --git a/Tests/CollectionsTestSupportTests/UtilitiesTests.swift b/Tests/CollectionsTestSupportTests/UtilitiesTests.swift index 52623c28..ce6bb5f7 100644 --- a/Tests/CollectionsTestSupportTests/UtilitiesTests.swift +++ b/Tests/CollectionsTestSupportTests/UtilitiesTests.swift @@ -14,7 +14,7 @@ import XCTest #if !COLLECTIONS_SINGLE_MODULE && DEBUG -@testable import _CollectionsTestSupport +import _CollectionsTestSupport #endif #if COLLECTIONS_SINGLE_MODULE || DEBUG diff --git a/Tests/DequeTests/DequeAllocationTests.swift b/Tests/DequeTests/DequeAllocationTests.swift index 66f66aba..30823ca1 100644 --- a/Tests/DequeTests/DequeAllocationTests.swift +++ b/Tests/DequeTests/DequeAllocationTests.swift @@ -13,10 +13,10 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport -@_spi(Testing) import DequeModule +import DequeModule #endif /// Clear box tests for `Deque`'s storage allocation behavior, observed through diff --git a/Tests/DequeTests/DequeInternals.swift b/Tests/DequeTests/DequeInternals.swift index dba7519a..90f28273 100644 --- a/Tests/DequeTests/DequeInternals.swift +++ b/Tests/DequeTests/DequeInternals.swift @@ -12,10 +12,10 @@ //===----------------------------------------------------------------------===// #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport -@_spi(Testing) import DequeModule +import DequeModule #endif @available(SwiftStdlib 5.0, *) diff --git a/Tests/DequeTests/DequeTests.swift b/Tests/DequeTests/DequeTests.swift index 6831db03..62847849 100644 --- a/Tests/DequeTests/DequeTests.swift +++ b/Tests/DequeTests/DequeTests.swift @@ -13,10 +13,10 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport -@_spi(Testing) import DequeModule +import DequeModule #endif final class DequeTests: CollectionTestCase { @@ -376,4 +376,3 @@ final class DequeTests: CollectionTestCase { } } - diff --git a/Tests/DequeTests/MutableCollectionTests.swift b/Tests/DequeTests/MutableCollectionTests.swift index 9601a263..c4189981 100644 --- a/Tests/DequeTests/MutableCollectionTests.swift +++ b/Tests/DequeTests/MutableCollectionTests.swift @@ -16,7 +16,7 @@ import XCTest import Collections #else import _CollectionsTestSupport -@_spi(Testing) import DequeModule +import DequeModule #endif final class MutableCollectiontests: CollectionTestCase { diff --git a/Tests/DequeTests/RangeReplaceableCollectionTests.swift b/Tests/DequeTests/RangeReplaceableCollectionTests.swift index 065febee..179f878f 100644 --- a/Tests/DequeTests/RangeReplaceableCollectionTests.swift +++ b/Tests/DequeTests/RangeReplaceableCollectionTests.swift @@ -13,10 +13,10 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport -@_spi(Testing) import DequeModule +import DequeModule #endif /// Exhaustive tests for `Deque`'s implementations for `RangeReplaceableCollection` diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift index 73797dac..44221129 100644 --- a/Tests/DequeTests/RigidDequeTests.swift +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -13,7 +13,7 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport import SpanPreview diff --git a/Tests/DequeTests/UniqueDequeTests.swift b/Tests/DequeTests/UniqueDequeTests.swift index 6127a7db..980ee6dc 100644 --- a/Tests/DequeTests/UniqueDequeTests.swift +++ b/Tests/DequeTests/UniqueDequeTests.swift @@ -13,7 +13,7 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport import DequeModule diff --git a/Tests/DequeTests/UnsafeBufferTrimTests.swift b/Tests/DequeTests/UnsafeBufferTrimTests.swift index 4a985d46..e55c808b 100644 --- a/Tests/DequeTests/UnsafeBufferTrimTests.swift +++ b/Tests/DequeTests/UnsafeBufferTrimTests.swift @@ -13,7 +13,7 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport import InternalCollectionsUtilities diff --git a/Tests/OrderedCollectionsTests/HashTable/HashTableTests.swift b/Tests/OrderedCollectionsTests/HashTable/HashTableTests.swift index 06e0b453..54cd5487 100644 --- a/Tests/OrderedCollectionsTests/HashTable/HashTableTests.swift +++ b/Tests/OrderedCollectionsTests/HashTable/HashTableTests.swift @@ -16,10 +16,10 @@ import XCTest #if DEBUG // These unit tests use internal decls #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) @testable import Collections +import Collections #else import _CollectionsTestSupport -@_spi(Testing) @testable import OrderedCollections +import OrderedCollections #endif class HashTableTests: CollectionTestCase { @@ -366,7 +366,7 @@ class HashTableTests: CollectionTestCase { withSampleHashTable(scale: scale) { hashTable, contents in var expected = hashTable.bucketIterator(startingAt: Bucket(offset: 0)) // Start a new iterator at every bucket and check that its initial - // state is match exactly what we'd get by starting at the first + // state matches exactly what we'd get by starting at the first // bucket and advancing step by step to the same position. withEvery("start", in: 0 ..< hashTable.bucketCount) { start in let bucket = Bucket(offset: start) @@ -374,14 +374,7 @@ class HashTableTests: CollectionTestCase { expectEqual(expected.currentBucket, bucket) expectEqual(expected.currentValue, contents[start]) - - expectEqual(actual.currentBucket, bucket) - expectEqual(actual.currentValue, contents[start]) - - expectEqual(actual._currentBucket, expected._currentBucket) - expectEqual(actual._currentRawValue, expected._currentRawValue) - expectEqual(actual._nextBits, expected._nextBits) - expectEqual(actual._remainingBitCount, expected._remainingBitCount) + expectTrue(actual.isIdentical(to: expected)) expected.advance() } @@ -414,10 +407,7 @@ class HashTableTests: CollectionTestCase { expectEqual(actual.currentBucket, bucket) expectEqual(actual.currentValue, contents[start]) - expectEqual(actual._currentBucket, expected._currentBucket) - expectEqual(actual._currentRawValue, expected._currentRawValue) - expectEqual(actual._nextBits, expected._nextBits) - expectEqual(actual._remainingBitCount, expected._remainingBitCount) + expectTrue(actual.isIdentical(to: expected)) expected.advance() } diff --git a/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary Tests.swift b/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary Tests.swift index ec9647a8..e7c2651d 100644 --- a/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary Tests.swift +++ b/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary Tests.swift @@ -13,9 +13,9 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else -@_spi(Testing) import OrderedCollections +import OrderedCollections import _CollectionsTestSupport #endif @@ -1570,4 +1570,3 @@ class OrderedDictionaryTests: CollectionTestCase { expectEqualElements(d2m, ["a": 2, "b": 2, "c": 1] as KeyValuePairs) } } - diff --git a/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Elements Tests.swift b/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Elements Tests.swift index d1e8d77a..477bb74f 100644 --- a/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Elements Tests.swift +++ b/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Elements Tests.swift @@ -13,9 +13,9 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else -@_spi(Testing) import OrderedCollections +import OrderedCollections import _CollectionsTestSupport #endif diff --git a/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Values Tests.swift b/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Values Tests.swift index ea5b7e8a..0dbf0697 100644 --- a/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Values Tests.swift +++ b/Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Values Tests.swift @@ -15,7 +15,7 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE import Collections #else -@_spi(Testing) import OrderedCollections +import OrderedCollections import _CollectionsTestSupport #endif @@ -36,7 +36,7 @@ class OrderedDictionaryValueTests: CollectionTestCase { expectEqual(left.values, left.values) // Identity fast path expectEqual(left.values, right.values) // Linear algorithm } - + func test_values_getter_not_equal() { let left: OrderedDictionary = [ "one": 1, @@ -53,7 +53,7 @@ class OrderedDictionaryValueTests: CollectionTestCase { ] expectNotEqual(left.values, right.values) } - + func test_values_getter_equal_elements() { let d: OrderedDictionary = [ "one": 1, diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSet.UnorderedView Tests.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSet.UnorderedView Tests.swift index 48d59ccf..1d96d93c 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSet.UnorderedView Tests.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSet.UnorderedView Tests.swift @@ -15,7 +15,7 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE import Collections #else -@_spi(Testing) import OrderedCollections +import OrderedCollections import _CollectionsTestSupport #endif diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetInternals.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetInternals.swift index b7715a70..3f3cf1f3 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetInternals.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetInternals.swift @@ -12,10 +12,10 @@ //===----------------------------------------------------------------------===// #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else import _CollectionsTestSupport -@_spi(Testing) import OrderedCollections +import OrderedCollections #endif struct OrderedSetLayout: Hashable, CustomStringConvertible { diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift index 35252ff9..4a97aeed 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift @@ -13,9 +13,9 @@ import XCTest #if COLLECTIONS_SINGLE_MODULE -@_spi(Testing) import Collections +import Collections #else -@_spi(Testing) import OrderedCollections +import OrderedCollections import _CollectionsTestSupport import InternalCollectionsUtilities #endif @@ -1637,7 +1637,7 @@ class OrderedSetTests: CollectionTestCase { let os = OrderedSet([1, 2, 3, 4]).filter { $0.isMultiple(of: 2) } expectType(os, OrderedSet.self) } - + func test_equal() { withEvery("count", in: 0 ..< 20) { count in let set = OrderedSet(0 ..< count) @@ -1645,7 +1645,7 @@ class OrderedSetTests: CollectionTestCase { expectEqual(copy, set) } } - + func test_not_equal() { withEvery("count", in: 0 ..< 20) { count in let left = OrderedSet(0 ..< count) @@ -1653,14 +1653,14 @@ class OrderedSetTests: CollectionTestCase { expectNotEqual(left, right) } } - + func test_equal_elements() { withEvery("count", in: 0 ..< 20) { count in let set = OrderedSet(0 ..< count) expectEqualElements(set, 0 ..< count) } } - + func test_subsequence_equality() { let c = 5 let items1 = OrderedSet(0 ..< c) @@ -1672,7 +1672,7 @@ class OrderedSetTests: CollectionTestCase { } } } - + func test_subsequence_not_equality() { let c = 5 let items1 = OrderedSet(0 ..< c) diff --git a/Tests/SortedCollectionsTests/BTree/BTree Tests.swift b/Tests/SortedCollectionsTests/BTree/BTree Tests.swift index 4b2422df..633f9942 100644 --- a/Tests/SortedCollectionsTests/BTree/BTree Tests.swift +++ b/Tests/SortedCollectionsTests/BTree/BTree Tests.swift @@ -15,7 +15,7 @@ #if DEBUG import _CollectionsTestSupport -@_spi(Testing) @testable import SortedCollections +import SortedCollections func btreeOfSize( _ size: Int, @@ -41,7 +41,7 @@ final class BTreeTests: CollectionTestCase { } } } - + func test_indexAtOffset() { withEvery("count", in: [1, 2, 4, 8, 16, 32, 64]) { count in btreeOfSize(count) { btree, kvs in @@ -52,7 +52,7 @@ final class BTreeTests: CollectionTestCase { } } } - + func test_startIndex() { withEvery("count", in: [0, 1, 2, 4, 8, 16, 32, 64]) { count in btreeOfSize(count) { btree, kvs in @@ -64,27 +64,27 @@ final class BTreeTests: CollectionTestCase { } } } - + func test_indexAfter() { withEvery("count", in: [1, 2, 4, 8, 16, 32, 64]) { count in btreeOfSize(count) { btree, kvs in var index = btree.startIndex - + for i in 0.. _Node { let kvs = self.keys.map { (key: $0, value: $0 * 2) } return _Node( @@ -29,20 +29,20 @@ struct NodeTemplate { capacity: capacity ) } - + func toBTree(ofCapacity capacity: Int) -> _BTree { return _BTree(rootedAt: self.toNode(ofCapacity: capacity), internalCapacity: capacity) } - + func matches(_ btree: _BTree) -> Bool { return self.matches(btree.root) } - + func matches(_ node: _Node) -> Bool { return node.read { handle in if self.keys.count != handle.elementCount { return false } if (self.children == nil) != handle.isLeaf { return false } - + if let children = self.children { for (i, child) in children.enumerated() { if !child.matches(handle[childAt: i]) { @@ -50,13 +50,13 @@ struct NodeTemplate { } } } - + for (i, key) in self.keys.enumerated() { if handle[keyAt: i] != key { return false } } - + return true } } diff --git a/Tests/SortedCollectionsTests/BTree/Node+Balancing Tests.swift b/Tests/SortedCollectionsTests/BTree/Node+Balancing Tests.swift index 0aaf9b93..17885d1f 100644 --- a/Tests/SortedCollectionsTests/BTree/Node+Balancing Tests.swift +++ b/Tests/SortedCollectionsTests/BTree/Node+Balancing Tests.swift @@ -15,7 +15,7 @@ #if DEBUG import _CollectionsTestSupport -@_spi(Testing) @testable import SortedCollections +import SortedCollections final class NodeBalancingTests: CollectionTestCase { func test_collapseAtSlot() { @@ -58,7 +58,7 @@ final class NodeBalancingTests: CollectionTestCase { print(btree.debugDescription) // print(SortedDictionary(_rootedAt: btree)) } - + // MARK: Right Rotation func test_internalRightRotation() { let t = tree { @@ -74,10 +74,10 @@ final class NodeBalancingTests: CollectionTestCase { tree { 10; 11 } } } - + var node = t.toNode(ofCapacity: 2) node.update { $0.rotateRight(atSlot: 0) } - + expectTrue( tree { tree { @@ -94,17 +94,17 @@ final class NodeBalancingTests: CollectionTestCase { }.matches(node) ) } - + func test_leafRightRotation() { let t = tree { tree { 0; 1 } 2 tree { 3 } } - + var node = t.toNode(ofCapacity: 2) node.update { $0.rotateRight(atSlot: 0) } - + expectTrue( tree { tree { 0 } @@ -113,7 +113,7 @@ final class NodeBalancingTests: CollectionTestCase { }.matches(node) ) } - + // MARK: Left Rotation func test_internalLeftRotation() { let t = tree { @@ -129,10 +129,10 @@ final class NodeBalancingTests: CollectionTestCase { tree { 10; 11 } } } - + var node = t.toNode(ofCapacity: 2) node.update { $0.rotateLeft(atSlot: 0) } - + expectTrue( tree { tree { @@ -149,17 +149,17 @@ final class NodeBalancingTests: CollectionTestCase { }.matches(node) ) } - + func test_leafLeftRotation() { let t = tree { tree { 0 } 1 tree { 2; 3 } } - + var node = t.toNode(ofCapacity: 2) node.update { $0.rotateLeft(atSlot: 0) } - + expectTrue( tree { tree { 0; 1 } @@ -168,17 +168,17 @@ final class NodeBalancingTests: CollectionTestCase { }.matches(node) ) } - + func test_emptyLeafLeftRotation() { let t = tree { tree { } 1 tree { 2; 3 } } - + var node = t.toNode(ofCapacity: 2) node.update { $0.rotateLeft(atSlot: 0) } - + expectTrue( tree { tree { 1 } @@ -187,7 +187,7 @@ final class NodeBalancingTests: CollectionTestCase { }.matches(node) ) } - + // MARK: Collapse func test_internalCollapse() { let t = tree { @@ -201,10 +201,10 @@ final class NodeBalancingTests: CollectionTestCase { tree { 6; 7 } } } - + var node = t.toNode(ofCapacity: 2) node.update { $0.collapse(atSlot: 0) } - + expectTrue( tree { tree { @@ -217,7 +217,7 @@ final class NodeBalancingTests: CollectionTestCase { }.matches(node) ) } - + func test_leafCollapse() { let t = tree { tree { } @@ -229,7 +229,7 @@ final class NodeBalancingTests: CollectionTestCase { var node = t.toNode(ofCapacity: 2) node.update { $0.collapse(atSlot: 0) } - + expectTrue( tree { tree { 2; 3 } diff --git a/Tests/SortedCollectionsTests/BTree/Node+Insertion Tests.swift b/Tests/SortedCollectionsTests/BTree/Node+Insertion Tests.swift index 14b50366..80adf0ca 100644 --- a/Tests/SortedCollectionsTests/BTree/Node+Insertion Tests.swift +++ b/Tests/SortedCollectionsTests/BTree/Node+Insertion Tests.swift @@ -15,7 +15,7 @@ #if DEBUG import _CollectionsTestSupport -@_spi(Testing) @testable import SortedCollections +import SortedCollections func expectInsertionInTree( capacity: Int, @@ -23,9 +23,9 @@ func expectInsertionInTree( inserting key: Int, toEqual refTree: NodeTemplate) { var btree = tree.toBTree(ofCapacity: capacity) - + btree.updateAnyValue(key * 2, forKey: key) - + let refMatches = refTree.matches(btree) if !refMatches { print("Expected: ") @@ -49,7 +49,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 2 } } ) - + expectInsertionInTree( capacity: 4, tree: tree { 0; 1; 3; 4 }, @@ -60,7 +60,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 3; 4 } } ) - + expectInsertionInTree( capacity: 5, tree: tree { 0; 1; 3; 4; 5 }, @@ -72,7 +72,7 @@ final class NodeInsertionTests: CollectionTestCase { } ) } - + // MARK: Median Internal Node Insertion func test_medianInternalInsertion() { expectInsertionInTree( @@ -99,7 +99,7 @@ final class NodeInsertionTests: CollectionTestCase { } } ) - + expectInsertionInTree( capacity: 3, tree: tree { @@ -128,7 +128,7 @@ final class NodeInsertionTests: CollectionTestCase { } } ) - + expectInsertionInTree( capacity: 4, tree: tree { @@ -161,7 +161,7 @@ final class NodeInsertionTests: CollectionTestCase { } } ) - + expectInsertionInTree( capacity: 5, tree: tree { @@ -199,7 +199,7 @@ final class NodeInsertionTests: CollectionTestCase { } ) } - + // MARK: Right Leaf Insertion func test_rightLeafInsertion() { expectInsertionInTree( @@ -212,7 +212,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 3 } } ) - + expectInsertionInTree( capacity: 3, tree: tree { 1; 2; 4 }, @@ -223,7 +223,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 3; 4 } } ) - + expectInsertionInTree( capacity: 4, tree: tree { 0; 1; 2; 4 }, @@ -234,7 +234,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 3; 4 } } ) - + expectInsertionInTree( capacity: 5, tree: tree { 0; 1; 2; 3; 5 }, @@ -246,7 +246,7 @@ final class NodeInsertionTests: CollectionTestCase { } ) } - + // MARK: Right Internal Node Insertion func test_rightInternalNodeInsertion() { expectInsertionInTree( @@ -273,7 +273,7 @@ final class NodeInsertionTests: CollectionTestCase { } } ) - + expectInsertionInTree( capacity: 3, tree: tree { @@ -373,7 +373,7 @@ final class NodeInsertionTests: CollectionTestCase { } ) } - + // MARK: Left Leaf Insertion func test_leftLeafInsertion() { expectInsertionInTree( @@ -386,7 +386,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 2 } } ) - + expectInsertionInTree( capacity: 3, tree: tree { 1; 2; 3 }, @@ -397,7 +397,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 3 } } ) - + expectInsertionInTree( capacity: 4, tree: tree { 0; 2; 3; 4 }, @@ -408,7 +408,7 @@ final class NodeInsertionTests: CollectionTestCase { tree { 3; 4 } } ) - + expectInsertionInTree( capacity: 5, tree: tree { 0; 2; 3; 4; 5 }, @@ -420,7 +420,7 @@ final class NodeInsertionTests: CollectionTestCase { } ) } - + // MARK: Left Internal Node Insertion func test_leftInternalNodeInsertion() { expectInsertionInTree( @@ -447,7 +447,7 @@ final class NodeInsertionTests: CollectionTestCase { } } ) - + expectInsertionInTree( capacity: 3, tree: tree { diff --git a/Tests/SortedCollectionsTests/BTree/Node+Join Tests.swift b/Tests/SortedCollectionsTests/BTree/Node+Join Tests.swift index 8ece8581..60a4dd9f 100644 --- a/Tests/SortedCollectionsTests/BTree/Node+Join Tests.swift +++ b/Tests/SortedCollectionsTests/BTree/Node+Join Tests.swift @@ -15,7 +15,7 @@ #if DEBUG import _CollectionsTestSupport -@_spi(Testing) @testable import SortedCollections +import SortedCollections func expectNodeJoin( capacity: Int, @@ -26,14 +26,14 @@ func expectNodeJoin( ) { var tree1 = tree1.toNode(ofCapacity: capacity) var tree2 = tree2.toNode(ofCapacity: capacity) - + let newTree = _Node.join( &tree1, with: &tree2, separatedBy: (separator, -separator), capacity: capacity ) - + expectTrue(refTree.matches(newTree)) _BTree(rootedAt: newTree, internalCapacity: capacity).checkInvariants() } @@ -52,7 +52,7 @@ final class NodeJoinTests: CollectionTestCase { }, toEqual: tree { 0; 1; 2; 3; 4 } ) - + expectNodeJoin( capacity: 5, tree1: tree { @@ -69,7 +69,7 @@ final class NodeJoinTests: CollectionTestCase { } ) } - + func test_joinMedian() { expectNodeJoin( capacity: 2, diff --git a/Tests/SortedCollectionsTests/BTree/NodeTests.swift b/Tests/SortedCollectionsTests/BTree/NodeTests.swift index af15e850..70a98317 100644 --- a/Tests/SortedCollectionsTests/BTree/NodeTests.swift +++ b/Tests/SortedCollectionsTests/BTree/NodeTests.swift @@ -15,7 +15,7 @@ #if DEBUG import _CollectionsTestSupport -@_spi(Testing) @testable import SortedCollections +import SortedCollections func nodeFromKeys(_ keys: [Int], capacity: Int) -> _Node { let kvPairs = keys.map { (key: $0, value: $0 * 2) } @@ -70,14 +70,14 @@ func withEveryNode( let possibleShifts = keys - duplicates + 1 try withEvery("shift", in: 0...Splinter? = node.update { handle in let index = handle.endSlot(forKey: newKey) return handle.insertElement((newKey, newKey * 2), withRightChild: nil, atSlot: index) } insertSortedValue(newKey, into: &array) - + expectNil(splinter) node.read { handle in let keys = UnsafeBufferPointer(start: handle.keys, count: handle.elementCount) @@ -111,7 +111,7 @@ final class NodeTests: CollectionTestCase { } } } - + func test_firstIndexOfDuplicates() { withEvery("capacity", in: 2..<10) { capacity in withEvery("keys", in: 0...capacity) { keys in @@ -128,7 +128,7 @@ final class NodeTests: CollectionTestCase { } } } - + func test_lastIndexOfDuplicates() { withEvery("capacity", in: 2..<10) { capacity in withEvery("keys", in: 0...capacity) { keys in diff --git a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift index fc25dddd..bd0f1207 100644 --- a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift +++ b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift @@ -15,7 +15,7 @@ #if DEBUG import _CollectionsTestSupport -@_spi(Testing) @testable import SortedCollections +import SortedCollections final class SortedDictionaryTests: CollectionTestCase { func test_empty() { @@ -23,7 +23,7 @@ final class SortedDictionaryTests: CollectionTestCase { expectEqualElements(d, []) expectEqual(d.count, 0) } - + func test_keysWithValues_unique() { let items: KeyValuePairs = [ 3: "three", @@ -39,7 +39,7 @@ final class SortedDictionaryTests: CollectionTestCase { (key: 3, value: "three") ]) } - + func test_keysWithValues_bulk() { withEvery("count", in: [0, 1, 2, 4, 8, 16, 32, 64, 128, 1024, 4096]) { count in let kvs = (0.. = [ 3: "three", @@ -65,7 +65,7 @@ final class SortedDictionaryTests: CollectionTestCase { (key: 3, value: "three-1") ]) } - + func test_grouping_initializer() { let items: [String] = [ "one", "two", "three", "four", "five", @@ -78,7 +78,7 @@ final class SortedDictionaryTests: CollectionTestCase { (key: 5, value: ["three", "seven", "eight"]), ]) } - + func test_ExpressibleByDictionaryLiteral() { let d0: SortedDictionary = [:] expectTrue(d0.isEmpty) @@ -92,7 +92,7 @@ final class SortedDictionaryTests: CollectionTestCase { expectEqualElements(d1.map { $0.key }, [1, 2, 3, 4]) expectEqualElements(d1.map { $0.value }, ["one", "two", "three", "four"]) } - + func test_counts() { withEvery("count", in: 0 ..< 30) { count in withLifetimeTracking { tracker in @@ -103,12 +103,12 @@ final class SortedDictionaryTests: CollectionTestCase { } } } - + func test_bidirectionalCollection() { withEvery("count", in: [1, 2, 4, 8, 16, 32, 64]) { count in withLifetimeTracking { tracker in let (d, kvs) = tracker.sortedDictionary(keys: 0 ..< count) - + checkBidirectionalCollection( d, expectedContents: kvs, @@ -117,73 +117,73 @@ final class SortedDictionaryTests: CollectionTestCase { } } } - + func test_orderedInsertion() { withEvery("count", in: [0, 1, 2, 3, 4, 8, 16, 64]) { count in var sortedDictionary: SortedDictionary = [:] - + for i in 0.. = [:] - + for i in (0..(keysWithValues: kvs) sortedDictionary[i * 2] = -i - + var comparison = Array(kvs) comparison.insert((key: i * 2, value: -i), at: i) - + expectEqualElements(comparison, sortedDictionary) } } } - + func test_subscriptSet() { withEvery("count", in: [1, 2, 4, 8, 16, 32, 64, 512]) { count in var sortedDictionary: SortedDictionary = [:] - + for i in 0..(keysWithValues: kvs) - + withEvery("isShared", in: [false, true]) { isShared in withHiddenCopies(if: isShared, of: &d) { d in modify(&d[key], setTo: nil) var comparisonKeys = Array(0.. Self { + @_alwaysEmitIntoClient + package func _squareRoot() -> Self { // Newton's method precondition(self >= 0) guard self != 0 else { return 0 }