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 and dequeue operations run in amortized constant time.

    Conforms to Sequence, ExpressibleByArrayLiteral, CustomStringConvertible.

    See more

    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 and dequeueLast operations run in amortized constant time.

    Conforms to Sequence, ExpressibleByArrayLiteral, CustomStringConvertible.

    See more

    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 and pop operations run in amortized constant time.

    Conforms to Sequence, ExpressibleByArrayLiteral, CustomStringConvertible.

    See more

    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 and dequeue operations run in O(log(n)) time.

    Conforms to Sequence, CustomStringConvertible.

    See more

    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 Sequence, ExpressibleByArrayLiteral and Hashable.

    See more

    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 Sequence, ExpressibleByDictionaryLiteral, Equatable and CustomStringConvertible

    See more

    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 or bimap[key: aKey] = aValue

    Conforms to Sequence, Collection, ExpressibleByDictionaryLiteral, Equatable, Hashable and CustomStringConvertible.

    See more

    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 Sequence.

    See more

    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 CustomStringConvertible, Hashable.

    See more

    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 with Double matrices. Check the Functions section for more information.

    Conforms to MutableCollection, ExpressibleByArrayLiteral and CustomStringConvertible.

    See more

    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 MutableCollection, ExpressibleByArrayLiteral , Equatable, Hashable, CustomStringConvertible

    See more

    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 MutableCollection, ExpressibleByArrayLiteral, Equatable, CustomStringConvertible.

    See more

    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 BloomFilterType protocol. Types already conforming to the protocol include, but are not limited to: Int, Double and String.

    See more

    Declaration

    Swift

    public struct BloomFilter<T: BloomFilterType>