I'm trying to use boost:disjoint_sets for non overlaping intervals (in my case the intervals in a set must have no intersection between its members) that are represented by the following struct:
struct dataum {
int x,y;
bool operator< (const dataum& o) const { return y < o.x ; }
bool operator==(const dataum& o) const {
if(x <= o.x && o.x <= y && y <= o.y )
return true;
if(x <= o.x && o.y <= y)
return true;
if(o.x <= x && y <= o.y)
return true;
if(o.x <= x && x <= o.y && o.y <= y )
return true;
return false;
}
bool operator!=(const dataum& o) const {
return !operator==(o);
}
};
Let's say I have a list of intervals e.g. ([1,3], [4,5], [6,10], [8,9]). I initialize a disjoint set as below:
boost::disjoint_sets<
associative_property_map<std::map<dataum,int>>,
associative_property_map<std::map<dataum,dataum>> > ds(
make_assoc_property_map(rank),
make_assoc_property_map(parent));
Then I perform a make_set in all elements of my list, which will result in 4 disjoint sets, right? After this, I perform the following operations:
std::cout << ds.count_sets(S.begin(), S.end()) << std::endl;
ds.union_set(S[0],S[1]);
ds.union_set(S[1],S[2]);
std::cout << ds.count_sets(S.begin(), S.end()) << std::endl;
What I don't understand is why the last cout says that I have only one set, which in my understanding should say that I have 2 sets {[1,3], [4,5], [6,10]} and {[8,9]}.
Can anyone help me to understand what's happening ?