ArrayStorage
public struct ArrayStorage<Element>
extension ArrayStorage : RandomAccessCollection, MutableCollection
Bounded-sized, reference-semantic, contiguous storage of Element
s.
-
Returns
true
iff the memory ofself
is 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 acapacity
of at leastminimumCapacity
.Declaration
Swift
public init<Contents: Collection>(_ contents: Contents, minimumCapacity: Int = 0) where Contents.Element == Element
-
Creates an empty instance with
capacity
at 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
initializeElements
initializes exactlycount
contiguous 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
body
on 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
initialize
with 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
self
after appendingx
, moving elements from the existing storage iffmoveElements
is true.Postcondition
ifcount == capacity
on invocation, the result’scapacity
isself.capacity
scaled up by a constant factor. Otherwise, it is the same asself.capacity
.Postcondition
if
moveElements
istrue
,self.count == 0
Complexity
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, ornil
if 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; ifi
is out-of-range, the behavior is undefined.Declaration
Swift
public subscript(i: Int) -> Element { get set }