diff --git a/README.md b/README.md index 9dc71ddf..10de447b 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,6 @@ Read more about the package, and the intent behind it, in the [announcement on s The package currently provides the following implementations: -- [`UniqueArray`][UniqueArray], a dynamically self-resizing, heap allocated, noncopyable array of potentially noncopyable elements. - -- [`RigidArray`][RigidArray], a fixed capacity, heap allocated, noncopyable array of potentially noncopyable elements. - - [`BitSet`][BitSet] and [`BitArray`][BitArray], dynamic bit collections. - [`Deque`][Deque], a double-ended queue backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections. @@ -26,8 +22,10 @@ The package currently provides the following implementations: - [`TreeSet`][TreeSet] and [`TreeDictionary`][TreeDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements. -[RigidArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/basiccontainers/rigidarray -[UniqueArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/basiccontainers/uniquearray +- [`UniqueArray`][UniqueArray] and [`RigidArray`][RigidArray], noncopyable array variants trading some of `Array`'s flexibility for more predictable performance. + +- [`TrailingArray`][TrailingArray], a low-level, ownership-aware variant of `ManagedBuffer`, for interoperability with C constructs that consist of a fixed-size header directly followed by variable-size storage buffer. + [BitSet]: https://swiftpackageindex.com/apple/swift-collections/documentation/bitcollections/bitset [BitArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/bitcollections/bitarray [Deque]: https://swiftpackageindex.com/apple/swift-collections/documentation/dequemodule/deque @@ -36,8 +34,11 @@ The package currently provides the following implementations: [OrderedDictionary]: https://swiftpackageindex.com/apple/swift-collections/documentation/orderedcollections/ordereddictionary [TreeSet]: https://swiftpackageindex.com/apple/swift-collections/documentation/hashtreecollections/treeset [TreeDictionary]: https://swiftpackageindex.com/apple/swift-collections/documentation/hashtreecollections/treedictionary +[RigidArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/basiccontainers/rigidarray +[UniqueArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/basiccontainers/uniquearray +[TrailingArray]: https://swiftpackageindex.com/apple/swift-collections/documentation/trailingelementsmodule/trailingarray -Swift Collections uses the same modularization approach as [**Swift Numerics**](https://github.com/apple/swift-numerics): it provides a standalone module for each thematic group of data structures it implements. For instance, if you only need a double-ended queue type, you can pull in only that by importing `DequeModule`. `OrderedSet` and `OrderedDictionary` share much of the same underlying implementation, so they are provided by a single module, called `OrderedCollections`. However, there is also a top-level `Collections` module that gives you every collection type with a single import statement: +Swift Collections uses the same modularization approach as [**Swift Numerics**](https://github.com/apple/swift-numerics): it provides a standalone module for each thematic group of data structures it implements. For instance, if you only need a double-ended queue type, you can pull in only that by importing `DequeModule`. `OrderedSet` and `OrderedDictionary` share much of the same underlying implementation, so they are provided by a single module, called `OrderedCollections`. However, there is also a top-level `Collections` module that gives you the most commonly used collection types with a single import statement: ``` swift import Collections @@ -95,7 +96,7 @@ The following table maps package releases to their minimum required Swift toolch To use this package in a SwiftPM project, you need to set it up as a package dependency: ```swift -// swift-tools-version:6.1 +// swift-tools-version:6.2 import PackageDescription let package = Package( @@ -132,14 +133,14 @@ We maintain separate branches for each minor version of the package: | Package version | Branch | Status | | ----------------------- | ----------- | -------- | | swift-collections 1.0.x | release/1.0 | Obsolete | -| swift-collections 1.1.x | release/1.1 | Critical bugfixes only | -| swift-collections 1.2.x | release/1.2 | Critical bugfixes only | +| swift-collections 1.1.x | release/1.1 | Obsolete | +| swift-collections 1.2.x | release/1.2 | Bugfixes only | | swift-collections 1.3.x | release/1.3 | Bugfixes only | | n.a. | main | Feature work towards next minor release | Changes must land on the branch corresponding to the earliest release that they will need to ship on. They are periodically propagated to subsequent branches, in the following direction: -`release/1.0` → `release/1.1` → `release/1.2` → `release/1.3` → `main` +`release/1.1` → `release/1.2` → `release/1.3` → `main` For example, anything landing on `release/1.2` will eventually appear on `release/1.3` and then `main` too; there is no need to file standalone PRs for each release line. Change propagation is not instantaneous, as it currently requires manual work -- it is performed by project maintainers. diff --git a/Sources/BasicContainers/BasicContainers.docc/BasicContainers.md b/Sources/BasicContainers/BasicContainers.docc/BasicContainers.md index bc50e4b6..d10b3606 100644 --- a/Sources/BasicContainers/BasicContainers.docc/BasicContainers.md +++ b/Sources/BasicContainers/BasicContainers.docc/BasicContainers.md @@ -8,7 +8,7 @@ This currently consists of two noncopyable variants of the standard `Array` type Unlike `Array`, these new types do not support copy-on-write value semantics -- indeed, they aren't (implicitly) copyable at all, even if their element type happens to be copyable. -### `struct UniqueArray` +### struct UniqueArray ``UniqueArray`` is a dynamically self-resizing array type that automatically grows its storage as needed to accommodate inserted items. Its name highlights that unlike `Array`, instances of this type are always uniquely owned, never shared. Mutations of a `UniqueArray` therefore never need to copy their storage. @@ -41,7 +41,7 @@ Note how preserving a copy of the array at the start of the loop forces the subs Taking away the freedom to make implicit copies forces you to think a lot more about ownership concerns when using this type -- it can feel a lot more constrained and nitpicky. In exchange though, it gets much easier to reason about the runtime performance of your code; the subscript mutation looks the same as before, but now it is guaranteed to _always_ have constant complexity. -### `struct RigidArray` +### struct RigidArray ``RigidArray`` goes a step even further than ``UniqueArray`` by also disabling automatic storage reallocations: it is a fixed-capacity array type. Rigid array instances get created with a specific capacity, and they never resize themselves. If they run out of room, they report a runtime error! @@ -62,7 +62,7 @@ This allows ``RigidArray`` to still provide _explicit_ resizing operations: it h ## Topics -### Structures +### Types - ``UniqueArray`` - ``RigidArray`` diff --git a/Sources/BasicContainers/BasicContainers.docc/Extensions/RigidArray.md b/Sources/BasicContainers/BasicContainers.docc/Extensions/RigidArray.md index cfb311f6..306b9912 100644 --- a/Sources/BasicContainers/BasicContainers.docc/Extensions/RigidArray.md +++ b/Sources/BasicContainers/BasicContainers.docc/Extensions/RigidArray.md @@ -79,7 +79,7 @@ - ``replaceSubrange(_:newCount:initializingWith:)`` - ``replaceSubrange(_:moving:)-(_,OutputSpan)`` -- ``replaceSubrange(_:moving:)-(_,RigidArray))`` +- ``replaceSubrange(_:moving:)-(_,RigidArray)`` - ``replaceSubrange(_:moving:)-(_,UnsafeMutableBufferPointer)`` - ``replaceSubrange(_:consuming:)`` - ``replaceSubrange(_:copying:)-(_,Collection)`` diff --git a/Sources/BasicContainers/BasicContainers.docc/Extensions/UniqueArray.md b/Sources/BasicContainers/BasicContainers.docc/Extensions/UniqueArray.md index 612486c8..5328248b 100644 --- a/Sources/BasicContainers/BasicContainers.docc/Extensions/UniqueArray.md +++ b/Sources/BasicContainers/BasicContainers.docc/Extensions/UniqueArray.md @@ -2,7 +2,7 @@ ## Topics -### Creating a rigid array +### Creating a Unique Array - ``init()`` - ``init(capacity:)`` @@ -12,7 +12,7 @@ - ``init(capacity:copying:)-(_,Sequence)`` - ``init(capacity:copying:)-(_,Collection)`` -### Inspecting a rigid array +### Inspecting a Unique Array - ``isEmpty`` - ``isFull`` @@ -27,13 +27,13 @@ - ``endIndex`` - ``indices`` -### Accessing elements +### Accessing Elements - ``subscript(position:)`` - ``swapAt(_:_:)`` - ``edit(_:)`` -### Memory management +### Memory Management - ``reallocate(capacity:)`` - ``reserveCapacity(_:)`` @@ -49,7 +49,7 @@ - ``mutableSpan(after:)`` - ``mutableSpan(before:)`` -### Appending items +### Appending Items - ``append(_:)`` - ``pushLast(_:)`` @@ -62,7 +62,7 @@ - ``append(copying:)-(UnsafeBufferPointer)`` - ``append(copying:)-(UnsafeMutableBufferPointer)`` -### Inserting items +### Inserting Items - ``insert(_:at:)`` - ``insert(count:at:initializingWith:)`` @@ -75,11 +75,11 @@ - ``insert(copying:at:)-(UnsafeBufferPointer,_)`` - ``insert(copying:at:)-(UnsafeMutableBufferPointer,_)`` -### Replacing items +### Replacing Items - ``replaceSubrange(_:newCount:initializingWith:)`` - ``replaceSubrange(_:moving:)-(_,OutputSpan)`` -- ``replaceSubrange(_:moving:)-(_,RigidArray))`` +- ``replaceSubrange(_:moving:)-(_,RigidArray)`` - ``replaceSubrange(_:moving:)-(_,UnsafeMutableBufferPointer)`` - ``replaceSubrange(_:consuming:)`` - ``replaceSubrange(_:copying:)-(_,Collection)`` @@ -87,7 +87,7 @@ - ``replaceSubrange(_:copying:)-(_,UnsafeBufferPointer)`` - ``replaceSubrange(_:copying:)-(_,UnsafeMutableBufferPointer)`` -### Removing items +### Removing Items - ``removeAll()`` - ``removeLast()`` diff --git a/Sources/Collections/Collections.docc/Collections.md b/Sources/Collections/Collections.docc/Collections.md index ef2231c0..bb9109b0 100644 --- a/Sources/Collections/Collections.docc/Collections.md +++ b/Sources/Collections/Collections.docc/Collections.md @@ -4,18 +4,17 @@ ## Overview +### Modules +- [**Basic Containers**](./basiccontainers) - Defines [`UniqueArray`][UniqueArray] and [`RigidArray`][RigidArray], noncopyable array variants trading some of `Array`'s flexibility for more predictable performance. +- [**Bit Collections**](./bitcollections) - Defines [`BitSet`](./bitcollections/bitset) and [`BitArray`](./bitcollections/bitarray), dynamic bit collections. +- [**Deque Module**](./dequemodule) - Defines [`Deque`](./dequemodule/deque), a double-ended queue backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections. +- [**Heap Module**](./heapmodule) - Defines [`Heap`](./heapmodule/heap), a min-max heap backed by an array, suitable for use as a priority queue. +- [**Ordered Collections**](./orderedcollections) - Defines [`OrderedSet`](./orderedcollections/orderedset), a variant of the standard `Set` where the order of items is well-defined and items can be arbitrarily reordered. Uses a `ContiguousArray` as its backing store, augmented by a separate hash table of bit packed offsets into it. [`OrderedDictionary`](./orderedcollections/ordereddictionary), an ordered variant of the standard `Dictionary`, providing similar benefits. +- [**Hash Tree Collections**](./hashtreecollections) - Defines [`TreeSet`](./hashtreecollections/treeset) and [`TreeDictionary`](./hashtreecollections/treedictionary), persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements. +- [**Trailing Elements Module**](./trailingelementsmodule) - Defines [`TrailingArray`](./trailingarray), a low-level, ownership-aware variant of `ManagedBuffer`, for interoperability with C constructs that consist of a fixed-size header directly followed by variable-size storage buffer. -#### Additional Resources +### Additional Resources - [`Swift Collections` on GitHub](https://github.com/apple/swift-collections/) - [`Swift Collections` on the Swift Forums](https://forums.swift.org/c/related-projects/collections/72) - -### Modules - -- [Basic Containers](./basiccontainers) - [`RigidArray`](./basiccontainers/rigidarray), a fixed capacity and no implicit resizing dynamic non-copyable array capable of storing non-copyable elements. [`UniqueArray`](./basiccontainers/uniquearray), an implicitly resizable dynamic non-copyable array capable of storing non-copyable elements. -- [Bit Collections](./bitcollections) - [`BitSet`](./bitcollections/bitset) and [`BitArray`](./bitcollections/bitarray), dynamic bit collections. -- [Deque Module](./dequemodule) - [`Deque`](./dequemodule/deque), a double-ended queue backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections. -- [Heap Module](./heapmodule) - [`Heap`](./heapmodule/heap), a min-max heap backed by an array, suitable for use as a priority queue. -- [Ordered Collections](./orderedcollections) - [`OrderedSet`](./orderedcollections/orderedset), a variant of the standard `Set` where the order of items is well-defined and items can be arbitrarily reordered. Uses a `ContiguousArray` as its backing store, augmented by a separate hash table of bit packed offsets into it. [`OrderedDictionary`](./orderedcollections/ordereddictionary), an ordered variant of the standard `Dictionary`, providing similar benefits. -- [Hash Tree Collections](./hashtreecollections) - [`TreeSet`](./hashtreecollections/treeset) and [`TreeDictionary`](./hashtreecollections/treedictionary), persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements.