Understanding Set and DynamicSet
The next collection type we are going to discuss is Set
. Sets are containers for unique values with constant access time. This means that no matter how many values we have in a set, accessing a value will take the same amount of time, regardless of the value we are looking for. It's worth repeating the fact that all the elements of a set must be unique. Depending on their implementation, adding a duplicated element to a set will either throw an error or simply do nothing. Another characteristic of a set is that there is no such thing as element order. You cannot retrieve, for example, the 5th element from a set – there's simply no such thing because, in sets, there are no any indexes that would determine an order. In fact, there is also no such thing as retrieving an element from a set – we can only check if a given element is already in the set or not. And it makes a lot of sense if you think about it. You can think of a Set...