[BasicContainers] RigidArray, UniqueArray: Add formIndex(before:)

This commit is contained in:
Karoy Lorentey committed 2026-02-03 15:10:11 -08:00
1 parent 030f751515
commit 99da8a72e0
5 files changed
+262 -225

No files matched your search

@@ -153,108 +153,6 @@ extension UniqueArray where Element: ~Copyable {
//MARK: - Container primitives
@available(SwiftStdlib 5.0, *)
extension UniqueArray where Element: ~Copyable {
/// A Boolean value indicating whether this array contains no elements.
///
/// - Complexity: O(1)
@inlinable
@inline(__always)
public var isEmpty: Bool { _storage.isEmpty }
/// The number of elements in this array.
///
/// - Complexity: O(1)
@inlinable
@inline(__always)
public var count: Int { _storage.count }
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension UniqueArray: BorrowingSequence where Element: ~Copyable {
public typealias BorrowingIterator = RigidArray<Element>.BorrowingIterator
public var estimatedCount: ContainersPreview.EstimatedCount {
.exactly(count)
}
@_alwaysEmitIntoClient
@inline(__always)
public func makeBorrowingIterator() -> BorrowingIterator {
self._storage.makeBorrowingIterator()
}
}
#endif
@available(SwiftStdlib 5.0, *)
extension UniqueArray where Element: ~Copyable {
/// A type that represents a position in the array: an integer offset from the
/// start.
///
/// Valid indices consist of the position of every element and a "past the
/// end” position that’s not valid for use as a subscript argument.
public typealias Index = Int
/// The position of the first element in a nonempty array. This is always zero.
///
/// - Complexity: O(1)
@inlinable
@inline(__always)
public var startIndex: Int { _storage.startIndex }
/// The array’s "past the end” position—that is, the position one greater than
/// the last valid subscript argument. This is always equal to array's count.
///
/// - Complexity: O(1)
@inlinable
@inline(__always)
public var endIndex: Int { _storage.count }
/// The range of indices that are valid for subscripting the array.
///
/// - Complexity: O(1)
@inlinable
@inline(__always)
public var indices: Range<Int> { _storage.indices }
/// Accesses the element at the specified position.
///
/// - Parameter position: The position of the element to access.
/// The position must be a valid index of the array that is not equal
/// to the `endIndex` property.
///
/// - Complexity: O(1)
@inlinable
public subscript(position: Int) -> Element {
@inline(__always)
unsafeAddress {
_storage._ptr(to: position)
}
@inline(__always)
unsafeMutableAddress {
_storage._mutablePtr(to: position)
}
}
}
@available(SwiftStdlib 5.0, *)
extension UniqueArray where Element: ~Copyable {
/// Exchanges the values at the specified indices of the array.
///
/// Both parameters must be valid indices of the array and not equal to
/// endIndex. Passing the same index as both `i` and `j` has no effect.
///
/// - Parameter i: The index of the first value to swap.
/// - Parameter j: The index of the second valud to swap.
///
/// - Complexity: O(1)
@inlinable
public mutating func swapAt(_ i: Int, _ j: Int) {
_storage.swapAt(i, j)
}
}
@available(SwiftStdlib 5.0, *)
extension UniqueArray where Element: ~Copyable {
/// Return a borrowing span over the maximal storage chunk following the