Your IP : 3.145.37.211


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/pyrsistent/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/pyrsistent/__pycache__/_pbag.cpython-311.pyc

�

��bgJ��
�ddlmZmZmZmZddlmZddlmZd�Z	Gd�de
��Zeje��eje��eje��eje��d�Z
d�Zee����Zd	S)
�)�	Container�Iterable�Sized�Hashable)�reduce)�pmapc�\�|�||�|d��dz��S)Nr�)�set�get)�counters�elements  �G/opt/cloudlinux/venv/lib64/python3.11/site-packages/pyrsistent/_pbag.py�_add_to_countersrs)���<�<�����g�q�!9�!9�A�!=�>�>�>�c��eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZeZeZeZd�Zd�Zd�Zd�Zd�ZdS)�PBaga�
    A persistent bag/multiset type.

    Requires elements to be hashable, and allows duplicates, but has no
    ordering. Bags are hashable.

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

    Some examples:

    >>> s = pbag([1, 2, 3, 1])
    >>> s2 = s.add(4)
    >>> s3 = s2.remove(1)
    >>> s
    pbag([1, 1, 2, 3])
    >>> s2
    pbag([1, 1, 2, 3, 4])
    >>> s3
    pbag([1, 2, 3, 4])
    )�_counts�__weakref__c��||_dS)N�r)�self�countss  r�__init__z
PBag.__init__#s
������rc�F�tt|j|����S)z�
        Add an element to the bag.

        >>> s = pbag([1])
        >>> s2 = s.add(1)
        >>> s3 = s.add(2)
        >>> s2
        pbag([1, 1])
        >>> s3
        pbag([1, 2])
        )rrr�rrs  r�addzPBag.add&s���$�T�\�7�;�;�<�<�<rc�Z�|r(ttt||j����S|S)z�
        Update bag with all elements in iterable.

        >>> s = pbag([1])
        >>> s.update([1, 2])
        pbag([1, 1, 2])
        )rrrr)r�iterables  r�updatezPBag.update4s/���	J���/��4�<�H�H�I�I�I��rc��||jvrt|���|j|dkr|j�|��}n)|j�||j|dz
��}t	|��S)z�
        Remove an element from the bag.

        >>> s = pbag([1, 1, 2])
        >>> s2 = s.remove(1)
        >>> s3 = s.remove(2)
        >>> s2
        pbag([1, 2])
        >>> s3
        pbag([1, 1])
        r
)r�KeyError�removerr)rr�newcs   rr#zPBag.removeAsw���$�,�&�&��7�#�#�#�
�\�'�
"�a�
'�
'��<�&�&�w�/�/�D�D��<�#�#�G�T�\�'�-B�Q�-F�G�G�D��D�z�z�rc�8�|j�|d��S)z�
        Return the number of times an element appears.


        >>> pbag([]).count('non-existent')
        0
        >>> pbag([1, 1, 2]).count(1)
        2
        r)rrrs  r�countz
PBag.countUs���|�����+�+�+rc�N�t|j�����S)ze
        Return the length including duplicates.

        >>> len(pbag([1, 1, 2]))
        3
        )�sumr�
itervalues�rs r�__len__zPBag.__len__as ���4�<�*�*�,�,�-�-�-rc#�tK�|j���D]\}}t|��D]}|V���dS)z�
        Return an iterator of all elements, including duplicates.

        >>> list(pbag([1, 1, 2]))
        [1, 1, 2]
        >>> list(pbag([1, 2]))
        [1, 2]
        N)r�	iteritems�range)r�eltr&�is    r�__iter__z
PBag.__iter__jsX�����,�0�0�2�2�	�	�J�C���5�\�\�
�
���	�	�	�	�
�	�	rc��||jvS)z�
        Check if an element is in the bag.

        >>> 1 in pbag([1, 1, 2])
        True
        >>> 0 in pbag([1, 2])
        False
        r)rr/s  r�__contains__zPBag.__contains__ws���d�l�"�"rc�F�d�t|����S)Nz	pbag({0}))�format�listr*s r�__repr__z
PBag.__repr__�s���!�!�$�t�*�*�-�-�-rc�l�t|��turtd���|j|jkS)z�
        Check if two bags are equivalent, honoring the number of duplicates,
        and ignoring insertion order.

        >>> pbag([1, 1, 2]) == pbag([1, 2])
        False
        >>> pbag([2, 1, 0]) == pbag([0, 1, 2])
        True
        z Can only compare PBag with PBags)�typer�	TypeErrorr�r�others  r�__eq__zPBag.__eq__�s3����;�;�d�"�"��>�?�?�?��|�u�}�,�,rc� �td���)NzPBags are not orderable)r:r;s  r�__lt__zPBag.__lt__�s���1�2�2�2rc�"�t|t��stS|j���}|j���D] \}}|�|��|z||<�!t|�����S)z�
        Combine elements from two PBags.

        >>> pbag([1, 2, 2]) + pbag([2, 3, 3])
        pbag([1, 2, 2, 2, 3, 3])
        )�
isinstancer�NotImplementedr�evolverr-r&�
persistent)rr<�result�elem�other_counts     r�__add__zPBag.__add__�s����%��&�&�	"�!�!���%�%�'�'��!&��!8�!8�!:�!:�	:�	:��D�+��:�:�d�+�+�k�9�F�4�L�L��F�%�%�'�'�(�(�(rc�f�t|t��stS|j���}|j���D]B\}}|�|��|z
}|dkr|||<�)||vr|�|���Ct|�����S)z�
        Remove elements from one PBag that are present in another.

        >>> pbag([1, 2, 2, 2, 3]) - pbag([2, 3, 3, 4])
        pbag([1, 2, 2])
        r)	rArrBrrCr-r&r#rD)rr<rErFrG�newcounts      r�__sub__zPBag.__sub__�s����%��&�&�	"�!�!���%�%�'�'��!&��!8�!8�!:�!:�	$�	$��D�+��z�z�$�'�'�+�5�H��!�|�|�'��t��������
�
�d�#�#�#���F�%�%�'�'�(�(�(rc�@�t|t��stS|j���}|j���D]/\}}|�|��}t||��}|||<�0t|�����S)z�
        Union: Keep elements that are present in either of two PBags.

        >>> pbag([1, 2, 2, 2]) | pbag([2, 3, 3])
        pbag([1, 2, 2, 2, 3, 3])
        )	rArrBrrCr-r&�maxrD)rr<rErFrGr&rJs       r�__or__zPBag.__or__�s����%��&�&�	"�!�!���%�%�'�'��!&��!8�!8�!:�!:�	$�	$��D�+��J�J�t�$�$�E��5�+�.�.�H�#�F�4�L�L��F�%�%�'�'�(�(�(rc�V�t|t��stSt�����}|j���D]3\}}t||�|����}|dkr|||<�4t|�	����S)z�
        Intersection: Only keep elements that are present in both PBags.

        >>> pbag([1, 2, 2, 2]) & pbag([2, 3, 3])
        pbag([2])
        r)
rArrBrrCrr-�minr&rD)rr<rErFr&rJs      r�__and__zPBag.__and__�s����%��&�&�	"�!�!������!�!���<�1�1�3�3�	(�	(�K�D�%��5�%�+�+�d�"3�"3�4�4�H��!�|�|�'��t����F�%�%�'�'�(�(�(rc�*�t|j��S)z�
        Hash based on value of elements.

        >>> m = pmap({pbag([1, 2]): "it's here!"})
        >>> m[pbag([2, 1])]
        "it's here!"
        >>> pbag([1, 1, 2]) in m
        False
        )�hashrr*s r�__hash__z
PBag.__hash__�s���D�L�!�!�!rN)�__name__�
__module__�__qualname__�__doc__�	__slots__rrr r#r&r+r1r3r7r=r?�__le__�__gt__�__ge__rHrKrNrQrT�rrrr
s&��������,+�I����=�=�=�������(
,�
,�
,�.�.�.����	#�	#�	#�.�.�.�-�-�-�3�3�3��F�
�F�
�F�)�)�)�)�)�)�$)�)�)� )�)�)� 
"�
"�
"�
"�
"rrc� �t|��S)z�
    Construct a persistent bag.

    Takes an arbitrary number of arguments to insert into the new persistent
    bag.

    >>> b(1, 2, 3, 2)
    pbag([1, 2, 2, 3])
    )�pbag��elementss r�brb�s����>�>�rc�r�|stSttt|t	������S)z�
    Convert an iterable to a persistent bag.

    Takes an iterable with elements to insert.

    >>> pbag([1, 2, 3, 2])
    pbag([1, 2, 2, 3])
    )�_EMPTY_PBAGrrrrr`s rr_r_�s1��������'��4�6�6�:�:�;�;�;rN)�collections.abcrrrr�	functoolsr�pyrsistent._pmaprr�objectr�registerrbr_rdr]rr�<module>rjs��@�@�@�@�@�@�@�@�@�@�@�@�������!�!�!�!�!�!�?�?�?�\"�\"�\"�\"�\"�6�\"�\"�\"�~�	��4�������$�������t�������$����
�
�
�<�<�<��d�4�4�6�6�l�l���r

?>