Ë
    D^(h—(  ã                   ót   — 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y)z
Min-heaps.
é    )ÚheappopÚheappush)ÚcountN)ÚMinHeapÚPairingHeapÚ
BinaryHeapc                   ó^   — 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y)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y)úMinHeap._Itemz2Used by subclassess to represent a key-value pair.©ÚkeyÚvaluec                 ó    — || _         || _        y ©Nr   )Úselfr   r   s      úR/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/utils/heaps.pyÚ__init__zMinHeap._Item.__init__   s   € ØˆDŒHØˆD�Jó    c                 óD   — 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   „ Ù@à$ˆ	ò	ó	0r   r   c                 ó   — i | _         y)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   c                 ó   — 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‘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‘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òò"ò"ó"ó&"ò. ò òó!r   r   c                   óz   ‡ — 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 | _        y r   )Úsuperr   rB   rC   rD   rE   )r   r   r   Ú	__class__s      €r   r   zPairingHeap._Node.__init__�   s.   ø€ Ü‰GÑ˜S %Ô(àˆDŒIàˆDŒIàˆDŒIàˆD�Kr   )r   r   r   r   r   r   Ú__classcell__©rH   s   @r   Ú_NoderA   ‡   s   ø„ ñ	ð 7ˆ	÷		ð 		r   rK   c                 ó0   •— t         ‰| �  «        d| _        y)zInitialize a pairing heap.N)rG   r   Ú_root©r   rH   s    €r   r   zPairingHeap.__init__›   s   ø€ ä‰ÑÔØˆ�
r   c                 óœ   — | 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    s;   € Ø�:‰:ÐÜ×"Ñ"Ð#3Ó4Ð4Ø—
‘
—‘ §
¡
× 0Ñ 0Ð1Ð1r   c                 óú   — | j                   €t        j                  d«      ‚| j                   }| j                  | j                   «      | _         | j                  |j
                  = |j
                  |j                  fS rP   )rM   rQ   rR   Ú_merge_childrenr"   r   r   )r   Úmin_nodes     r   r)   zPairingHeap.pop¥   s`   € Ø�:‰:ÐÜ×"Ñ"Ð#3Ó4Ð4Ø—:‘:ˆØ×)Ñ)¨$¯*©*Ó5ˆŒ
Ø�J‰J�x—|‘|Ð$Ø—‘˜hŸn™nÐ-Ð-r   c                 óX   — | j                   j                  |«      }|�|j                  S |S r   )r"   r-   r   )r   r   r,   Únodes       r   r-   zPairingHeap.get­   s(   € Ø�z‰z�~‰~˜cÓ"ˆØ!Ð-ˆt�z‰zÐ:°7Ð:r   c                 ó,  — | j                   j                  |«      }| j                  }|�©||j                  k  rM||_        ||urA||j                  j                  k  r(| j                  |«       | j                  ||«      | _        y|rJ||j                  kD  r;||_        | j                  |«      }|�!| j                  | j                  |«      | _        y| j                  ||«      }|| j                   |<   |�| j                  ||«      | _        y|| _        y)NTF)	r"   r-   rM   r   rE   Ú_cutÚ_linkrT   rK   )r   r   r   r/   rW   ÚrootÚchilds          r   r0   zPairingHeap.insert±   sþ   € Ø�z‰z�~‰~˜cÓ"ˆØ�z‰zˆØÐØ�t—z‘zÒ!Ø"�”
Ø˜tÑ#¨°·±×0AÑ0AÒ(AØ—I‘I˜d”OØ!%§¡¨D°$Ó!7�D”JØÙ E¨D¯J©JÒ$6Ø"�”
Ø×,Ñ,¨TÓ2�ð Ð$Ø!%§¡¨D¯J©J¸Ó!>�D”Jð ð —:‘:˜c 5Ó)ˆDØ"ˆD�J‰J�s‰OØ37Ð3C˜Ÿ™ D¨$Ó/ˆDŒJØð JNˆDŒJØr   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Õ   sT   € ð �;‰;˜Ÿ™Ò#Ø �%ˆDØ�y‰yˆØˆŒ
ØÐØˆDŒIØˆŒ
ØˆŒ	ØˆŒØˆr   c                 ó<  — |j                   }d|_         |�†| j                  }d}	 |j                  }|€||_        n$|j                  } |||«      }||_        |}|€n|}Œ:|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‰yˆØˆŒ	ØÐØ—:‘:ˆDð
 ˆDØØ—y‘y�Ø�<Ø $�D”IØØ ŸI™I�	Ù˜D $Ó'�Ø �”	Ø�ØÐ$ØØ �ð ð —9‘9ˆDØÐ"Ø ŸI™I�	Ù˜D $Ó'�Ø �ð Ñ"ð
 ˆDŒIØˆDŒIØˆDŒKØˆr   c                 ó¦   — |j                   }|j                  }|�||_        n||j                  _        d|_         |�||_         d|_        d|_        y)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ˆØ�y‰yˆØÐØˆD�Ià#ˆD�K‰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ò
.ó;ó"ò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                 óN   •— t         ‰| �  «        g | _        t        «       | _        y)zInitialize a binary heap.N)rG   r   Ú_heapr   Ú_countrN   s    €r   r   zBinaryHeap.__init__  s   ø€ ä‰ÑÔØˆŒ
Ü“gˆ�r   c                 ó´   — | j                   }|st        j                  d«      ‚| j                  }t        }	 |d   \  }}}||v r|||   k(  r	 ||fS  ||«       Œ#©Nzheap is emptyr   ©r"   rQ   rR   rf   r   ©r   ÚdictÚheapr)   r   Ú_r   s          r   r&   zBinaryHeap.min"  sn   € Ø�z‰zˆÙÜ×"Ñ" ?Ó3Ð3Ø�z‰zˆÜˆð Ø  ™G‰MˆE�1�cØ�d‰{˜u¨¨S©	Ò1Øà�Uˆ|Ðñ �ŒIð	 r   c                 óº   — | j                   }|st        j                  d«      ‚| j                  }t        }	 |d   \  }}} ||«       ||v r	|||   k(  rnŒ||= ||fS ri   rj   rk   s          r   r)   zBinaryHeap.pop1  su   € Ø�z‰zˆÙÜ×"Ñ" ?Ó3Ð3Ø�z‰zˆÜˆð Ø  ™G‰MˆE�1�cÙ�ŒIØ�d‰{˜u¨¨S©	Ò1Øð	 ð
 �ˆIØ�Uˆ|Ðr   c                 ó:   — | j                   j                  ||«      S r   )r"   r-   r+   s      r   r-   zBinaryHeap.getA  s   € Ø�z‰z�~‰~˜c 7Ó+Ð+r   c                 ó  — | j                   }||v rH||   }||k  s|r;||kD  r6|||<   t        | j                  |t        | j                  «      |f«       ||k  S y|||<   t        | j                  |t        | j                  «      |f«       y)NFT)r"   r   rf   rC   rg   )r   r   r   r/   rl   Ú	old_values         r   r0   zBinaryHeap.insertD  s�   € Ø�z‰zˆØ�$‰;Ø˜S™	ˆIØ�yÒ ¡^¸À	Ò8Ið
 "��S‘	Ü˜Ÿ™ e¬T°$·+±+Ó->ÀÐ%DÔEØ˜yÑ(Ð(ØàˆD�‰IÜ�T—Z‘Z %¬¨d¯k©kÓ):¸CÐ!@ÔAØr   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      sB   ðñ÷ $Ý ã â
2€÷t!ñ t!ônR�'ô Rôj;�õ ;r   