1.6 KiB
Collections
Swift Collections is an open-source package of data structure implementations for the Swift programming language.
The package currently provides the following implementations:
-
Deque, a double-ended queue backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections. -
OrderedSet, a variant of the standardSetwhere the order of items is well-defined and items can be arbitrarily reordered. Uses aContiguousArrayas its backing store, augmented by a separate hash table of bit packed offsets into it. -
OrderedDictionary, an ordered variant of the standardDictionary, providing similar benefits.
Modules
This package provides separate products for each group of data structures it implements:
Collections. This is an umbrella module that exports every other public module in the package.DequeModule. DefinesDeque.OrderedCollections. Defines the ordered collection typesOrderedSetandOrderedDictionary.
If you aren't constrained by code size limitations, then importing Collections is the simplest way to start using the package.
import Collections
var deque: Deque = ["Ted", "Rebecca"]
deque.prepend("Keeley")
let people = OrderedSet(deque)
people.contains("Rebecca") // true
Additional Resources
Topics
Deque Module
Deque
Ordered Collections
OrderedSetOrderedDictionary