
    8iB                         d Z ddlZddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZ  ed      ZdZ ed      Zee
e   ee   f   Zee
e   ee   ee   f   ZdedefdZ G d	 d
e	e   ee         Zy)a  
An OrderedSet is a custom MutableSet that remembers its order, so that every
entry has an index that can be looked up. It can also act like a Sequence.

Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger,
and released under the MIT license.
    N)AnyDictIterableIteratorList
MutableSetAbstractSetSequenceSetTypeVarUnionoverloadz4.1.0Tobjreturnc                 F    t        | t              xs t        | t              S )ak  
    Returns True for objects which are iterable but should not be iterated in
    the context of indexing an OrderedSet.

    When we index by an iterable, usually that means we're being asked to look
    up a list of things.

    However, in the case of the .index() method, we shouldn't handle strings
    and tuples like other iterables. They're not sequences of things to look
    up, they're the single, atomic thing we're trying to find.

    As an example, oset.index('hello') should give the index of 'hello' in an
    OrderedSet of strings. It shouldn't give the indexes of each individual
    character.
    )
isinstancestrtuple)r   s    G/var/www/html/venv/lib/python3.12/site-packages/ordered_set/__init__.py
_is_atomicr   $   s      c39:c5#99    c                   x   e Zd ZdZd-dee   fdZd Zede	ddfd	       Z
edee   dee   fd
       Z
ededefd       Z
d Z
d.dZd Zd ZdedefdZdedefdZeZdee   defdZedee   dee   fd       Zededefd       Zd ZeZeZd/defdZdeddfdZd0dZdee   fdZdee   fdZ de!fdZ"dedefdZ#d ee   ddfd!Z$dee   ddfd"Z%d ee   ddfd#Z&d ee   ddfd$Z'dee   defd%Z(dee   defd&Z)dee   ddfd'Z*d(e+ddfd)Z,d ee   ddfd*Z-dee   ddfd+Z.dee   ddfd,Z/y)1
OrderedSetz
    An OrderedSet is a custom MutableSet that remembers its order, so that
    every entry has an index that can be looked up.

    Example:
        >>> OrderedSet([1, 1, 2, 3, 2])
        OrderedSet([1, 2, 3])
    Ninitialc                 0    g | _         i | _        || |z  } y y N)itemsmap)selfr   s     r   __init__zOrderedSet.__init__A   s&     
!# GOD	 r   c                 ,    t        | j                        S )z
        Returns the number of unique elements in the ordered set

        Example:
            >>> len(OrderedSet([]))
            0
            >>> len(OrderedSet([1, 2]))
            2
        )lenr   r    s    r   __len__zOrderedSet.__len__J   s     4::r   indexr   OrderedSet[T]c                      y r    r    r&   s     r   __getitem__zOrderedSet.__getitem__V       r   c                      y r   r)   r*   s     r   r+   zOrderedSet.__getitem__Z   r,   r   c                      y r   r)   r*   s     r   r+   zOrderedSet.__getitem__^   r,   r   c                 p   t        |t              r|t        k(  r| j                         S t        |t              r|D cg c]  }| j
                  |    c}S t        |t              st        |d      r2| j
                  |   }t        |t              r| j                  |      S |S t        d|z        c c}w )aQ  
        Get the item at a given index.

        If `index` is a slice, you will get back that slice of items, as a
        new OrderedSet.

        If `index` is a list or a similar iterable, you'll get a list of
        items corresponding to those indices. This is similar to NumPy's
        "fancy indexing". The result is not an OrderedSet because you may ask
        for duplicate indices, and the number of elements returned should be
        the number of elements asked for.

        Example:
            >>> oset = OrderedSet([1, 2, 3])
            >>> oset[1]
            2
        	__index__z+Don't know how to index an OrderedSet by %r)
r   slice	SLICE_ALLcopyr   r   hasattrlist	__class__	TypeError)r    r&   iresults       r   r+   zOrderedSet.__getitem__c   s    $ eU#(:99;x(+01aDJJqM11u%)DZZ&F&$'~~f--IEQRR 2s   B3c                 $    | j                  |       S )z
        Return a shallow copy of this object.

        Example:
            >>> this = OrderedSet([1, 2, 3])
            >>> other = this.copy()
            >>> this == other
            True
            >>> this is other
            False
        )r6   r$   s    r   r3   zOrderedSet.copy   s     ~~d##r   c                 6    t        |       dk(  ryt        |       S )Nr   r   )r#   r5   r$   s    r   __getstate__zOrderedSet.__getstate__   s    t9> :r   c                 T    |dk(  r| j                  g        y | j                  |       y )Nr   )r!   )r    states     r   __setstate__zOrderedSet.__setstate__   s"    GMM"MM% r   keyc                     || j                   v S )z
        Test if the item is in this ordered set.

        Example:
            >>> 1 in OrderedSet([1, 3, 2])
            True
            >>> 5 in OrderedSet([1, 3, 2])
            False
        )r   r    r@   s     r   __contains__zOrderedSet.__contains__   s     dhhr   c                     || j                   vr=t        | j                        | j                   |<   | j                  j                  |       | j                   |   S )aE  
        Add `key` as an item to this OrderedSet, then return its index.

        If `key` is already in the OrderedSet, return the index it already
        had.

        Example:
            >>> oset = OrderedSet()
            >>> oset.append(3)
            0
            >>> print(oset)
            OrderedSet([3])
        )r   r#   r   appendrB   s     r   addzOrderedSet.add   sE     dhh

ODHHSMJJc"xx}r   sequencec                     d}	 |D ]  }| j                  |      } 	 |S # t        $ r t        dt        |      z        w xY w)a<  
        Update the set with the given iterable sequence, then return the index
        of the last element inserted.

        Example:
            >>> oset = OrderedSet([1, 2, 3])
            >>> oset.update([3, 1, 5, 1, 4])
            4
            >>> print(oset)
            OrderedSet([1, 2, 3, 5, 4])
        r   z(Argument needs to be an iterable, got %s)rF   r7   
ValueErrortype)r    rG   
item_indexitems       r   updatezOrderedSet.update   s\     
	  ,!XXd^
, 	  	:T(^K 	s	    !A c                      y r   r)   rB   s     r   r&   zOrderedSet.index   r,   r   c                      y r   r)   rB   s     r   r&   zOrderedSet.index   r,   r   c                     t        |t              r*t        |      s|D cg c]  }| j                  |       c}S | j                  |   S c c}w )aH  
        Get the index of a given entry, raising an IndexError if it's not
        present.

        `key` can be an iterable of entries that is not a string, in which case
        this returns a list of indices.

        Example:
            >>> oset = OrderedSet([1, 2, 3])
            >>> oset.index(2)
            1
        )r   r   r   r&   r   )r    r@   subkeys      r   r&   zOrderedSet.index   sA     c8$Z_5896DJJv&99xx} :s   A
c                     | j                   st        d      | j                   |   }| j                   |= | j                  |= |S )a  
        Remove and return item at index (default last).

        Raises KeyError if the set is empty.
        Raises IndexError if index is out of range.

        Example:
            >>> oset = OrderedSet([1, 2, 3])
            >>> oset.pop()
            3
        zSet is empty)r   KeyErrorr   )r    r&   elems      r   popzOrderedSet.pop   s@     zz>**zz% JJuHHTNr   c                     || v rd| j                   |   }| j                  |= | j                   |= | j                   j                         D ]  \  }}||k\  s|dz
  | j                   |<    yy)a  
        Remove an element.  Do not raise an exception if absent.

        The MutableSet mixin uses this to implement the .remove() method, which
        *does* raise an error when asked to remove a non-existent item.

        Example:
            >>> oset = OrderedSet([1, 2, 3])
            >>> oset.discard(2)
            >>> print(oset)
            OrderedSet([1, 3])
            >>> oset.discard(2)
            >>> print(oset)
            OrderedSet([1, 3])
           N)r   r   )r    r@   r8   kvs        r   discardzOrderedSet.discard  si      $;A

1( (16"#a%DHHQK(	 r   c                 V    | j                   dd= | j                  j                          y)z8
        Remove all items from this OrderedSet.
        N)r   r   clearr$   s    r   r\   zOrderedSet.clear)  s     JJqMr   c                 ,    t        | j                        S )zb
        Example:
            >>> list(iter(OrderedSet([1, 2, 3])))
            [1, 2, 3]
        )iterr   r$   s    r   __iter__zOrderedSet.__iter__0  s     DJJr   c                 ,    t        | j                        S )zf
        Example:
            >>> list(reversed(OrderedSet([1, 2, 3])))
            [3, 2, 1]
        )reversedr   r$   s    r   __reversed__zOrderedSet.__reversed__8  s     

##r   c                     | s| j                   j                  dS | j                   j                  dt        |       dS )Nz()())r6   __name__r5   r$   s    r   __repr__zOrderedSet.__repr__@  s1    !^^4466>>22DJ??r   otherc                     t        |t              rt        |       t        |      k(  S 	 t        |      }t        |       |k(  S # t        $ r Y yw xY w)a  
        Returns true if the containers have the same items. If `other` is a
        Sequence, then order is checked, otherwise it is ignored.

        Example:
            >>> oset = OrderedSet([1, 3, 2])
            >>> oset == [1, 3, 2]
            True
            >>> oset == [1, 2, 3]
            False
            >>> oset == [2, 3]
            False
            >>> oset == OrderedSet([3, 2, 1])
            False
        F)r   r
   r5   setr7   )r    rh   other_as_sets      r   __eq__zOrderedSet.__eq__E  sV      eX& :e,,	-u:L
 t9,,	  		s   A 	AAsetsc                     t         }t        | t               r| j                  }t        t        t        j                  | g|            }t
        j                  j                  |      } ||      S )a  
        Combines all unique items.
        Each items order is defined by its first appearance.

        Example:
            >>> oset = OrderedSet.union(OrderedSet([3, 1, 4, 1, 5]), [1, 3], [2, 0])
            >>> print(oset)
            OrderedSet([3, 1, 4, 5, 2, 0])
            >>> oset.union([8, 9])
            OrderedSet([3, 1, 4, 5, 2, 0, 8, 9])
            >>> oset | {10}
            OrderedSet([3, 1, 4, 5, 2, 0, 10])
        )r   r   r6   r   r5   itchainfrom_iterable)r    rm   cls
containersr   s        r   unionzOrderedSet.uniona  sS     dJ'..Crxx56
&&z25zr   c                 $    | j                  |      S r   )intersectionr    rh   s     r   __and__zOrderedSet.__and__v  s      ''r   c                     t         }| }t        | t               r| j                  }|r+t        j                  t        t        |       fd| D        } ||      S )a  
        Returns elements in common between all sets. Order is defined only
        by the first set.

        Example:
            >>> oset = OrderedSet.intersection(OrderedSet([0, 1, 2, 3]), [1, 2, 3])
            >>> print(oset)
            OrderedSet([1, 2, 3])
            >>> oset.intersection([2, 4, 5], [1, 2, 3, 4])
            OrderedSet([2])
            >>> oset.intersection()
            OrderedSet([1, 2, 3])
        c              3   ,   K   | ]  }|v s|  y wr   r)   ).0rL   commons     r   	<genexpr>z*OrderedSet.intersection.<locals>.<genexpr>  s     =ddfnT=   	)r   r   r6   rj   rv   r   )r    rm   rr   r   r|   s       @r   rv   zOrderedSet.intersectionz  sO     *.dJ'..C%%s3~6F=d=E5zr   c                     | j                   }| }|r+t        j                  t        t        |       fd| D        } ||      S )a  
        Returns all elements that are in this set but not the others.

        Example:
            >>> OrderedSet([1, 2, 3]).difference(OrderedSet([2]))
            OrderedSet([1, 3])
            >>> OrderedSet([1, 2, 3]).difference(OrderedSet([2]), OrderedSet([3]))
            OrderedSet([1])
            >>> OrderedSet([1, 2, 3]) - OrderedSet([2])
            OrderedSet([1, 3])
            >>> OrderedSet([1, 2, 3]).difference()
            OrderedSet([1, 2, 3])
        c              3   ,   K   | ]  }|vs|  y wr   r)   r{   rL   rh   s     r   r}   z(OrderedSet.difference.<locals>.<genexpr>  s     @dd%.?T@r~   )r6   rj   rt   r   )r    rm   rr   r   rh   s       @r   
differencezOrderedSet.difference  s>     nn*.IIs3~.E@d@E5zr   c                 \    t        |       t              kD  ryt        fd| D              S )a7  
        Report whether another set contains this set.

        Example:
            >>> OrderedSet([1, 2, 3]).issubset({1, 2})
            False
            >>> OrderedSet([1, 2, 3]).issubset({1, 2, 3, 4})
            True
            >>> OrderedSet([1, 2, 3]).issubset({1, 4, 3, 5})
            False
        Fc              3   &   K   | ]  }|v  
 y wr   r)   r   s     r   r}   z&OrderedSet.issubset.<locals>.<genexpr>  s     2T45=2   r#   allrw   s    `r   issubsetzOrderedSet.issubset  s)     t9s5z!2T222r   c                 \     t               t        |      k  ryt         fd|D              S )a=  
        Report whether this set contains another set.

        Example:
            >>> OrderedSet([1, 2]).issuperset([1, 2, 3])
            False
            >>> OrderedSet([1, 2, 3, 4]).issuperset({1, 2, 3})
            True
            >>> OrderedSet([1, 4, 3, 5]).issuperset({1, 2, 3})
            False
        Fc              3   &   K   | ]  }|v  
 y wr   r)   )r{   rL   r    s     r   r}   z(OrderedSet.issuperset.<locals>.<genexpr>  s     2D44<2r   r   rw   s   ` r   
issupersetzOrderedSet.issuperset  s)     t9s5z!2E222r   c                     t         }t        | t               r| j                  } ||       j                  |      } ||      j                  |       }|j	                  |      S )a  
        Return the symmetric difference of two OrderedSets as a new set.
        That is, the new set will contain all elements that are in exactly
        one of the sets.

        Their order will be preserved, with elements from `self` preceding
        elements from `other`.

        Example:
            >>> this = OrderedSet([1, 4, 3, 5, 7])
            >>> other = OrderedSet([9, 7, 1, 3, 2])
            >>> this.symmetric_difference(other)
            OrderedSet([4, 5, 9, 2])
        )r   r   r6   r   rt   )r    rh   rr   diff1diff2s        r   symmetric_differencezOrderedSet.symmetric_difference  sS     dJ'..CD	$$U+E
%%d+{{5!!r   r   c                 f    || _         t        |      D ci c]  \  }}||
 c}}| _        yc c}}w )zt
        Replace the 'items' list of this OrderedSet with a new one, updating
        self.map accordingly.
        N)r   	enumerater   )r    r   idxrL   s       r   _update_itemszOrderedSet._update_items  s-    
 
1:51AB+3D#IBBs   -c                     t               }|D ]  }t        |      }||z  } | j                  | j                  D cg c]	  }||vs| c}       yc c}w )a  
        Update this OrderedSet to remove items from one or more other sets.

        Example:
            >>> this = OrderedSet([1, 2, 3])
            >>> this.difference_update(OrderedSet([2, 4]))
            >>> print(this)
            OrderedSet([1, 3])

            >>> this = OrderedSet([1, 2, 3, 4, 5])
            >>> this.difference_update(OrderedSet([2, 4]), OrderedSet([1, 4, 6]))
            >>> print(this)
            OrderedSet([3, 5])
        Nrj   r   r   )r    rm   items_to_removerh   items_as_setrL   s         r   difference_updatezOrderedSet.difference_update  sV     % 	,Eu:L|+O	, 	TZZWT4;VDWXWs   	AAc                     t        |      }| j                  | j                  D cg c]	  }||v s| c}       yc c}w )a^  
        Update this OrderedSet to keep only items in another set, preserving
        their order in this set.

        Example:
            >>> this = OrderedSet([1, 4, 3, 5, 7])
            >>> other = OrderedSet([9, 7, 1, 3, 2])
            >>> this.intersection_update(other)
            >>> print(this)
            OrderedSet([1, 3, 7])
        Nr   )r    rh   rL   s      r   intersection_updatezOrderedSet.intersection_update  s3     E
TZZIT45=DIJIs   	;;c                     |D cg c]	  }|| vs| }}t        |      }| j                  | j                  D cg c]	  }||vs| c}|z          yc c}w c c}w )a  
        Update this OrderedSet to remove items from another set, then
        add items from the other set that were not present in this set.

        Example:
            >>> this = OrderedSet([1, 4, 3, 5, 7])
            >>> other = OrderedSet([9, 7, 1, 3, 2])
            >>> this.symmetric_difference_update(other)
            >>> print(this)
            OrderedSet([4, 5, 9, 2])
        Nr   )r    rh   rL   items_to_addr   s        r   symmetric_difference_updatez&OrderedSet.symmetric_difference_update  s_     */C$d2BCCe*"jjHdD,GTH<W	
 D Is   	AA	AAr   )r   r'   ))r   N)0rf   
__module____qualname____doc__OrderedSetInitializerr   r!   r%   r   r1   r+   r
   intr   r3   r<   r?   r   boolrC   rF   rE   SetLikerM   r&   get_locget_indexerrU   rZ   r\   r   r_   rb   r   rg   rl   rt   rx   rv   r   r   r   r   r5   r   r   r   r   r)   r   r   r   r   7   s    5a 8 
  ?   # 47      S>$"
!
 
 
q S & Fwqz c , ! c    s  $ GKq ((1 ( (0 (1+  $hqk $@# @
-C -D -871: / *(WQZ (O ('!*  .
  *3gaj 3T 3 3
 3t 3 "'!* " ",C4 CD CYwqz Yd Y*K K K
 
 
r   r   )r   	itertoolsro   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r1   r2   __version__r   r   r   r   r   r   r)   r   r   <module>r      s        $K	 CL A+
,k!nhqk8A;FG :C :D :&a
A a
r   