Q2NSViz 0.1.0
Q2NS trace visualizer
Loading...
Searching...
No Matches
q2nsviz.logic.UnionFind Class Reference

Disjoint-set data structure with path compression and union by rank. More...

Public Member Functions

str find (self, str x)
 Find the root representative of the set containing x.
 
 union (self, str a, str b)
 Merge the sets containing a and b using union by rank.
 
dict[str, list[str]] groups (self)
 Return all components as {root: [members]}.
 

Detailed Description

Disjoint-set data structure with path compression and union by rank.

Used by SimulationStateManager to compute the connected components of the entanglement graph.

Definition at line 124 of file logic.py.

Member Function Documentation

◆ find()

str q2nsviz.logic.UnionFind.find (   self,
str  x 
)

Find the root representative of the set containing x.

Inserts x into the structure on first access. Uses iterative two-pass path compression so the call stack never grows with set size.

Parameters
xElement label to look up.
Returns
Root representative of the component containing x.

Definition at line 136 of file logic.py.

Referenced by q2nsviz.logic.UnionFind.groups(), and q2nsviz.logic.UnionFind.union().

Here is the caller graph for this function:

◆ groups()

dict[str, list[str]] q2nsviz.logic.UnionFind.groups (   self)

Return all components as {root: [members]}.

Returns
Dictionary mapping each component root to its member list. Every element appears in exactly one list.

Definition at line 178 of file logic.py.

References q2nsviz.logic.UnionFind.find().

Here is the call graph for this function:

◆ union()

q2nsviz.logic.UnionFind.union (   self,
str  a,
str  b 
)

Merge the sets containing a and b using union by rank.

Parameters
aFirst element label.
bSecond element label.

Definition at line 161 of file logic.py.

References q2nsviz.logic.UnionFind.find().

Here is the call graph for this function:

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