Your IP : 13.58.72.156


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/__pycache__/_pmap.cpython-37.pyc

B

+�[39�@s�ddlmZmZddlmZddlZddlmZddlm	Z	Gdd�de
�Ze�e�e�e�d	d
�Z
e
id�Zidfdd�Zd
d�ZdS)�)�Mapping�Hashable�)�chainN)�pvector)�	transformcs@eZdZdZdZ�fdd�Zedd��Zedd��Zd	d
�Z	edd��Z
d
d�Zej
Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZejZd%d&�ZeZeZeZd'd(�Zd)d*�Zd+d,�Z d-d.�Z!d/d0�Z"d1d2�Z#d3d4�Z$d5d6�Z%d7d8�Z&d9d:�Z'd;d<�Z(Gd=d>�d>e)�Z*d?d@�Z+�Z,S)A�PMapa�
    Persistent map/dict. Tries to follow the same naming conventions as the built in dict where feasible.

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

    Was originally written as a very close copy of the Clojure equivalent but was later rewritten to closer
    re-assemble the python dict. This means that a sparse vector (a PVector) of buckets is used. The keys are
    hashed and the elements inserted at position hash % len(bucket_vector). Whenever the map size exceeds 2/3 of
    the containing vectors size the map is reallocated to a vector of double the size. This is done to avoid
    excessive hash collisions.

    This structure corresponds most closely to the built in dict type and is intended as a replacement. Where the
    semantics are the same (more or less) the same function names have been used but for some cases it is not possible,
    for example assignments and deletion of values.

    PMap implements the Mapping protocol and is Hashable. It also supports dot-notation for
    element access.

    Random access and insert is log32(n) where n is the size of the map.

    The following are examples of some common operations on persistent maps

    >>> m1 = m(a=1, b=3)
    >>> m2 = m1.set('c', 3)
    >>> m3 = m2.remove('a')
    >>> m1
    pmap({'a': 1, 'b': 3})
    >>> m2
    pmap({'a': 1, 'c': 3, 'b': 3})
    >>> m3
    pmap({'c': 3, 'b': 3})
    >>> m3['c']
    3
    >>> m3.c
    3
    )�_size�_buckets�__weakref__�_cached_hashcs tt|��|�}||_||_|S)N)�superr�__new__r	r
)�cls�size�buckets�self)�	__class__��C/opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/_pmap.pyr0szPMap.__new__cCs t|�t|�}||}||fS)N)�hash�len)r�key�index�bucketrrr�_get_bucket6szPMap._get_bucketcCs>t�||�\}}|r2x|D]\}}||kr|SqWt|��dS)N)rr�KeyError)rr�_r�k�vrrr�_getitem<sz
PMap._getitemcCst�|j|�S)N)rr r
)rrrrr�__getitem__FszPMap.__getitem__cCs:t�||�\}}|r6x|D]\}}||krdSqWdSdS)NTF)rr)rrrrrrrr�	_containsIszPMap._containscCs|�|j|�S)N)r"r
)rrrrr�__contains__UszPMap.__contains__cCs|��S)N)�iterkeys)rrrr�__iter__Zsz
PMap.__iter__cCs8y||Stk
r2td�t|�j|���YnXdS)Nz{0} has no attribute '{1}')r�AttributeError�format�type�__name__)rrrrr�__getattr__]s
zPMap.__getattr__ccs x|��D]\}}|Vq
WdS)N)�	iteritems)rrrrrrr$esz
PMap.iterkeysccs x|��D]\}}|Vq
WdS)N)r+)rrrrrr�
itervalueslszPMap.itervaluesccs4x.|jD]$}|rx|D]\}}||fVqWqWdS)N)r
)rrrrrrrr+pszPMap.iteritemscCst|���S)N)rr,)rrrr�valuesvszPMap.valuescCst|���S)N)rr$)rrrr�keysysz	PMap.keyscCst|���S)N)rr+)rrrr�items|sz
PMap.itemscCs|jS)N)r	)rrrr�__len__szPMap.__len__cCsd�tt|���S)Nz	pmap({0}))r'�str�dict)rrrr�__repr__�sz
PMap.__repr__cCs�||krdSt|t�stSt|�t|�kr.dSt|t�r�t|d�r\t|d�r\|j|jkr\dS|j|jkrldSt|�	��t|�	��kSt|t�r�t|�	��|kSt|�	��tt
�	|��kS)NTFr)�
isinstancer�NotImplementedrr�hasattrrr
r2r+�six)r�otherrrr�__eq__�s 


zPMap.__eq__cCstd��dS)NzPMaps are not orderable)�	TypeError)rr8rrr�__lt__�szPMap.__lt__cCs|��S)N)r3)rrrr�__str__�szPMap.__str__cCs"t|d�stt|����|_|jS)Nr)r6r�	frozensetr+r)rrrr�__hash__�s
z
PMap.__hash__cCs|���||���S)a.
        Return a new PMap with key and val inserted.

        >>> m1 = m(a=1, b=2)
        >>> m2 = m1.set('a', 3)
        >>> m3 = m1.set('c' ,4)
        >>> m1
        pmap({'a': 1, 'b': 2})
        >>> m2
        pmap({'a': 3, 'b': 2})
        >>> m3
        pmap({'a': 1, 'c': 4, 'b': 2})
        )�evolver�set�
persistent)rr�valrrrr@�szPMap.setcCs|���|���S)z�
        Return a new PMap without the element specified by key. Raises KeyError if the element
        is not present.

        >>> m1 = m(a=1, b=2)
        >>> m1.remove('a')
        pmap({'b': 2})
        )r?�removerA)rrrrrrC�s	zPMap.removecCs$y
|�|�Stk
r|SXdS)a
        Return a new PMap without the element specified by key. Returns reference to itself
        if element is not present.

        >>> m1 = m(a=1, b=2)
        >>> m1.discard('a')
        pmap({'b': 2})
        >>> m1 is m1.discard('c')
        True
        N)rCr)rrrrr�discard�s
zPMap.discardcGs|jdd�f|��S)a*
        Return a new PMap with the items in Mappings inserted. If the same key is present in multiple
        maps the rightmost (last) value is inserted.

        >>> m1 = m(a=1, b=2)
        >>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35})
        pmap({'a': 17, 'c': 3, 'b': 2, 'd': 35})
        cSs|S)Nr)�l�rrrr�<lambda>��zPMap.update.<locals>.<lambda>)�update_with)r�mapsrrr�update�s	zPMap.updatecGsV|��}xD|D]<}x6|��D]*\}}|�|||kr@||||�n|�qWqW|��S)a#
        Return a new PMap with the items in Mappings maps inserted. If the same key is present in multiple
        maps the values will be merged using merge_fn going from left to right.

        >>> from operator import add
        >>> m1 = m(a=1, b=2)
        >>> m1.update_with(add, m(a=2))
        pmap({'a': 3, 'b': 2})

        The reverse behaviour of the regular merge. Keep the leftmost element instead of the rightmost.

        >>> m1 = m(a=1)
        >>> m1.update_with(lambda l, r: l, m(a=2), {'a':3})
        pmap({'a': 1})
        )r?r/r@rA)rZ	update_fnrJr?�mapr�valuerrrrI�s

*zPMap.update_withcCs
|�|�S)N)rK)rr8rrr�__add__�szPMap.__add__cCstt|�ffS)N)�pmapr2)rrrr�
__reduce__�szPMap.__reduce__cGs
t||�S)a�
        Transform arbitrarily complex combinations of PVectors and PMaps. A transformation
        consists of two parts. One match expression that specifies which elements to transform
        and one transformation function that performs the actual transformation.

        >>> from pyrsistent import freeze, ny
        >>> news_paper = freeze({'articles': [{'author': 'Sara', 'content': 'A short article'},
        ...                                   {'author': 'Steve', 'content': 'A slightly longer article'}],
        ...                      'weather': {'temperature': '11C', 'wind': '5m/s'}})
        >>> short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:25] + '...' if len(c) > 25 else c)
        >>> very_short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:15] + '...' if len(c) > 15 else c)
        >>> very_short_news.articles[0].content
        'A short article'
        >>> very_short_news.articles[1].content
        'A slightly long...'

        When nothing has been transformed the original data structure is kept

        >>> short_news is news_paper
        True
        >>> very_short_news is news_paper
        False
        >>> very_short_news.articles[0] is news_paper.articles[0]
        True
        )r)rZtransformationsrrrr�szPMap.transformcCs|S)Nr)rrrr�copysz	PMap.copyc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)z
PMap._Evolver)�_buckets_evolverr	�_original_pmapcCs||_|j��|_|j|_dS)N)rSr
r?rRr	)rZ
original_pmaprrr�__init__szPMap._Evolver.__init__cCst�|j|�S)N)rr rR)rrrrrr!#szPMap._Evolver.__getitem__cCs|�||�dS)N)r@)rrrBrrr�__setitem__&szPMap._Evolver.__setitem__cs�t|j�d|jkr(|�dt|j��|�f}t�|j|�\}}|r�xB|D]:\�}�|krL|�k	r���fdd�|D�}||j|<|SqLW|g}|�|�||j|<|jd7_n|g|j|<|jd7_|S)Ngq=
ףp�?�cs(g|] \}}|�kr||fn|�f�qSrr)�.0Zk2Zv2)rrBrr�
<listcomp>3sz%PMap._Evolver.set.<locals>.<listcomp>r)rrRr	�_reallocaterr�extend)rrrB�kvrrr�
new_bucketr)rrBrr@)s$


zPMap._Evolver.setcCs�|dg}|j��}xVt�dd�|D��D]>\}}t|�|}||rZ||�||f�q*||fg||<q*Wt���|_|j�|�dS)Ncss|]}|r|VqdS)Nr)rW�xrrr�	<genexpr>Esz,PMap._Evolver._reallocate.<locals>.<genexpr>)	rRrAr�
from_iterabler�appendrr?rZ)rZnew_sizeZnew_listrrrrrrrrYBs

zPMap._Evolver._reallocatecCs
|j��S)N)rR�is_dirty)rrrrraQszPMap._Evolver.is_dirtycCs"|��rt|j|j���|_|jS)N)rarr	rRrArS)rrrrrATszPMap._Evolver.persistentcCs|jS)N)r	)rrrrr0ZszPMap._Evolver.__len__cCst�|j|�S)N)rr"rR)rrrrrr#]szPMap._Evolver.__contains__cCs|�|�dS)N)rC)rrrrr�__delitem__`szPMap._Evolver.__delitem__csnt�|j��\}}|r\�fdd�|D�}t|�t|�kr\|r@|nd|j|<|jd8_|Std�����dS)Ncs g|]\}}|�kr||f�qSrr)rWrr)rrrrXgsz(PMap._Evolver.remove.<locals>.<listcomp>rz{0})rrrRrr	rr')rrrrr\r)rrrCcszPMap._Evolver.removeN)r)�
__module__�__qualname__�	__slots__rTr!rUr@rYrarAr0r#rbrCrrrr�_EvolversrfcCs
|�|�S)a)
        Create a new evolver for this pmap. For a discussion on evolvers in general see the
        documentation for the pvector evolver.

        Create the evolver and perform various mutating updates to it:

        >>> m1 = m(a=1, b=2)
        >>> e = m1.evolver()
        >>> e['c'] = 3
        >>> len(e)
        3
        >>> del e['a']

        The underlying pmap remains the same:

        >>> m1
        pmap({'a': 1, 'b': 2})

        The changes are kept in the evolver. An updated pmap can be created using the
        persistent() function on the evolver.

        >>> m2 = e.persistent()
        >>> m2
        pmap({'c': 3, 'b': 2})

        The new pmap will share data with the original pmap in the same way that would have
        been done if only using operations on the pmap.
        )rf)rrrrr?oszPMap.evolver)-r)rcrd�__doc__rer�staticmethodrr r!r"r#r�getr%r*r$r,r+r-r.r/r0r3r9�__ne__r;�__le__�__gt__�__ge__r<r>r@rCrDrKrIrNrPrrQ�objectrfr?�
__classcell__rr)rrrsL%
Trc	Cs�|r
|}n.ydt|�pd}Wntk
r6d}YnX|dg}t|t�sTt|�}xPt�|�D]B\}}t|�}||}||}|r�|�||f�q`||fg||<q`Wt	t|�t
��|��S)NrV�)r�	Exceptionr4rr2r7r+rr`rrrZ)	�initial�pre_sizerrrr�hrrrrr�_turbo_mapping�s"


rucCs|stSt||�S)a�
    Create new persistent map, inserts all elements in initial into the newly created map.
    The optional argument pre_size may be used to specify an initial size of the underlying bucket vector. This
    may have a positive performance impact in the cases where you know beforehand that a large number of elements
    will be inserted into the map eventually since it will reduce the number of reallocations required.

    >>> pmap({'a': 13, 'b': 14})
    pmap({'a': 13, 'b': 14})
    )�_EMPTY_PMAPru)rrrsrrrrO�s
rOcKst|�S)z�
    Creates a new persitent map. Inserts all key value arguments into the newly created map.

    >>> m(a=13, b=14)
    pmap({'a': 13, 'b': 14})
    )rO)�kwargsrrr�m�srx)�_compatrr�	itertoolsrr7Zpyrsistent._pvectorrZpyrsistent._transformationsrrnr�registerrurvrOrxrrrr�<module>s	

 


?>