
    Tg%eM	                     H    d dl mZmZmZmZmZ d dlmZ  G d d          ZdS )    )AnyCallableIterableListOptional)	BaseQueuec                       e Zd ZdZddeegef         dee         ddfdZdd	e	d
eddfdZ
dee	         fdZdee	         fdZdee         fdZdefdZdS )PriorityQueuea  A priority queue implemented using multiple internal queues (typically,
    FIFO queues). The internal queue must implement the following methods:

        * push(obj)
        * pop()
        * peek()
        * close()
        * __len__()

    The constructor receives a qfactory argument, which is a callable used to
    instantiate a new (internal) queue when a new priority is allocated. The
    qfactory function is called with the priority number as first and only
    argument.

    Only integer priorities should be used. Lower numbers are higher
    priorities.

    startprios is a sequence of priorities to start with. If the queue was
    previously closed leaving some priority buckets non-empty, those priorities
    should be passed in startprios.

     qfactory
startpriosreturnNc                     i | _         || _        |D ]}|                     |          | j         |<    |rt          |          nd | _        d S N)queuesr   mincurprio)selfr   r   ps       /lib/python3.11/site-packages/queuelib/pqueue.py__init__zPriorityQueue.__init__   sR      	. 	.A!]]1--DKNN*4>s:$    r   objpriorityc                     || j         vr|                     |          | j         |<   | j         |         }|                    |           | j        || j        k     r	|| _        d S d S r   )r   r   pushr   )r   r   r   qs       r   r   zPriorityQueue.push%   si    4;&&$(MM($;$;DK!K!	s<8dl#:#:#DLLL $;#:r   c                 B   | j         d S | j        | j                  }|                                }t          |          dk    r\| j        | j         = |                                 d | j                                        D             }|rt          |          nd | _         |S )Nr   c                 >    g | ]\  }}t          |          d k    |S r   len).0r   r   s      r   
<listcomp>z%PriorityQueue.pop.<locals>.<listcomp>5   s'    EEE41a#a&&1**Q***r   )r   r   popr"   closeitemsr   )r   r   mprioss       r   r%   zPriorityQueue.pop-   s    <4K%EEGGq66Q;;DL)GGIIIEE4;#4#4#6#6EEEE).83u:::DDLr   c                 \    | j         d S | j        | j                                                  S r   )r   r   peekr   s    r   r+   zPriorityQueue.peek9   s*    <4{4<(--///r   c                     g }| j                                         D ]=\  }}t          |          r|                    |           |                                 >|S r   )r   r'   r"   appendr&   )r   activer   r   s       r   r&   zPriorityQueue.close>   s\    K%%'' 	 	DAq1vv !a   GGIIIIr   c                 t    | j         r0t          d | j                                         D                       ndS )Nc              3   4   K   | ]}t          |          V  d S r   r!   )r#   xs     r   	<genexpr>z(PriorityQueue.__len__.<locals>.<genexpr>G   s(      88a3q66888888r   r   )r   sumvaluesr,   s    r   __len__zPriorityQueue.__len__F   s9    <@KNs884;#5#5#7#7888888QNr   )r   r    )__name__
__module____qualname____doc__r   intr   r   r   r   r   r   r%   r+   r   r&   r6   r   r   r   r
   r
      s        .? ?3%*:!; ?RU ?`d ? ? ? ?$ $ $s $4 $ $ $ $
Xc] 
 
 
 
0hsm 0 0 0 0
tCy    O O O O O O Or   r
   N)	typingr   r   r   r   r   queuelib.queuer   r
   r   r   r   <module>r>      s    : : : : : : : : : : : : : : $ $ $ $ $ $AO AO AO AO AO AO AO AO AO AOr   