o
    "Õj;  ã                   @   s   G d d„ dƒZ dS )c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )Ú	UnionFinda:  Union-find data structure.

    Union-find is a data structure that keeps track of a set of elements partitioned
    into a number of disjoint (non-overlapping) subsets.

    Reference:
    https://en.wikipedia.org/wiki/Disjoint-set_data_structure

    Args:
      elements(list): The initialize element list.
    Nc                 C   sV   g | _ i | _d| _|sg }|D ]}| j  | j¡ | j || ji¡ |  jd7  _qd S )Né    é   )Ú_parentsÚ_indexZ	_curr_idxÚappendÚupdate)ÚselfZ	elementesZele© r	   úl/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/distributed/transpiler/details/ufind.pyÚ__init__   s   ýzUnionFind.__init__c                 C   sV   || j vrdS | j | }|| j| kr)| j| }| j| | j|< |}|| j| ks|S )Néÿÿÿÿ)r   r   )r   ÚxÚidxÚtr	   r	   r
   Úfind(   s   


ýzUnionFind.findc                 C   s.   |   |¡}|   |¡}||krd S || j|< d S ©N)r   r   )r   r   ÚyZx_rootZy_rootr	   r	   r
   Úunion4   s
   

zUnionFind.unionc                 C   s   |   |¡|   |¡kS r   )r   )r   r   r   r	   r	   r
   Úis_connected=   s   zUnionFind.is_connectedr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r	   r	   r
   r      s    
	r   N)r   r	   r	   r	   r
   Ú<module>   s   