o
    €Ï  ã                   @   s^   d dl mZ zd dlmZ W n ey   d dlZY nw G dd„ deƒZG dd„ dej	ƒZ
dS )é    )ÚproxyNc                   @   s   e Zd ZdZdS )ÚLink)ÚprevÚnextÚkeyÚ__weakref__N)Ú__name__Ú
__module__Ú__qualname__Ú	__slots__© r   r   ú?/tmp/google-cloud-sdk/lib/third_party/uritemplate/orderedset.pyr      s    r   c                   @   sl   e Zd Z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d„Zdd„ Zdd„ Zdd„ ZdS )Ú
OrderedSetz/Set the remembers the order elements were addedNc                 C   s6   t ƒ  | _}| |_|_i | _|d ur| |O } d S d S ©N)r   Ú_OrderedSet__rootr   r   Ú_OrderedSet__map)ÚselfÚiterableÚrootr   r   r   Ú__init__   s   ÿzOrderedSet.__init__c                 C   s
   t | jƒS r   )Úlenr   ©r   r   r   r   Ú__len__!   ó   
zOrderedSet.__len__c                 C   s
   || j v S r   )r   )r   r   r   r   r   Ú__contains__$   r   zOrderedSet.__contains__c                 C   sT   || j vr(tƒ  | j |< }| j}|j}||||_|_|_t|ƒ |_|_d S d S r   )r   r   r   r   r   r   r   )r   r   Úlinkr   Úlastr   r   r   Úadd'   s   
ûzOrderedSet.addc                 C   s2   || j v r| j  |¡}|j|j_|j|j_d S d S r   )r   Úpopr   r   )r   r   r   r   r   r   Údiscard0   s
   

ýzOrderedSet.discardc                 c   ó4    | j }|j}||ur|jV  |j}||usd S d S r   )r   r   r   ©r   r   Úcurrr   r   r   Ú__iter__8   ó   €þzOrderedSet.__iter__c                 c   r    r   )r   r   r   r!   r   r   r   Ú__reversed__@   r$   zOrderedSet.__reversed__Tc                 C   s6   | st dƒ‚|rtt| ƒƒntt| ƒƒ}|  |¡ |S )Nzset is empty)ÚKeyErrorr   ÚreversedÚiterr   )r   r   r   r   r   r   r   H   s
   
zOrderedSet.popc                 C   s&   | s	d| j jf S d| j jt| ƒf S )Nz%s()z%s(%r))Ú	__class__r   Úlistr   r   r   r   Ú__repr__O   s   zOrderedSet.__repr__c                 C   s   |   ¡ S r   )r+   r   r   r   r   Ú__str__T   s   zOrderedSet.__str__c                 C   s6   t |tƒrt| ƒt|ƒkot| ƒt|ƒkS |  |¡ S r   )Ú
isinstancer   r   r*   Ú
isdisjoint)r   Úotherr   r   r   Ú__eq__W   s   
 zOrderedSet.__eq__r   )T)r   r	   r
   Ú__doc__r   r   r   r   r   r#   r%   r   r+   r,   r0   r   r   r   r   r      s    

	
r   )Úweakrefr   Úcollections.abcÚabcÚcollections_abcÚImportErrorÚcollectionsÚobjectr   Ú
MutableSetr   r   r   r   r   Ú<module>   s   ÿ