9 # include <vcl_msvc_warnings.h> 41 if (
nodes_[i].parent !=
nullptr)
59 curnode = const_cast<node*>(
nodes_.begin() + element_id);
60 while (curnode->
parent !=
nullptr)
66 curnode = const_cast<node*>(
nodes_.begin()+element_id);
67 while (curnode != root)
85 node* set1 = const_cast<node*>(
nodes_.begin()+setId1);
86 node* set2 = const_cast<node*>(
nodes_.begin()+setId2);
92 if (set1->
rank > set2->rank) {
94 set1->
size = set1->
size + set2->size;
96 else if (set1->
rank < set2->rank) {
98 set2->
size = set2->size + set1->
size;
104 set1->
size = set1->
size + set2->size;
113 assert(num_to_add >= 0);
117 for (
int i = n; i < num_to_add + n; ++i)
141 return nodes_[set_id].size;
int rank
represents the approximate max height of the node in its subtree.
void add_elements(int num_to_add)
~vbl_disjoint_sets()
Destructor.
vbl_array_1d< node > nodes_
implements a disjoint set (union, find)
void set_union(int set_id1, int set_id2)
Combine two sets into one.
int find_set(int element) const
Find the set identifier that an element currently belongs to.
int num_sets() const
Returns the number of sets.
int size(int set_id) const
Returns the number of elements in set specified by set_id.