sorted array, exclude duplicates


I need all 4 items be equal as per below, to make condition true
it is actually true when any part of below is equal. How can I ammend the code?
if (attempt[0][0] == clean[i][0] && attempt[0][1] == clean[i][1] && attempt[0][2] == clean[i][2] && attempt[0][3] == clean[i][3])

Easiest way to avoid duplicates (per your topic title) in a container is to use a std::set.
https://www.cplusplus.com/reference/set/set/
oh, its too complicated..
Is there a way to exclude duplicates with if condition?
Not as easily as using a std::set container, unique values is a key feature of std::set.

I'd personally find trying to use if/else statements to avoid duplication a lot more complicated than using a std::set (or maybe a std::map). The more elements you deal with the more complicated and prone-to-be-wrong your if/else logic will be.

https://www.cplusplus.com/reference/map/map/

maps and sets are automatically sorted for you, no need to do it "manually" before- or after-the-fact.

This assignment(?) seems to be a "have a hammer, every problem is a nail" situation.

I prefer using what the C++ toolbox has to offer, instead of constantly reinventing a flat wheel.
If the array is sorted, then you can use std::duplicate() to remove duplicated consecutive items.

http://www.cplusplus.com/reference/algorithm/unique/

Note that it returns the new end of the data after the duplicates are removed.
Oh, I'm still looking for somethings basic, close to C solution, which makes me understand the code better...
Basically, i just need to find proper combination of & and |
if its just 4, wasting time for simple code is fine. \
1) sort it. (C has a sort() function)
2) copy it discarding duplicates into final result. (this is a simple loop). this could also just be a running bool that turns false if you found a duplicate.

yea its inefficient, but it will take a large # of the above to begin to notice that, millions (possibly, 10s of millions) of groups of 4 on a modern desktop.

the statement you show looks fine. it should not be true if any of the equalities is false.
however you can do a memcmp to clean it up if you want a C like answer. this will work because you are comparing across the dimension that is a block of bytes, (assuming that the types being compared can be used with memcmp)
Last edited on
Oh! I finally found slight mistake on function entry, but statement from first message indeed was true..
Having one duplicate to 2000 rows, if will not handle myself will post it here soon :)
Thank you, guys!
Topic archived. No new replies allowed.