o
    Þý°j%x  ã                	   @   sz  d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZ dZe
dƒZG dd„ dee ƒZe
ded	�Zd
edefdd„Zd
edefdd„ZG dd„ dƒZG dd„ deeef ƒZG dd„ deeef ƒZG dd„ deƒZG dd„ deeef ƒZe
dƒZG dd„ deeeef ƒZG dd„ deeef eeeeef f eeef ƒZG dd „ d eee ƒZG d!d"„ d"eee ee ƒZd#S )$zµ
A BTree in the style of Cormen, Leiserson, and Rivest's "Algorithms" book, with
copy-on-write node updates, cursors, and optional space optimization for mostly-in-order
insertion.
é    )ÚMutableMappingÚ
MutableSet)ÚAnyÚCallableÚGenericÚOptionalÚTupleÚTypeVarÚcasté   ÚKTc                   @   s   e Zd ZdZdefdd„ZdS )ÚElementz+All items stored in the BTree are Elements.Úreturnc                 C   s   t ‚)zFThe key for this element; the returned type must implement comparison.)ÚNotImplementedError©Úself© r   ú|/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/dns/btree.pyÚkey   s   zElement.keyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   ÚET)ÚboundÚtr   c                 C   s   | d S )z[The minimum number of keys in a non-root node for a BTree with the specified
    ``t``
    é   r   ©r   r   r   r   Ú_MIN   s   r   c                 C   s   d|  d S )zGThe maximum number of keys in node for a BTree with the specified ``t``é   r   r   r   r   r   r   Ú_MAX#   s   r    c                   @   s   e Zd ZdZdd„ ZdS )Ú_CreatorzÓA _Creator class instance is used as a unique id for the BTree which created
    a node.

    We use a dedicated creator rather than just a BTree reference to avoid circularity
    that would complicate GC.
    c                 C   s   t | ƒd›S )NÚx©Úidr   r   r   r   Ú__str__0   ó   z_Creator.__str__N)r   r   r   r   r%   r   r   r   r   r!   (   s    r!   c                	   @   s
  e Zd ZdZg d¢Zdededefdd„Zdefd	d
„Z	defdd„Z
dedeeef fdd„Zdeddfdd„Zdedeed ef fdd„ZdededB fdd„Zdeddfdd„ZdedededB fdd„Zdededf fdd „Zd!ddedefd"d#„Zd!ddedefd$d%„Zd&dd'ed(dddfd)d*„Zd!ddeddfd+d,„Zdefd-d.„Zdefd/d0„Zd!ddeddfd1d2„Zded!ed d3edB dedB fd4d5„Zd6eegdf ddfd7d8„Z d6edgdf ddfd9d:„Z!deded fd;d<„Z"deddfd=d>„Z#d?d@„ Z$dS )AÚ_NodezFA Node in the BTree.

    A Node (leaf or internal) of the BTree.
    ©r   ÚcreatorÚis_leafÚeltsÚchildrenr   r)   r*   c                 C   s.   |dksJ ‚|| _ || _|| _g | _g | _d S )Né   r(   )r   r   r)   r*   r   r   r   Ú__init__<   s   
z_Node.__init__r   c                 C   s,   t | jƒt| jƒksJ ‚t | jƒt| jƒkS )z/Does this node have the maximal number of keys?)Úlenr+   r    r   r   r   r   r   Ú
is_maximalD   ó   z_Node.is_maximalc                 C   s,   t | jƒt| jƒksJ ‚t | jƒt| jƒkS )z/Does this node have the minimal number of keys?)r/   r+   r   r   r   r   r   r   Ú
is_minimalI   r1   z_Node.is_minimalr   c                 C   s´   t | jƒ}|dkr|| j|d   ¡ kr|dfS d}t | jƒ}|d }d}||krV|| d }| j|  ¡ }||krC|}d}	 ||fS ||k rN|}|d }n|d }||ks)||fS )z×Get the index of the ``Element`` matching ``key`` or the index of its
        least successor.

        Returns a tuple of the index and an ``equal`` boolean that is ``True`` iff.
        the key was found.
        r   r   Fr   T)r/   r+   r   )r   r   ÚlÚiÚrÚequalÚmÚkr   r   r   Úsearch_in_nodeN   s*   

û
õz_Node.search_in_nodeÚindexz_Node[KT, ET]c                 C   s6   | j rJ ‚| j| }| | j¡}|r|| j|< |S |S ©N)r*   r,   Ú	maybe_cowr)   )r   r:   ÚchildÚclonedr   r   r   Úmaybe_cow_childk   s   


z_Node.maybe_cow_childc                 C   s8   |   |¡\}}|r| |fS | jrdS |  |¡}| |¡S )zÜGet the node associated with key and its index, doing
        copy-on-write if we have to descend.

        Returns a tuple of the node and the index, or the tuple ``(None, 0)``
        if the key was not found.
        ©Nr   )r9   r*   r?   Ú	_get_node)r   r   r4   r6   r=   r   r   r   rA   u   s   

z_Node._get_nodeNc                 C   s6   |   |¡\}}|r| j| S | jrdS | j|  |¡S )z8Get the element associated with *key* or return ``None``N)r9   r+   r*   r,   Úget)r   r   r4   r6   r   r   r   rB   …   s   
z	_Node.getc                 C   s„   |dkrdS | j |d  }t|jƒt| jƒkrdS |  |d ¡}t|jƒt| jƒk r@| | |d ¡s4dS t|jƒt| jƒk s*dS dS )a-  Try to minimize the number of Nodes in a BTree where the insertion
        is done in-order or close to it, by stealing as much as we can from our
        right sibling.

        If we don't do this, then an in-order insertion will produce a BTree
        where most of the nodes are minimal.
        r   Nr   )r,   r/   r+   r    r   r?   Útry_right_steal)r   r:   Úleftr   r   r   Úoptimize_in_order_insertion�   s   þz!_Node.optimize_in_order_insertionÚelementÚin_orderc           	      C   s˜   |   ¡ rJ ‚	 | ¡ }|  |¡\}}|r | j| }|| j|< |S | jr,| j ||¡ d S |  |¡}|  ¡ r=| j| ¡ Ž  q| 	||¡}|rJ|  
|¡ |S r;   )r0   r   r9   r+   r*   Úinsertr?   ÚadoptÚsplitÚinsert_nonfullrE   )	r   rF   rG   r   r4   r6   Úoldr=   Úoeltr   r   r   rK   ¡   s&   



z_Node.insert_nonfullc                 C   s´   |   ¡ sJ ‚|  | j| j| j¡}t| jt| jƒd d… ƒ|_| jt| jƒ }t| jdt| jƒ… ƒ| _| jsUt| jt| jƒd d… ƒ|_t| jdt| jƒd … ƒ| _| ||fS )zASplit a maximal node into two minimal ones and a central element.r   N)	r0   Ú	__class__r   r)   r*   Úlistr+   r   r,   )r   ÚrightÚmiddler   r   r   rJ   º   s   
z_Node.splitÚparentc                 C   sŒ   |dkrD|j |d  }| ¡ sD| |d ¡}|j|d  }|j ¡ |j|d < | j d|¡ |jsB| jr6J ‚|j  ¡ }| j  d|¡ dS dS )z—Try to steal from this Node's left sibling for balancing purposes.

        Returns ``True`` if the theft was successful, or ``False`` if not.
        r   r   TF)r,   r2   r?   r+   ÚpoprH   r*   )r   rR   r:   rD   Úeltr=   r   r   r   Útry_left_stealÆ   s   

z_Node.try_left_stealc                 C   sŽ   |d t |jƒk rE|j|d  }| ¡ sE| |d ¡}|j| }|j d¡|j|< | j |¡ |jsC| jr7J ‚|j d¡}| j |¡ dS dS )z˜Try to steal from this Node's right sibling for balancing purposes.

        Returns ``True`` if the theft was successful, or ``False`` if not.
        r   r   TF)r/   r,   r2   r?   r+   rS   Úappendr*   )r   rR   r:   rP   rT   r=   r   r   r   rC   Ù   s   

z_Node.try_right_stealrD   rQ   rP   c                 C   s†   |   ¡ rJ ‚| jrJ ‚| ¡ }|  |¡\}}|rJ ‚| j ||¡ t| jƒdkr/||g| _dS | j| |ks8J ‚| j |d |¡ dS )zÒAdopt left, middle, and right into our Node (which must not be maximal,
        and which must not be a leaf).  In the case were we are not the new root,
        then the left child must already be in the Node.r   r   N)r0   r*   r   r9   r+   rH   r/   r,   )r   rD   rQ   rP   r   r4   r6   r   r   r   rI   ì   s   
z_Node.adoptc                 C   sN   |j  |d ¡}| j |j |¡¡ | j |j¡ | js%| j  |j ¡ dS dS )z>Merge this node's parent and its right sibling into this node.r   N)r,   rS   r+   rV   Úextendr*   )r   rR   r:   rP   r   r   r   Úmergeý   s   ÿz_Node.mergec                 C   ó   | j r| jd S | jd  ¡ S )z"The least element in this subtree.r   )r*   r+   r,   Úminimumr   r   r   r   rZ     ó   
z_Node.minimumc                 C   rY   )z%The greatest element in this subtree.éÿÿÿÿ)r*   r+   r,   Úmaximumr   r   r   r   r]     r[   z_Node.maximumc                 C   sd   |j rJ ‚|  ||¡rdS |  ||¡rdS |dkr!|  ||¡ dS | |d ¡}| ||d ¡ dS )z¶This Node is minimal, and we want to make it non-minimal so we can delete.
        We try to steal from our siblings, and if that doesn't work we will merge
        with one of them.Nr   r   )r*   rU   rC   rX   r?   )r   rR   r:   rD   r   r   r   Úbalance  s   
z_Node.balanceÚexactc                 C   s@  |du s
|   ¡ r
J ‚|  |¡\}}d}|rB|dur$| j| |ur$tdƒ‚| jr-| j |¡S d}|}| j|d   ¡ }| ¡ }|d }| jrO|durMtdƒ‚dS |  	|¡}|  ¡ rt| 
| |¡ |  |¡\}}|riJ ‚| j| }|  ¡ rtJ ‚| || |¡}	|durž|  |¡\}
}|
dusŒJ ‚|	dus’J ‚|
j| }|	|
j|< |}	|	S )zÁDelete an element matching *key* if it exists.  If *exact* is not ``None``
        then it must be an exact match with that element.  The Node must not be
        minimal unless it is the root.Nz'exact delete did not match existing eltr   zexact delete had no match)r2   r9   r+   Ú
ValueErrorr*   rS   r,   rZ   r   r?   r^   ÚdeleterA   )r   r   rR   r_   r4   r6   Úoriginal_keyÚleast_successorr=   rT   ÚnoderM   r   r   r   ra   &  sB   



z_Node.deleteÚvisitc                 C   sP   t | jƒD ]\}}| js| j|  |¡ ||ƒ q| js&| jd  |¡ dS dS )z-Call *visit* on all of the elements in order.r\   N)Ú	enumerater+   r*   r,   Úvisit_in_order)r   re   r4   rT   r   r   r   rg   U  s   
ÿz_Node.visit_in_orderc                 C   s,   || ƒ | j s| jD ]	}| |¡ q
dS dS )z?Visit nodes in preorder.  This method is only used for testing.N)r*   r,   Ú_visit_preorder_by_node)r   re   r=   r   r   r   rh   ^  s   
þz_Node._visit_preorder_by_nodec                 C   s   | j |ur
|  |¡S dS )zœReturn a clone of this Node if it was not created by *creator*, or ``None``
        otherwise (i.e. copy for copy-on-write if we haven't already copied it).N)r)   Úclone)r   r)   r   r   r   r<   e  s   

z_Node.maybe_cowc                 C   s8   |   | j|| j¡}|j | j¡ | js|j | j¡ |S )z+Make a shallow-copy duplicate of this node.)rN   r   r*   r+   rW   r,   )r   r)   r>   r   r   r   ri   m  s
   z_Node.clonec                 C   sH   | j sdd dd„ | jD ƒ¡ }nd}t| ƒd›d| j› d| j› |› �S )Nú c                 S   s   g | ]}t |ƒd ›‘qS )r"   r#   )Ú.0Úcr   r   r   Ú
<listcomp>w  s    z!_Node.__str__.<locals>.<listcomp>Ú r"   )r*   Újoinr,   r$   r)   r+   )r   r,   r   r   r   r%   u  s   "z_Node.__str__)%r   r   r   r   Ú	__slots__Úintr!   Úboolr.   r0   r2   r   Útupler9   r?   r   r   rA   r   rB   rE   rK   rJ   rU   rC   rI   rX   rZ   r]   r^   ra   r   rg   rh   r<   ri   r%   r   r   r   r   r'   4   sD    

ÿÿÿ
þ/	r'   c                   @   s´   e Zd ZdZd$dd„Zd%dd	„Zd%d
d„Zdd„ Zdd„ Zde	dB fdd„Z
de	dB fdd„Zdededdfdd„Zd&dededdfdd„Zd%dd„Zd%dd„Zd d!„ Zd"d#„ ZdS )'ÚCursorzÍA seekable cursor for a BTree.

    If you are going to use a cursor on a mutable BTree, you should use it
    in a ``with`` block so that any mutations of the BTree automatically park
    the cursor.
    ÚbtreeúBTree[KT, ET]c                 C   s:   || _ d | _d| _d| _d| _g | _d| _d | _d| _d S )Nr   FT)	ru   Úcurrent_nodeÚcurrent_indexÚrecurseÚ
increasingÚparentsÚparkedÚparking_keyÚparking_key_read)r   ru   r   r   r   r.   …  s   
zCursor.__init__r   Nc                 C   s^   | j d usJ ‚| j js-| j | j | jf¡ | j j| j | _ | j d us$J ‚d| _| j jrd S d S r@   )rw   r*   r{   rV   rx   r,   r   r   r   r   Ú_seek_least“  s   üzCursor._seek_leastc                 C   sf   | j d usJ ‚| j js1| j | j | jf¡ | j j| j | _ | j d us$J ‚t| j jƒ| _| j jrd S d S r;   )rw   r*   r{   rV   rx   r,   r/   r+   r   r   r   r   Ú_seek_greatest�  s   üzCursor._seek_greatestc                 C   ó   | j sd| _ dS dS )a§  Park the cursor.

        A cursor must be "parked" before mutating the BTree to avoid undefined behavior.
        Cursors created in a ``with`` block register with their BTree and will park
        automatically.  Note that a parked cursor may not observe some changes made when
        it is parked; for example a cursor being iterated with next() will not see items
        inserted before its current position.
        TN)r|   r   r   r   r   Úpark§  s   	
ÿzCursor.parkc                 C   sT   | j r(| jd ur | j}| jr| j }n| j}|  | j|¡ || _d| _ d | _d S d S ©NF)r|   r}   rz   r~   Úseek)r   rz   Úbeforer   r   r   Ú_maybe_unpark³  s   


ðzCursor._maybe_unparkc                 C   sô   |   ¡  d| _| jdu r+| jdkrdS | jdksJ ‚| jj| _t| jjjƒ| _|  ¡  	 | j	r9| j
s6|  ¡  d| _	d| _
|  jd8  _| jdkr`| jj| j }| jjsVd| _	| ¡ | _d| _|S t| jƒdkrq| j ¡ \| _| _nd| _d| _dS q,)zAGet the previous element, or return None if on the left boundary.Nr   r   TF)r†   r}   rw   rx   ru   Úrootr/   r+   r€   ry   rz   r*   r   r~   r{   rS   ©r   rT   r   r   r   ÚprevÆ  s:   




êzCursor.prevc                 C   sò   |   ¡  d| _| jdu r&| jdkrdS | jdksJ ‚| jj| _d| _|  ¡  	 | jr4| jr1|  ¡  d| _d| _| jt	| jj
ƒk r_| jj
| j }|  jd7  _| jjsUd| _| ¡ | _d| _|S t	| jƒdkrp| j ¡ \| _| _nd| _d| _dS q')z>Get the next element, or return None if on the right boundary.Nr   r   TF)r†   r}   rw   rx   ru   r‡   r   ry   rz   r/   r+   r*   r   r~   r{   rS   rˆ   r   r   r   Únextî  s:   



êzCursor.nextr…   r4   c                 C   s   |r|| _ d S |d | _ d S )Nr   )rx   )r   r…   r4   r   r   r   Ú_adjust_for_before  s   
zCursor._adjust_for_beforeTr   c                 C   sä   | j j| _| jdusJ ‚d| _g | _|| _d| _|| _d| _| jj	s[| j 
|¡\}}|r@|  ||¡ |r:|  ¡  dS |  ¡  dS | j | j|f¡ | jj| | _| jdusWJ ‚| jj	r"| j 
|¡\}}|rm|  ||¡ dS || _dS )a½  Seek to the specified key.

        If *before* is ``True`` (the default) then the cursor is positioned just
        before *key* if it exists, or before its least successor if it doesn't.  A
        subsequent next() will retrieve this value.  If *before* is ``False``, then
        the cursor is positioned just after *key* if it exists, or its greatest
        precessessor if it doesn't.  A subsequent prev() will return this value.
        NF)ru   r‡   rw   ry   r{   rz   r|   r}   r~   r*   r9   r‹   r€   r   rV   r,   rx   )r   r   r…   r4   r6   r   r   r   r„     s2   
	ÿõ
zCursor.seekc                 C   s.   d| _ d| _d| _d| _g | _d| _d| _dS )z”Seek to the left boundary (i.e. just before the least element).

        A subsequent next() will return the least element if the BTree isn't empty.Nr   FT©rw   rx   ry   rz   r{   r|   r}   r   r   r   r   Ú
seek_first?  s   
zCursor.seek_firstc                 C   s.   d| _ d| _d| _d| _g | _d| _d| _dS )z£Seek to the right boundary (i.e. just after the greatest element).

        A subsequent prev() will return the greatest element if the BTree isn't empty.
        Nr   FrŒ   r   r   r   r   Ú	seek_lastK  s   
zCursor.seek_lastc                 C   s   | j  | ¡ | S r;   )ru   Úregister_cursorr   r   r   r   Ú	__enter__X  ó   zCursor.__enter__c                 C   s   | j  | ¡ dS rƒ   )ru   Úderegister_cursor)r   Úexc_typeÚ	exc_valueÚ	tracebackr   r   r   Ú__exit__\  r‘   zCursor.__exit__)ru   rv   ©r   N)T)r   r   r   r   r.   r   r€   r‚   r†   r   r‰   rŠ   rr   rq   r‹   r   r„   r�   rŽ   r�   r–   r   r   r   r   rt   }  s    




((
#
rt   c                   @   s   e Zd ZdZdS )Ú	ImmutablezThe BTree is immutable.N)r   r   r   r   r   r   r   r   r˜   a  s    r˜   c                   @   sF  e Zd ZdZeddœdeded  fdd„Zdd	„ Zd/dd„Z	d0de
ded
e
dB fdd„Zded
e
dB fdd„Zdede
dB d
e
dB fdd„Zded
e
dB fdd„Zde
d
e
dB fdd„Zdd„ Zdee
gdf d
dfd d!„Zdeegdf d
dfd"d#„Zd
eee
f fd$d%„Zd&ed
dfd'd(„Zd&ed
dfd)d*„Zd+d,„ Zd-d.„ ZdS )1ÚBTreez2An in-memory BTree with copy-on-write and cursors.N©r   Úoriginalr   r›   c                C   s†   t ƒ | _d| _|  |  |  tƒ | _|dur*|jstdƒ‚|j| _|j| _|j| _dS |dk r2tdƒ‚|| _t	| j| jdƒ| _d| _dS )zýCreate a BTree.

        If *original* is not ``None``, then the BTree is shallow-cloned from
        *original* using copy-on-write.  Otherwise a new BTree with the specified
        *t* value is created.

        The BTree is not thread-safe.
        FNzoriginal BTree is not immutabler-   zt must be >= 3Tr   )
r!   r)   Ú
_immutableÚsetÚcursorsr`   r   r‡   Úsizer'   )r   r   r›   r   r   r   r.   h  s"   
zBTree.__init__c                 C   r�   )z®Make the BTree immutable.

        Attempts to alter the BTree after making it immutable will raise an
        Immutable exception.  This operation cannot be undone.
        TN)rœ   r   r   r   r   Úmake_immutable†  s   
ÿzBTree.make_immutabler   c                 C   s"   | j rt‚| jD ]}| ¡  qd S r;   )rœ   r˜   rž   r‚   ©r   Úcursorr   r   r   Ú_check_mutable_and_park�  s
   

ÿzBTree._check_mutable_and_parkFrT   rG   c                 C   sz   |   ¡  | j | j¡}|r|| _| j ¡ r)| j}t| j| jdƒ| _| jj| ¡ Ž  | j 	||¡}|du r;|  j
d7  _
|S )aE  Insert the element into the BTree.

        If *in_order* is ``True``, then extra work will be done to make left siblings
        full, which optimizes storage space when the the elements are inserted in-order
        or close to it.

        Returns the previously existing element at the element's key or ``None``.
        FNr   )r£   r‡   r<   r)   r0   r'   r   rI   rJ   rK   rŸ   )r   rT   rG   r>   Úold_rootrM   r   r   r   Úinsert_element™  s   	
zBTree.insert_elementr   c                 C   s   | j  |¡S )zhGet the element matching *key* from the BTree, or return ``None`` if it
        does not exist.
        )r‡   rB   ©r   r   r   r   r   Úget_element°  s   zBTree.get_elementr_   c                 C   s„   |   ¡  | j | j¡}|r|| _| j |d |¡}|d ur@|  jd8  _t| jjƒdkr@| jjs@t| jj	ƒdks9J ‚| jj	d | _|S )Nr   r   )
r£   r‡   r<   r)   ra   rŸ   r/   r+   r*   r,   )r   r   r_   r>   rT   r   r   r   Ú_delete¶  s   zBTree._deletec                 C   s   |   |d¡S )z‚Delete the element matching *key* from the BTree.

        Returns the matching element or ``None`` if it does not exist.
        N)r¨   r¦   r   r   r   Ú
delete_keyÇ  s   zBTree.delete_keyrF   c                 C   s    |   | ¡ |¡}||u sJ ‚|S )zwDelete *element* from the BTree.

        Returns the matching element or ``None`` if it was not in the BTree.
        )r¨   r   )r   rF   Údeltr   r   r   Údelete_exactÎ  s   zBTree.delete_exactc                 C   ó   | j S r;   )rŸ   r   r   r   r   Ú__len__×  ó   zBTree.__len__re   c                 C   ó   | j  |¡ dS )zBCall *visit*(element) on all elements in the tree in sorted order.N)r‡   rg   ©r   re   r   r   r   rg   Ú  ó   zBTree.visit_in_orderc                 C   s   | j  |¡ d S r;   )r‡   rh   r°   r   r   r   rh   Þ  s   zBTree._visit_preorder_by_nodec                 C   s   t | ƒS )zCreate a cursor.)rt   r   r   r   r   r¢   á  s   zBTree.cursorr¢   c                 C   r¯   )z4Register a cursor for the automatic parking service.N)rž   Úaddr¡   r   r   r   r�   å  r±   zBTree.register_cursorc                 C   r¯   )z7Deregister a cursor from the automatic parking service.N)rž   Údiscardr¡   r   r   r   r’   é  r±   zBTree.deregister_cursorc                 C   s   | j | d�S )N)r›   ©rN   r   r   r   r   Ú__copy__í  r&   zBTree.__copy__c                 c   sP   � |   ¡ �}	 | ¡ }|d u rn| ¡ V  qW d   ƒ d S 1 s!w   Y  d S r;   )r¢   rŠ   r   )r   r¢   rT   r   r   r   Ú__iter__ð  s   €

ü"üzBTree.__iter__r—   )F)r   r   r   r   Ú	DEFAULT_Trq   r   r.   r    r£   r   rr   r¥   r   r§   r¨   r©   r«   r­   r   rg   r'   rh   rt   r¢   r�   r’   rµ   r¶   r   r   r   r   r™   e  s$    
	
	r™   ÚVTc                   @   sN   e Zd ZdZdedefdd„Zdefdd„Zdefd	d
„Zdd„ Z	dd„ Z
dS )ÚKVz/The BTree element type used in a ``BTreeDict``.r   Úvaluec                 C   s   || _ || _d S r;   ©Ú_keyÚ_value)r   r   rº   r   r   r   r.   ÿ  s   
zKV.__init__r   c                 C   r¬   r;   ©r¼   r   r   r   r   r     r®   zKV.keyc                 C   r¬   r;   )r½   r   r   r   r   rº     r®   zKV.valuec                 C   ó   d| j › d| j› d�S ©NzKV(z, ú)r»   r   r   r   r   r%   	  ó   z
KV.__str__c                 C   r¿   rÀ   r»   r   r   r   r   Ú__repr__  rÂ   zKV.__repr__N)r   r   r   r   r   r¸   r.   r   rº   r%   rÃ   r   r   r   r   r¹   ü  s    r¹   c                       sv   e Zd ZdZedddœdededB def‡ fdd	„Zd
e	de
fdd„Zd
e	de
ddfdd„Zd
e	ddfdd„Z‡  ZS )Ú	BTreeDictzA MutableMapping implemented with a BTree.

    Unlike a normal Python dict, the BTreeDict may be mutated while iterating.
    NF©r   r›   rG   r   r›   rG   c                   ó   t ƒ j||d� || _d S ©Nrš   ©Úsuperr.   rG   ©r   r   r›   rG   r´   r   r   r.     ó   
zBTreeDict.__init__r   r   c                 C   s$   |   |¡}|d u rt‚tt|ƒ ¡ S r;   )r§   ÚKeyErrorr
   r¹   rº   )r   r   rT   r   r   r   Ú__getitem__   s   
zBTreeDict.__getitem__rº   c                 C   s   t ||ƒ}|  || j¡ d S r;   )r¹   r¥   rG   )r   r   rº   rT   r   r   r   Ú__setitem__'  s   
zBTreeDict.__setitem__c                 C   s   |   |¡d u r	t‚d S r;   )r©   rÌ   r¦   r   r   r   Ú__delitem__+  s   ÿzBTreeDict.__delitem__)r   r   r   r   r·   rq   r™   rr   r.   r   r¸   rÍ   rÎ   rÏ   Ú__classcell__r   r   r´   r   rÄ     s    ûýüû
rÄ   c                   @   s,   e Zd ZdZdefdd„Zdefdd„ZdS )	ÚMemberz.The BTree element type used in a ``BTreeSet``.r   c                 C   s
   || _ d S r;   r¾   r¦   r   r   r   r.   3  s   
zMember.__init__r   c                 C   r¬   r;   r¾   r   r   r   r   r   6  r®   z
Member.keyN)r   r   r   r   r   r.   r   r   r   r   r   rÑ   0  s    rÑ   c                       sr   e Zd ZdZedddœdededB def‡ fdd	„Zd
e	defdd„Z
deddfdd„Zdeddfdd„Z‡  ZS )ÚBTreeSetzyA MutableSet implemented with a BTree.

    Unlike a normal Python set, the BTreeSet may be mutated while iterating.
    NFrÅ   r   r›   rG   c                   rÆ   rÇ   rÈ   rÊ   r´   r   r   r.   @  rË   zBTreeSet.__init__r   r   c                 C   s   |   |¡d uS r;   )r§   r¦   r   r   r   Ú__contains__J  ó   zBTreeSet.__contains__rº   c                 C   s   t |ƒ}|  || j¡ d S r;   )rÑ   r¥   rG   )r   rº   rT   r   r   r   r²   M  s   zBTreeSet.addc                 C   s   |   |¡ d S r;   )r©   )r   rº   r   r   r   r³   Q  rÔ   zBTreeSet.discard)r   r   r   r   r·   rq   r™   rr   r.   r   rÓ   r   r²   r³   rÐ   r   r   r´   r   rÒ   :  s    ûýüû
rÒ   N)r   Úcollections.abcr   r   Útypingr   r   r   r   r   r	   r
   r·   r   r   r   rq   r   r    r!   r'   rt   Ú	Exceptionr˜   r™   r¸   r¹   rÄ   rÑ   rÒ   r   r   r   r   Ú<module>   s.   $  K e 4  
