%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/pyrsistent/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/pyrsistent/__pycache__/_pdeque.cpython-312.pyc

�

n�9e�/����ddlmZmZddlmZmZddlmZddlm	Z	m
Z
ddlmZe	dd��Z
Gd	�d
e
e
�Zeje�eje�dd�Zd
�Zy)�)�Sequence�Hashable)�islice�chain)�Integral)�TypeVar�Generic)�plist�T_coT)�	covariantc�*��eZdZdZdZd�fd�	Zed��Zed��Ze	d��Z
d�Zd�ZeZ
ed	��Zd d
�Zd d�Ze	d��Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Ze	d��Zd�Zd�Zd�Zd�Zd�Zd�Z e Z!d�Z"d�Z#d�Z$e%jLZ&�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__c���tt|�|�}||_||_||_|�+t
|t�std��|dkrtd��||_
|S)Nz An integer is required as maxlenrzmaxlen must be non-negative)�superr�__new__rrr�
isinstancer�	TypeError�
ValueErrorr)�cls�	left_list�
right_list�length�maxlen�instance�	__class__s      ��4/usr/lib/python3/dist-packages/pyrsistent/_pdeque.pyrzPDeque.__new__5sh������-�c�2��'���)���!������f�h�/�� B�C�C���z� �!>�?�?�!�����c�V�tj|j|j�S)z.
        Rightmost element in dqueue.
        )r�_tip_from_listsrr��selfs r!�rightzPDeque.rightEs!��
�%�%�d�&6�&6����H�Hr"c�V�tj|j|j�S)z-
        Leftmost element in dqueue.
        )rr$rrr%s r!�leftzPDeque.leftLs!��
�%�%�d�o�o�t�7G�7G�H�Hr"c�B�|r|jS|r|dStd��)N���zNo elements in empty deque)�first�
IndexError)�primary_list�secondary_lists  r!r$zPDeque._tip_from_listsSs+����%�%�%��!�"�%�%��5�6�6r"c�^�t|j|jj��S�N)rrr�reverser%s r!�__iter__zPDeque.__iter__]s"���T�_�_�d�&6�&6�&>�&>�&@�A�Ar"c��djt|�|j�dj|j��Sd�S)Nzpdeque({0}{1})z, maxlen={0}�)�format�listrr%s r!�__repr__zPDeque.__repr__`sG���&�&�t�D�z�NR�l�l�Nf�~�'<�'<�T�\�\�'J�p�	p�ln�p�	pr"c��|jS)z.
        Maximum length of the queue.
        )rr%s r!rz
PDeque.maxlenes��
�|�|�r"c���|dkr|j|�Stj|j|j|�\}}t||t|j|z
d�|j�S)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])
        r)�popleftr�
_pop_listsrr�maxrr)r&�count�new_right_list�
new_left_lists    r!�popz
PDeque.poplsh���1�9��<�<���'�'�(.�(9�(9�$�:J�:J�D�O�O�]b�(c�%��
��m�^�S�����9M�q�5Q�SW�S_�S_�`�`r"c���|dkr|j|�Stj|j|j|�\}}t||t|j|z
d�|j�S)z�
        Return new deque with leftmost element removed. Otherwise functionally
        equivalent to pop().

        >>> pdeque([1, 2]).popleft()
        pdeque([2])
        r)rArr<rrr=rr)r&r>r@r?s    r!r;zPDeque.popleft�sh���1�9��8�8�U�F�#�#�(.�(9�(9�$�/�/�4�K[�K[�]b�(c�%�
�~��m�^�S�����9M�q�5Q�SW�S_�S_�`�`r"c��|}|}|dkDrn|s|rj|dz}|jr
|j}nA|r|j�}t�}n$|j�j}t�}|dkDr|r�g|r�j||fS�Nr�)�restr2r
)r.r/r>�new_primary_list�new_secondary_lists     r!r<zPDeque._pop_lists�s���'��+���a�i�-�1C��Q�J�E��$�$�#3�#8�#8� �!�#5�#=�#=�#?� �%*�W�"�#5�#=�#=�#?�#D�#D� �%*�W�"��a�i�-�1C� �!3�3�3r"c�:�|jxr
|jSr1)rrr%s r!�	_is_emptyzPDeque._is_empty�s���?�?�"�;�4�+;�+;�';�;r"c�\�t|t�stSt|�t|�kSr1)rr�NotImplemented�tuple�r&�others  r!�__lt__z
PDeque.__lt__�s%���%��(�!�!��T�{�U�5�\�)�)r"c��t|t�stSt|�t|�k(rt	|�t	|�k(sJ�yy)NTF)rrrLrM�lenrNs  r!�__eq__z
PDeque.__eq__�s>���%��(�!�!���;�%��,�&��t�9��E�
�*�*�*��r"c�*�tt|��Sr1)�hashrMr%s r!�__hash__zPDeque.__hash__�s���E�$�K� � r"c��|jSr1)rr%s r!�__len__zPDeque.__len__�s���|�|�r"c��|j|j|j|�\}}}t||||j�S)z�
        Return new deque with elem as the rightmost element.

        >>> pdeque([1, 2]).append(3)
        pdeque([1, 2, 3])
        )�_appendrrrr)r&�elemr@r?�
new_lengths     r!�appendz
PDeque.append�s>��59�L�L����RV�Rb�Rb�dh�4i�1�
�~�z��m�^�Z����N�Nr"c��|j|j|j|�\}}}t||||j�S)z�
        Return new deque with elem as the leftmost element.

        >>> pdeque([1, 2]).appendleft(3)
        pdeque([3, 1, 2])
        )rZrrrr)r&r[r?r@r\s     r!�
appendleftzPDeque.appendleft�s@��59�L�L��AQ�AQ�SW�Sb�Sb�dh�4i�1��
�z��m�^�Z����N�Nr"c�&�|j�e|j|jk(rL|jdk(r||dfStj||d�\}}||j	|�|jfS||j	|�|jdzfSrD)rrrr<�cons)r&r.r/r[rGrHs      r!rZzPDeque._append�s����<�<�#�������(D��|�|�q� �#�^�Q�6�6�39�3D�3D�\�Sa�cd�3e�0��0�#�%7�%<�%<�T�%B�D�L�L�P�P��^�0�0��6����q�8H�H�Hr"c�H�d}|D]}|j|�}|dz
}�||fSrD)ra)�the_list�iterabler>r[s    r!�_extend_listzPDeque._extend_list�s9�����	�D��}�}�T�*�H��Q�J�E�	����r"c���tj||�\}}|}|j|z}|j�=||jkDr.||jz
}tj	|||�\}}||z}|||fSr1)rrerrr<)	r&r.r/rdrG�extend_countrH�current_len�pop_lens	         r!�_extendzPDeque._extend�s���)/�)<�)<�\�8�)T�&��,�+���l�l�\�1���<�<�#��d�l�l�(B�!�D�L�L�0�G�39�3D�3D�EW�Yi�kr�3s�0�� 0��G�#�L��!3�\�A�Ar"c��|j|j|j|�\}}}t|||j|z|j
�S)z�
        Return new deque with all elements of iterable appended to the right.

        >>> pdeque([1, 2]).extend([3, 4])
        pdeque([1, 2, 3, 4])
        )rjrrrrr)r&rdr?r@rgs     r!�extendz
PDeque.extend�sL��7;�l�l�4�CS�CS�UY�Ud�Ud�fn�6o�3��
�|��m�^�T�\�\�L�5P�RV�R^�R^�_�_r"c��|j|j|j|�\}}}t|||j|z|j
�S)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])
        )rjrrrrr)r&rdr@r?rgs     r!�
extendleftzPDeque.extendleft�sJ��7;�l�l�4�?�?�TX�Td�Td�fn�6o�3�
�~�|��m�^�T�\�\�L�5P�RV�R^�R^�_�_r"c�p�|jj|�|jj|�zS)z�
        Return the number of elements equal to elem present in the queue

        >>> pdeque([1, 2, 1]).count(1)
        2
        )rr>r)r&r[s  r!r>zPDeque.counts/�����$�$�T�*�T�-=�-=�-C�-C�D�-I�I�Ir"c��	t|jj|�|j|jdz
�S#t
$r�	t|j|jj
�j|�j
�|jdz
�cYS#t
$r }tdj|��|�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])
        rEz{0} not found in PDequeN)rr�removerrrr2r6)r&r[�es   r!rqz
PDeque.remove
s���		P��$�/�/�0�0��6��8H�8H�$�,�,�YZ�JZ�[�[���	P�
P��d�o�o�"�.�.�6�6�8�?�?��E�M�M�O�QU�Q]�Q]�`a�Qa�c�c���
P� �!:�!A�!A�$�!G�H�a�O��
P��
	P�s.�<?�	C�	AB$�!C�$	C
�-C�C
�
Cc�X�t|j|j|j�S)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])
        )rrrrr%s r!r2zPDeque.reverses!���d�&�&�������F�Fr"c��|j|�}|dk\r)|jt|j�|��S|j	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)rArnrr2rl)r&�steps�popped_deques   r!�rotatez
PDeque.rotate,sP���x�x�����A�:��*�*�6�$�,�,�.�%�+H�I�I��"�"�6�$���#7�8�8r"c�<�tt|�|jffSr1)�pdequer7rr%s r!�
__reduce__zPDeque.__reduce__<s����T�
�D�L�L�1�1�1r"c���t|t�r�|j�2|jdk7r#tt	|�||j
��S|}|j�(|j|j|jz�}|j�5|j|j|j|jzz
�}|St|t�s!tdt|�jz��|dk\r|j|�jSt!|�|z}|dkr$t#dj%|t!|����|j|�jS)NrE)rz-'%s' object cannot be interpreted as an indexrz!pdeque index {0} out of range {1})r�slice�stepryrMr�startr;r�stoprArr�type�__name__r)rRr-r6)r&�index�result�shifteds    r!�__getitem__zPDeque.__getitem__@s&���e�U�#��z�z�%�%�*�*��/��e�D�k�%�0����F�F��F��{�{�&�������d�l�l�(B�C���z�z�%����D�L�L�E�J�J����4M�$N�O���M��%��*��K�d�SX�k�Nb�Nb�b�c�c��A�:��<�<��&�+�+�+��d�)�e�#���Q�;��3�:�:�5�#�d�)�L��
��|�|�G�$�)�)�)r"r1)rE)(r��
__module__�__qualname__�__doc__�	__slots__r�propertyr'r)�staticmethodr$r3r8�__str__rrAr;r<rJrPrSrVrXr]r_rZrerjrlrnr>rqr2�__reversed__rwrzr�rr��
__classcell__)r s@r!rr
s���'�PS�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
�N�N�Er"rNc��t|�}|�||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)
    N�T)r2)rMrR�intr
r)rdr�tr�pivotr)r's       r!ryryasi��	�h��A�
��
�v�g�h�K��
��V�F����
�O�E���6�E���D��!�E�F�)�T�*�E��$��v�v�.�.r"c��t|�S)z[
    Return deque containing all arguments.

    >>> dq(1, 2, 3)
    pdeque([1, 2, 3])
    )ry)�elementss r!�dqr�ts���(��r")�N)�collections.abcrr�	itertoolsrr�numbersr�typingrr	�pyrsistent._plistr
rr�registerryr�r�r"r!�<module>r�s_��.�#��#�#��v��&��Q�W�T�]�Q�f
����&������&��/�&r"

Zerion Mini Shell 1.0