I have 2 instances of std::set, for examples one instance correspond to the state of a set at time t, and the other one at t+1.
I want to iterate over the union (in the mathematical sense) of these 2 sets, such that :
- each element of the union is processed once
- for each element I can tell in constant time if it is in the first set, the second set, or both
Here is an example of what I'm currently doing :
std::set<A> old_set, new_set;
for(auto it = old_set.begin(); it != old_set.end(); ++it) {
if(new_set.count(*it) == 0) {
//only in old set but not in new set
}
}
for(auto it = new_set.begin(); it != new_set.end(); ++it) {
if(old_set.count(*it) == 0) {
//only in new set but not in old set
}
}
As you can see, it is missing the part where we process elements in both sets, and also the complexity isn't good enough. I think there should be a way to do what I want by simply iterating over all the elements of the set
Does anyone have an idea?
Thanks