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:
storagehas reference semantics. Clients that mutate thestoragemust take care to preserveArrayBuffer’s value semantics by ensuring thatstorageis 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
selfwithout 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 acapacityof at leastminimumCapacity.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 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 ) -
Creates an instance using the memory of
sfor 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 - Fails unless
-
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
bodyon the elements ofself.Declaration
Swift
public func withUnsafeBufferPointer<R>( body: (UnsafeBufferPointer<Element>)->R ) -> R -
Returns the result of calling
bodyon the elements ofself.Declaration
Swift
public mutating func withUnsafeMutableBufferPointer<R>( _ body: (inout UnsafeMutableBufferPointer<Element>)->R ) -> R -
Ensure that
selfholds 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; ifiis out-of-range, the behavior is undefined.Declaration
Swift
public subscript(i: Index) -> Element { get set }
View on GitHub
ArrayBuffer Structure Reference