A Swift library providing fast sorted collections (Map, List, SortedSet, SortedBag) using in-memory B-trees with copy-on-write semantics.
BTree is a Swift library that implements in-memory B-trees, providing fast sorted collection types like Map, List, SortedSet, and SortedBag. It solves performance issues with Swift's standard collections by offering efficient sorted storage, granular copy-on-write semantics, and guaranteed O(log n) worst-case time for operations like insertion, removal, and lookup.
Swift developers who need high-performance sorted collections for applications dealing with large datasets, such as databases, real-time analytics, or systems requiring stable and predictable performance with ordered data.
Developers choose BTree over Swift's standard collections because it provides ordered data structures with strong performance guarantees, efficient memory management, and granular copy-on-write that avoids unnecessary copying. Its B-tree design ensures locality of reference and handles large element counts without quadratic slowdowns.
Fast sorted collections for Swift using in-memory B-trees
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides O(log n) time for insertion, removal, and lookup in sorted collections, solving Array's O(n) cost for mid-operations as highlighted in the README's comparison with standard types.
Only copies affected nodes (O(log n)) during mutations, improving performance over standard collections' all-or-nothing approach, which the README notes avoids unnecessary full copies.
Ensures no allocation spikes and predictable worst-case performance, unlike hash-based collections that can suffer from collisions, as discussed in the 'Laundry List of Issues' section.
Supports union, intersection, and other operations with O(log n) time for non-interleaved sets, leveraging the B-tree structure for optimal merging, as described in the implementation notes.
The README admits that imported generics in Swift suffer a 10-200x slowdown for basic types due to compiler limitations, requiring code embedding for critical performance paths.
Focused solely on in-memory use, it lacks built-in persistence features, making it unsuitable for applications needing disk-based storage without additional layers.
Restricted to Apple platforms (macOS, iOS, watchOS, tvOS), which hinders adoption in cross-platform Swift projects targeting Linux or Windows.