Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. iOS
  3. SwiftPriorityQueue

SwiftPriorityQueue

MITSwift

A pure Swift implementation of a generic priority queue data structure using a binary heap.

GitHubGitHub
375 stars40 forks0 contributors

What is SwiftPriorityQueue?

SwiftPriorityQueue is a pure Swift implementation of a generic priority queue data structure. It provides an efficient way to manage collections where elements are processed based on priority, using a binary heap for O(log n) performance on insertions and removals. It solves the need for a platform-agnostic, dependency-free priority queue in Swift projects.

Target Audience

Swift developers across macOS, iOS, Linux, and other platforms who need an efficient, generic priority queue for algorithms like A* pathfinding, task scheduling, or any scenario requiring prioritized processing.

Value Proposition

Developers choose SwiftPriorityQueue for its simplicity, pure Swift implementation without Cocoa dependencies, excellent performance with binary heap operations, and full support for Swift's standard protocols like Sequence and Collection for easy integration.

Overview

A Generic Priority Queue in Pure Swift

Use Cases

Best For

  • Implementing A* pathfinding algorithms in Swift games or applications
  • Task scheduling systems where tasks have different priority levels
  • Managing event queues in simulation or discrete-event simulation projects
  • Algorithm implementations requiring efficient priority queue operations (Dijkstra's, Prim's)
  • Processing data streams where items need to be handled in priority order
  • Educational purposes for learning about priority queues and binary heaps in Swift

Not Ideal For

  • Applications requiring thread-safe concurrent access from multiple threads
  • Projects needing efficient O(1) or O(log n) removal of arbitrary elements by value
  • Systems where priority is determined by separate numeric keys rather than element comparison
  • High-performance scenarios where O(n) size-limited pushes are prohibitive

Pros & Cons

Pros

Cross-Platform Compatibility

Implemented purely in Swift without Cocoa dependencies, it works seamlessly on macOS, iOS, Linux, and all Swift-supported platforms, as highlighted in the README's platform badges.

Efficient Core Operations

Uses a classic binary heap to ensure O(log n) time complexity for push and pop operations, making it reliable for performance-critical algorithms like A* pathfinding.

Swift Standard Library Integration

Conforms to Sequence, IteratorProtocol, and Collection protocols, allowing easy iteration with for-in loops and integration with Swift's built-in functions.

Clean and Intuitive API

Provides familiar methods like push(), pop(), and peek(), with flexible initialization options for ascending/descending order and starting arrays, as documented in the README.

Cons

Lack of Thread Safety

The README explicitly states it is not thread-safe, requiring external synchronization if used in concurrent environments, which limits its use in multi-threaded applications.

Inefficient Size Management

The push with maxCount method is O(n) due to binary heap limitations, making it unsuitable for real-time applications needing efficient size-limited queues.

Limited to Comparable Types

Only supports elements that implement Comparable, preventing the use of separate priority values without wrapping types, which can be restrictive for complex prioritization logic.

Frequently Asked Questions

Quick Stats

Stars375
Forks40
Contributors0
Open Issues0
Last commit3 years ago
CreatedSince 2015

Tags

#collection#data-structures#priority-queue#data-structure#priority-queues#cross-platform#swift#algorithms#generic-programming

Built With

S
Swift

Included in

iOS51.7k
Auto-fetched 2 hours ago

Related Projects

DollarDollar

A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript

Stars4,242
Forks362
Last commit2 years ago
DifferenceKitDifferenceKit

💻 A fast and flexible O(n) difference algorithm framework for Swift collection.

Stars3,658
Forks242
Last commit2 years ago
ResultResult

Swift type modelling the success/failure of arbitrary operations.

Stars2,497
Forks228
Last commit5 years ago
EKAlgorithms contains some well known CS algorithms & data structuresEKAlgorithms contains some well known CS algorithms & data structures

EKAlgorithms contains some well known CS algorithms & data structures.

Stars2,410
Forks352
Last commit1 year ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub