Swiftpack.co - Package - Zehua-Chen/swift-queue

Swift Queue

The package provides an array-backed queue implementation

Interface

var queue = Queue<Int>()
queue.enqueue(1)
queue.enqueue(2)

let peek = queue.peek(offset: 1) // should be 2

let head = queue.dequeue()

Protocol Conformance

  • protocol Collection;
  • protocol Equatable if element coforms to protocol Equatable;
  • protocol CustomStringConvertible if the element type conforms to protocol CustomStringConvertible;

Implementation

The storage of the queue is implemented as a subclass of class ManagedMemory<Header, Element> from Swift Standard Library:

@usableFromInline
internal class _QueueBuffer<Element>: ManagedBuffer<_QueueHeader, Element> {
    ....
}

Two indexes enqueueIndex and dequeueIndex are used to keep track of where dequeue and enqueue operation should occur at (implemented in internal struct _QueueHeader)

@usableFromInline
internal struct _QueueHeader: CustomStringConvertible {
    ....
}

Planned Features

  • protocol Encodable conformance
  • Enqueue and initialize queue from a sequence

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

1.0.0 - Aug 6, 2019

  • public class Queue<Element> becomes public struct Queue<Element>;
  • Queue becomes array-backed;