Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/pyrsistent/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/pyrsistent/__pycache__/_pbag.cpython-35.opt-1.pyc



+�[b�@s�ddlmZmZmZmZddlmZddlmZdd�Z	Gdd�de
�Zeje�eje�eje�eje�d	d
�Z
dd�Zee��Zd
S)�)�	Container�Iterable�Sized�Hashable�)�reduce)�pmapcCs |j||j|d�d�S)Nrr)�set�get)Zcounters�element�r�C/opt/alt/python35/lib64/python3.5/site-packages/pyrsistent/_pbag.py�_add_to_counterssrc@s�eZdZdZd%Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZeZeZeZdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)&�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__cCs
||_dS)N)r)�selfZcountsrrr
�__init__#sz
PBag.__init__cCstt|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)rrrrr
�add&szPBag.addcCs#|rttt||j��S|S)z�
        Update bag with all elements in iterable.

        >>> s = pbag([1])
        >>> s.update([1, 2])
        pbag([1, 1, 2])
        )rrrr)r�iterablerrr
�update4szPBag.updatecCsp||jkrt|��nH|j|dkrF|jj|�}n |jj||j|d�}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�remover	r)rrZnewcrrr
rAs zPBag.removecCs|jj|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
)rrrrr
�countUs
z
PBag.countcCst|jj��S)ze
        Return the length including duplicates.

        >>> len(pbag([1, 1, 2]))
        3
        )�sumrZ
itervalues)rrrr
�__len__aszPBag.__len__ccs@x9|jj�D](\}}xt|�D]}|Vq)WqWdS)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�irrr
�__iter__js	z
PBag.__iter__cCs
||jkS)z�
        Check if an element is in the bag.

        >>> 1 in pbag([1, 1, 2])
        True
        >>> 0 in pbag([1, 2])
        False
        )r)rrrrr
�__contains__ws	zPBag.__contains__cCsdjt|��S)Nz	pbag({0}))�format�list)rrrr
�__repr__�sz
PBag.__repr__cCs.t|�tk	rtd��|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�otherrrr
�__eq__�s
zPBag.__eq__cCstd��dS)NzPBags are not orderable)r&)rr'rrr
�__lt__�szPBag.__lt__cCsit|t�stS|jj�}x4|jj�D]#\}}|j|�|||<q2Wt|j��S)z� 
        Combine elements from two PBags.

        >>> pbag([1, 2, 2]) + pbag([2, 3, 3])
        pbag([1, 2, 2, 2, 3, 3])
        )�
isinstancer�NotImplementedr�evolverrr�
persistent)rr'�result�elem�other_countrrr
�__add__�szPBag.__add__cCs�t|t�stS|jj�}xb|jj�D]Q\}}|j|�|}|dkrj|||<q2||kr2|j|�q2Wt|j��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)	r*rr+rr,rrrr-)rr'r.r/r0�newcountrrr
�__sub__�s
zPBag.__sub__cCszt|t�stS|jj�}xE|jj�D]4\}}|j|�}t||�}|||<q2Wt|j��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])
        )	r*rr+rr,rr�maxr-)rr'r.r/r0rr2rrr
�__or__�szPBag.__or__cCs�t|t�stSt�j�}xK|jj�D]:\}}t||j|��}|dkr2|||<q2Wt|j	��S)z�
        Intersection: Only keep elements that are present in both PBags.
        
        >>> pbag([1, 2, 2, 2]) & pbag([2, 3, 3])
        pbag([2])
        r)
r*rr+rr,rr�minrr-)rr'r.r/rr2rrr
�__and__�szPBag.__and__cCs
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
        )�hashr)rrrr
�__hash__�s
z
PBag.__hash__N)rr)�__name__�
__module__�__qualname__�__doc__�	__slots__rrrrrrr r!r$r(r)�__le__�__gt__�__ge__r1r3r5r7r9rrrr
r
s*
	
rcGs
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)�elementsrrr
�b�s
rDcCs#|s
tSttt|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_PBAGrrrr)rCrrr
rB�s	rBN)Z_compatrrrr�	functoolsrZpyrsistent._pmaprr�objectr�registerrDrBrErrrr
�<module>s"�