A Swift collection that maintains unique elements in insertion order with fast lookup performance.
OrderedSet is a Swift collection that maintains unique elements in a specific order, combining the characteristics of arrays and sets. It provides fast lookup performance while preserving insertion order and supports strong typing through generics. The project was created to offer a native Swift alternative to Foundation's NSOrderedSet with support for Swift structs and enums.
Swift developers building iOS, macOS, or other Apple platform applications who need ordered collections with unique elements and fast membership checking.
Developers choose OrderedSet because it provides a type-safe, performant implementation of ordered unique collections that integrates seamlessly with Swift's ecosystem. It offers better performance than using Swift's global contains() method with arrays while maintaining the familiar array interface.
A Swift collection of unique, ordered objects
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The contains() method is optimized for efficient O(1) average lookups by leveraging an internal set, avoiding linear searches like in arrays, as noted in the README's performance advice.
Supports array literals, subscripting, and concatenation, making it intuitive for Swift developers accustomed to arrays, with examples in the README showing direct usage.
Uses Swift generics for compile-time type checking, allowing storage of structs and enums natively, as highlighted in the project's philosophy for bridging gaps with Foundation.
Maintains insertion order like an array while ensuring element uniqueness, combining set and array characteristics for predictable iteration.
As a single-file implementation, it lacks advanced collection functionalities such as concurrent access support, custom equality comparators, or built-in Codable conformance, which might require extra work.
The README directs users to unit tests for comprehensive examples, which can be less accessible than detailed API documentation or tutorials for beginners.
Maintaining both an array for order and a set for uniqueness can lead to increased memory usage and complexity for operations like insertions and deletions compared to simpler collections.