ff/ddlmZmZddlmZmZddlmZddlm Z Gdde Z ej e ej e d d Z d ZdS) )SequenceHashable)islicechain)Integral)plistcDeZdZdZdZd!fd ZedZedZe dZ dZ d Z e Z ed Zd"d Zd"d Ze dZdZdZdZdZdZdZdZdZe dZdZdZdZdZdZdZ e Z!dZ"dZ#d Z$e%j&Z&xZ'S)#PDequea 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) ) _left_list _right_list_length_maxlen __weakref__Nctt||}||_||_||_|9t |tstd|dkrtd||_ |S)Nz An integer is required as maxlenrzmaxlen must be non-negative) superr __new__r r r isinstancer TypeError ValueErrorr)cls left_list right_listlengthmaxleninstance __class__s r/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pyrsistent/_pdeque.pyrzPDeque.__new__2s%%--c22')!  fh// D BCCCzz !>???!cLt|j|jS)z. Rightmost element in dqueue. )r _tip_from_listsr r selfs rrightz PDeque.rightBs %%d&6HHHrcLt|j|jS)z- Leftmost element in dqueue. )r r r r r!s rleftz PDeque.leftIs %%dot7GHHHrcF|r|jS|r|dStd)NzNo elements in empty deque)first IndexError) primary_listsecondary_lists rr zPDeque._tip_from_listsPs5  &% %  &!"% %5666rcZt|j|jSN)rr r reverser!s r__iter__zPDeque.__iter__Zs#T_d&6&>&>&@&@AAArcdt||jd|jndS)Nzpdeque({0}{1})z , maxlen={0})formatlistrr!s r__repr__zPDeque.__repr__]sE&&tDzzNRlNf~'<'>> pdeque([1, 2]).pop() pdeque([1]) >>> pdeque([1, 2]).pop(2) pdeque([]) >>> pdeque([1, 2]).pop(-1) pdeque([2]) r)popleftr _pop_listsr r maxr r)r"countnew_right_list new_left_lists rpopz PDeque.popisl 199<<'' '(.(9(9$:JDO]b(c(c% m^S9Mq5Q5QSWS_```rc|dkr|| St|j|j|\}}t||t |j|z d|jS)z Return new deque with leftmost element removed. Otherwise functionally equivalent to pop(). >>> pdeque([1, 2]).popleft() pdeque([2]) r)r>r r9r r r:r r)r"r;r=r<s rr8zPDeque.popleft}sl 19988UF## #(.(9(9$/4K[]b(c(c% ~m^S9Mq5Q5QSWS_```rc|}|}|dkrn|s|rj|dz}|jr|j}nL|r#|}t}n'|j}t}|dkr|h|j||fSNrr6)restr.r)r*r+r;new_primary_listnew_secondary_lists rr9zPDeque._pop_listss'+aii-i1Ci QJE$ -#3#8  ! -#5#=#=#?#? %*WW""#5#=#=#?#?#D %*WW"aii-i1Ci !333rc"|j o|j Sr-)r r r!s r _is_emptyzPDeque._is_emptys?";4+;';;rczt|tstSt|t|kSr-)rr NotImplementedtupler"others r__lt__z PDeque.__lt__s1%(( "! !T{{U5\\))rct|tstSt|t|kr$t |t |ksJdSdS)NTF)rr rHrIlenrJs r__eq__z PDeque.__eq__sX%(( "! ! ;;%,, & &t99E ****4urc:tt|Sr-)hashrIr!s r__hash__zPDeque.__hash__sU4[[!!!rc|jSr-)r r!s r__len__zPDeque.__len__s |rcz||j|j|\}}}t||||jS)z Return new deque with elem as the rightmost element. >>> pdeque([1, 2]).append(3) pdeque([1, 2, 3]) )_appendr r r r)r"elemr=r< new_lengths rappendz PDeque.appends=59LLRVRbdh4i4i1 ~zm^ZNNNrcz||j|j|\}}}t||||jS)z Return new deque with elem as the leftmost element. >>> pdeque([1, 2]).appendleft(3) pdeque([3, 1, 2]) )rVr r r r)r"rWr<r=rXs r appendleftzPDeque.appendlefts>59LLAQSWSbdh4i4i1 zm^ZNNNrc|j\|j|jkrL|jdkr||dfSt||d\}}||||jfS||||jdzfSrA)rr r r9cons)r"r*r+rWrCrDs rrVzPDeque._appends < #  (D(D|q  #^Q66393D3D\Sacd3e3e 0 0#%7%<%>> pdeque([1, 2]).extend([3, 4]) pdeque([1, 2, 3, 4]) )rfr r r r r)r"r`r<r=rcs rextendz PDeque.extendsG7;ll4CSUYUdfn6o6o3 |m^T\L5PRVR^___rc||j|j|\}}}t|||j|z|jS)a 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]) )rfr r r r r)r"r`r=r<rcs r extendleftzPDeque.extendleftsF7;ll4?TXTdfn6o6o3 ~|m^T\L5PRVR^___rcl|j||j|zS)z Return the number of elements equal to elem present in the queue >>> pdeque([1, 2, 1]).count(1) 2 )r r;r )r"rWs rr;z PDeque.counts0$$T**T-=-C-CD-I-IIIrc t|j||j|jdz S#t $r t|j|j||jdz cYS#t $r(}t d||d}~wwxYwwxYw)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]) r6z{0} not found in PDequeN)r r remover r rr.r2)r"rWes rrmz PDeque.removes P$/00668H$,YZJZ[[ [ P P P Pdo#/7799@@FFNNPPRVR^abRbddddd P P P !:!A!A$!G!GHHaO P  Ps.58 CABC C)#C  CCcBt|j|j|jS)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 rr.zPDeque.reversesd&FFFrc||}|dkr5|t||S|t|| S)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]) r)r>rjrr.rh)r"steps popped_deques rrotatez PDeque.rotate)sbxx A::**6$,,..%+H+HII I""6$#7#7888rc<tt||jffSr-)pdequer3rr!s r __reduce__zPDeque.__reduce__9sT DL111rct|tr|j4|jdkr)tt |||jS|}|j"||j|jz}|j *| |j|j |jzz }|St|ts$tdt|jz|dkr||jSt!||z}|dkr0t#d|t!|||jS)Nr6)rz-'%s' object cannot be interpreted as an indexrz!pdeque index {0} out of range {1})rslicesteprurIrstartr8r stopr>rrtype__name__r%rNr)r2)r"indexresultshifteds r __getitem__zPDeque.__getitem__=sE eU # # z%%*//eDkk%0FFFFF{& dl(BCCz%DLEJ4M$NOOM%** dKdSXkkNbbcc c A::<<&&+ +d))e# Q;;3::5#d))LL ||G$$))rr-)r6)(r} __module__ __qualname____doc__ __slots__rpropertyr#r% staticmethodr r/r4__str__rr>r8r9rFrLrOrRrTrYr[rVrarfrhrjr;rmr. __reversed__rsrvrrr~ __classcell__)rs@rr r so''PSI IIXI IIXI 77\7BBBpppG X aaaa( a a a a44\4"<<<***   """OOOOOOIII\ B B B``` ` ` `JJJPPP& G G GL999 222***6 NEEEEErr Nct|}| || d}t|}t|dz }t|d|}t||dd}t ||||S)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)r.)rIrNintrr )r`rtrpivotr%r#s rruru^s hA  vghhK VVF  OOE 6E6  D !EFF)T * * *E $vv . ..rc t|S)z[ Return deque containing all arguments. >>> dq(1, 2, 3) pdeque([1, 2, 3]) )ru)elementss rdqrqs (  r)rN)collections.abcrr itertoolsrrnumbersrpyrsistent._plistrobjectr registerrurrrrrs........##############QQQQQVQQQf &&////&r