From a95daaa253bf6d36e8c64916209cb95cf28f9a23 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Sun, 17 Aug 2025 13:05:19 -0700 Subject: [PATCH] [ArrayModule] Add (not yet functional) experimental/unstable API --- Sources/ArrayModule/CMakeLists.txt | 2 + .../DynamicArray+Experimental.swift | 364 ++++++++++++++ .../ArrayModule/RigidArray+Experimental.swift | 455 ++++++++++++++++++ Xcode/Collections.xcodeproj/project.pbxproj | 8 + 4 files changed, 829 insertions(+) create mode 100644 Sources/ArrayModule/DynamicArray+Experimental.swift create mode 100644 Sources/ArrayModule/RigidArray+Experimental.swift diff --git a/Sources/ArrayModule/CMakeLists.txt b/Sources/ArrayModule/CMakeLists.txt index cd2dc1e3..aa18f99b 100644 --- a/Sources/ArrayModule/CMakeLists.txt +++ b/Sources/ArrayModule/CMakeLists.txt @@ -24,5 +24,7 @@ endif() target_sources(${module_name} PRIVATE "DynamicArray.swift" + "DynamicArray+Experimental.swift" "RigidArray.swift" + "RigidArray+Experimental.swift" ) diff --git a/Sources/ArrayModule/DynamicArray+Experimental.swift b/Sources/ArrayModule/DynamicArray+Experimental.swift new file mode 100644 index 00000000..7598aa0d --- /dev/null +++ b/Sources/ArrayModule/DynamicArray+Experimental.swift @@ -0,0 +1,364 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +import ContainersPreview +#endif +#endif + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +#if FIXME +extension DynamicArray /*where Element: Copyable*/ { + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + @inline(__always) + public init & ~Copyable & ~Escapable>( + capacity: Int? = nil, + copying contents: borrowing C + ) { + self.init(consuming: RigidArray(capacity: capacity, copying: contents)) + } + + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + @inline(__always) + public init & Sequence>( + capacity: Int? = nil, + copying contents: C + ) { + self.init(consuming: RigidArray(capacity: capacity, copying: contents)) + } +} +#endif + +#if FIXME +extension DynamicArray where Element: ~Copyable { + @inlinable + @inline(__always) + @_lifetime(borrow self) + public func borrowElement(at index: Int) -> Borrow { + _storage.borrowElement(at: index) + } +} +#endif + +#if FIXME +extension DynamicArray: RandomAccessContainer where Element: ~Copyable {} +#endif + +#if FIXME +extension DynamicArray where Element: ~Copyable { + @inlinable + @_lifetime(&self) + public mutating func mutateElement(at index: Int) -> Inout { + _storage.mutateElement(at: index) + } +} +#endif + +extension DynamicArray where Element: ~Copyable { + @available(SwiftStdlib 5.0, *) + @inlinable + @_transparent + internal mutating func _edit( + freeCapacity: Int, + inPlaceMutation: (inout OutputSpan) -> R, + reallocatingMutation: (inout InputSpan, inout OutputSpan) -> R + ) -> R { + if _storage.freeCapacity >= freeCapacity { + return edit(inPlaceMutation) + } + let newCapacity = _grow(freeCapacity: freeCapacity) + return _storage.reallocate(capacity: newCapacity, with: reallocatingMutation) + } +} + +#if FIXME +extension DynamicArray where Element: ~Copyable { + /// Removes all the elements that satisfy the given predicate. + /// + /// Use this method to remove every element in a container that meets + /// particular criteria. The order of the remaining elements is preserved. + /// + /// - Parameter shouldBeRemoved: A closure that takes an element of the + /// sequence as its argument and returns a Boolean value indicating + /// whether the element should be removed from the array. + /// + /// - Complexity: O(`count`) + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + public mutating func removeAll( + where shouldBeRemoved: (borrowing Element) throws(E) -> Bool + ) throws(E) { + // FIXME: Remove this in favor of a standard algorithm. + let suffixStart = try _halfStablePartition(isSuffixElement: shouldBeRemoved) + removeSubrange(suffixStart...) + } +} +#endif + +extension DynamicArray where Element: ~Copyable { + @available(SwiftStdlib 5.0, *) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout InputSpan + ) { + _ensureFreeCapacity(items.count) + _storage.append(moving: &items) + } + + @available(SwiftStdlib 5.0, *) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout OutputSpan + ) { + _ensureFreeCapacity(items.count) + _storage.append(moving: &items) + } +} + +extension DynamicArray { +#if FIXME + public mutating func _appendContainer< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C + ) { + var i = newElements.startIndex + while true { + let span = newElements.span(after: &i) + if span.isEmpty { break } + self.append(copying: span) + } + } +#endif + +#if FIXME + /// Copies the elements of a container to the end of this array. + /// + /// If the array does not have sufficient capacity to hold enough elements, + /// then this reallocates the array's storage to extend its capacity. + /// + /// - Parameters + /// - newElements: A container whose contents to copy into the array. + /// + /// - Complexity: O(`newElements.count`), when amortized over many invocations + /// over the same array. + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + public mutating func append< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C + ) { + _appendContainer(copying: newElements) + } +#endif + +#if FIXME + /// Copies the elements of a container to the end of this array. + /// + /// If the array does not have sufficient capacity to hold enough elements, + /// then this reallocates the array's storage to extend its capacity. + /// + /// - Parameters + /// - newElements: A container whose contents to copy into the array. + /// + /// - Complexity: O(`newElements.count`), when amortized over many invocations + /// over the same array. + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + public mutating func append< + C: Container & Sequence + >( + copying newElements: borrowing C + ) { + _appendContainer(copying: newElements) + } +#endif +} + +#if FIXME +extension DynamicArray { + @available(SwiftStdlib 6.2, *) + @inlinable + internal mutating func _insertContainer< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C, at index: Int + ) { + // FIXME: Avoiding moving the subsequent elements twice. + let newCount = newElements.count + _ensureFreeCapacity(newCount) + _storage._insertContainer( + at: index, copying: newElements, newCount: newCount) + } + + /// Copies the elements of a container into this array at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the array’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the array. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new item. + /// + /// If the array does not have sufficient capacity to hold enough elements, + /// then this reallocates the array's storage to extend its capacity. + /// + /// - Parameters + /// - newElements: The new elements to insert into the array. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the array. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C, at index: Int + ) { + _insertContainer(copying: newElements, at: index) + } + + /// Copies the elements of a container into this array at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the array’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the array. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new item. + /// + /// If the array does not have sufficient capacity to hold enough elements, + /// then this reallocates the array's storage to extend its capacity. + /// + /// - Parameters + /// - newElements: The new elements to insert into the array. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the array. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & Collection + >( + copying newElements: borrowing C, at index: Int + ) { + _insertContainer(copying: newElements, at: index) + } + +} +#endif + +#if FIXME +extension DynamicArray { + @available(SwiftStdlib 6.2, *) + @inlinable + public mutating func _replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copyingContainer newElements: borrowing C + ) { + // FIXME: Avoiding moving the subsequent elements twice. + let c = newElements.count + _ensureFreeCapacity(c) + _storage._replaceSubrange( + subrange, copyingContainer: newElements, newCount: c) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same location. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length container as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(SwiftStdlib 6.2, *) + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copying newElements: borrowing C + ) { + _replaceSubrange(subrange, copyingContainer: newElements) + } + + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same location. + /// The number of new elements need not match the number of elements being + /// removed. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length container as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @available(SwiftStdlib 6.2, *) + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & Collection + >( + _ subrange: Range, + copying newElements: borrowing C + ) { + _replaceSubrange(subrange, copyingContainer: newElements) + } +} +#endif + +#endif diff --git a/Sources/ArrayModule/RigidArray+Experimental.swift b/Sources/ArrayModule/RigidArray+Experimental.swift new file mode 100644 index 00000000..3ea4604a --- /dev/null +++ b/Sources/ArrayModule/RigidArray+Experimental.swift @@ -0,0 +1,455 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +import ContainersPreview +#endif +#endif + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +extension RigidArray /*where Element: Copyable*/ { +#if FIXME + @_alwaysEmitIntoClient + @inline(__always) + public init & Sequence>( + capacity: Int, + copying contents: C + ) { + self.init(capacity: capacity) + self.append(copying: contents) + } +#endif + +#if FIXME + @_alwaysEmitIntoClient + @inline(__always) + public init & ~Copyable & ~Escapable>( + capacity: Int? = nil, + copying contents: borrowing C + ) { + self.init(capacity: capacity ?? contents.count) + self.append(copying: contents) + } +#endif + +#if FIXME + @_alwaysEmitIntoClient + @inline(__always) + public init & Collection>( + capacity: Int? = nil, + copying contents: C + ) { + self.init(capacity: capacity ?? contents.count) + self.append(copying: contents) + } +#endif +} + +#if FIXME +extension RigidArray where Element: ~Copyable { + @inlinable + @_lifetime(borrow self) + public func borrowElement(at index: Int) -> Borrow { + precondition(index >= 0 && index < _count, "Index out of bounds") + return unsafe Borrow( + unsafeAddress: _storage.baseAddress.unsafelyUnwrapped.advanced(by: index), + borrowing: self + ) + } +} +#endif + +#if FIXME +extension RigidArray: RandomAccessContainer where Element: ~Copyable { +} +#endif + +#if FIXME +extension RigidArray where Element: ~Copyable { + @inlinable + @_lifetime(&self) + public mutating func mutateElement(at index: Int) -> Inout { + precondition(index >= 0 && index < _count) + return unsafe Inout( + unsafeAddress: _storage.baseAddress.unsafelyUnwrapped.advanced(by: index), + mutating: &self + ) + } +} +#endif + +#if FIXME +extension RigidArray: MutableContainer where Element: ~Copyable { +} +#endif + +extension RigidArray where Element: ~Copyable { + @available(SwiftStdlib 5.0, *) + @inlinable + public mutating func reallocate( + capacity: Int, + with body: ( + inout InputSpan, + inout OutputSpan + ) throws(E) -> R + ) throws(E) -> R { + var source = InputSpan(buffer: _storage, initializedCount: _count) + let newStorage: UnsafeMutableBufferPointer = .allocate( + capacity: capacity) + var target = OutputSpan(buffer: newStorage, initializedCount: 0) + defer { + _ = consume source + _storage.deallocate() + _count = target.finalize(for: newStorage) + _storage = newStorage + source = .init() + target = .init() + } + return try body(&source, &target) + } +} + +#if FIXME +extension RigidArray where Element: ~Copyable { + /// Removes all the elements that satisfy the given predicate. + /// + /// Use this method to remove every element in a container that meets + /// particular criteria. The order of the remaining elements is preserved. + /// + /// - Parameter shouldBeRemoved: A closure that takes an element of the + /// sequence as its argument and returns a Boolean value indicating + /// whether the element should be removed from the array. + /// + /// - Complexity: O(`count`) + @available(SwiftStdlib 6.2, *) + @_alwaysEmitIntoClient + public mutating func removeAll( + where shouldBeRemoved: (borrowing Element) throws(E) -> Bool + ) throws(E) { + // FIXME: Remove this in favor of a standard algorithm. + let suffixStart = try _halfStablePartition(isSuffixElement: shouldBeRemoved) + removeSubrange(suffixStart...) + } +} +#endif + +extension RigidArray where Element: ~Copyable { + @_lifetime(&self) + public mutating func popLast(_ count: Int) -> InputSpan { + let c = Swift.min(count, self.count) + self._count &-= c + let span = InputSpan( + buffer: self._storage._extracting(last: c), + initializedCount: c) + return _overrideLifetime(span, mutating: &self) + } +} + +extension RigidArray where Element: ~Copyable { + @available(SwiftStdlib 5.0, *) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout InputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.append(moving: source) + count = 0 + } + } + + @available(SwiftStdlib 5.0, *) + @_alwaysEmitIntoClient + public mutating func append( + moving items: inout OutputSpan + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.append(moving: source) + count = 0 + } + } +} + +extension RigidArray { +#if FIXME + @inlinable + internal mutating func _appendContainer< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C + ) { + let (copied, end) = unsafe _freeSpace._initializePrefix( + copying: newElements) + precondition(end == newElements.endIndex, "RigidArray capacity overflow") + _count += copied + } +#endif + +#if FIXME + /// Copies the elements of a container to the end of this array. + /// + /// If the array does not have sufficient capacity to hold all items in the + /// container, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: A container whose contents to copy into the array. + /// + /// - Complexity: O(`newElements.count`) + @_alwaysEmitIntoClient + @inline(__always) + public mutating func append & ~Copyable & ~Escapable>( + copying newElements: borrowing C + ) { + _appendContainer(copying: newElements) + } +#endif + +#if FIXME + /// Copies the elements of a container to the end of this array. + /// + /// If the array does not have sufficient capacity to hold all items in the + /// container, then this triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to copy into the array. + /// + /// - Complexity: O(*m*), where *m* is the length of `newElements`. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func append< + C: Container & Sequence + >(copying newElements: C) { + _appendContainer(copying: newElements) + } +#endif +} + +extension RigidArray where Element: ~Copyable { + @available(SwiftStdlib 5.0, *) + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout InputSpan, + at index: Int + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(last: count) + unsafe self.append(moving: source) + count = 0 + } + } + + @available(SwiftStdlib 5.0, *) + @_alwaysEmitIntoClient + public mutating func insert( + moving items: inout OutputSpan, + at index: Int + ) { + items.withUnsafeMutableBufferPointer { buffer, count in + let source = buffer._extracting(first: count) + unsafe self.append(moving: source) + count = 0 + } + } +} + +extension RigidArray { +#if FIXME + @inlinable + internal mutating func _insertContainer< + C: Container & ~Copyable & ~Escapable + >( + at index: Int, + copying items: borrowing C, + newCount: Int + ) { + precondition(index >= 0 && index <= _count, "Index out of bounds") + precondition(newCount <= freeCapacity, "RigidArray capacity overflow") + let target = unsafe _openGap(at: index, count: newCount) + let (copied, end) = unsafe target._initializePrefix(copying: items) + precondition( + copied == newCount && end == items.endIndex, + "Broken Container: count doesn't match contents") + _count += newCount + } +#endif + +#if FIXME + /// Copies the elements of a container into this array at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the array’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the array. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new item. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the array. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the array. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & ~Copyable & ~Escapable + >( + copying newElements: borrowing C, at index: Int + ) { + _insertContainer( + at: index, copying: newElements, newCount: newElements.count) + } +#endif + +#if FIXME + /// Copies the elements of a container into this array at the specified + /// position. + /// + /// The new elements are inserted before the element currently at the + /// specified index. If you pass the array’s `endIndex` as the `index` + /// parameter, then the new elements are appended to the end of the array. + /// + /// All existing elements at or following the specified position are moved to + /// make room for the new item. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// - Parameters + /// - newElements: The new elements to insert into the array. + /// - index: The position at which to insert the new elements. It must be + /// a valid index of the array. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @_alwaysEmitIntoClient + @inline(__always) + public mutating func insert< + C: Container & Collection + >( + copying newElements: borrowing C, at index: Int + ) { + _insertContainer( + at: index, copying: newElements, newCount: newElements.count) + } +#endif +} + +extension RigidArray { +#if FIXME + @inlinable + public mutating func _replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copyingContainer newElements: borrowing C, + newCount: Int + ) { + let gap = unsafe _gapForReplacement(of: subrange, withNewCount: newCount) + let (copied, end) = unsafe gap._initializePrefix(copying: newElements) + precondition( + copied == newCount && end == newElements.endIndex, + "Broken Container: count doesn't match contents") + } +#endif + +#if FIXME + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length container as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(`self.count` + `newElements.count`) + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & ~Copyable & ~Escapable + >( + _ subrange: Range, + copying newElements: borrowing C + ) { + _replaceSubrange( + subrange, copyingContainer: newElements, newCount: newElements.count) + } +#endif + +#if FIXME + /// Replaces the specified subrange of elements by copying the elements of + /// the given container. + /// + /// This method has the effect of removing the specified range of elements + /// from the array and inserting the new elements starting at the same + /// location. The number of new elements need not match the number of elements + /// being removed. + /// + /// If the capacity of the array isn't sufficient to accommodate the new + /// elements, then this method triggers a runtime error. + /// + /// If you pass a zero-length range as the `subrange` parameter, this method + /// inserts the elements of `newElements` at `subrange.lowerBound`. Calling + /// the `insert(copying:at:)` method instead is preferred in this case. + /// + /// Likewise, if you pass a zero-length container as the `newElements` + /// parameter, this method removes the elements in the given subrange + /// without replacement. Calling the `removeSubrange(_:)` method instead is + /// preferred in this case. + /// + /// - Parameters: + /// - subrange: The subrange of the array to replace. The bounds of + /// the range must be valid indices in the array. + /// - newElements: The new elements to copy into the collection. + /// + /// - Complexity: O(*n* + *m*), where *n* is count of this array and + /// *m* is the count of `newElements`. + @inlinable + @inline(__always) + public mutating func replaceSubrange< + C: Container & Collection + >( + _ subrange: Range, + copying newElements: C + ) { + _replaceSubrange( + subrange, copyingContainer: newElements, newCount: newElements.count) + } +#endif +} + +#endif diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index f570b0bb..d9fbaf1a 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -10,8 +10,10 @@ 7D48BCD12E51524200D7F6F7 /* InputSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCCB2E51524200D7F6F7 /* InputSpan.swift */; }; 7D48BCD22E51524200D7F6F7 /* DynamicArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC22E51524200D7F6F7 /* DynamicArray.swift */; }; 7D48BCD32E51524200D7F6F7 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC82E51524200D7F6F7 /* Box.swift */; }; + 7D48BCD42E51524200D7F6F7 /* DynamicArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC32E51524200D7F6F7 /* DynamicArray+Experimental.swift */; }; 7D48BCD52E51524200D7F6F7 /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC42E51524200D7F6F7 /* RigidArray.swift */; }; 7D48BCD62E51524200D7F6F7 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCCD2E51524200D7F6F7 /* Shared.swift */; }; + 7D48BCD72E51524200D7F6F7 /* RigidArray+Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC52E51524200D7F6F7 /* RigidArray+Experimental.swift */; }; 7D48BCD82E51524200D7F6F7 /* Borrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCC72E51524200D7F6F7 /* Borrow.swift */; }; 7D48BCD92E51524200D7F6F7 /* Inout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCCA2E51524200D7F6F7 /* Inout.swift */; }; 7D48BCDC2E51554900D7F6F7 /* ClassBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCDB2E51554900D7F6F7 /* ClassBox.swift */; }; @@ -446,7 +448,9 @@ /* Begin PBXFileReference section */ 7D48BCC12E51524200D7F6F7 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; 7D48BCC22E51524200D7F6F7 /* DynamicArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicArray.swift; sourceTree = ""; }; + 7D48BCC32E51524200D7F6F7 /* DynamicArray+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DynamicArray+Experimental.swift"; sourceTree = ""; }; 7D48BCC42E51524200D7F6F7 /* RigidArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidArray.swift; sourceTree = ""; }; + 7D48BCC52E51524200D7F6F7 /* RigidArray+Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Experimental.swift"; sourceTree = ""; }; 7D48BCC72E51524200D7F6F7 /* Borrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Borrow.swift; sourceTree = ""; }; 7D48BCC82E51524200D7F6F7 /* Box.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Box.swift; sourceTree = ""; }; 7D48BCC92E51524200D7F6F7 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; @@ -935,7 +939,9 @@ children = ( 7D48BCC12E51524200D7F6F7 /* CMakeLists.txt */, 7D48BCC22E51524200D7F6F7 /* DynamicArray.swift */, + 7D48BCC32E51524200D7F6F7 /* DynamicArray+Experimental.swift */, 7D48BCC42E51524200D7F6F7 /* RigidArray.swift */, + 7D48BCC52E51524200D7F6F7 /* RigidArray+Experimental.swift */, ); path = ArrayModule; sourceTree = ""; @@ -2051,8 +2057,10 @@ 7D48BCD12E51524200D7F6F7 /* InputSpan.swift in Sources */, 7D48BCD22E51524200D7F6F7 /* DynamicArray.swift in Sources */, 7D48BCD32E51524200D7F6F7 /* Box.swift in Sources */, + 7D48BCD42E51524200D7F6F7 /* DynamicArray+Experimental.swift in Sources */, 7D48BCD52E51524200D7F6F7 /* RigidArray.swift in Sources */, 7D48BCD62E51524200D7F6F7 /* Shared.swift in Sources */, + 7D48BCD72E51524200D7F6F7 /* RigidArray+Experimental.swift in Sources */, 7D48BCD82E51524200D7F6F7 /* Borrow.swift in Sources */, 7D48BCD92E51524200D7F6F7 /* Inout.swift in Sources */, 7DE9208629CA70F4004483EB /* BigString+LosslessStringConvertible.swift in Sources */,