num::basic_disjoint_set¶
Defined in header <structures/containers/disjoint_set.hpp>
template <std::integral Index = num::idx>
class basic_disjoint_set;
Disjoint sets stored as a forest: find and unite in nearly \(O(1)\) amortized time.
Members¶
| member | description |
|---|---|
using index_type = Index |
|
explicit basic_disjoint_set(Index n = 0) |
Construct n sets of one element each: \(\{0\}, \ldots, \{n-1\}\). |
Index find(Index u) |
Return the representative of \([u]\), shortening the path. |
Index find(Index u) const |
Return the representative of \([u]\) without changing the forest. |
bool unite(Index u, Index v) |
Merge \([u]\) and \([v]\); return whether they were different sets. |
bool connected(Index u, Index v) |
Test whether \(u \sim v\). |
Index component_size(Index u) |
Return the size of \([u]\). |
Index count() const noexcept |
Return the number of sets. |
Index size() const noexcept |
Return the number of elements. |
void reset(Index n = 0) |
Reset to n sets of one element each. |
array<array<Index>> components() |
Return all sets, as lists of elements. |