Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# UnionFind.UnionFind

All Samples(26)  |  Call(13)  |  Derive(0)  |  Import(13)
```Union-find data structure.

Each unionFind instance X maintains a family of disjoint sets of
hashable objects, supporting the following two methods:

- X[item] returns a name for the set containing the given item.
Each set is named by an arbitrarily-chosen one of its members; as
long as the set remains unchanged it will keep the same name. If
the item is not yet part of a set in X, a new singleton set is
created for it.(more...)
```

```"""

from UnionFind import UnionFind

def MinimumSpanningTree(G):
```
```    # implement once UnionFind exists, and second, because the only slow
# part (the sort) is sped up by being built in to Python.
subtrees = UnionFind()
tree = []
edges = [(G[u][v],u,v) for u in G for v in G[u]]
```

```"""

from UnionFind import UnionFind

def MinimumSpanningTree(G):
```
```    # implement once UnionFind exists, and second, because the only slow
# part (the sort) is sped up by being built in to Python.
subtrees = UnionFind()
tree = []
edges = [(G[u][v],u,v) for u in G for v in G[u]]
```

```import Medium
from Bipartite import isBipartite
from UnionFind import UnionFind
from StrongConnectivity import StronglyConnectedComponents
from Graphs import isUndirected
```
```    # - CG: contracted graph at current stage of algorithm
# - LL: limit on number of remaining available labels
UF = UnionFind()
CG = dict([(v,dict([(w,(v,w)) for w in G[v]])) for v in G])
NL = len(CG)-1
```
```    # Here with all edge equivalence classes represented by UF.
# Turn them into a labeled graph and return it.
return dict([(v,dict([(w,UF[v,w]) for w in G[v]])) for v in G])

```

```import Medium
from Bipartite import isBipartite
from UnionFind import UnionFind
from StrongConnectivity import StronglyConnectedComponents
from Graphs import isUndirected
```
```    # - CG: contracted graph at current stage of algorithm
# - LL: limit on number of remaining available labels
UF = UnionFind()
CG = {v:{w:(v,w) for w in G[v]} for v in G}
NL = len(CG)-1
```
```    # Here with all edge equivalence classes represented by UF.
# Turn them into a labeled graph and return it.
return {v:{w:UF[v,w] for w in G[v]} for v in G}

```

```
import unittest,random
from UnionFind import UnionFind
from sets import Set

```
```        #    one set for the descendants of each search path node.
# self.ancestors maps disjoint set ids to the ancestors themselves.
self.descendants = UnionFind()
self.ancestors = {}

```

```from sets import Set

from UnionFind import UnionFind
from Util import arbitrary_item

```
```        # are on the same side of the blossom and w is on the other side.

S = {}
T = {}
```

```import unittest,random
from collections import defaultdict
from UnionFind import UnionFind

def _decodeSlice(self,it):
```
```        #    one set for the descendants of each search path node.
# self.ancestors maps disjoint set ids to the ancestors themselves.
self.descendants = UnionFind()
self.ancestors = {}

```

```import sys

from UnionFind import UnionFind
from Util import arbitrary_item

```
```        # are on the same side of the blossom and w is on the other side.

S = {}
T = {}
```

```
from copy import copy
from UnionFind import UnionFind

# TODO: general code cleanup
```
```        self_pairs = [(x, x) for x in self.states]
fd_equiv_pairs = sd.right_finite_states(self_pairs)
sets = UnionFind()
for state in self.states:
sets.make_set(state)
```