Union Find class (Disjoint-set data structure).
More...
#include <gbase.h>
Union Find class (Disjoint-set data structure).
For more info see: http://en.wikipedia.org/wiki/Disjoint-set_data_structure).
Definition at line 230 of file gbase.h.
TUnionFind::TUnionFind |
( |
| ) |
|
|
inline |
Definition at line 239 of file gbase.h.
THash< TInt, TIntPr > KIdSetH
TUnionFind::TUnionFind |
( |
const int & |
ExpectKeys | ) |
|
|
inline |
Constructor that reserves enough memory for ExpectKeys elements.
Definition at line 241 of file gbase.h.
241 :
KIdSetH(ExpectKeys,
true) { }
THash< TInt, TIntPr > KIdSetH
TUnionFind::TUnionFind |
( |
const TUnionFind & |
UnionFind | ) |
|
|
inline |
Definition at line 242 of file gbase.h.
THash< TInt, TIntPr > KIdSetH
int TUnionFind::Add |
( |
const int & |
Key | ) |
|
|
inline |
Adds an element Key to the structure.
Definition at line 254 of file gbase.h.
TPair< TInt, TInt > TIntPr
THash< TInt, TIntPr > KIdSetH
TDat & AddDat(const TKey &Key)
void TUnionFind::Dump |
( |
| ) |
|
Prints out the structure to standard output.
Definition at line 53 of file gbase.cpp.
54 printf(
" key\tset\n");
59 }
THash< TInt, TIntPr > KIdSetH
int Find(const int &Key)
Returns the set that contains element Key.
const TKey & GetKey(const int &KeyId) const
int TUnionFind::Find |
( |
const int & |
Key | ) |
|
Returns the set that contains element Key.
Definition at line 23 of file gbase.cpp.
24 int SetId = Key, parent =
Parent(Key);
26 while (parent != -1) {
32 while (parent != -1) {
33 const int tmp =
Parent(parent);
34 if (tmp != -1) {
Parent(parent) = SetId; }
TInt & Parent(const int &Key)
Returns the parent of element Key.
int TUnionFind::GetKeyI |
( |
const int & |
KeyN | ) |
const |
|
inline |
Returns the element KeyN.
Definition at line 250 of file gbase.h.
THash< TInt, TIntPr > KIdSetH
const TKey & GetKey(const int &KeyId) const
bool TUnionFind::IsKey |
( |
const int & |
Key | ) |
const |
|
inline |
Returns true if the structure contains element Key.
Definition at line 248 of file gbase.h.
THash< TInt, TIntPr > KIdSetH
bool IsKey(const TKey &Key) const
bool TUnionFind::IsSameSet |
( |
const int & |
Key1, |
|
|
const int & |
Key2 |
|
) |
| |
|
inline |
Returns true if elements Key1 and Key2 are in the same set.
Definition at line 258 of file gbase.h.
int Find(const int &Key)
Returns the set that contains element Key.
int TUnionFind::Len |
( |
| ) |
const |
|
inline |
Returns the number of elements in the structure.
Definition at line 246 of file gbase.h.
THash< TInt, TIntPr > KIdSetH
Definition at line 243 of file gbase.h.
THash< TInt, TIntPr > KIdSetH
TInt& TUnionFind::Parent |
( |
const int & |
Key | ) |
|
|
inline |
Returns the parent of element Key.
Definition at line 235 of file gbase.h.
const TDat & GetDat(const TKey &Key) const
THash< TInt, TIntPr > KIdSetH
TInt& TUnionFind::Rank |
( |
const int & |
Key | ) |
|
|
inline |
Returns the rank of element Key.
Definition at line 237 of file gbase.h.
const TDat & GetDat(const TKey &Key) const
THash< TInt, TIntPr > KIdSetH
void TUnionFind::Union |
( |
const int & |
Key1, |
|
|
const int & |
Key2 |
|
) |
| |
Merges sets with elements Key1 and Key2.
Definition at line 40 of file gbase.cpp.
41 const int root1 =
Find(Key1);
42 const int root2 =
Find(Key2);
45 if (rank1 > rank2) {
Parent(root2) = root1; }
46 else if (rank1 < rank2) {
Parent(root1) = root2; }
47 else if (root1 != root2) {
int Find(const int &Key)
Returns the set that contains element Key.
TInt & Rank(const int &Key)
Returns the rank of element Key.
TInt & Parent(const int &Key)
Returns the parent of element Key.
The documentation for this class was generated from the following files: