Deque

public struct Deque<Element>
extension Deque: Queue
extension Deque: HierarchicalCollection

A dynamically-sized double-ended queue that allows pushing and popping at both the front and the back.

  • The number of elements contained within self.

    Declaration

    Swift

    public private(set) var count: Int
  • Creates an empty Deque.

    Declaration

    Swift

    public init(initialCapacity: Int? = nil)

    Parameters

    bufferSize

    The capacity (in terms of elements) of the initial Deque. If unspecified, Deque uses a heuristic to pick a value, tuned for performance.

  • True iff no values are contained in `self.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Add elem to the back of self.

    Declaration

    Swift

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

    Precondition

    !isEmpty

    Declaration

    Swift

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

    Declaration

    Swift

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

    Precondition

    !isEmpty

    Declaration

    Swift

    public mutating func popFront() -> Element

Deques

  • Declaration

    Swift

    public mutating func pop() -> Element?
  • Declaration

    Swift

    public mutating func push(_ element: Element)
  • Declaration

    Swift

    public struct Cursor : Equatable, Comparable
  • Call fn for each element in the collection until fn returns false.

    Declaration

    Swift

    @discardableResult
    public func forEachWhile(
      startingAt start: Cursor?,
      _ fn: (Element) throws -> Bool
    ) rethrows -> Cursor?

    Parameters

    start

    Start iterating at elements corresponding to this index. If nil, starts at the beginning of the collection.

    Return Value

    a cursor into the data structure corresponding to the first element that returns false.