+
    n9e/                         ^ RI HtHt ^ RIHtHt ^ RIHt ^ RIH	t	H
t
 ^ RIHt ]	! RRR7      t ! R	 R
]
],          4      t]P                  ! ]4       ]P                  ! ]4       RR ltR tR# )    )SequenceHashable)islicechain)Integral)TypeVarGeneric)plistT_coT)	covariantc                   D  a a ] tR t^
t oRtRtR V 3R llt]R 4       t]R 4       t	]
R 4       tR tR t]t]R 4       tR!R	 ltR!R
 lt]
R 4       tR tR tR tR tR tR tR tR t]
R 4       tR tR tR tR tR t R t!]!t"R t#R t$R t%]&PN                  t'Rt(Vt)V ;t*# )"PDequeab  
Persistent double ended queue (deque). Allows quick appends and pops in both ends. Implemented
using two persistent lists.

A maximum length can be specified to create a bounded queue.

Fully supports the Sequence and Hashable protocols including indexing and slicing but
if you need fast random access go for the PVector instead.

Do not instantiate directly, instead use the factory functions :py:func:`dq` or :py:func:`pdeque` to
create an instance.

Some examples:

>>> x = pdeque([1, 2, 3])
>>> x.left
1
>>> x.right
3
>>> x[0] == x.left
True
>>> x[-1] == x.right
True
>>> x.pop()
pdeque([1, 2])
>>> x.pop() == x[:-1]
True
>>> x.popleft()
pdeque([2, 3])
>>> x.append(4)
pdeque([1, 2, 3, 4])
>>> x.appendleft(4)
pdeque([4, 1, 2, 3])

>>> y = pdeque([1, 2, 3], maxlen=3)
>>> y.append(4)
pdeque([2, 3, 4], maxlen=3)
>>> y.appendleft(4)
pdeque([4, 1, 2], maxlen=3)
c                   < \         \        V `  V 4      pWn        W%n        W5n        Ve4   \        V\        4      '       g   \        R4      hV^ 8  d   \        R4      hWEn
        V# )Nz An integer is required as maxlenzmaxlen must be non-negative)superr   __new__
_left_list_right_list_length
isinstancer   	TypeError
ValueError_maxlen)cls	left_list
right_listlengthmaxleninstance	__class__s   &&&&& 4/usr/lib/python3/dist-packages/pyrsistent/_pdeque.pyr   PDeque.__new__5   sc    -c2')!fh// BCCz !>??!    c                V    \         P                  V P                  V P                  4      # )z
Rightmost element in dqueue.
)r   _tip_from_listsr   r   selfs   &r    rightPDeque.rightE   s!    
 %%d&6&6HHr"   c                V    \         P                  V P                  V P                  4      # )z
Leftmost element in dqueue.
)r   r$   r   r   r%   s   &r    leftPDeque.leftL   s!    
 %%doot7G7GHHr"   c                b    V '       d   V P                   # V'       d
   VR,          # \        R4      h)   zNo elements in empty deque)first
IndexError)primary_listsecondary_lists   &&r    r$   PDeque._tip_from_listsS   s+    %%%!"%%566r"   c                ^    \        V P                  V P                  P                  4       4      # N)r   r   r   reverser%   s   &r    __iter__PDeque.__iter__]   s"    T__d&6&6&>&>&@AAr"   c                    R P                  \        V 4      V P                  e    RP                  V P                  4      4      # R4      # )zpdeque({0}{1})z, maxlen={0} )formatlistr   r%   s   &r    __repr__PDeque.__repr__`   sG    &&tDzNRllNf~'<'<T\\'Jp 	plnp 	pr"   c                    V P                   # )z
Maximum length of the queue.
)r   r%   s   &r    r   PDeque.maxlene   s    
 ||r"   c                    V^ 8  d   V P                  V) 4      # \        P                  V P                  V P                  V4      w  r#\        W2\        V P                  V,
          ^ 4      V P                  4      # )a  
Return new deque with rightmost element removed. Popping the empty queue
will return the empty queue. A optional count can be given to indicate the
number of elements to pop. Popping with a negative index is the same as
popleft. Executes in amortized O(k) where k is the number of elements to pop.

>>> pdeque([1, 2]).pop()
pdeque([1])
>>> pdeque([1, 2]).pop(2)
pdeque([])
>>> pdeque([1, 2]).pop(-1)
pdeque([2])
)popleftr   
_pop_listsr   r   maxr   r   )r&   countnew_right_listnew_left_lists   &&  r    pop
PDeque.popl   sd     19<<''(.(9(9$:J:JDOO]b(c%mS9Mq5QSWS_S_``r"   c                    V^ 8  d   V P                  V) 4      # \        P                  V P                  V P                  V4      w  r#\        W#\        V P                  V,
          ^ 4      V P                  4      # )z
Return new deque with leftmost element removed. Otherwise functionally
equivalent to pop().

>>> pdeque([1, 2]).popleft()
pdeque([2])
)rH   r   rC   r   r   rD   r   r   )r&   rE   rG   rF   s   &&  r    rB   PDeque.popleft   sd     1988UF##(.(9(9$//4K[K[]b(c%mS9Mq5QSWS_S_``r"   c                $   T pTpV^ 8  d   V'       g	   V'       dt   V^,          pVP                   '       d   VP                   pK@  V'       d   VP                  4       p\        4       pKd  VP                  4       P                   p\        4       pK  W43# r   )restr6   r
   )r1   r2   rE   new_primary_listnew_secondary_lists   &&&  r    rC   PDeque._pop_lists   s|    '+ai-1CQJE$$$#3#8#8 !#5#=#=#? %*W"#5#=#=#?#D#D %*W"33r"   c                V    V P                   '       * ;'       d    V P                  '       * # r5   )r   r   r%   s   &r    	_is_emptyPDeque._is_empty   s     ??";;4+;+;';;r"   c                h    \        V\        4      '       g   \        # \        V 4      \        V4      8  # r5   )r   r   NotImplementedtupler&   others   &&r    __lt__PDeque.__lt__   s(    %((!!T{U5\))r"   c                    \        V\        4      '       g   \        # \        V 4      \        V4      8X  d   \	        V 4      \	        V4      8X  g   Q hR # R# )TF)r   r   rV   rW   lenrX   s   &&r    __eq__PDeque.__eq__   sA    %((!!;%,&t9E
***r"   c                *    \        \        V 4      4      # r5   )hashrW   r%   s   &r    __hash__PDeque.__hash__   s    E$K  r"   c                    V P                   # r5   )r   r%   s   &r    __len__PDeque.__len__   s    ||r"   c                    V P                  V P                  V P                  V4      w  r#p\        W#W@P                  4      # )zf
Return new deque with elem as the rightmost element.

>>> pdeque([1, 2]).append(3)
pdeque([1, 2, 3])
)_appendr   r   r   r   )r&   elemrG   rF   
new_lengths   &&   r    appendPDeque.append   s8     59LLRVRbRbdh4i1zmZNNr"   c                    V P                  V P                  V P                  V4      w  r#p\        W2W@P                  4      # )zi
Return new deque with elem as the leftmost element.

>>> pdeque([1, 2]).appendleft(3)
pdeque([3, 1, 2])
)rh   r   r   r   r   )r&   ri   rF   rG   rj   s   &&   r    
appendleftPDeque.appendleft   s:     59LLAQAQSWSbSbdh4i1zmZNNr"   c                0   V P                   ef   V P                  V P                   8X  dK   V P                   ^ 8X  d   W^ 3# \        P                  W^4      w  rEWEP	                  V4      V P                  3# WP	                  V4      V P                  ^,           3# r5   )r   r   r   rC   cons)r&   r1   r2   ri   rO   rP   s   &&&&  r    rh   PDeque._append   s    <<#(D||q #Q66393D3D\cd3e0#%<%<T%BDLLPP006q8HHHr"   c                R    ^ pV F  pV P                  V4      p V^,          pK  	  W3# rM   )rq   )the_listiterablerE   ri   s   &&  r    _extend_listPDeque._extend_list   s2    D}}T*HQJE  r"   c                   \         P                  W4      w  rETpV P                  V,           pV P                  eC   WpP                  8  d3   WpP                  ,
          p\         P	                  WdV4      w  rdWX,          pWFV3# r5   )r   rv   r   r   rC   )	r&   r1   r2   ru   rO   extend_countrP   current_lenpop_lens	   &&&&     r    _extendPDeque._extend   st    )/)<)<\)T&+ll\1<<#ll(B!LL0G393D3DEWkr3s0#L\AAr"   c                    V P                  V P                  V P                  V4      w  r#p\        W2V P                  V,           V P
                  4      # )z
Return new deque with all elements of iterable appended to the right.

>>> pdeque([1, 2]).extend([3, 4])
pdeque([1, 2, 3, 4])
)r|   r   r   r   r   r   )r&   ru   rF   rG   ry   s   &&   r    extendPDeque.extend   sH     7;ll4CSCSUYUdUdfn6o3|mT\\L5PRVR^R^__r"   c                    V P                  V P                  V P                  V4      w  r#p\        W#V P                  V,           V P
                  4      # )z
Return new deque with all elements of iterable appended to the left.

NB! The elements will be inserted in reverse order compared to the order in the iterable.

>>> pdeque([1, 2]).extendleft([3, 4])
pdeque([4, 3, 1, 2])
)r|   r   r   r   r   r   )r&   ru   rG   rF   ry   s   &&   r    
extendleftPDeque.extendleft   sF     7;ll4??TXTdTdfn6o3|mT\\L5PRVR^R^__r"   c                x    V P                   P                  V4      V P                  P                  V4      ,           # )zd
Return the number of elements equal to elem present in the queue

>>> pdeque([1, 2, 1]).count(1)
2
)r   rE   r   )r&   ri   s   &&r    rE   PDeque.count  s/     $$T*T-=-=-C-CD-IIIr"   c                    \        V P                  P                  V4      V P                  V P                  ^,
          4      #   \
         d     \        T P                  T P                  P                  4       P                  T4      P                  4       T P                  ^,
          4      u #   \
         d!   p\        RP                  T4      4      ThRp?ii ; ii ; i)z
Return new deque with first element from left equal to elem removed. If no such element is found
a ValueError is raised.

>>> pdeque([2, 1, 2]).remove(2)
pdeque([1, 2])
z{0} not found in PDequeN)r   r   remover   r   r   r6   r;   )r&   ri   es   && r    r   PDeque.remove
  s    		P$//0068H8H$,,YZJZ[[ 	PPdoo"..668??EMMOQUQ]Q]`aQac c P !:!A!A$!GHaOP	Ps1   A A CAB.+C.C9CCCc                X    \        V P                  V P                  V P                  4      # )z
Return reversed deque.

>>> pdeque([1, 2, 3]).reverse()
pdeque([3, 2, 1])

Also supports the standard python reverse function.

>>> reversed(pdeque([1, 2, 3]))
pdeque([3, 2, 1])
)r   r   r   r   r%   s   &r    r6   PDeque.reverse  s!     d&&FFr"   c                    V P                  V4      pV^ 8  d*   VP                  \        V P                  4       V4      4      # VP	                  \        W) 4      4      # )z
Return deque with elements rotated steps steps.

>>> x = pdeque([1, 2, 3])
>>> x.rotate(1)
pdeque([3, 1, 2])
>>> x.rotate(-2)
pdeque([3, 1, 2])
)rH   r   r   r6   r   )r&   stepspopped_deques   && r    rotatePDeque.rotate,  sN     xxA:**6$,,.%+HII""6$#788r"   c                <    \         \        V 4      V P                  33# r5   )pdequer<   r   r%   s   &r    
__reduce__PDeque.__reduce__<  s    T
DLL111r"   c                6   \        V\        4      '       d   VP                  e9   VP                  ^8w  d(   \        \	        V 4      V,          V P
                  R7      # T pVP                  e-   VP                  VP                  V P                  ,          4      pVP                  e>   VP                  V P                  VP                  V P                  ,          ,
          4      pV# \        V\        4      '       g&   \        R\        V4      P                  ,          4      hV^ 8  d   V P                  V4      P                  # \!        V 4      V,           pV^ 8  d%   \#        RP%                  V\!        V 4      4      4      hV P                  V4      P                  # )N)r   z-'%s' object cannot be interpreted as an indexz!pdeque index {0} out of range {1})r   slicestepr   rW   r   startrB   r   stoprH   r   r   type__name__r*   r]   r0   r;   )r&   indexresultshifteds   &&  r    __getitem__PDeque.__getitem__@  s,   eU##zz%%**/eDk%0FFF{{&dll(BCzz%DLLEJJ4M$NOM%**KdSXkNbNbbccA:<<&+++d)e#Q;3::5#d)L  ||G$)))r"    )r   r   r   r   __weakref__r5   )r-   )+r   
__module____qualname____firstlineno____doc__	__slots__r   propertyr'   r*   staticmethodr$   r7   r=   __str__r   rH   rB   rC   rS   rZ   r^   rb   re   rk   rn   rh   rv   r|   r   r   rE   r   r6   __reversed__r   r   r   r   r   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r    r   r   
   s#    'P SI  I I I I 7 7Bp G a(a 4 4"<*	!OOI  	B`
`JP&G L9 2*6 NNEEr"   r   Nc                    \        V 4      pVe   W!) R p\        V4      p\        V^,          4      p\        VRV 4      p\        W$R RR7      p\	        WVW14      # )a  
Return deque containing the elements of iterable. If maxlen is specified then
len(iterable) - maxlen elements are discarded from the left to if len(iterable) > maxlen.

>>> pdeque([1, 2, 3])
pdeque([1, 2, 3])
>>> pdeque([1, 2, 3, 4], maxlen=2)
pdeque([3, 4], maxlen=2)
NT)r6   )rW   r]   intr
   r   )ru   r   tr   pivotr*   r'   s   &&     r    r   r   a  sa     	hAghKVF
OE6ED!F)T*E$v..r"   c                     \        V 4      # )zK
Return deque containing all arguments.

>>> dq(1, 2, 3)
pdeque([1, 2, 3])
)r   )elementss   *r    dqr   t  s     (r"   )r   N)collections.abcr   r   	itertoolsr   r   numbersr   typingr   r	   pyrsistent._plistr
   r   r   registerr   r   r   r"   r    <module>r      s[    . #  # #v&QWT] Qf
 	  &    & /&r"   