ArrayStorage
public struct ArrayStorage<Element>
extension ArrayStorage : RandomAccessCollection, MutableCollection
Bounded-sized, reference-semantic, contiguous storage of Elements.
-
Returns
trueiff the memory ofselfis uniquely-referenced.Declaration
Swift
public mutating func memoryIsUniquelyReferenced() -> Bool -
Returns a distinct, uniquely-referenced, copy of
self—unless its capacity is 0, in which case it returnsself.Declaration
Swift
public func makeCopy() -> ArrayStorage<Element> -
The number of elements stored in
self.Invariant
count <= capacity.Declaration
Swift
public fileprivate(set) var count: Int { get set } -
The maximum number of elements that can be stored in
self.Declaration
Swift
public var capacity: Int { get } -
Creates an instance with the same elements as
contents, having acapacityof at leastminimumCapacity.Declaration
Swift
public init<Contents: Collection>(_ contents: Contents, minimumCapacity: Int = 0) where Contents.Element == Element -
Creates an empty instance with
capacityat leastminimumCapacity.Declaration
Swift
public init(minimumCapacity: Int = 0) -
Creates an instance with the given
count, and capacity at leastminimumCapacity, and elements initialized byinitializeElements, which is passed the address of the (uninitialized) first element.Requires
initializeElementsinitializes exactlycountcontiguous elements starting with the address it is passed.Declaration
Swift
public init( count: Int, minimumCapacity: Int = 0, initializeElements: (_ uninitializedElements: UnsafeMutablePointer<Element>) -> Void ) -
Returns the result of calling
bodyon the elements ofself.Declaration
Swift
public func withUnsafeMutableBufferPointer<R>( _ body: (inout UnsafeMutableBufferPointer<Element>)->R ) -> R -
Returns new storage having at least the given capacity, calling
initializewith pointers to the base addresses of self and the new storage.Requires
self.isUsable(forElementType: TypeID(Element.self))Declaration
Swift
public func replacementStorage( count newCount: Int, minimumCapacity: Int, initialize: ( _ firstExistingElement: UnsafeMutablePointer<Element>, _ firstUninitializedElement: UnsafeMutablePointer<Element>) -> Void ) -> Self -
Returns a copy of
selfafter appendingx, moving elements from the existing storage iffmoveElementsis true.Postcondition
ifcount == capacityon invocation, the result’scapacityisself.capacityscaled up by a constant factor. Otherwise, it is the same asself.capacity.Postcondition
if
moveElementsistrue,self.count == 0Complexity
O(N).
Declaration
Swift
@inline(never) public mutating func appending(_ x: Element, moveElements: Bool) -> ArrayStorage<Element> -
Appends
x, returning the index of the appended element, ornilif there was insufficient capacity remainingComplexity
O(1)Declaration
Swift
public func append(_ x: Element) -> Int? -
The position of the first element.
Declaration
Swift
public var startIndex: Index { get } -
The position just past the last element.
Declaration
Swift
public var endIndex: Index { get } -
Accesses the element at
i.Requires
i >= 0 && i < count.Note
this is not a memory-safe API; ifiis out-of-range, the behavior is undefined.Declaration
Swift
public subscript(i: Int) -> Element { get set }
View on GitHub
ArrayStorage Structure Reference