mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
Include notes about index mutation in span(after/before:)
The indexes passed to span(after:) and friends on UniqueArray and RigidArray are modified before return. This adds notes about the updated values to the method documentation, along with a few other minor formatting changes (dropping smart quotes, single-sentence abstracts).
This commit is contained in:
1 parent
aa337b4caf
commit
54ca53612f
28 files changed
+143
-109
No files matched your search
@@ -20,12 +20,12 @@ import ContainersPreview
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray: BorrowingSequence where Element: ~Copyable {
|
||||
public typealias BorrowingIterator = Span<Element>.BorrowingIterator
|
||||
|
||||
|
||||
@inlinable
|
||||
public var estimatedCount: EstimatedCount {
|
||||
.exactly(count)
|
||||
}
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public func makeBorrowingIterator() -> BorrowingIterator {
|
||||
@@ -63,7 +63,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
/// 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.
|
||||
/// 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.
|
||||
@@ -73,7 +73,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
@inline(__always)
|
||||
public var startIndex: Int { 0 }
|
||||
|
||||
/// The array’s "past the end” position—that is, the position one greater than
|
||||
/// The array's "past the end" position—that is, the position one greater than
|
||||
/// the last valid subscript argument. This is always equal to the array's
|
||||
/// count.
|
||||
///
|
||||
@@ -88,7 +88,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public var indices: Range<Int> { unsafe Range(uncheckedBounds: (0, count)) }
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
package func _checkItemIndex(_ index: Int) {
|
||||
@@ -96,7 +96,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
UInt(bitPattern: index) < UInt(bitPattern: _count),
|
||||
"Index out of bounds")
|
||||
}
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
package func _checkValidIndex(_ index: Int) {
|
||||
@@ -104,7 +104,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
UInt(bitPattern: index) <= UInt(bitPattern: _count),
|
||||
"Index out of bounds")
|
||||
}
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
package func _checkValidBounds(_ subrange: Range<Int>) {
|
||||
@@ -185,7 +185,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public func index(after index: Int) -> Int { index + 1 }
|
||||
|
||||
|
||||
/// Returns the position immediately before the given index.
|
||||
///
|
||||
/// - Note: To improve performance, this method does not validate that the
|
||||
@@ -251,7 +251,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
public func index(_ index: Int, offsetBy n: Int) -> Int {
|
||||
index + n
|
||||
}
|
||||
|
||||
|
||||
/// Returns the distance between two indices.
|
||||
///
|
||||
/// - Note: To improve performance, this method does not validate that the
|
||||
@@ -269,7 +269,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
public func distance(from start: Index, to end: Index) -> Int {
|
||||
end - start
|
||||
}
|
||||
|
||||
|
||||
/// Offsets the given index by the specified distance, but no further than
|
||||
/// the given limiting index.
|
||||
///
|
||||
@@ -390,4 +390,3 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -318,7 +318,7 @@ extension RigidArray {
|
||||
/// 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`
|
||||
/// 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
|
||||
@@ -348,7 +348,7 @@ extension RigidArray {
|
||||
/// 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`
|
||||
/// 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
|
||||
@@ -376,7 +376,7 @@ extension RigidArray {
|
||||
/// Copies the elements of a span 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`
|
||||
/// 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
|
||||
@@ -454,7 +454,7 @@ extension RigidArray {
|
||||
/// position.
|
||||
///
|
||||
/// The new elements are inserted before the element currently at the
|
||||
/// specified index. If you pass the array’s `endIndex` as the `index`
|
||||
/// 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
|
||||
@@ -485,7 +485,7 @@ extension RigidArray {
|
||||
/// position.
|
||||
///
|
||||
/// The new elements are inserted before the element currently at the
|
||||
/// specified index. If you pass the array’s `endIndex` as the `index`
|
||||
/// 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
|
||||
@@ -514,7 +514,7 @@ extension RigidArray {
|
||||
/// position.
|
||||
///
|
||||
/// The new elements are inserted before the element currently at the
|
||||
/// specified index. If you pass the array’s `endIndex` as the `index`
|
||||
/// 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
|
||||
|
||||
@@ -91,7 +91,7 @@ public struct RigidArray<Element: ~Copyable>: ~Copyable {
|
||||
unsafe _storage.extracting(0 ..< _count).deinitialize()
|
||||
unsafe _storage.deallocate()
|
||||
}
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
package init(_storage: UnsafeMutableBufferPointer<Element>, count: Int) {
|
||||
self._storage = _storage
|
||||
@@ -125,6 +125,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
/// A Boolean value indicating whether this rigid array is fully populated.
|
||||
///
|
||||
/// If this property returns true, then the array's storage is at capacity,
|
||||
/// and it cannot accommodate any additional elements.
|
||||
///
|
||||
@@ -196,6 +197,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
extension RigidArray 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 at most once, allowing it to
|
||||
/// arbitrarily modify the contents of the output span it is given.
|
||||
/// The argument is free to add, remove or reorder any items; however,
|
||||
@@ -256,10 +258,14 @@ extension RigidArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
/// Return a borrowing span over the maximal storage chunk following the
|
||||
/// specified position in the array. The span provides direct read-only access
|
||||
/// to all array elements in the range `index ..< count`.
|
||||
/// specified position in the array.
|
||||
///
|
||||
/// The returned span provides direct read-only access to all array elements
|
||||
/// in the range `index ..< count`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `span(after:)` returns, `index` is equal to the array's
|
||||
/// `endIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
@@ -269,10 +275,14 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
/// Return a borrowing span over the maximal storage chunk preceding the
|
||||
/// specified position in the array. The span provides direct read-only access
|
||||
/// to all array elements in the range `0 ..< index`.
|
||||
/// specified position in the array.
|
||||
///
|
||||
/// The returned span provides direct read-only access to all array elements
|
||||
/// in the range `0 ..< index`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `span(before:)` returns, `index` is equal to the array's
|
||||
/// `startIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
@@ -285,10 +295,14 @@ extension RigidArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
/// Return a mutable span over the maximal storage chunk following the
|
||||
/// specified position in the array. The span provides direct mutating access
|
||||
/// to all array elements in the range `index ..< count`.
|
||||
/// specified position in the array.
|
||||
///
|
||||
/// The returned span provides direct mutating access to all array elements
|
||||
/// in the range `index ..< count`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `mutableSpan(after:)` returns, `index` is equal to the array's
|
||||
/// `endIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@_lifetime(&self)
|
||||
@@ -299,10 +313,14 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
/// Return a mutable span over the maximal storage chunk preceding the specified
|
||||
/// position in the array. The span provides direct mutating access to all
|
||||
/// array elements in the range `0 ..< index`.
|
||||
/// position in the array.
|
||||
///
|
||||
/// The returned span provides direct mutating access to all array elements
|
||||
/// in the range `0 ..< index`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `mutableSpan(before:)` returns, `index` is equal to the array's
|
||||
/// `startIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@_lifetime(&self)
|
||||
@@ -367,7 +385,7 @@ extension RigidArray {
|
||||
public func clone() -> Self {
|
||||
clone(capacity: self.count)
|
||||
}
|
||||
|
||||
|
||||
/// Copy the contents of this array into a newly allocated rigid array
|
||||
/// instance with the specified capacity.
|
||||
///
|
||||
@@ -421,7 +439,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
return unsafe _storage.extracting(
|
||||
Range(uncheckedBounds: (index, index + count)))
|
||||
}
|
||||
|
||||
|
||||
/// Resize the gap in the given subrange to have the specified count.
|
||||
/// This operation moves elements following the gap to be at their expected
|
||||
/// new location, and it adjusts the container's count to reflect the change.
|
||||
|
||||
@@ -20,7 +20,7 @@ import ContainersPreview
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: BorrowingSequence where Element: ~Copyable {
|
||||
public typealias BorrowingIterator = RigidArray<Element>.BorrowingIterator
|
||||
|
||||
|
||||
public var estimatedCount: EstimatedCount {
|
||||
.exactly(count)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
/// 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.
|
||||
/// 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.
|
||||
@@ -72,7 +72,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@inline(__always)
|
||||
public var startIndex: Int { _storage.startIndex }
|
||||
|
||||
/// The array’s "past the end” position—that is, the position one greater than
|
||||
/// 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)
|
||||
@@ -141,7 +141,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public func index(after index: Int) -> Int { index + 1 }
|
||||
|
||||
|
||||
/// Returns the position immediately before the given index.
|
||||
///
|
||||
/// - Note: To improve performance, this method does not validate that the
|
||||
@@ -207,7 +207,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
public func index(_ index: Int, offsetBy n: Int) -> Int {
|
||||
index + n
|
||||
}
|
||||
|
||||
|
||||
/// Returns the distance between two indices.
|
||||
///
|
||||
/// - Note: To improve performance, this method does not validate that the
|
||||
@@ -225,7 +225,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
public func distance(from start: Index, to end: Index) -> Int {
|
||||
end - start
|
||||
}
|
||||
|
||||
|
||||
/// Offsets the given index by the specified distance, but no further than
|
||||
/// the given limiting index.
|
||||
///
|
||||
|
||||
@@ -281,7 +281,7 @@ extension UniqueArray {
|
||||
/// 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`
|
||||
/// 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
|
||||
@@ -311,7 +311,7 @@ extension UniqueArray {
|
||||
/// 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`
|
||||
/// 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
|
||||
@@ -339,7 +339,7 @@ extension UniqueArray {
|
||||
/// Copies the elements of a span 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`
|
||||
/// 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
|
||||
@@ -369,7 +369,7 @@ extension UniqueArray {
|
||||
/// position.
|
||||
///
|
||||
/// The new elements are inserted before the element currently at the
|
||||
/// specified index. If you pass the array’s `endIndex` as the `index`
|
||||
/// 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
|
||||
@@ -404,7 +404,7 @@ extension UniqueArray {
|
||||
/// position.
|
||||
///
|
||||
/// The new elements are inserted before the element currently at the
|
||||
/// specified index. If you pass the array’s `endIndex` as the `index`
|
||||
/// 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
|
||||
@@ -436,7 +436,7 @@ extension UniqueArray {
|
||||
/// position.
|
||||
///
|
||||
/// The new elements are inserted before the element currently at the
|
||||
/// specified index. If you pass the array’s `endIndex` as the `index`
|
||||
/// 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
|
||||
|
||||
@@ -130,6 +130,7 @@ extension UniqueArray 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 at most once, allowing it to
|
||||
/// arbitrarily modify the contents of the output span it is given.
|
||||
/// The argument is free to add, remove or reorder any items; however,
|
||||
@@ -158,10 +159,14 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Return a borrowing span over the maximal storage chunk following the
|
||||
/// specified position in the array. The span provides direct read-only access
|
||||
/// to all array elements in the range `index ..< count`.
|
||||
/// specified position in the array.
|
||||
///
|
||||
/// The returned span provides direct read-only access to all array elements
|
||||
/// in the range `index ..< count`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `span(after:)` returns, `index` is equal to the array's
|
||||
/// `endIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
@@ -171,10 +176,14 @@ extension UniqueArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
/// Return a borrowing span over the maximal storage chunk preceding the
|
||||
/// specified position in the array. The span provides direct read-only access
|
||||
/// to all array elements in the range `0 ..< index`.
|
||||
/// specified position in the array.
|
||||
///
|
||||
/// The returned span provides direct read-only access to all array elements
|
||||
/// in the range `0 ..< index`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `span(before:)` returns, `index` is equal to the array's
|
||||
/// `startIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
@@ -187,10 +196,14 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
/// Return a mutable span over the maximal storage chunk following the
|
||||
/// specified position in the array. The span provides direct mutating access
|
||||
/// to all array elements in the range `index ..< count`.
|
||||
/// specified position in the array.
|
||||
///
|
||||
/// The returned span provides direct mutating access to all array elements
|
||||
/// in the range `index ..< count`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `mutableSpan(after:)` returns, `index` is equal to the array's
|
||||
/// `endIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@_lifetime(&self)
|
||||
@@ -201,10 +214,14 @@ extension UniqueArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
/// Return a mutable span over the maximal storage chunk preceding the specified
|
||||
/// position in the array. The span provides direct mutating access to all
|
||||
/// array elements in the range `0 ..< index`.
|
||||
/// position in the array.
|
||||
///
|
||||
/// The returned span provides direct mutating access to all array elements
|
||||
/// in the range `0 ..< index`.
|
||||
///
|
||||
/// - Parameter index: A valid index in the array, including the end index.
|
||||
/// When `mutableSpan(before:)` returns, `index` is equal to the array's
|
||||
/// `startIndex`.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@_lifetime(&self)
|
||||
@@ -291,7 +308,7 @@ extension UniqueArray {
|
||||
public func clone() -> Self {
|
||||
UniqueArray(consuming: _storage.clone())
|
||||
}
|
||||
|
||||
|
||||
/// Copy the contents of this array into a newly allocated unique array
|
||||
/// instance with the specified capacity.
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user