ArrayBuffer

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

A value-semantic collection of Storage.Element with unbounded growth.

  • Undocumented

    Declaration

    Swift

    public typealias Storage = ArrayStorage<Element>
  • A bounded contiguous buffer comprising all of self‘s storage.

    Note: storage has reference semantics. Clients that mutate the storage must take care to preserve ArrayBuffer’s value semantics by ensuring that storage is uniquely referenced.

    Declaration

    Swift

    public var storage: ArrayStorage<Element>
  • The number of stored elements.

    Declaration

    Swift

    public var count: Int { get }
  • The number of elements that can be stored in self without reallocation, provided its representation is not shared with other instances.

    Declaration

    Swift

    public var capacity: Int { get }
  • Creates an instance with capacity of at least minimumCapacity.

    Declaration

    Swift

    public init(minimumCapacity: Int = 0)
  • 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 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
    )
  • Creates an instance using the memory of s for its storage.

    Declaration

    Swift

    public init(_ s: Storage)
  • Creates an instance referring to the same elements as src.

    • Fails unless Element.self == src.elementType.

    Declaration

    Swift

    public init?<Dispatch>(_ src: AnyArrayBuffer<Dispatch>) where Dispatch : AnyObject
  • Creates an instance referring to the same elements as src.

    Requires

    Element.self == src.elementType.

    Declaration

    Swift

    public init<Dispatch>(unsafelyDowncasting src: AnyArrayBuffer<Dispatch>) where Dispatch : AnyObject
  • Appends x, returning the index of the appended element.

    Complexity

    Amortized O(1).

    Declaration

    Swift

    public mutating func append(_ x: Element) -> Int
  • Returns the result of calling body on the elements of self.

    Declaration

    Swift

    public func withUnsafeBufferPointer<R>(
      body: (UnsafeBufferPointer<Element>)->R
    ) -> R
  • Returns the result of calling body on the elements of self.

    Declaration

    Swift

    public mutating func withUnsafeMutableBufferPointer<R>(
      _ body: (inout UnsafeMutableBufferPointer<Element>)->R
    ) -> R
  • Ensure that self holds uniquely-referenced storage, copying its memory if necessary.

    Declaration

    Swift

    public mutating func ensureUniqueStorage()
  • A position in the buffer.

    Declaration

    Swift

    public typealias Index = Int
  • The position of the first element.

    Declaration

    Swift

    public var startIndex: Int { get }
  • The position just past the last element.

    Declaration

    Swift

    public var endIndex: Int { 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: Index) -> Element { get set }