Other Structures
The following structures are available globally.
-
A resizable, value-semantic buffer of homogenous elements of statically-unknown type.
See moreDeclaration
Swift
public struct AnyArrayBuffer<Dispatch> where Dispatch : AnyObject -
A wrapper for a value of any type, with efficient access and inline storage of bounded size for small values.
Existential types such as
Anyprovide the storage characteristics ofAnyValue, but many operations on existentials optimize poorly, soAnyValuemay be needed to achieve efficient access.Using
enumsand no existential, it is possible to build such storage for:- types that are trivially copiable (such as Int), or
- collections of elements with the inline storage being (roughly) a multiple of the element
size.
You might consider using the
enumapproach where applicable.
Declaration
Swift
public struct AnyValueextension AnyValue: CustomStringConvertible, CustomDebugStringConvertible -
A value-semantic collection of
See moreStorage.Elementwith unbounded growth.Declaration
Swift
public struct ArrayBuffer<Element>extension ArrayBuffer: RandomAccessCollection, MutableCollection -
Bounded-sized, reference-semantic, contiguous storage of
See moreElements.Declaration
Swift
public struct ArrayStorage<Element>extension ArrayStorage : RandomAccessCollection, MutableCollection -
A collection that is all the elements of one collection followed by all the elements of a second collection.
See moreDeclaration
Swift
public struct Concatenation<First: Collection, Second: Collection>: Collection where First.Element == Second.Elementextension Concatenation: BidirectionalCollection where First: BidirectionalCollection, Second: BidirectionalCollectionextension Concatenation: RandomAccessCollection where First: RandomAccessCollection, Second: RandomAccessCollectionextension Concatenation: MutableCollection where First: MutableCollection, Second: MutableCollection -
A replacement for
See moreVoidthat can conform to protocols.Declaration
Swift
public struct Empty : DefaultInitializableextension Empty: CustomStringConvertibleextension Empty: Hashable, Comparable -
A fixed sized collection of 0 elements.
See moreDeclaration
Swift
public struct Array0<T> : FixedSizeArrayextension Array0 : Equatable where T : Equatableextension Array0 : Hashable where T : Hashableextension Array0 : Comparable where Element : Comparable -
A fixed sized random access collection one element longer than
See moreTail, supporting efficient creation of instances of related types via single-element insertion and deletion.Declaration
Swift
public struct ArrayN<Tail> : FixedSizeArray where Tail : FixedSizeArrayextension ArrayN : Equatable where Element : Equatable, Tail : Equatableextension ArrayN : Hashable where Element : Hashable, Tail : Hashableextension ArrayN : Comparable where Element : Comparable, Tail : Comparable
-
A comparable tuple containing a comparable priority and an arbitrary payload.
See moreDeclaration
Swift
public struct PriorityQueueElement<Priority, Payload> where Priority : Comparableextension PriorityQueueElement: Equatable, Comparable -
Adapts a collection indexed by
Ints into aPriorityQueueIndexerandIndexProtocol.See moreSee also
ArrayPriorityQueueIndexer.Declaration
Swift
public struct CollectionPriorityQueueIndexer< Key: IdIndexable, Table: RandomAccessCollection & MutableCollection, Value >: PriorityQueueIndexer, IndexProtocol where Table.Index == Int, Table.Element == Value?extension CollectionPriorityQueueIndexer: DefaultInitializable where Table: DefaultInitializable -
A zero-sized type that does no indexing, and can be used when re-prioritization within a
See morePriorityQueueis not needed.Declaration
Swift
public struct NonIndexingPriorityQueueIndexer<Key, Value> : PriorityQueueIndexer, DefaultInitializable -
A collection of
Prioritys andPayloads that allows for efficient retrieval of the smallest priority and its associated payload, and insertion of payloads at arbitrary priorities.This is a min-priority queue, where
ahas “higher priority” thanbifa < b.See moreSee also
SimplePriorityQueue.Declaration
Swift
public struct GenericPriorityQueue< Priority: Comparable, Payload, Heap: RandomAccessCollection & RangeReplaceableCollection & MutableCollection, ElementLocations: PriorityQueueIndexer >: Queue where Heap.Element == PriorityQueueElement<Priority, Payload>, ElementLocations.Key == Payload, ElementLocations.Value == Heap.Indexextension GenericPriorityQueue: RandomAccessCollectionextension GenericPriorityQueue: CustomStringConvertibleextension GenericPriorityQueue: DefaultInitializable where Heap: DefaultInitializable, ElementLocations: DefaultInitializable
-
A collection of
Prioritys andPayloads that allows for efficient retrieval of the smallest priority and its associated payload, and insertion of payloads at arbitrary priorities.This is a max-priority queue, where
ahas “higher priority” thanbifa < b.See moreSee also
SimpleMaxPriorityQueue.Declaration
Swift
public struct GenericMaxPriorityQueue< Priority: Comparable, Payload, Heap: RandomAccessCollection & RangeReplaceableCollection & MutableCollection, ElementLocations: PriorityQueueIndexer >: Queue where Heap.Element == PriorityQueueElement<Priority, Payload>, ElementLocations.Key == Payload, ElementLocations.Value == Heap.Indexextension GenericMaxPriorityQueue: RandomAccessCollectionextension GenericMaxPriorityQueue: CustomStringConvertibleextension GenericMaxPriorityQueue: DefaultInitializable where Heap: DefaultInitializable, ElementLocations: DefaultInitializable -
A nominal version of the tuple type that is the
See moreElementofSwift.Dictionary.Declaration
Swift
public struct KeyValuePair<Key, Value>extension KeyValuePair: Equatable where Key: Equatable, Value: Equatableextension KeyValuePair: Comparable where Key: Comparable, Value: Comparableextension KeyValuePair: Hashable where Key: Hashable, Value: Hashableextension KeyValuePair : Decodable where Key : Decodable, Value : Decodableextension KeyValuePair : Encodable where Key : Encodable, Value : Encodable -
A Dictionary with a deterministic sequence traversal order determined by the order in which keys are added.
See moreDeclaration
Swift
public struct InsertionOrderedDictionary<Key, Value> where Key : Hashableextension InsertionOrderedDictionary : RandomAccessCollectionextension InsertionOrderedDictionary : Sequenceextension InsertionOrderedDictionary : CustomReflectableextension InsertionOrderedDictionary : CustomStringConvertible, CustomDebugStringConvertibleextension InsertionOrderedDictionary : Hashable where Value : Hashableextension InsertionOrderedDictionary : Equatable where Value : Equatableextension InsertionOrderedDictionary : Decodable where Key : Decodable, Value : Decodableextension InsertionOrderedDictionary : Encodable where Key : Encodable, Value : Encodable -
A Dictionary with a nominal
See moreElementtype, that can conform to things.Declaration
Swift
public struct NominalElementDictionary<Key, Value> where Key : Hashableextension NominalElementDictionary : Collectionextension NominalElementDictionary : Sequenceextension NominalElementDictionary : CustomReflectableextension NominalElementDictionary : CustomStringConvertible, CustomDebugStringConvertibleextension NominalElementDictionary : Hashable where Value : Hashableextension NominalElementDictionary : Equatable where Value : Equatableextension NominalElementDictionary : Decodable where Key : Decodable, Value : Decodableextension NominalElementDictionary : Encodable where Key : Encodable, Value : Encodable -
Fast pseudorandom number generator using permuted congruential generators.
It combines two underlying 32-bit output PCG-XSH-RS random number generators to balance speed with
See moreRandomNumberGenerator‘s requirement of 64-bit output.Declaration
Swift
public struct PCGRandomNumberGenerator : RandomNumberGenerator -
A Sequence whose elements are projections, through a lens of type
BaseElementPart, of the elements of someBasesequence.
See moreProjectionsis analogous toLazyMapSequencebut doesn’t store a closure or aKeyPath, and whenBaseconforms toMutableCollection, so doesProjections<Base, L>, as long asL.Focusis-aWritableKeyPath.Declaration
Swift
-
An algebraic product type whose first element is of type
See moreHeadand whose remaining elements can be stored inTail.Declaration
Swift
-
A type whose full identity is known to the type system.
Generic function/method APIs often accept a
T.Typeparameter, whereTis a generic parameter, to drive deduction, for example:extension UnsafeRawPointer { func assumingMemoryBound<T>(to _: T.Type) -> UnsafePointer<T> { ... } }which is then used as follows:
someRawPointer.assumingMemoryBound(to: Foo.self)The problem with such interfaces is that you can easily end up driving type deduction with a value that doesn’t match the deduced type:
let foo: Any.Type = Foo.self assert(foo == Foo.self) someRawPointer.assumingMemoryBound(to: foo) // not what you might expectDespite the fact that the function argument is equal to
Foo.self, the deduced type ofTisAny. It isn’t always obvious at the use site of such an API that the value of the function argument is irrelevant and only its type matters. To avoid this problem, we can instead useType<T>in the function signature:extension UnsafeRawPointer { func assumingMemoryBound<T>(to _: Type<T>) -> UnsafePointer<T> { ... } }which is then used as follows:
See moresomeRawPointer.assumingMemoryBound(to: Type<Foo>()) -
A nominal wrapper around
Any.Typethat conforms to useful protocols.Note that the
See moreComparableconformance will not have a stable ordering across program invocations. If reproducible ordering is important, you can sacrifice performance for stability by usingString(reflecting: self.value)as a sort key.Declaration
Swift
View on GitHub
Other Structures Reference