Enzo
Loading...
Searching...
No Matches
enzo::util::UnionFind Class Reference

Disjoint-set data structure for tracking connected components. More...

#include <UnionFind.h>

Public Member Functions

 UnionFind (std::size_t elementCount)
 Constructs an instance with each of elementCount elements in its own component.
 
std::size_t find (std::size_t x)
 Returns the root ID of the component containing x.
 
bool unite (std::size_t a, std::size_t b)
 Joins the components containing a and b.
 
bool sameSet (std::size_t a, std::size_t b)
 Reports whether a and b are in the same component.
 
std::size_t componentCount () const
 Number of distinct components currently tracked.
 
std::size_t size () const
 Total elements managed by this instance.
 

Detailed Description

Disjoint-set data structure for tracking connected components.

Operates on dense integer IDs from zero to elementCount minus one. Each call to find performs path compression and unite uses union by rank, giving amortized inverse-Ackermann time per operation. Treat as constant time for any practical input size.

Typical usage maps domain values (face offsets, point offsets) onto dense IDs and feeds pairs of related IDs into unite. Afterward find reports the root ID of the component containing any given element.

Member Function Documentation

◆ unite()

bool enzo::util::UnionFind::unite ( std::size_t a,
std::size_t b )

Joins the components containing a and b.

Returns
True when the two were in separate components before the call.

The documentation for this class was generated from the following files: