§
    bŠtjs(  ã                   óˆ   — d Z ddlmZmZ ddlmZ ddlZg d¢Z G d„ d¦  «        Z	 G d„ d	e	¦  «        Z
 G d
„ de	¦  «        ZdS )z
Min-heaps.
é    )ÚheappopÚheappush)ÚcountN)ÚMinHeapÚPairingHeapÚ
BinaryHeapc                   óf   — e Zd ZdZ G d„ d¦  «        Zd„ Zd„ Zd„ Zdd„Zdd
„Z	d„ Z
d„ Zd„ Zd„ ZdS )r   zúBase class for min-heaps.

    A MinHeap stores a collection of key-value pairs ordered by their values.
    It supports querying the minimum pair, inserting a new pair, decreasing the
    value in an existing pair and deleting the minimum pair.
    c                   ó"   — e Zd ZdZdZd„ Zd„ ZdS )úMinHeap._Itemz2Used by subclassess to represent a key-value pair.©ÚkeyÚvaluec                 ó"   — || _         || _        d S ©Nr   )Úselfr   r   s      úR/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/utils/heaps.pyÚ__init__zMinHeap._Item.__init__   s   € ØˆDŒHØˆDŒJˆJˆJó    c                 ó8   — t          | j        | j        f¦  «        S r   )Úreprr   r   ©r   s    r   Ú__repr__zMinHeap._Item.__repr__   s   € Ý˜œ 4¤:Ð.Ñ/Ô/Ð/r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   © r   r   Ú_Itemr      s=   € € € € € Ø@Ð@à$ˆ	ð	ð 	ð 	ð	0ð 	0ð 	0ð 	0ð 	0r   r   c                 ó   — i | _         dS )zInitialize a new min-heap.N©Ú_dictr   s    r   r   zMinHeap.__init__!   s   € àˆŒ
ˆ
ˆ
r   c                 ó   — t           ‚)a   Query the minimum key-value pair.

        Returns
        -------
        key, value : tuple
            The key-value pair with the minimum value in the heap.

        Raises
        ------
        NetworkXError
            If the heap is empty.
        ©ÚNotImplementedErrorr   s    r   ÚminzMinHeap.min%   ó
   € õ "Ð!r   c                 ó   — t           ‚)a  Delete the minimum pair in the heap.

        Returns
        -------
        key, value : tuple
            The key-value pair with the minimum value in the heap.

        Raises
        ------
        NetworkXError
            If the heap is empty.
        r$   r   s    r   ÚpopzMinHeap.pop4   r'   r   Nc                 ó   — t           ‚)a‰  Returns the value associated with a key.

        Parameters
        ----------
        key : hashable object
            The key to be looked up.

        default : object
            Default value to return if the key is not present in the heap.
            Default value: None.

        Returns
        -------
        value : object.
            The value associated with the key.
        r$   ©r   r   Údefaults      r   ÚgetzMinHeap.getC   s
   € õ" "Ð!r   Fc                 ó   — t           ‚)a<  Insert a new key-value pair or modify the value in an existing
        pair.

        Parameters
        ----------
        key : hashable object
            The key.

        value : object comparable with existing values.
            The value.

        allow_increase : bool
            Whether the value is allowed to increase. If False, attempts to
            increase an existing value have no effect. Default value: False.

        Returns
        -------
        decreased : bool
            True if a pair is inserted or the existing value is decreased.
        r$   )r   r   r   Úallow_increases       r   ÚinsertzMinHeap.insertV   s
   € õ* "Ð!r   c                 ó*   — t          | j        ¦  «        S ©z"Returns whether the heap if empty.©Úboolr"   r   s    r   Ú__nonzero__zMinHeap.__nonzero__m   ó   € å�D”JÑÔÐr   c                 ó*   — t          | j        ¦  «        S r2   r3   r   s    r   Ú__bool__zMinHeap.__bool__q   r6   r   c                 ó*   — t          | j        ¦  «        S )z2Returns the number of key-value pairs in the heap.)Úlenr"   r   s    r   Ú__len__zMinHeap.__len__u   s   € å�4”:‰ŒÐr   c                 ó   — || j         v S )z¡Returns whether a key exists in the heap.

        Parameters
        ----------
        key : any hashable object.
            The key to be looked up.
        r!   )r   r   s     r   Ú__contains__zMinHeap.__contains__y   s   € ð �d”jÐ Ð r   r   ©F)r   r   r   r   r   r   r&   r)   r-   r0   r5   r8   r;   r=   r   r   r   r   r      s×   € € € € € ðð ð
0ð 
0ð 
0ð 
0ð 
0ñ 
0ô 
0ð 
0ðð ð ð"ð "ð "ð"ð "ð "ð"ð "ð "ð "ð&"ð "ð "ð "ð. ð  ð  ð ð  ð  ðð ð ð!ð !ð !ð !ð !r   r   c                   óv   ‡ — e Zd ZdZ G d„ dej        ¦  «        Zˆ fd„Zd„ Zd„ Z	dd„Z
dd
„Zd„ Zd„ Zd„ Zˆ xZS )r   zA pairing heap.c                   ó&   ‡ — e Zd ZdZdZˆ fd„Zˆ xZS )úPairingHeap._NodezŠA node in a pairing heap.

        A tree in a pairing heap is stored using the left-child, right-sibling
        representation.
        )ÚleftÚnextÚprevÚparentc                 ó„   •— t          ¦   «                              ||¦  «         d | _        d | _        d | _        d | _        d S r   )Úsuperr   rB   rC   rD   rE   )r   r   r   Ú	__class__s      €r   r   zPairingHeap._Node.__init__�   s=   ø€ Ý‰GŒG×Ò˜S %Ñ(Ô(Ð(àˆDŒIàˆDŒIàˆDŒIàˆDŒKˆKˆKr   )r   r   r   r   r   r   Ú__classcell__©rH   s   @r   Ú_NoderA   ‡   sI   ø€ € € € € ð	ð 	ð 7ˆ	ð		ð 		ð 		ð 		ð 		ð 		ð 		ð 		ð 		r   rK   c                 óV   •— t          ¦   «                              ¦   «          d| _        dS )zInitialize a pairing heap.N)rG   r   Ú_root©r   rH   s    €r   r   zPairingHeap.__init__›   s$   ø€ å‰Œ×ÒÑÔÐØˆŒ
ˆ
ˆ
r   c                 óh   — | j         €t          j        d¦  «        ‚| j         j        | j         j        fS ©Nzheap is empty.)rM   ÚnxÚNetworkXErrorr   r   r   s    r   r&   zPairingHeap.min    s0   € ØŒ:ÐÝÔ"Ð#3Ñ4Ô4Ð4Ø”
” ¤
Ô 0Ð1Ð1r   c                 óº   — | j         €t          j        d¦  «        ‚| j         }|                      | j         ¦  «        | _         | j        |j        = |j        |j        fS rP   )rM   rQ   rR   Ú_merge_childrenr"   r   r   )r   Úmin_nodes     r   r)   zPairingHeap.pop¥   sU   € ØŒ:ÐÝÔ"Ð#3Ñ4Ô4Ð4Ø”:ˆØ×)Ò)¨$¬*Ñ5Ô5ˆŒ
ØŒJ�x”|Ð$Ø”˜hœnÐ-Ð-r   Nc                 óL   — | j                              |¦  «        }|�|j        n|S r   )r"   r-   r   )r   r   r,   Únodes       r   r-   zPairingHeap.get­   s&   € ØŒz�~Š~˜cÑ"Ô"ˆØ!Ð-ˆtŒzˆz°7Ð:r   Fc                 ó  — | j                              |¦  «        }| j        }|�¥||j        k     rM||_        ||ur@||j        j        k     r0|                      |¦  «         |                      ||¦  «        | _        dS |rI||j        k    r>||_        |                      |¦  «        }|� |                      | j        |¦  «        | _        dS |                      ||¦  «        }|| j         |<   |�|                      ||¦  «        n|| _        dS )NTF)	r"   r-   rM   r   rE   Ú_cutÚ_linkrT   rK   )r   r   r   r/   rW   ÚrootÚchilds          r   r0   zPairingHeap.insert±   s  € ØŒz�~Š~˜cÑ"Ô"ˆØŒzˆØÐØ�t”zÒ!Ð!Ø"�”
Ø˜tÐ#Ð#¨°´Ô0AÒ(AÐ(AØ—I’I˜d‘O”O�OØ!%§¢¨D°$Ñ!7Ô!7�D”JØ�tØð ? E¨D¬JÒ$6Ð$6Ø"�”
Ø×,Ò,¨TÑ2Ô2�ð Ð$Ø!%§¢¨D¬J¸Ñ!>Ô!>�D”Jð �5ð —:’:˜c 5Ñ)Ô)ˆDØ"ˆDŒJ�s‰OØ37Ð3C˜Ÿš D¨$Ñ/Ô/Ð/ÈˆDŒJØ�4r   c                 ó†   — |j         |j         k     r||}}|j        }||_        |�||_        d|_        ||_        ||_        |S )z_Link two nodes, making the one with the smaller value the parent of
        the other.
        N)r   rB   rC   rD   rE   )r   r[   ÚotherrC   s       r   rZ   zPairingHeap._linkÕ   sQ   € ð Œ;˜œÒ#Ð#Ø �%ˆDØŒyˆØˆŒ
ØÐØˆDŒIØˆŒ
ØˆŒ	ØˆŒØˆr   c                 ó
  — |j         }d|_         |�r| j        }d}	 |j        }|€||_        n"|j        } |||¦  «        }||_        |}|€n|}Œ3|j        }|�|j        } |||¦  «        }|}|­d|_        d|_        d|_        |S )z„Merge the subtrees of the root using the standard two-pass method.
        The resulting subtree is detached from the root.
        N)rB   rZ   rC   rD   rE   )r   r[   rW   ÚlinkrD   rC   Ú	next_nextÚ	prev_prevs           r   rT   zPairingHeap._merge_childrenä   sÈ   € ð ŒyˆØˆŒ	ØÐØ”:ˆDð
 ˆDð!Ø”y�Ø�<Ø $�D”IØØ œI�	Ø�t˜D $Ñ'Ô'�Ø �”	Ø�ØÐ$ØØ �ð!ð ”9ˆDØÐ"Ø œI�	Ø�t˜D $Ñ'Ô'�Ø �ð Ð"ð
 ˆDŒIØˆDŒIØˆDŒKØˆr   c                 óŠ   — |j         }|j        }|�||_        n||j        _        d|_         |�||_         d|_        d|_        dS )zCut a node from its parent.N)rD   rC   rE   rB   )r   rW   rD   rC   s       r   rY   zPairingHeap._cut
  sO   € àŒyˆØŒyˆØÐØˆDŒIˆIà#ˆDŒKÔØˆŒ	ØÐØˆDŒIØˆDŒIØˆŒˆˆr   r   r>   )r   r   r   r   r   r   rK   r   r&   r)   r-   r0   rZ   rT   rY   rI   rJ   s   @r   r   r   „   sß   ø€ € € € € ØÐðð ð ð ð �”ñ ô ð ð(ð ð ð ð ð
2ð 2ð 2ð
.ð .ð .ð;ð ;ð ;ð ;ð"ð "ð "ð "ðHð ð ð$ð $ð $ðLð ð ð ð ð ð r   r   c                   ó>   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd	d„Zd
d„Zˆ xZ	S )r   zA binary heap.c                 ó|   •— t          ¦   «                              ¦   «          g | _        t          ¦   «         | _        dS )zInitialize a binary heap.N)rG   r   Ú_heapr   Ú_countrN   s    €r   r   zBinaryHeap.__init__  s/   ø€ å‰Œ×ÒÑÔÐØˆŒ
Ý‘g”gˆŒˆˆr   c                 ó®   — | j         }|st          j        d¦  «        ‚| j        }	 |d         \  }}}||v r|||         k    rnt	          |¦  «         Œ-||fS ©Nzheap is emptyTr   ©r"   rQ   rR   rf   r   ©r   ÚdictÚheapr   Ú_r   s         r   r&   zBinaryHeap.min"  ss   € ØŒzˆØð 	4ÝÔ" ?Ñ3Ô3Ð3ØŒzˆð	Ø  œG‰MˆE�1�cØ�dˆ{ˆ{˜u¨¨S¬	Ò1Ð1ØÝ�D‰MŒMˆMð		ð
 �Uˆ|Ðr   c                 ó´   — | j         }|st          j        d¦  «        ‚| j        }	 |d         \  }}}t	          |¦  «         ||v r|||         k    rnŒ-||= ||fS ri   rj   rk   s         r   r)   zBinaryHeap.pop0  sz   € ØŒzˆØð 	4ÝÔ" ?Ñ3Ô3Ð3ØŒzˆð	Ø  œG‰MˆE�1�cÝ�D‰MŒMˆMØ�dˆ{ˆ{˜u¨¨S¬	Ò1Ð1Øð		ð
 �ˆIØ�Uˆ|Ðr   Nc                 ó8   — | j                              ||¦  «        S r   )r"   r-   r+   s      r   r-   zBinaryHeap.get?  s   € ØŒz�~Š~˜c 7Ñ+Ô+Ð+r   Fc                 ó  — | j         }||v rM||         }||k     s|r;||k    r5|||<   t          | j        |t          | j        ¦  «        |f¦  «         ||k     S dS |||<   t          | j        |t          | j        ¦  «        |f¦  «         dS )NFT)r"   r   rf   rC   rg   )r   r   r   r/   rl   Ú	old_values         r   r0   zBinaryHeap.insertB  s¤   € ØŒzˆØ�$ˆ;ˆ;Ø˜Sœ	ˆIØ�yÒ Ð  ^Ð ¸À	Ò8IÐ8Ið
 "��S‘	Ý˜œ e­T°$´+Ñ->Ô->ÀÐ%DÑEÔEÐEØ˜yÒ(Ð(Ø�5àˆD�‰IÝ�T”Z %­¨d¬kÑ):Ô):¸CÐ!@ÑAÔAÐAØ�4r   r   r>   )
r   r   r   r   r   r&   r)   r-   r0   rI   rJ   s   @r   r   r     s„   ø€ € € € € ØÐðð ð ð ð ðð ð ðð ð ð,ð ,ð ,ð ,ðð ð ð ð ð ð ð r   r   )r   Úheapqr   r   Ú	itertoolsr   ÚnetworkxrQ   Ú__all__r   r   r   r   r   r   ú<module>rw      sê   ððð ð $Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð à Ð Ð Ð à
2Ð
2Ð
2€ðt!ð t!ð t!ð t!ð t!ñ t!ô t!ð t!ðnRð Rð Rð Rð R�'ñ Rô Rð Rðj9ð 9ð 9ð 9ð 9�ñ 9ô 9ð 9ð 9ð 9r   