mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
Renaming: DynamicArray → UniqueArray; ArrayModule → BasicContainers
This commit is contained in:
11 files changed
+110
-110
No files matched your search
+3
-3
@@ -222,7 +222,7 @@ let targets: [CustomTarget] = [
|
||||
|
||||
.target(
|
||||
kind: .exported,
|
||||
name: "ArrayModule",
|
||||
name: "BasicContainers",
|
||||
dependencies: [
|
||||
"InternalCollectionsUtilities",
|
||||
"ContainersPreview",
|
||||
@@ -231,9 +231,9 @@ let targets: [CustomTarget] = [
|
||||
),
|
||||
.target(
|
||||
kind: .test,
|
||||
name: "ArrayTests",
|
||||
name: "BasicContainersTests",
|
||||
dependencies: [
|
||||
"ArrayModule", "_CollectionsTestSupport"
|
||||
"BasicContainers", "_CollectionsTestSupport"
|
||||
]),
|
||||
|
||||
.target(
|
||||
|
||||
@@ -243,7 +243,7 @@ let targets: [CustomTarget] = [
|
||||
|
||||
.target(
|
||||
kind: .exported,
|
||||
name: "ArrayModule",
|
||||
name: "BasicContainers",
|
||||
dependencies: [
|
||||
"InternalCollectionsUtilities",
|
||||
"ContainersPreview",
|
||||
@@ -252,9 +252,9 @@ let targets: [CustomTarget] = [
|
||||
),
|
||||
.target(
|
||||
kind: .test,
|
||||
name: "ArrayTests",
|
||||
name: "BasicContainersTests",
|
||||
dependencies: [
|
||||
"ArrayModule", "_CollectionsTestSupport"
|
||||
"BasicContainers", "_CollectionsTestSupport"
|
||||
]),
|
||||
|
||||
.target(
|
||||
|
||||
@@ -10,21 +10,21 @@ See https://swift.org/LICENSE.txt for license information
|
||||
if(COLLECTIONS_SINGLE_MODULE)
|
||||
set(module_name ${COLLECTIONS_MODULE_NAME})
|
||||
else()
|
||||
set(module_name ArrayModule)
|
||||
add_library(ArrayModule
|
||||
set(module_name BasicContainers)
|
||||
add_library(BasicContainers
|
||||
${COLLECTIONS_ARRAY_SOURCES})
|
||||
target_link_libraries(ArrayModule PRIVATE
|
||||
target_link_libraries(BasicContainers PRIVATE
|
||||
InternalCollectionsUtilities ContainersPreview)
|
||||
set_target_properties(ArrayModule PROPERTIES
|
||||
set_target_properties(BasicContainers PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
|
||||
_install_target(ArrayModule)
|
||||
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS ArrayModule)
|
||||
_install_target(BasicContainers)
|
||||
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS BasicContainers)
|
||||
endif()
|
||||
|
||||
target_sources(${module_name} PRIVATE
|
||||
"DynamicArray.swift"
|
||||
"DynamicArray+Experimental.swift"
|
||||
"UniqueArray.swift"
|
||||
"UniqueArray+Experimental.swift"
|
||||
"RigidArray.swift"
|
||||
"RigidArray+Experimental.swift"
|
||||
)
|
||||
File renamed without changes.
@@ -73,7 +73,7 @@ public struct RigidArray<Element: ~Copyable>: ~Copyable {
|
||||
/// spikes due to a reallocation getting triggered at an inopportune moment.
|
||||
///
|
||||
/// For use cases outside of these narrow domains, we generally recommmend
|
||||
/// the use of ``DynamicArray`` rather than `RigidArray`.
|
||||
/// the use of ``UniqueArray`` rather than `RigidArray`.
|
||||
@safe
|
||||
@frozen
|
||||
public struct RigidArray<Element: ~Copyable>: ~Copyable {
|
||||
+10
-10
@@ -19,7 +19,7 @@ import ContainersPreview
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray /*where Element: Copyable*/ {
|
||||
extension UniqueArray /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
@@ -43,7 +43,7 @@ extension DynamicArray /*where Element: Copyable*/ {
|
||||
#endif
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
@_lifetime(borrow self)
|
||||
@@ -54,11 +54,11 @@ extension DynamicArray where Element: ~Copyable {
|
||||
#endif
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray: RandomAccessContainer where Element: ~Copyable {}
|
||||
extension UniqueArray: RandomAccessContainer where Element: ~Copyable {}
|
||||
#endif
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
@_lifetime(&self)
|
||||
public mutating func mutateElement(at index: Int) -> Inout<Element> {
|
||||
@@ -67,7 +67,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
#endif
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@@ -85,7 +85,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Removes all the elements that satisfy the given predicate.
|
||||
///
|
||||
/// Use this method to remove every element in a container that meets
|
||||
@@ -108,7 +108,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
#endif
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(
|
||||
@@ -128,7 +128,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray {
|
||||
extension UniqueArray {
|
||||
#if FIXME
|
||||
public mutating func _appendContainer<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -190,7 +190,7 @@ extension DynamicArray {
|
||||
}
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray {
|
||||
extension UniqueArray {
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal mutating func _insertContainer<
|
||||
@@ -271,7 +271,7 @@ extension DynamicArray {
|
||||
#endif
|
||||
|
||||
#if FIXME
|
||||
extension DynamicArray {
|
||||
extension UniqueArray {
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func _replaceSubrange<
|
||||
+32
-32
@@ -18,8 +18,8 @@ import InternalCollectionsUtilities
|
||||
/// A dynamically self-resizing, heap allocated, noncopyable array
|
||||
/// of potentially noncopyable elements.
|
||||
@frozen
|
||||
@available(*, unavailable, message: "DynamicArray requires a Swift 6.2 toolchain")
|
||||
public struct DynamicArray<Element: ~Copyable>: ~Copyable {
|
||||
@available(*, unavailable, message: "UniqueArray requires a Swift 6.2 toolchain")
|
||||
public struct UniqueArray<Element: ~Copyable>: ~Copyable {
|
||||
@usableFromInline
|
||||
internal var _storage: RigidArray<Element>
|
||||
|
||||
@@ -34,9 +34,9 @@ public struct DynamicArray<Element: ~Copyable>: ~Copyable {
|
||||
/// A dynamically self-resizing, heap allocated, noncopyable array of
|
||||
/// potentially noncopyable elements.
|
||||
///
|
||||
/// `DynamicArray` instances automatically resize their underlying storage as
|
||||
/// `UniqueArray` instances automatically resize their underlying storage as
|
||||
/// needed to accommodate newly inserted items, using a geometric growth curve.
|
||||
/// This frees code using `DynamicArray` from having to allocate enough
|
||||
/// This frees code using `UniqueArray` from having to allocate enough
|
||||
/// capacity in advance; on the other hand, it makes it difficult to tell
|
||||
/// when and where such reallocations may happen.
|
||||
///
|
||||
@@ -57,7 +57,7 @@ public struct DynamicArray<Element: ~Copyable>: ~Copyable {
|
||||
/// a fixed-capacity array variant that caters specifically for these use cases,
|
||||
/// trading ease-of-use for more consistent/predictable execution.
|
||||
@frozen
|
||||
public struct DynamicArray<Element: ~Copyable>: ~Copyable {
|
||||
public struct UniqueArray<Element: ~Copyable>: ~Copyable {
|
||||
@usableFromInline
|
||||
internal var _storage: RigidArray<Element>
|
||||
|
||||
@@ -66,18 +66,18 @@ public struct DynamicArray<Element: ~Copyable>: ~Copyable {
|
||||
_storage = .init(capacity: 0)
|
||||
}
|
||||
}
|
||||
extension DynamicArray: Sendable where Element: Sendable & ~Copyable {}
|
||||
extension UniqueArray: Sendable where Element: Sendable & ~Copyable {}
|
||||
|
||||
//MARK: - Initializers
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
public init(capacity: Int) {
|
||||
_storage = .init(capacity: capacity)
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@inlinable
|
||||
public init<E: Error>(
|
||||
@@ -89,14 +89,14 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
public init(consuming storage: consuming RigidArray<Element>) {
|
||||
self._storage = storage
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray /*where Element: Copyable*/ {
|
||||
extension UniqueArray /*where Element: Copyable*/ {
|
||||
/// Creates a new array containing the specified number of a single,
|
||||
/// repeated value.
|
||||
///
|
||||
@@ -109,7 +109,7 @@ extension DynamicArray /*where Element: Copyable*/ {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray /*where Element: Copyable*/ {
|
||||
extension UniqueArray /*where Element: Copyable*/ {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init(capacity: Int? = nil, copying contents: some Sequence<Element>) {
|
||||
@@ -120,7 +120,7 @@ extension DynamicArray /*where Element: Copyable*/ {
|
||||
|
||||
//MARK: - Basics
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public var capacity: Int { _assumeNonNegative(_storage.capacity) }
|
||||
@@ -134,7 +134,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
|
||||
//MARK: - Span creation
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
public var span: Span<Element> {
|
||||
@_lifetime(borrow self)
|
||||
@@ -154,7 +154,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Arbitrarily edit the storage underlying this array by invoking a
|
||||
/// user-supplied closure with a mutable `OutputSpan` view over it.
|
||||
/// This method calls its function argument precisely once, allowing it to
|
||||
@@ -183,7 +183,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
|
||||
//MARK: - Random-access & mutable container primitives
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
public typealias Index = Int
|
||||
|
||||
@inlinable
|
||||
@@ -217,14 +217,14 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
public mutating func swapAt(_ i: Int, _ j: Int) {
|
||||
_storage.swapAt(i, j)
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@inlinable
|
||||
@_lifetime(borrow self)
|
||||
@@ -240,7 +240,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@_lifetime(&self)
|
||||
public mutating func mutableSpan(
|
||||
@@ -269,7 +269,7 @@ internal func _growDynamicArrayCapacity(_ capacity: Int) -> Int {
|
||||
return Int(bitPattern: c)
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable @inline(never)
|
||||
public mutating func reallocate(capacity: Int) {
|
||||
_storage.reallocate(capacity: capacity)
|
||||
@@ -304,7 +304,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
|
||||
//MARK: - Removal operations
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Removes all elements from the array, optionally preserving its
|
||||
/// allocated capacity.
|
||||
///
|
||||
@@ -393,7 +393,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Removes and returns the last element of the array, if there is one.
|
||||
///
|
||||
/// - Returns: The last element of the array if the array is not empty;
|
||||
@@ -409,7 +409,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
|
||||
//MARK: - Append operations
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Adds an element to the end of the array.
|
||||
///
|
||||
/// If the array does not have sufficient capacity to hold any more elements,
|
||||
@@ -425,7 +425,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Moves the elements of a buffer to the end of this array, leaving the
|
||||
/// buffer uninitialized.
|
||||
///
|
||||
@@ -469,7 +469,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Appends the elements of a given container to the end of this array by
|
||||
/// consuming the source container.
|
||||
///
|
||||
@@ -490,7 +490,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray {
|
||||
extension UniqueArray {
|
||||
/// Copies the elements of a buffer to the end of this array.
|
||||
///
|
||||
/// If the array does not have sufficient capacity to hold enough elements,
|
||||
@@ -576,7 +576,7 @@ extension DynamicArray {
|
||||
|
||||
//MARK: - Insert operations
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Inserts a new element into the array at the specified position.
|
||||
///
|
||||
/// If the array does not have sufficient capacity to hold any more elements,
|
||||
@@ -603,7 +603,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Moves the elements of a fully initialized buffer into this array,
|
||||
/// starting at the specified position, and leaving the buffer
|
||||
/// uninitialized.
|
||||
@@ -649,7 +649,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Inserts the elements of a given array into the given position in this
|
||||
/// array by consuming the source container.
|
||||
///
|
||||
@@ -672,7 +672,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray {
|
||||
extension UniqueArray {
|
||||
/// Copyies the elements of a fully initialized buffer pointer into this
|
||||
/// array at the specified position.
|
||||
///
|
||||
@@ -791,7 +791,7 @@ extension DynamicArray {
|
||||
|
||||
//MARK: - Range replacement
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Replaces the specified range of elements by moving the elements of a
|
||||
/// fully initialized buffer into their place. On return, the buffer is left
|
||||
/// in an uninitialized state.
|
||||
@@ -869,7 +869,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Replaces the specified range of elements by moving the elements of a
|
||||
/// given array into their place, consuming it in the process.
|
||||
///
|
||||
@@ -905,7 +905,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray {
|
||||
extension UniqueArray {
|
||||
/// Replaces the specified subrange of elements by copying the elements of
|
||||
/// the given buffer pointer, which must be fully initialized.
|
||||
///
|
||||
@@ -58,7 +58,7 @@ endif()
|
||||
add_subdirectory(InternalCollectionsUtilities)
|
||||
add_subdirectory(ContainersPreview)
|
||||
if(NOT COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
|
||||
add_subdirectory(ArrayModule)
|
||||
add_subdirectory(BasicContainers)
|
||||
add_subdirectory(BitCollections)
|
||||
add_subdirectory(HashTreeCollections)
|
||||
add_subdirectory(HeapModule)
|
||||
|
||||
@@ -14,7 +14,7 @@ import XCTest
|
||||
import Collections
|
||||
#else
|
||||
import _CollectionsTestSupport
|
||||
import ArrayModule
|
||||
import BasicContainers
|
||||
#endif
|
||||
|
||||
struct ArrayLayout {
|
||||
@@ -77,7 +77,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
init(layout: ArrayLayout, using generator: (Int) -> Element) {
|
||||
self.init(consuming: RigidArray(layout: layout, using: generator))
|
||||
}
|
||||
@@ -91,14 +91,14 @@ extension LifetimeTracker {
|
||||
RigidArray(layout: layout, using: { self.instance(for: generator($0)) })
|
||||
}
|
||||
|
||||
func dynamicArray<Element>(
|
||||
func uniqueArray<Element>(
|
||||
layout: ArrayLayout,
|
||||
using generator: (Int) -> Element = { $0 }
|
||||
) -> DynamicArray<LifetimeTracked<Element>> {
|
||||
) -> UniqueArray<LifetimeTracked<Element>> {
|
||||
let contents = RigidArray(layout: layout) {
|
||||
self.instance(for: generator($0))
|
||||
}
|
||||
return DynamicArray(consuming: contents)
|
||||
return UniqueArray(consuming: contents)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -14,7 +14,7 @@ import XCTest
|
||||
import Collections
|
||||
#else
|
||||
import _CollectionsTestSupport
|
||||
import ArrayModule
|
||||
import BasicContainers
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.2) && (compiler(>=6.3) || !os(Windows)) // FIXME: [2025-08-17] Windows has no 6.2 snapshot with OutputSpan
|
||||
+46
-46
@@ -14,7 +14,7 @@ import XCTest
|
||||
import Collections
|
||||
#else
|
||||
import _CollectionsTestSupport
|
||||
import ArrayModule
|
||||
import BasicContainers
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.2) && (compiler(>=6.3) || !os(Windows)) // FIXME: [2025-08-17] Windows has no 6.2 snapshot with OutputSpan
|
||||
@@ -26,7 +26,7 @@ public func expectContainerContents<
|
||||
Element: Equatable,
|
||||
C2: Collection<Element>,
|
||||
>(
|
||||
_ left: borrowing DynamicArray<Element>,
|
||||
_ left: borrowing UniqueArray<Element>,
|
||||
equalTo right: C2,
|
||||
_ message: @autoclosure () -> String = "",
|
||||
trapping: Bool = false,
|
||||
@@ -45,7 +45,7 @@ public func expectContainerContents<
|
||||
E1: ~Copyable,
|
||||
C2: Collection,
|
||||
>(
|
||||
_ left: borrowing DynamicArray<E1>,
|
||||
_ left: borrowing UniqueArray<E1>,
|
||||
equivalentTo right: C2,
|
||||
by areEquivalent: (borrowing E1, C2.Element) -> Bool,
|
||||
_ message: @autoclosure () -> String = "",
|
||||
@@ -63,11 +63,11 @@ public func expectContainerContents<
|
||||
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
class DynamicArrayTests: CollectionTestCase {
|
||||
class UniqueArrayTests: CollectionTestCase {
|
||||
func test_validate_Container() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let items = DynamicArray(consuming: tracker.rigidArray(layout: layout))
|
||||
let items = UniqueArray(consuming: tracker.rigidArray(layout: layout))
|
||||
let expected = (0 ..< layout.count).map { tracker.instance(for: $0) }
|
||||
expectEqual(tracker.instances, 2 * layout.count)
|
||||
expectContainerContents(items, equalTo: expected)
|
||||
@@ -82,7 +82,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
withLifetimeTracking { tracker in
|
||||
typealias Value = LifetimeTrackedStruct<Int>
|
||||
|
||||
var array = DynamicArray<Value>()
|
||||
var array = UniqueArray<Value>()
|
||||
expectTrue(array.isEmpty)
|
||||
expectEqual(array.count, 0)
|
||||
expectEqual(array.capacity, 0)
|
||||
@@ -126,7 +126,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
|
||||
func test_init_capacity() {
|
||||
do {
|
||||
let a = DynamicArray<Int>(capacity: 0)
|
||||
let a = UniqueArray<Int>(capacity: 0)
|
||||
expectEqual(a.capacity, 0)
|
||||
expectEqual(a.count, 0)
|
||||
expectEqual(a.freeCapacity, 0)
|
||||
@@ -134,7 +134,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
}
|
||||
|
||||
do {
|
||||
let a = DynamicArray<Int>(capacity: 10)
|
||||
let a = UniqueArray<Int>(capacity: 10)
|
||||
expectEqual(a.capacity, 10)
|
||||
expectEqual(a.count, 0)
|
||||
expectEqual(a.freeCapacity, 10)
|
||||
@@ -145,7 +145,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_init_generator() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let a = tracker.dynamicArray(layout: layout)
|
||||
let a = tracker.uniqueArray(layout: layout)
|
||||
expectEqual(a.capacity, layout.capacity)
|
||||
expectEqual(a.count, layout.count)
|
||||
expectEqual(a.freeCapacity, layout.capacity - layout.count)
|
||||
@@ -159,7 +159,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
withEvery("c", in: [0, 10, 100]) { c in
|
||||
withLifetimeTracking { tracker in
|
||||
let value = tracker.instance(for: 0)
|
||||
let a = DynamicArray(repeating: value, count: c)
|
||||
let a = UniqueArray(repeating: value, count: c)
|
||||
expectEqual(a.capacity, c)
|
||||
expectEqual(a.count, c)
|
||||
expectEqual(a.freeCapacity, 0)
|
||||
@@ -174,7 +174,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_init_copying_Sequence() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let a = DynamicArray(
|
||||
let a = UniqueArray(
|
||||
capacity: layout.capacity,
|
||||
copying: (0 ..< layout.count).map { tracker.instance(for: $0) })
|
||||
expectEqual(tracker.instances, layout.count)
|
||||
@@ -202,7 +202,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
copying: (0 ..< layout.count).map { tracker.instance(for: $0) }),
|
||||
spanCounts: spanCounts)
|
||||
|
||||
let array = DynamicArray(
|
||||
let array = UniqueArray(
|
||||
capacity: layout.capacity, copying: additions)
|
||||
expectEqual(tracker.instances, layout.count)
|
||||
expectEqual(array.capacity, layout.capacity)
|
||||
@@ -219,7 +219,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_span() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let a = tracker.dynamicArray(layout: layout)
|
||||
let a = tracker.uniqueArray(layout: layout)
|
||||
let span = a.span
|
||||
expectEqual(span.count, layout.count)
|
||||
for i in 0 ..< span.count {
|
||||
@@ -232,7 +232,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_mutableSpan() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
var span = a.mutableSpan
|
||||
expectEqual(span.count, layout.count)
|
||||
for i in 0 ..< layout.count {
|
||||
@@ -250,10 +250,10 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
}
|
||||
|
||||
func test_nextSpan() {
|
||||
// DynamicArray is expected to have exactly one span.
|
||||
// UniqueArray is expected to have exactly one span.
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let a = tracker.dynamicArray(layout: layout)
|
||||
let a = tracker.uniqueArray(layout: layout)
|
||||
let whole = a.span
|
||||
var i = 0
|
||||
let first = a.span(after: &i)
|
||||
@@ -270,7 +270,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
// RigidArray is expected to have exactly one span.
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let a = tracker.dynamicArray(layout: layout)
|
||||
let a = tracker.uniqueArray(layout: layout)
|
||||
let whole = a.span
|
||||
var i = layout.count
|
||||
let first = a.span(before: &i)
|
||||
@@ -287,7 +287,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
// RigidArray is expected to have exactly one span.
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
var i = 0
|
||||
var span = a.mutableSpan(after: &i)
|
||||
expectEqual(i, layout.count)
|
||||
@@ -301,7 +301,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
|
||||
func test_index_properties() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
let a = DynamicArray(layout: layout, using: { $0 })
|
||||
let a = UniqueArray(layout: layout, using: { $0 })
|
||||
expectEqual(a.startIndex, 0)
|
||||
expectEqual(a.endIndex, layout.count)
|
||||
expectEqual(a.indices, 0 ..< layout.count)
|
||||
@@ -311,7 +311,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_swapAt() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
withEvery("i", in: 0 ..< layout.count / 2) { i in
|
||||
a.swapAt(i, layout.count - 1 - i)
|
||||
}
|
||||
@@ -327,7 +327,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_borrowElement() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let a = tracker.dynamicArray(layout: layout)
|
||||
let a = tracker.uniqueArray(layout: layout)
|
||||
for i in 0 ..< layout.count {
|
||||
let item = a.borrowElement(at: i)
|
||||
expectEqual(item[].payload, i)
|
||||
@@ -341,7 +341,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_mutateElement() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
for i in 0 ..< layout.count {
|
||||
var item = a.mutateElement(at: i)
|
||||
expectEqual(item[].payload, i)
|
||||
@@ -356,7 +356,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_edit() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.edit { span in
|
||||
expectEqual(span.capacity, layout.capacity)
|
||||
expectEqual(span.count, layout.count)
|
||||
@@ -412,7 +412,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
] as Set
|
||||
) { newCapacity in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
expectEqual(a.count, layout.count)
|
||||
expectEqual(a.capacity, layout.capacity)
|
||||
a.reallocate(capacity: newCapacity)
|
||||
@@ -436,7 +436,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
] as Set
|
||||
) { newCapacity in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
expectEqual(a.count, layout.count)
|
||||
expectEqual(a.capacity, layout.capacity)
|
||||
a.reserveCapacity(newCapacity)
|
||||
@@ -453,7 +453,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_removeAll() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.removeAll()
|
||||
expectTrue(a.isEmpty)
|
||||
expectEqual(a.capacity, 0)
|
||||
@@ -465,7 +465,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_removeAll_keepingCapacity() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.removeAll(keepingCapacity: true)
|
||||
expectTrue(a.isEmpty)
|
||||
expectEqual(a.capacity, layout.capacity)
|
||||
@@ -477,7 +477,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
func test_removeLast() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
withEvery("i", in: 0 ..< layout.count) { i in
|
||||
let old = a.removeLast()
|
||||
expectEqual(old.payload, layout.count - 1 - i)
|
||||
@@ -496,7 +496,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
var expected = Array(0 ..< layout.count)
|
||||
expected.removeLast(k)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
expectEqual(tracker.instances, layout.count)
|
||||
a.removeLast(k)
|
||||
expectEqual(tracker.instances, layout.count - k)
|
||||
@@ -514,7 +514,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
var expected = Array(0 ..< layout.count)
|
||||
expected.remove(at: i)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let old = a.remove(at: i)
|
||||
expectEqual(old.payload, i)
|
||||
expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 })
|
||||
@@ -530,7 +530,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
var expected = Array(0 ..< layout.count)
|
||||
expected.removeSubrange(range)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.removeSubrange(range)
|
||||
expectContainerContents(a, equivalentTo: expected, by: { $0.payload == $1 })
|
||||
}
|
||||
@@ -545,7 +545,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
var expected = Array(0 ..< layout.count)
|
||||
expected.removeAll(where: { $0.isMultiple(of: 2) })
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.removeAll(where: { $0.payload.isMultiple(of: 2) })
|
||||
expectContainerContents(
|
||||
a, equivalentTo: expected, by: { $0.payload == $1 })
|
||||
@@ -560,7 +560,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
var expected = Array(0 ..< layout.count)
|
||||
let expectedItem = expected.popLast()
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let item = a.popLast()
|
||||
|
||||
expectEquivalent(item, expectedItem, by: { $0?.payload == $1 })
|
||||
@@ -571,13 +571,13 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
}
|
||||
|
||||
func test_append_geometric_growth() {
|
||||
// This test depends on the precise growth curve of DynamicArray,
|
||||
// This test depends on the precise growth curve of UniqueArray,
|
||||
// which is not part of its stable API. The test may need to be updated
|
||||
// accordingly.
|
||||
withLifetimeTracking { tracker in
|
||||
typealias Value = LifetimeTracked<Int>
|
||||
|
||||
var array = DynamicArray<Value>()
|
||||
var array = UniqueArray<Value>()
|
||||
expectEqual(array.capacity, 0)
|
||||
|
||||
array.append(tracker.instance(for: 0))
|
||||
@@ -630,7 +630,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withLifetimeTracking { tracker in
|
||||
let c = 2 * layout.capacity + 10
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
for i in layout.count ..< c {
|
||||
a.append(tracker.instance(for: i))
|
||||
expectEqual(a.count, i + 1)
|
||||
@@ -646,7 +646,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
withEvery("isContiguous", in: [false, true]) { isContiguous in
|
||||
withLifetimeTracking { tracker in
|
||||
let c = 2 * layout.capacity + 10
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.append(copying: MinimalSequence(
|
||||
elements: (layout.count ..< c).map { tracker.instance(for: $0) },
|
||||
underestimatedCount: .half,
|
||||
@@ -663,7 +663,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
withEvery("additions", in: [0, 1, 10, 100]) { additions in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let b = RigidArray(capacity: additions) { span in
|
||||
for i in 0 ..< additions {
|
||||
span.append(tracker.instance(for: layout.count + i))
|
||||
@@ -685,7 +685,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
withEvery("additions", in: [0, 1, 10, 100]) { additions in
|
||||
withEvery("spanCount", in: 1 ... Swift.max(1, layout.capacity - layout.count)) { spanCount in
|
||||
withLifetimeTracking { tracker in
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
|
||||
let c = layout.count + additions
|
||||
let addition = (layout.count ..< c).map {
|
||||
@@ -712,7 +712,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
var expected = Array(0 ..< layout.count)
|
||||
expected.insert(-1, at: i)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.insert(tracker.instance(for: -1), at: i)
|
||||
|
||||
expectContainerContents(
|
||||
@@ -734,7 +734,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
expected.insert(contentsOf: addition, at: i)
|
||||
|
||||
let trackedAddition = addition.map { tracker.instance(for: $0) }
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.insert(copying: trackedAddition, at: i)
|
||||
|
||||
expectContainerContents(
|
||||
@@ -759,7 +759,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
let rigidAddition = RigidArray(
|
||||
copying: (0 ..< addition.count).lazy.map { tracker.instance(for: addition[$0]) }
|
||||
)
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
a.insert(copying: rigidAddition.span, at: i)
|
||||
|
||||
expectContainerContents(
|
||||
@@ -783,7 +783,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
let addition = Array(layout.count ..< layout.count + c)
|
||||
expected.insert(contentsOf: addition, at: i)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let rigidAddition = StaccatoContainer(
|
||||
contents: RigidArray(count: addition.count) {
|
||||
tracker.instance(for: addition[$0])
|
||||
@@ -811,7 +811,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
let addition = (0 ..< c).map { -100 - $0 }
|
||||
expected.replaceSubrange(range, with: addition)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let trackedAddition = addition.map { tracker.instance(for: $0) }
|
||||
a.replaceSubrange(range, copying: trackedAddition)
|
||||
|
||||
@@ -833,7 +833,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
let addition = (0 ..< c).map { -100 - $0 }
|
||||
expected.replaceSubrange(range, with: addition)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let trackedAddition = RigidArray(
|
||||
copying: addition.map { tracker.instance(for: $0) })
|
||||
a.replaceSubrange(range, copying: trackedAddition.span)
|
||||
@@ -858,7 +858,7 @@ class DynamicArrayTests: CollectionTestCase {
|
||||
let addition = (0 ..< c).map { -100 - $0 }
|
||||
expected.replaceSubrange(range, with: addition)
|
||||
|
||||
var a = tracker.dynamicArray(layout: layout)
|
||||
var a = tracker.uniqueArray(layout: layout)
|
||||
let trackedAddition = StaccatoContainer(
|
||||
contents: RigidArray(
|
||||
copying: addition.map { tracker.instance(for: $0) }),
|
||||
Reference in new issue
Block a user