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

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Zehua-Chen.
Zehua-Chen/swift-queue 1.0.0
Array-backed queue implementation for swift
⭐️ 0
🕓 3 weeks ago
.package(url: "https://github.com/Zehua-Chen/swift-queue.git", from: "1.0.0")

Swift Queue

The package provides an array-backed queue implementation


var queue = Queue<Int>()

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;


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

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)

internal struct _QueueHeader: CustomStringConvertible {

Planned Features

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


Stars: 0
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Struct and Array!
3 years ago
  • public class Queue<Element> becomes public struct Queue<Element>;
  • Queue becomes array-backed;

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics