Data Structures
-
A queue is a First-In-First-Out (FIFO) collection, the first element added to the queue will be the first one to be removed.
The
enqueue
anddequeue
operations run in amortized constant time.Conforms to
See moreSequence
,ExpressibleByArrayLiteral
,CustomStringConvertible
.Declaration
Swift
public struct Queue<T>
-
A double-ended queue (deque) is a collection that generalizes a queue, for which elements can be added to or removed from either the front or back.
The
enqueueFirst
,enqueueLast
,dequeueFirst
anddequeueLast
operations run in amortized constant time.Conforms to
See moreSequence
,ExpressibleByArrayLiteral
,CustomStringConvertible
.Declaration
Swift
public struct Deque<T>
-
A Stack is a Last-In-First-Out (LIFO) collection, the last element added to the stack will be the first one to be removed.
The
push
andpop
operations run in amortized constant time.Conforms to
See moreSequence
,ExpressibleByArrayLiteral
,CustomStringConvertible
.Declaration
Swift
public struct Stack<T>
-
In a priority queue each element is associated with a
priority
, elements are dequeued in highest-priority-first order (the elements with the highest priority are dequeued first).The
enqueue
anddequeue
operations run in O(log(n)) time.Conforms to
See moreSequence
,CustomStringConvertible
.Declaration
Swift
public struct PriorityQueue<T>
-
A Multiset (sometimes called a bag) is a special kind of set in which members are allowed to appear more than once. It’s possible to convert a multiset to a set:
let set = Set(multiset)
Conforms to
See moreSequence
,ExpressibleByArrayLiteral
andHashable
.Declaration
Swift
public struct Multiset<T: Hashable>
-
A Multimap is a special kind of dictionary in which each key may be associated with multiple values. This implementation allows duplicate key-value pairs.
Comforms to
See moreSequence
,ExpressibleByDictionaryLiteral
,Equatable
andCustomStringConvertible
Declaration
Swift
public struct Multimap<Key: Hashable, Value: Equatable>
-
A Bimap is a special kind of dictionary that allows bidirectional lookup between keys and values. All keys and values must be unique. It allows to get, set, or delete a key-value pairs using subscript notation:
bimap[value: aValue] = aKey
orbimap[key: aKey] = aValue
Conforms to
See moreSequence
,Collection
,ExpressibleByDictionaryLiteral
,Equatable
,Hashable
andCustomStringConvertible
.Declaration
Swift
public struct Bimap<Key: Hashable, Value: Hashable>
-
A simple directed graph: that is, one with no loops (edges connected at both ends to the same vertex) and no more than one edge in the same direction between any two different vertices. All vertices in the graph are unique. Edges are not allowed to be generic types. The preferred way to acess and insert vertices or edges is using subscript notation. Example:
graph["NY", "Boston"] = distance
Conforms to
See moreSequence
.Declaration
Swift
public struct Graph<Vertex: Hashable, Edge>
-
A Trie (sometimes called a prefix tree) is used for storing a set of strings compactly and searching for full words or partial prefixes very efficiently.
The operations for insertion, removal, lookup, and prefix matching run in O(n) time, where n is the length of the sequence or prefix.
Conforms to
See moreCustomStringConvertible
,Hashable
.Declaration
Swift
public struct Trie
-
A Matrix is a fixed size generic 2D collection. You can set and get elements using subscript notation. Example:
matrix[row, column] = value
This collection also provides linear algebra functions and operators such as
inverse()
,+
and*
using Apple’s Accelerate framework where vailable. Please note that these operations are designed to work exclusively withDouble
matrices. Check theFunctions
section for more information.Conforms to
See moreMutableCollection
,ExpressibleByArrayLiteral
andCustomStringConvertible
.Declaration
Swift
public struct Matrix<T>
-
An array of boolean values stored using individual bits, thus providing a very small memory footprint. It has most of the features of a standard array such as constant time random access and amortized constant time insertion at the end of the array.
Conforms to
See moreMutableCollection
,ExpressibleByArrayLiteral
,Equatable
,Hashable
,CustomStringConvertible
Declaration
Swift
public struct BitArray
-
A circular array provides most of the features of a standard array such as constant-time random access in addition to amortized constant-time insertion/removal at both ends, instead of just one end. It allows to get or set elements using subscript notation.
Conforms to
See moreMutableCollection
,ExpressibleByArrayLiteral
,Equatable
,CustomStringConvertible
.Declaration
Swift
public struct CircularArray<T>
-
A Bloom filter is a probabilistic set designed to check rapidly and memory-efficiently, whether an element is definitely not in the set or may be in the set. The false positive probability is provided at construction time.
Inserted elements must conform to the
See moreBloomFilterType
protocol. Types already conforming to the protocol include, but are not limited to:Int
,Double
andString
.Declaration
Swift
public struct BloomFilter<T: BloomFilterType>