40 if (num_nodes == old_num_nodes) {
43 CHECK_GT(num_nodes, old_num_nodes);
46 parent_.resize(num_nodes);
47 std::iota(parent_.begin() + old_num_nodes, parent_.end(), old_num_nodes);
49 component_size_.resize(num_nodes, 1);
51 rank_.resize(num_nodes);
53 num_components_ += num_nodes - old_num_nodes;
77 if (num_nodes != num_nodes_at_last_get_roots_call_) {
81 const int previous_num_roots = roots_.size();
82 roots_.resize(previous_num_roots + num_nodes -
83 num_nodes_at_last_get_roots_call_);
84 std::iota(roots_.begin() + previous_num_roots, roots_.end(),
85 num_nodes_at_last_get_roots_call_);
92 &roots_, [&](
const int node) {
return node !=
FindRoot(node); });
94 num_nodes_at_last_get_roots_call_ = num_nodes;
100 const int min_num_nodes = std::max(node1, node2) + 1;
110 if (root1 == root2) {
114 DCHECK_GE(num_components_, 2);
117 const int component_size = component_size_[root1] + component_size_[root2];
122 if (rank_[root1] > rank_[root2]) {
123 parent_[root2] = root1;
124 component_size_[root1] = component_size;
126 parent_[root1] = root2;
127 component_size_[root2] = component_size;
129 if (rank_[root1] == rank_[root2]) {