DoubleEndedBuffer

public struct DoubleEndedBuffer<T>
extension DoubleEndedBuffer: Collection

A fixed-size, contiguous collection allowing additions and removals at either end (space permitting).

Beware: unbalanced pushes/pops to either the front or the back will result in the effective working size to be diminished. If you would like this to be managed for you automatically, please use a Deque.

See also

Deque
  • Allocate with a given capacity and insertion initialPolicy.

    Declaration

    Swift

    public init(capacity: Int, with initialPolicy: DoubleEndedAllocationPolicy)

    Parameters

    capacity

    The capacity of the buffer.

    initialPolicy

    The policy for where initial values should be inserted into the buffer. Note: asymmetric pushes/pops to front/back will cause the portion of the consumed buffer to drift. If you need management to occur automatically, please use a Deque.

  • True if no elements are contained within the data structure, false otherwise.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Returns the number of elements contained within self.

    Declaration

    Swift

    public var count: Int { get }
  • Returns the capacity of self.

    Declaration

    Swift

    public var capacity: Int { get }
  • True iff there is available space at the beginning of the buffer.

    Declaration

    Swift

    public var canPushFront: Bool { get }
  • True iff there is available space at the end of the buffer.

    Declaration

    Swift

    public var canPushBack: Bool { get }
  • Add elem to the back of the buffer.

    Precondition

    canPushBack.

    Declaration

    Swift

    public mutating func pushBack(_ elem: T)
  • Removes and returns the element at the back, reducing self‘s count by one.

    Precondition

    !isEmpty

    Declaration

    Swift

    public mutating func popBack() -> T
  • Adds elem to the front of the buffer.

    Precondition

    canPushFront.

    Declaration

    Swift

    public mutating func pushFront(_ elem: T)
  • Removes and returns the element at the front, reducing self‘s count by one.

    Declaration

    Swift

    public mutating func popFront() -> T
  • Explicitly reallocate the backing buffer.

    Declaration

    Swift

    public mutating func reallocate(
      newCapacity: Int,
      with initialPolicy: DoubleEndedAllocationPolicy
    )

Deques