Redundant search for representative in disjoint sets
mglisse opened this issue · 0 comments
We have a general function to join 2 sets
graph/include/boost/pending/disjoint_sets.hpp
Lines 78 to 82 in 0002876
This function finds the representative for each set, then calls the more specialized
graph/include/boost/pending/disjoint_sets.hpp
Lines 72 to 76 in 0002876
which requires that we pass the representative of each set. It then calls the worker
graph/include/boost/pending/detail/disjoint_sets.hpp
Lines 55 to 59 in 0002876
which starts by looking for the representative of each set... (if anything, this could be
assert(i == comp_rep(p, i));
)
It isn't horrible, the search of the representative only takes one query in parent to check that it is indeed already good, it is probably already in cache and the branch predictor probably learns that this comparison is always true. Still, this defeats the purpose of having 2 different functions.
Note that fixing this has the potential to break code for users who mistakenly used link instead of union_sets, and didn't notice since they are currently equivalent.