I think it would be very useful to have a data structure representing an unordered collection of non-unique elements. Using an
Array ascribes a certain degree of significance to the order of elements, which can be misleading and detrimental to both hashing and equivalence checks.
There are reference-type implementations of the concept in Foundation (
NSCountedSet) and CoreFoundation (
As for my proposed implementation: if elements were
Hashable, a simple
Dictionary of type
[Element: UInt] could be used to back the data structure, with the value being the quantity of elements. I’m not certain that constraint is truly necessary, though, so I’d welcome alternative suggestions.