ArrayStorage

public struct ArrayStorage<Element>
extension ArrayStorage : RandomAccessCollection, MutableCollection

Bounded-sized, reference-semantic, contiguous storage of Elements.

  • Returns true iff the memory of self 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 returns self.

    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 a capacity of at least minimumCapacity.

    Declaration

    Swift

    public init<Contents: Collection>(_ contents: Contents, minimumCapacity: Int = 0)
      where Contents.Element == Element
  • Creates an empty instance with capacity at least minimumCapacity.

    Declaration

    Swift

    public init(minimumCapacity: Int = 0)
  • Creates an instance with the given count, and capacity at least minimumCapacity, and elements initialized by initializeElements, which is passed the address of the (uninitialized) first element.

    Requires

    initializeElements initializes exactly count 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 of self.

    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 appending x, moving elements from the existing storage iff moveElements is true.

    Postcondition

    if count == capacity on invocation, the result’s capacity is self.capacity scaled up by a constant factor. Otherwise, it is the same as self.capacity.

    Postcondition

    if moveElements is true, 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, or nil if there was insufficient capacity remaining

    Complexity

    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; if i is out-of-range, the behavior is undefined.

    Declaration

    Swift

    public subscript(i: Int) -> Element { get set }