class documentation

class UnionFind: (source)

View In Hierarchy

A disjoint-set data structure for `AliasingDict`. This is used to record the alias information for `AliasingDict`. It is consist of different components. Each component will contain the names that represent the same thing. E.g., for a five-node component/tree, the representative for all the nodes in the component is `T`: T [T] The root node and representative / \ [U] Its parent is `T` U V [V] Its parent is `T` / \ [W] Its parent is `V` W X [X] Its parent is `V` For performance consideration, we will compress the path each time when we compute the representative of a node. E.g., if we try to get the representative of node `W`, then the above tree will become: T /|\ U W V \ X Attributes: name2id: mapping all names to unique id. parent: the parent id of current unique id. rank: the height of the tree for corresponding component, it is an optimization to merge two components. id2name: mapping unique id to corresponding names, the reverse map of `name2id`. latest_id: the maximal allocated id.

Method __init__ Undocumented
Method __repr__ Undocumented
Method find_by_name Find the representative of a component represented by given name.
Method merge Merge two components represented by the given names.
Method merge_from Merge a UnionFind into the current one.
Instance Variable id2name Undocumented
Instance Variable latest_id Undocumented
Instance Variable name2id Undocumented
Instance Variable parent Undocumented
Instance Variable rank Undocumented
Method _find Find the tree root.
Method _get_or_add_id Undocumented
Method _merge Merge two components.
def __init__(self): (source)

Undocumented

def __repr__(self): (source)

Undocumented

def find_by_name(self, name): (source)

Find the representative of a component represented by given name.

def merge(self, name1, name2): (source)

Merge two components represented by the given names.

def merge_from(self, uf): (source)

Merge a UnionFind into the current one.

Undocumented

latest_id: int = (source)

Undocumented

Undocumented

Undocumented

Undocumented

def _find(self, key): (source)

Find the tree root.

def _get_or_add_id(self, name): (source)

Undocumented

def _merge(self, k1, k2): (source)

Merge two components.