
    Be                    T    d dl mZ d dlmZmZ d dlmZ d dlmZ  G d dee         Z	y)    )annotations)IterableIterator)
MutableSet)Tc                  v    e Zd ZU dZded<   dZdddZddZddZddZ	dd	Z
dd
ZddZddZddZeZddZy)InsertionSortedSetzA set-like that retains insertion order, like a dict. Thread-safe.

    Equality does not compare order or class, but only compares against the contents of
    any other set-like, coherently with dict and the AbstractSet design.
    zdict[T, None]_dr
   c                8    t         j                  |      | _        y N)dictfromkeysr
   )selfothers     *lib/python3.12/site-packages/zict/utils.py__init__zInsertionSortedSet.__init__   s    --&    c                    || j                   v S r   r   )r   items     r   __contains__zInsertionSortedSet.__contains__   s    twwr   c                ,    t        | j                        S r   )iterr
   r   s    r   __iter__zInsertionSortedSet.__iter__   s    DGG}r   c                ,    t        | j                        S r   )lenr
   r   s    r   __len__zInsertionSortedSet.__len__   s    477|r   c                "    d| j                   |<   y)zoAdd element to the set. If the element is already in the set, retain original
        insertion order.
        Nr   r   values     r   addzInsertionSortedSet.add   s     r   c                >    	 | j                   |= y # t        $ r Y y w xY wr   )r
   KeyErrorr    s     r   discardzInsertionSortedSet.discard%   s$    	 		s    	c                    | j                   |= y r   r   r    s     r   removezInsertionSortedSet.remove,   s    GGENr   c                    	 	 t        t        | j                              }| j                  |= |S # t        $ r t	        d      t        t
        f$ r Y Sw xY w)z(Pop the oldest-inserted key from the setzpop from an empty set)nextr   r
   StopIterationr$   RuntimeErrorr    s     r   popleftzInsertionSortedSet.popleft/   sW    T$'']+GGEN  8677l+ s   ,0 "AAc                <    | j                   j                         d   S )z(Pop the latest-inserted key from the setr   )r
   popitemr   s    r   poprightzInsertionSortedSet.popright<   s    ww ##r   c                8    | j                   j                          y r   )r
   clearr   s    r   r1   zInsertionSortedSet.clearB   s    r   N) )r   zIterable[T]returnNone)r   objectr3   bool)r3   zIterator[T])r3   int)r!   r   r3   r4   )r3   r   )r3   r4   )__name__
__module____qualname____doc____annotations__	__slots__r   r   r   r   r"   r%   r'   r,   r/   popr1   r2   r   r   r	   r	   	   sM     	I'$ Cr   r	   N)

__future__r   collections.abcr   r   typingr   zict.commonr   r	   r2   r   r   <module>rC      s!    " .  :A :r   