class UnionFind: (source)
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 |
Find the representative of a component represented by given name. |
Method | merge |
Merge two components represented by the given names. |
Method | merge |
Merge a UnionFind into the current one. |
Instance Variable | id2name |
Undocumented |
Instance Variable | latest |
Undocumented |
Instance Variable | name2id |
Undocumented |
Instance Variable | parent |
Undocumented |
Instance Variable | rank |
Undocumented |
Method | _find |
Find the tree root. |
Method | _get |
Undocumented |
Method | _merge |
Merge two components. |