I have an std::set
, which stores std::pair
s of two integers. The std::set
is also sorted, by allowing me to pass a helping class. However, I have written many lines of code so far and now, at the last tests, "they" told me something, that actually means that I need to allow possible duplicates in the std::set
. Of course this isn't done with std::set
. Any alternative that will not make me change the whole-big project?
In short, I use the std::set
as an ordered list with data an std::pair
of two ints.
In Set duplicate values are not allowed to get stored. On other hand in case of MultiSet we can store duplicate values. In case of Set, one cannot change the value once it gets inserted however we can delete or insert it again. However in case of MultiSet also we cannot change the value once get inserted.
A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction.
Unordered sets do not allow duplicates and are initialized using comma-delimited values enclosed in curly braces.
One more way to detect duplication in the java array is adding every element of the array into HashSet which is a Set implementation. Since the add(Object obj) method of Set returns false if Set already contains an element to be added, it can be used to find out if the array contains duplicates in Java or not.
You can use std::multiset
. That should work for what you are describing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With