Ë
    D^(hÈ'  ã                   ó>   — d Z ddlZdgZ G d„ d«      Z G d„ d«      Zy)ú/Priority queue class with updatable priorities.é    NÚMappedQueuec                   óH   — e Zd ZdZg d¢Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zy)Ú_HeapElementaÕ  This proxy class separates the heap element from its priority.

    The idea is that using a 2-tuple (priority, element) works
    for sorting, but not for dict lookup because priorities are
    often floating point values so round-off can mess up equality.

    So, we need inequalities to look at the priority (for sorting)
    and equality (and hash) to look at the element to enable
    updates to the priority.

    Unfortunately, this class can be tricky to work with if you forget that
    `__lt__` compares the priority while `__eq__` compares the element.
    In `greedy_modularity_communities()` the following code is
    used to check that two _HeapElements differ in either element or priority:

        if d_oldmax != row_max or d_oldmax.priority != row_max.priority:

    If the priorities are the same, this implementation uses the element
    as a tiebreaker. This provides compatibility with older systems that
    use tuples to combine priority and elements.
    )ÚpriorityÚelementÚ_hashc                 ó@   — || _         || _        t        |«      | _        y ©N)r   r   Úhashr	   )Úselfr   r   s      úY/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/utils/mapped_queue.pyÚ__init__z_HeapElement.__init__!   s   € Ø ˆŒØˆŒÜ˜'“]ˆ�
ó    c                 ó   — 	 |j                   }| j                   |k(  r	 | j                  |j                  k  S | j                   |k  S # t        $ r | j                   |k  cY S w xY w# t        $ r}t        d«      ‚d }~ww xY w©NzCConsider using a tuple, with a priority value that can be compared.©r   ÚAttributeErrorr   Ú	TypeError©r   ÚotherÚother_priorityÚerrs       r   Ú__lt__z_HeapElement.__lt__&   óˆ   € ð	)Ø"Ÿ^™^ˆNð �=‰=˜NÒ*ðØ—|‘| e§m¡mÑ3Ð3ð
 �}‰}˜~Ñ-Ð-øô ò 	)Ø—=‘= 5Ñ(Ò(ð	)ûô ò ÜØYóð ûðúó(   ‚A žA$ ÁA!Á A!Á$	A=Á-A8Á8A=c                 ó   — 	 |j                   }| j                   |k(  r	 | j                  |j                  kD  S | j                   |kD  S # t        $ r | j                   |kD  cY S w xY w# t        $ r}t        d«      ‚d }~ww xY wr   r   r   s       r   Ú__gt__z_HeapElement.__gt__5   r   r   c                 ór   — 	 | j                   |j                   k(  S # t        $ r | j                   |k(  cY S w xY wr   )r   r   )r   r   s     r   Ú__eq__z_HeapElement.__eq__D   s8   € ð	)Ø—<‘< 5§=¡=Ñ0Ð0øÜò 	)Ø—<‘< 5Ñ(Ò(ð	)ús   ‚ ›6µ6c                 ó   — | j                   S r   )r	   ©r   s    r   Ú__hash__z_HeapElement.__hash__J   s   € Ø�z‰zÐr   c                 óH   — |dk(  r| j                   S | j                  |dz
     S )Nr   é   ©r   r   )r   Úindxs     r   Ú__getitem__z_HeapElement.__getitem__M   s$   € Ø $¨¢	ˆt�}‰}ÐE¨t¯|©|¸DÀ1¹HÑ/EÐEr   c              #   ó�   K  — | j                   –— 	 | j                  E d {  –—†  y 7 Œ# t        $ r | j                  –— Y y w xY w­wr   )r   r   r   r"   s    r   Ú__iter__z_HeapElement.__iter__P   s:   è ø€ Ø�m‰mÒð	Ø—|‘|×#Ò#ùÜò 	Ø—,‘,Ôð	üs1   ‚A’) ¡'¢) ¦A§) ©AÁ AÁAÁAc                 ó<   — d| j                   › d| j                  › d�S )Nz_HeapElement(z, ú)r&   r"   s    r   Ú__repr__z_HeapElement.__repr__W   s   € Ø˜tŸ}™}˜o¨R°·±¨~¸QÐ?Ð?r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r    r#   r(   r*   r-   © r   r   r   r      s8   „ ñò, 1€Iò#ò
.ò.ò)òòFòó@r   r   c                   óL   — e Zd ZdZdd„Zd„ Zd„ Zdd„Zd„ Zdd„Z	d	„ Z
d
„ Zd„ Zy)r   a×  The MappedQueue class implements a min-heap with removal and update-priority.

    The min heap uses heapq as well as custom written _siftup and _siftdown
    methods to allow the heap positions to be tracked by an additional dict
    keyed by element to position. The smallest element can be popped in O(1) time,
    new elements can be pushed in O(log n) time, and any element can be removed
    or updated in O(log n) time. The queue cannot contain duplicate elements
    and an attempt to push an element already in the queue will have no effect.

    MappedQueue complements the heapq package from the python standard
    library. While MappedQueue is designed for maximum compatibility with
    heapq, it adds element removal, lookup, and priority update.

    Parameters
    ----------
    data : dict or iterable

    Examples
    --------

    A `MappedQueue` can be created empty, or optionally, given a dictionary
    of initial elements and priorities.  The methods `push`, `pop`,
    `remove`, and `update` operate on the queue.

    >>> colors_nm = {"red": 665, "blue": 470, "green": 550}
    >>> q = MappedQueue(colors_nm)
    >>> q.remove("red")
    >>> q.update("green", "violet", 400)
    >>> q.push("indigo", 425)
    True
    >>> [q.pop().element for i in range(len(q.heap))]
    ['violet', 'indigo', 'blue']

    A `MappedQueue` can also be initialized with a list or other iterable. The priority is assumed
    to be the sort order of the items in the list.

    >>> q = MappedQueue([916, 50, 4609, 493, 237])
    >>> q.remove(493)
    >>> q.update(237, 1117)
    >>> [q.pop() for i in range(len(q.heap))]
    [50, 916, 1117, 4609]

    An exception is raised if the elements are not comparable.

    >>> q = MappedQueue([100, "a"])
    Traceback (most recent call last):
    ...
    TypeError: '<' not supported between instances of 'int' and 'str'

    To avoid the exception, use a dictionary to assign priorities to the elements.

    >>> q = MappedQueue({100: 0, "a": 1})

    References
    ----------
    .. [1] Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2001).
       Introduction to algorithms second edition.
    .. [2] Knuth, D. E. (1997). The art of computer programming (Vol. 3).
       Pearson Education.
    Nc                 óø   — |€g | _         nSt        |t        «      r3|j                  «       D ��cg c]  \  }}t	        ||«      ‘Œ c}}| _         nt        |«      | _         i | _        | j                  «        yc c}}w )r   N)ÚheapÚ
isinstanceÚdictÚitemsr   ÚlistÚpositionÚ_heapify)r   ÚdataÚkÚvs       r   r   zMappedQueue.__init__™   s\   € àˆ<ØˆD�IÜ˜œdÔ#Ø8<¿
¹
»×E±°°1œ a¨Õ+ÓEˆD�Iä˜T›
ˆDŒIØˆŒØ�‰�ùó	 Fs   ®A6c                 ó  — t        j                  | j                  «       t        | j                  «      D ��ci c]  \  }}||“Œ
 c}}| _        t        | j                  «      t        | j                  «      k7  rt        d«      ‚yc c}}w )z+Restore heap invariant and recalculate map.z Heap contains duplicate elementsN)ÚheapqÚheapifyr6   Ú	enumerater;   ÚlenÚAssertionError)r   ÚposÚelts      r   r<   zMappedQueue._heapify¤   se   € ä�‰�d—i‘iÔ Ü2;¸D¿I¹IÓ2F×G¡h c¨3˜˜c™ÓGˆŒÜˆt�y‰y‹>œS §¡Ó/Ò/Ü Ð!CÓDÐDð 0ùó Hs   ¸Bc                 ó,   — t        | j                  «      S r   )rD   r6   r"   s    r   Ú__len__zMappedQueue.__len__«   s   € Ü�4—9‘9‹~Ðr   c                 óà   — |�t        ||«      }|| j                  v ryt        | j                  «      }| j                  j	                  |«       || j                  |<   | j                  d|«       y)zAdd an element to the queue.Fr   T)r   r;   rD   r6   ÚappendÚ	_siftdown)r   rG   r   rF   s       r   ÚpushzMappedQueue.push®   sa   € àÐÜ˜x¨Ó-ˆCà�$—-‘-ÑØä�$—)‘)‹nˆØ�	‰	×Ñ˜ÔØ ˆ�‰�cÑà�‰�q˜#ÔØr   c                 ó8  — | j                   d   }| j                  |= t        | j                   «      dk(  r| j                   j                  «        |S | j                   j                  «       }|| j                   d<   d| j                  |<   | j	                  d«       |S )z4Remove and return the smallest element in the queue.r   r%   )r6   r;   rD   ÚpopÚ_siftup)r   rG   Úlasts      r   rO   zMappedQueue.pop½   sy   € ð �i‰i˜‰lˆØ�M‰M˜#Ðäˆt�y‰y‹>˜QÒØ�I‰I�M‰MŒOØˆJà�y‰y�}‰}‹ˆØˆ�	‰	�!‰Øˆ�‰�dÑà�‰�QŒàˆ
r   c                 ó¶   — |�t        ||«      }| j                  |   }|| j                  |<   | j                  |= || j                  |<   | j                  |«       y)z/Replace an element in the queue with a new one.N)r   r;   r6   rP   )r   rG   Únewr   rF   s        r   ÚupdatezMappedQueue.updateÏ   sU   € àÐÜ˜x¨Ó-ˆCà�m‰m˜CÑ ˆØˆ�	‰	�#‰Ø�M‰M˜#ÐØ ˆ�‰�cÑà�‰�SÕr   c                 óX  — 	 | j                   |   }| j                   |= |t        | j                  «      dz
  k(  r| j                  j	                  «        y| j                  j	                  «       }|| j                  |<   || j                   |<   | j                  |«       y# t        $ r ‚ w xY w)z!Remove an element from the queue.r%   N)r;   ÚKeyErrorrD   r6   rO   rP   )r   rG   rF   rQ   s       r   ÚremovezMappedQueue.removeÛ   s’   € ð	Ø—-‘- Ñ$ˆCØ—‘˜cÐ"ð
 ”#�d—i‘i“. 1Ñ$Ò$Ø�I‰I�M‰MŒOØà�y‰y�}‰}‹ˆØˆ�	‰	�#‰Ø!ˆ�‰�dÑà�‰�SÕøô ò 	àð	ús   ‚B ÂB)c                 óH  — | j                   | j                  }}t        |«      }|}||   }|dz  dz   }||k  r7||   }|dz   }	|	|k  r||	   }
||
k  s|
}|	}|||<   |||<   |}|dz  dz   }||k  rŒ7|dkD  r%|dz
  dz	  }||   }||k  sn|||<   |||<   |}|dkD  rŒ%|||<   |||<   y)zŒMove smaller child up until hitting a leaf.

        Built to mimic code for heapq._siftup
        only updating position dict too.
        r%   r   N)r6   r;   rD   )r   rF   r6   r;   Úend_posÚstartposÚnewitemÚ	child_posÚchildÚ	right_posÚrightÚ
parent_posÚparents                r   rP   zMappedQueue._siftupï   s  € ð Ÿ™ D§M¡MˆhˆÜ�d“)ˆØˆØ�s‘)ˆà˜A‘X ‘Nˆ	Ø˜'Ò!à˜‘OˆEØ! A™ˆIØ˜7Ò"Ø˜Y™�Ø˜u’}Ø!�EØ )�IàˆD�‰IØ!ˆH�U‰OØˆCØ ™ Q™ˆIð ˜'Ó!ð  �AŠgØ ™' a™ˆJØ˜*Ñ%ˆFØ˜VÒ#ØØˆD�‰IØ"ˆH�VÑØˆCð �A‹gð ˆˆS‰	Øˆ�Òr   c                 ó¦   — | j                   | j                  }}||   }||kD  r%|dz
  dz	  }||   }||k  sn|||<   |||<   |}||kD  rŒ%|||<   |||<   y)zžRestore invariant. keep swapping with parent until smaller.

        Built to mimic code for heapq._siftdown
        only updating position dict too.
        r%   N)r6   r;   )r   Ú	start_posrF   r6   r;   r[   r`   ra   s           r   rL   zMappedQueue._siftdown  s   € ð Ÿ™ D§M¡MˆhˆØ�s‘)ˆð �IŠoØ ™' a™ˆJØ˜*Ñ%ˆFØ˜VÒ#ØØˆD�‰IØ"ˆH�VÑØˆCð �I‹oð ˆˆS‰	Øˆ�Òr   r   )r.   r/   r0   r1   r   r<   rI   rM   rO   rT   rW   rP   rL   r3   r   r   r   r   [   s7   „ ñ;óz	òEòóòó$
òò(% óN r   )r1   rA   Ú__all__r   r   r3   r   r   ú<module>re      s-   ðÙ 5ã àˆ/€÷P@ñ P@÷fN ò N r   