Implementing equivalence relations in C++ (using boost::disjoint_sets)
Assume you have many elements, and you need to keep track of the equivalence relations between them. If element A is equivalent to element B, it is equivalent to all the other elements B is equivalent to. I am looking for an efficient data structure to encode this information. It should be possible to dynamically add new elements through an equivalence with an existing element, and from that information it should be possible to efficiently compute all the elements the new element is equivalent to. For example, consider the following equivalence sets of the elements [0,1,2,3,4]: 0 = 1 = 2 3 = 4