ó
|£*^c           @   s   d  Z  d d d „  ƒ  YZ d S(   s   
Union-find data structure.
t	   UnionFindc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sž  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.

    - X.union(item1, item2, ...) merges the sets containing each item
      into a single larger set.  If any item is not yet part of a set
      in X, it is added to X as one of the members of the merged set.

      Union-find data structure. Based on Josiah Carlson's code,
      http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/215912
      with significant additional changes by D. Eppstein.
      http://www.ics.uci.edu/~eppstein/PADS/UnionFind.py

    c         C   s   i  |  _  i  |  _ d S(   s(   Create a new empty union-find structure.N(   t   weightst   parents(   t   self(    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyt   __init__#   s    	c         C   s–   | |  j  k r- | |  j  | <d |  j | <| S| g } |  j  | } x. | | d k rs | j | ƒ |  j  | } qF Wx | D] } | |  j  | <q{ W| S(   s:   Find and return the name of the set containing the object.i   iÿÿÿÿ(   R   R   t   append(   R   t   objectt   patht   roott   ancestor(    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyt   __getitem__(   s    	c         C   s   t  |  j ƒ S(   sL   Iterate through all items ever found or unioned by this structure.

        (   t   iterR   (   R   (    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyt   __iter__=   s    c            sƒ   g  | D] } ˆ  | ^ q } t  | d ‡  f d †  ƒ} xD | D]< } | | k r? ˆ  j | c ˆ  j | 7<| ˆ  j | <q? q? Wd S(   s8   Find the sets containing the objects and merge them all.t   keyc            s   ˆ  j  |  S(   N(   R   (   t   r(   R   (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyt   <lambda>G   s    N(   t   maxR   R   (   R   t   objectst   xt   rootst   heaviestR   (    (   R   sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyt   unionC   s    (   t   __name__t
   __module__t   __doc__R   R
   R   R   (    (    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyR       s
   			N(    (   R   R    (    (    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/utils/union_find.pyt   <module>   s   	