25 void Resize(
const int entries);
31 int Union(
const int i,
const int j);
33 void GetSets(std::vector<int>& sets);
37 void GetRoots(std::vector<int>& roots)
const;
39 void EnumerateSets(std::vector<std::vector<int> >& sets)
const;
44 inline bool IsRoot(
const int i)
const {
return parents[i]==-1; }
45 int FindRoot(
const int i)
const;
48 std::vector<int> parents;
49 void PathCompress(
const int i,
const int root);
From an indexed set of elments, allows fast unioning of the elements into sets.
Definition: unionfind.h:18
void GetRoots(std::vector< int > &roots) const
Returns the roots of all sets.
Definition: unionfind.cpp:66
void GetSets(std::vector< int > &sets)
Returns the sets to which the items belong, such that sets[i] = set(xi)
Definition: unionfind.cpp:51
size_t CountSets() const
Counts the number of sets.
Definition: unionfind.cpp:58
void Resize(const int entries)
Resize X to size entries, sets all sets Si={xi}.
Definition: unionfind.cpp:15
void EnumerateSet(int i, std::vector< int > &s) const
Returns the entire set for item i.
Definition: unionfind.cpp:86
int AddEntry()
Increment the size of X by 1, sets Sn={xn}.
Definition: unionfind.cpp:20
void EnumerateSets(std::vector< std::vector< int > > &sets) const
Returns the sets, by listing all items for each set.
Definition: unionfind.cpp:74
int Union(const int i, const int j)
Unions the sets to which xi and xj belong.
Definition: unionfind.cpp:34
int FindSet(const int i)
Returns the id of the set to which xi belongs.
Definition: unionfind.cpp:26
void Initialize(const int entries)
Resize X to size entries, sets all sets Si={xi}.
Definition: unionfind.cpp:9