Home >Backend Development >Python Tutorial >Explanation on the set--unordered feature
Unordered set is a container that stores unique elements in no specific order, which allows fast retrieval of each element based on its value.
In an unordered_set, an element's value is at the same time its key, identifying it uniquely. Keys are immutable, so elements in an unordered_set cannot be modified once in the container - they can be inserted or removed, though.
Internally, the elements of the unordered_set are sorted in any particular order, but organized according to their hash values to allow fast access to individual elements directly by their values (with average constant average time complexity ) value area.
Unordered_set containers can access individual elements by key faster than group containers, although they are generally inefficient for range iteration through a subset of their elements.
Iterators in containers are at least forward iterators.
Regarding the issue of set sorting being out of order, the reason is that set uses a hash table as a memory index.
Detailed introduction can be found at:
and wiki:
The above is the detailed content of Explanation on the set--unordered feature. For more information, please follow other related articles on the PHP Chinese website!