Does Swift have an ordered collection type? And if not, what are my options if I want to use one?
The standard library is Set
disordered, as the documentation clearly shows:
Arrays are ordered collections of values. Sets are unordered collections of unique values. Dictionaries are unordered collections of key-value associations.
However, there are many data structures suitable for implementing ordered sets (and dictionaries), in particular balanced binary trees, such as red-black trees .
As an example of this, c ++ stl has ordered sets and maps and allows you to perform range queries on them using the lower and upper bounds.
I know that the members of a set can be sorted into an array, but I am after a data structure with O(log(n))
insert, delete and query.
source
share