A Union/Find data structure for maintaining disjoint sets. More...
#include <ogdf/basic/DisjointSets.h>
Public Member Functions | |
DisjointSets (const DisjointSets ©) | |
DisjointSets (DisjointSets &&move) noexcept | |
DisjointSets (int maxNumberOfElements=(1<< 15)) | |
Creates an empty DisjointSets structure. | |
~DisjointSets () | |
int | find (int set) |
Returns the id of the largest superset of set and compresses the path according to CompressionOptions. | |
int | getNumberOfElements () |
Returns the current number of elements. | |
int | getNumberOfSets () |
Returns the current number of disjoint sets. | |
int | getRepresentative (int set) const |
Returns the id of the largest superset of set . | |
void | init () |
Resets the DisjointSets structure to be empty, preserving the previous value of maxNumberOfElements. | |
void | init (int maxNumberOfElements) |
Resets the DisjointSets structure to be empty, also changing the expected number of elements. | |
int | link (int set1, int set2) |
Unions set1 and set2 . | |
int | makeSet () |
Initializes a singleton set. | |
DisjointSets & | operator= (DisjointSets copy_by_value) noexcept |
Assign this DisjointSets to be a copy of copy_by_value . | |
bool | quickUnion (int set1, int set2) |
Unions the maximal disjoint sets containing set1 and set2 . | |
Private Attributes | |
int | m_maxNumberOfElements |
Maximum number of elements (array size) adjusted dynamically. | |
int | m_numberOfElements |
Current number of elements. | |
int | m_numberOfSets |
Current number of disjoint sets. | |
int * | m_parameters |
Maps set id to rank/size. | |
int * | m_parents |
Maps set id to parent set id. | |
int * | m_siblings |
Maps set id to sibling set id. | |
Friends | |
void | swap (DisjointSets &first, DisjointSets &second) noexcept |
A Union/Find data structure for maintaining disjoint sets.
Definition at line 90 of file DisjointSets.h.
|
inlineexplicit |
Creates an empty DisjointSets structure.
maxNumberOfElements | Expected number of Elements. |
Definition at line 146 of file DisjointSets.h.
|
inline |
Definition at line 151 of file DisjointSets.h.
|
inline |
Definition at line 157 of file DisjointSets.h.
|
inlinenoexcept |
Definition at line 180 of file DisjointSets.h.
|
private |
Definition at line 396 of file DisjointSets.h.
|
private |
Definition at line 387 of file DisjointSets.h.
|
private |
Definition at line 332 of file DisjointSets.h.
|
private |
Definition at line 346 of file DisjointSets.h.
|
private |
Definition at line 358 of file DisjointSets.h.
|
private |
Definition at line 372 of file DisjointSets.h.
|
inline |
Returns the id of the largest superset of set
and compresses the path according to CompressionOptions.
set | Set. |
set
is a non negative properly initialized id. Definition at line 210 of file DisjointSets.h.
|
inline |
Returns the current number of elements.
Definition at line 305 of file DisjointSets.h.
|
inline |
Returns the current number of disjoint sets.
Definition at line 302 of file DisjointSets.h.
|
inline |
Returns the id of the largest superset of set
.
set | Set. |
set
is a non negative properly initialized id. Definition at line 222 of file DisjointSets.h.
|
inline |
Resets the DisjointSets structure to be empty, preserving the previous value of maxNumberOfElements.
Definition at line 189 of file DisjointSets.h.
|
inline |
Resets the DisjointSets structure to be empty, also changing the expected number of elements.
Definition at line 183 of file DisjointSets.h.
|
private |
Definition at line 576 of file DisjointSets.h.
|
private |
Definition at line 624 of file DisjointSets.h.
|
private |
Definition at line 588 of file DisjointSets.h.
|
private |
Definition at line 607 of file DisjointSets.h.
|
inline |
Unions set1
and set2
.
set1
and set2
are maximal disjoint sets. Definition at line 277 of file DisjointSets.h.
|
inlineprivate |
Unions set1
and set2
w/o decreasing the numberOfSets.
set1
and set2
are maximal disjoint sets. Definition at line 313 of file DisjointSets.h.
|
inline |
Initializes a singleton set.
Definition at line 235 of file DisjointSets.h.
|
inlinenoexcept |
Assign this DisjointSets to be a copy of copy_by_value
.
Internally, this will use the copy constructor to create a temporary copy of the argument copy_by_value
(as it is passed by value) and then swap this object instance with the temporary copy. If the assigned-from object can be moved, the move constructor will be automatically used instead of copying. Note that this method thereby covers both copy-assignment and move-assignment. See https://stackoverflow.com/a/3279550 for more details on this idiom. This method is noexcept as a potentially-throwing copy constructor call is made within the context of the caller (see https://stackoverflow.com/a/7628345) and swap is expected to be noexcept.
Definition at line 180 of file DisjointSets.h.
|
private |
Definition at line 403 of file DisjointSets.h.
|
private |
Definition at line 459 of file DisjointSets.h.
|
private |
Use path splitting to compress the path of set1 and get the root
Redirect all nodes with smaller indices on the path of set2 to the root
Definition at line 489 of file DisjointSets.h.
|
private |
Definition at line 421 of file DisjointSets.h.
|
private |
Definition at line 542 of file DisjointSets.h.
|
inline |
Unions the maximal disjoint sets containing set1
and set2
.
set1
and set2
were disjoint und joined correctly. False otherwise. Definition at line 291 of file DisjointSets.h.
|
friend |
Definition at line 171 of file DisjointSets.h.
|
private |
Maximum number of elements (array size) adjusted dynamically.
Definition at line 105 of file DisjointSets.h.
|
private |
Current number of elements.
Definition at line 104 of file DisjointSets.h.
|
private |
Current number of disjoint sets.
Definition at line 103 of file DisjointSets.h.
|
private |
Maps set id to rank/size.
Definition at line 110 of file DisjointSets.h.
|
private |
Maps set id to parent set id.
Definition at line 109 of file DisjointSets.h.
|
private |
Maps set id to sibling set id.
Definition at line 111 of file DisjointSets.h.