
    i%x              
       z   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ee                   Z e
de	          Zd
edefdZd
edefdZ G d d          Z G d deeef                   Z G d deeef                   Z G d de          Z G d deeef                   Z e
d          Z G d deeeef                   Z G d deeef         eeeeef         f         eeef                   Z G d deee                   Z G 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                       e Zd ZdZdefdZdS )Elementz+All items stored in the BTree are Elements.returnc                     t           )zFThe key for this element; the returned type must implement comparison.)NotImplementedErrorselfs    Y/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/dns/btree.pykeyzElement.key   s    !!    N)__name__
__module____qualname____doc__r   r    r   r   r   r      s5        55"R " " " " " "r   r   ET)boundtr   c                     | dz
  S )z[The minimum number of keys in a non-root node for a BTree with the specified
    ``t``
       r   r   s    r   _MINr#      s     q5Lr   c                     d| z  dz
  S )zGThe maximum number of keys in node for a BTree with the specified ``t``   r!   r   r"   s    r   _MAXr&   #   s    q519r   c                       e Zd ZdZd ZdS )_CreatorzA _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                 $    t          |           dS )Nxidr   s    r   __str__z_Creator.__str__0   s    T((r   N)r   r   r   r   r-   r   r   r   r(   r(   (   s-             r   r(   c            	       &   e Zd ZdZg dZdededefdZdefdZ	defd	Z
d
edeeef         fdZdeddfdZd
edeed         ef         fdZd
ededz  fdZdeddfdZdedededz  fdZdededf         fdZdddedefdZdddedefdZdddeddddfdZdddeddfdZdefdZdefd Zdddeddfd!Zd
eded         d"edz  dedz  fd#Zd$eegdf         ddfd%Z d$edgdf         ddfd&Z!deded         fd'Z"deddfd(Z#d) Z$dS )*_NodezFA Node in the BTree.

    A Node (leaf or internal) of the BTree.
    r   creatoris_leafeltschildrenr   r1   r2   c                 \    |dk    sJ || _         || _        || _        g | _        g | _        d S )N   r0   )r   r   r1   r2   s       r   __init__z_Node.__init__<   s6    Avvvv 	-/r   r   c                     t          | j                  t          | j                  k    sJ t          | j                  t          | j                  k    S )z/Does this node have the maximal number of keys?)lenr3   r&   r   r   s    r   
is_maximalz_Node.is_maximalD   >    49~~df----49~~df--r   c                     t          | j                  t          | j                  k    sJ t          | j                  t          | j                  k    S )z/Does this node have the minimal number of keys?)r9   r3   r#   r   r   s    r   
is_minimalz_Node.is_minimalI   r;   r   r   c                 n   t          | j                  }|dk    r*|| j        |dz
                                           k    r|dfS d}t          | j                  }|dz
  }d}||k    rK||z   dz  }| j        |                                         }||k    r|}d}n||k     r|}|dz
  }n|dz   }||k    K||fS )zGet 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)r9   r3   r   )r   r   lirequalmks           r   search_in_nodez_Node.search_in_nodeN   s     	NNq55S49QU+//1111e8O	NNE1ffQ1A	!  ""AaxxqEE 1ff %xr   indexz_Node[KT, ET]c                     | j         rJ | j        |         }|                    | j                  }|r|| j        |<   |S |S N)r2   r4   	maybe_cowr1   )r   rF   childcloneds       r   maybe_cow_childz_Node.maybe_cow_childk   sM    <e$.. 	#)DM% MLr   c                     |                      |          \  }}|r| |fS | j        rdS |                     |          }|                    |          S )zGet 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   )rE   r2   rL   	_get_node)r   r   r@   rB   rJ   s        r   rO   z_Node._get_nodeu   sa     &&s++5 	(!9\ 	(9((++E??3'''r   Nc                     |                      |          \  }}|r| j        |         S | j        rdS | j        |                             |          S )z8Get the element associated with *key* or return ``None``N)rE   r3   r2   r4   get)r   r   r@   rB   s       r   rQ   z	_Node.get   sW    &&s++5 	-9Q<\ 	-4=#'',,,r   c                    |dk    rdS | j         |dz
           }t          |j                  t          | j                  k    rdS |                     |dz
            }t          |j                  t          | j                  k     rG|                    | |dz
            sdS t          |j                  t          | j                  k     Ed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!   )r4   r9   r3   r&   r   rL   try_right_steal)r   rF   lefts      r   optimize_in_order_insertionz!_Node.optimize_in_order_insertion   s     A::F}UQY'ty>>T$&\\))F##EAI..$)nntDF||++''eai88  $)nntDF||++++++r   elementin_orderc                    |                                  rJ 	 |                                }|                     |          \  }}|r| j        |         }|| j        |<   |S | j        r| j                            ||           d S |                     |          }|                                 r | j        |                                  |	                    ||          }|r| 
                    |           |S rH   )r:   r   rE   r3   r2   insertrL   adoptsplitinsert_nonfullrU   )	r   rV   rW   r   r@   rB   oldrJ   oelts	            r   r\   z_Node.insert_nonfull   s   ??$$$$$	++--C**3//HAu il&	!
 	  G,,,t,,Q//##%% DJ.. ++GX>> 844Q777r   c                 z   |                                  sJ |                     | j        | j        | j                  }t          | j        t          | j                  dz   d                   |_        | j        t          | j                           }t          | j        dt          | j                                     | _        | j        slt          | j        t          | j                  dz   d                   |_        t          | j        dt          | j                  dz                      | _        | ||fS )zASplit a maximal node into two minimal ones and a central element.r!   N)	r:   	__class__r   r1   r2   listr3   r#   r4   )r   rightmiddles      r   r[   z_Node.split   s         tvt|T\BB$)DLL1$4$6$6788
4<<(>T$&\\>233	| 	D!$-TVq0@0B0B"CDDEN /Adf1A/A!BCCDMVU""r   parentc                    |dk    r|j         |dz
           }|                                s|                    |dz
            }|j        |dz
           }|j                                        |j        |dz
  <   | j                            d|           |j        s=| j        rJ |j                                         }| j                             d|           dS dS )zTry 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)r4   r=   rL   r3   poprY   r2   )r   rd   rF   rT   eltrJ   s         r   try_left_stealz_Node.try_left_steal   s    
 A::?519-D??$$ 	--eai88k%!),)-EAI&	  C(((| 3#|+++ M--//EM((E222tur   c                    |dz   t          |j                  k     r|j        |dz            }|                                s|                    |dz             }|j        |         }|j                            d          |j        |<   | j                            |           |j        s=| j        rJ |j                            d          }| j                            |           dS dS )zTry 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)r9   r4   r=   rL   r3   rf   appendr2   )r   rd   rF   rb   rg   rJ   s         r   rS   z_Node.try_right_steal   s    
 19s6?++++OEAI.E##%% 	..uqy99k%(%*Z^^A%6%6E"	  %%%} 0#|+++!N..q11EM((///tur   rT   rc   rb   c                    |                                  rJ | j        rJ |                                }|                     |          \  }}|rJ | j                            ||           t          | j                  dk    r||g| _        dS | j        |         |k    sJ | j                            |dz   |           dS )zAdopt 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)r:   r2   r   rE   r3   rY   r9   r4   )r   rT   rc   rb   r   r@   rB   s          r   rZ   z_Node.adopt   s     ??$$$$$<jjll&&s++5	F###t}""!5MDMMM=#t++++M  Q.....r   c                 2   |j                             |dz             }| 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)r4   rf   r3   rj   extendr2   )r   rd   rF   rb   s       r   mergez_Node.merge   s    ##EAI..	//000	$$$| 	1M  00000	1 	1r   c                 h    | j         r| j        d         S | j        d                                         S )z"The least element in this subtree.r   )r2   r3   r4   minimumr   s    r   rp   z_Node.minimum  s1    < 	.9Q<=#++---r   c                 h    | j         r| j        d         S | j        d                                         S )z%The greatest element in this subtree.)r2   r3   r4   maximumr   s    r   rs   z_Node.maximum  s1    < 	/9R= =$,,...r   c                    |j         rJ |                     ||          rdS |                     ||          rdS |dk    r|                     ||           dS |                    |dz
            }|                    ||dz
             dS )zThis 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!   )r2   rh   rS   rn   rL   )r   rd   rF   rT   s       r   balancez_Node.balance  s     >!!!vu-- 	F.. 	FA::JJvu%%%%% ))%!)44DJJvuqy)))))r   exactc                 B   ||                                  rJ |                     |          \  }}d}|r|| j        |         |urt          d          | j        r| j                            |          S d}|}| j        |dz                                            }|                                }|dz   }| j        r|t          d          dS | 	                    |          }|                                 rU|
                    | |           |                     |          \  }}|rJ | j        |         }|                                 rJ |                    || |          }	|9|                     |          \  }
}|
J |	J |
j        |         }|	|
j        |<   |}	|	S )zDelete 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)r=   rE   r3   
ValueErrorr2   rf   r4   rp   r   rL   ru   deleterO   )r   r   rd   rv   r@   rB   original_keyleast_successorrJ   rg   noder^   s               r   ry   z_Node.delete&  s    ~T__%6%6~~~&&s++5 	 TYq\%>%> !JKKK| (y}}Q''' EL"mAE2::<<O!%%''CAA< 	  !<===4$$Q'' 	*MM$"""**3//HAuM!$E'')))))ll3e,,#nn\22GD!###???9Q<DDIaLC
r   visitc                     t          | j                  D ]7\  }}| j        s | j        |                             |            ||           8| j        s"| j        d                             |           dS dS )z-Call *visit* on all of the elements in order.rr   N)	enumerater3   r2   r4   visit_in_order)r   r}   r@   rg   s       r   r   z_Node.visit_in_orderU  s    	** 	 	FAs< 7a //666E#JJJJ| 	4M",,U33333	4 	4r   c                 l     ||            | j         s| j        D ]}|                    |           dS dS )z?Visit nodes in preorder.  This method is only used for testing.N)r2   r4   _visit_preorder_by_node)r   r}   rJ   s      r   r   z_Node._visit_preorder_by_node^  sU    d| 	5 5 5--e4444	5 	55 5r   c                 B    | j         |ur|                     |          S dS )zReturn 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)r1   clone)r   r1   s     r   rI   z_Node.maybe_cowe  s(     <w&&::g&&&4r   c                     |                      | j        || j                  }|j                            | j                   | j        s|j                            | j                   |S )z+Make a shallow-copy duplicate of this node.)r`   r   r2   r3   rm   r4   )r   r1   rK   s      r   r   z_Node.clonem  sZ    >>49%%%| 	2O""4=111r   c                     | j         s(dd                    d | j        D                       z   }nd}t          |           dd| j         d| j         | S )N c                 0    g | ]}t          |          d S )r*   r+   ).0cs     r   
<listcomp>z!_Node.__str__.<locals>.<listcomp>w  s"    &K&K&K"Q%%||&K&K&Kr    r*   )r2   joinr4   r,   r1   r3   )r   r4   s     r   r-   z_Node.__str__u  sh    | 	SXX&K&KT]&K&K&KLLLHHHT((CCCt|CCdiCCCCr   )%r   r   r   r   	__slots__intr(   boolr7   r:   r=   r   tuplerE   rL   r	   r   rO   r   rQ   rU   r\   r[   rh   rS   rZ   rn   rp   rs   ru   ry   r   r   r   rI   r   r-   r   r   r   r/   r/   4   s        
 @??I0# 0 04 0 0 0 0.D . . . .
.D . . . .
" sDy)9    :S _    (R (E(?*CS*H$I ( ( ( ( -r -b4i - - - -     $b D R$Y    2
#u_b/AB 
# 
# 
# 
#_ S T    &o c d    &// /2 /o /RV / / / /"1O 1C 1D 1 1 1 1. . . . ./ / / / /*o *c *d * * * *&--'8-ACd-	d- - - -^4HbT4Z$8 4T 4 4 4 45X6G6M-N 5SW 5 5 5 5 h.G    X /    D D D D Dr   r/   c                       e Zd ZdZddZddZddZd	 Zd
 Zde	dz  fdZ
de	dz  fdZdededdfdZddededdfdZddZddZd Zd ZdS )CursorzA 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                     || _         d | _        d| _        d| _        d| _        g | _        d| _        d | _        d| _        d S )Nr   FT)	r   current_nodecurrent_indexrecurse
increasingparentsparkedparking_keyparking_key_read)r   r   s     r   r7   zCursor.__init__  sM    
*. #$02&* %r   r   Nc                     | j         J | j         j        s`| j                            | j         | j        f           | j         j        | j                 | _         | j         J d| _        | j         j        ^d S d S rN   )r   r2   r   rj   r   r4   r   s    r   _seek_leastzCursor._seek_least  s      ,,,#+ 	#L!2D4F GHHH $ 1 :4;M ND$000!"D	 #+ 	# 	# 	# 	# 	#r   c                    | j         J | j         j        sw| j                            | j         | j        f           | j         j        | j                 | _         | j         J t          | j         j                  | _        | j         j        ud S d S rH   )r   r2   r   rj   r   r4   r9   r3   r   s    r   _seek_greatestzCursor._seek_greatest  s      ,,,#+ 	=L!2D4F GHHH $ 1 :4;M ND$000!$T%6%;!<!<D	 #+ 	= 	= 	= 	= 	=r   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   s    r   parkzCursor.park  s#     { 	DKKK	 	r   c                     | j         rW| j        @| j        }| j        r	| j         }n| j        }|                     | j        |           || _        d| _         d | _        d S d S NF)r   r   r   r   seek)r   r   befores      r   _maybe_unparkzCursor._maybe_unpark  s{    ; 	$+!_
( - "&0FF
 "_F		$*F333",DK#D!	$ 	$r   c                    |                                   d| _        | j        b| j        dk    rdS | j        dk    sJ | j        j        | _        t          | j        j        j                  | _        |                                  	 | j	        r"| j
        s|                                  d| _	        d| _
        | xj        dz  c_        | j        dk    rL| j        j        | j                 }| j        j        sd| _	        |                                | _        d| _        |S t          | j                  dk    r'| j                                        \  | _        | _        nd| _        d| _        dS )zAGet the previous element, or return None if on the left boundary.Nr   r!   TF)r   r   r   r   r   rootr9   r3   r   r   r   r2   r   r   r   rf   r   rg   s     r   prevzCursor.prev  su   $!Q&&t)Q.... %)JO!%()=%>%>"##%%%	 | % * '')))$#DO!#!Q&&',T-?@(0 (#'DL#&7799 (,%
t|$$q((<@L<L<L<N<N9D%t'9'9(,D%)*D&4-	 r   c                    |                                   d| _        | j        F| j        dk    rdS | j        dk    sJ | j        j        | _        d| _        |                                  	 | j        r"| j        r|                                  d| _        d| _        | j        t          | j        j
                  k     r\| j        j
        | j                 }| xj        dz  c_        | j        j        sd| _        |                                | _        d| _        |S t          | j                  dk    r'| j                                        \  | _        | _        nd| _        d| _        dS )z>Get the next element, or return None if on the right boundary.Nr!   r   TF)r   r   r   r   r   r   r   r   r   r9   r3   r2   r   r   r   rf   r   s     r   nextzCursor.next  st   $!Q&&t)Q.... %)JO!%&"  """	 | %? ' $$&&&$"DO!C(9(>$?$???',T-?@""a'""(0 (#'DL#&7799 (,%
t|$$q((<@L<L<L<N<N9D%t'9'9(,D%)*D&4-	 r   r   r@   c                 0    |r	|| _         d S |dz   | _         d S )Nr!   )r   )r   r   r@   s      r   _adjust_for_beforezCursor._adjust_for_before  s*     	'!"D!"QDr   Tr   c                    | j         j        | _        | j        J d| _        g | _        || _        d| _        || _        d| _        | j        j	        s| j        
                    |          \  }}|rC|                     ||           |r|                                  n|                                  dS | j                            | j        |f           | j        j        |         | _        | j        J | j        j	        | j        
                    |          \  }}|r|                     ||           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)r   r   r   r   r   r   r   r   r   r2   rE   r   r   r   rj   r4   r   )r   r   r   r@   rB   s        r   r   zCursor.seek  sc    !JO ,,,  %#+ 	1(77<<HAu ''222 '''))))$$&&&L!2A 6777 $ 1 :1 =D$000 #+ 	1 $33C885 	###FA.....!"Dr   c                 h    d| _         d| _        d| _        d| _        g | _        d| _        d| _        dS )zSeek 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r   r   r   r   r   r   r   r   s    r   
seek_firstzCursor.seek_first?  s>     !r   c                 h    d| _         d| _        d| _        d| _        g | _        d| _        d| _        dS )zSeek 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   s    r   	seek_lastzCursor.seek_lastK  s>    
 !r   c                 :    | j                             |            | S rH   )r   register_cursorr   s    r   	__enter__zCursor.__enter__X  s    
""4(((r   c                 :    | j                             |            dS r   )r   deregister_cursor)r   exc_type	exc_value	tracebacks       r   __exit__zCursor.__exit__\  s    
$$T***ur   )r   r   r   N)T)r   r   r   r   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   }  sV        & & & &# # # #= = = =
 
 
$ $ $&& b4i &  &  &  & P& b4i &  &  &  & P' '# '$ ' ' ' '!# !# !#D !#D !# !# !# !#F
  
  
  
              r   r   c                       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   r   c                   T   e Zd ZdZedddeded          fdZd Zdd	Z	d de
dede
dz  fdZdede
dz  fdZdede
dz  de
dz  fdZdede
dz  fdZde
de
dz  fdZd Zdee
gdf         ddfdZdeegdf         ddfdZdeee
f         fdZdeddfdZdeddfdZd Zd ZdS )!BTreez2An in-memory BTree with copy-on-write and cursors.Nr   originalr   r   c                n   t                      | _        d| _        |  |  |  t                      | _        |<|j        st          d          |j        | _        |j        | _        |j        | _        dS |dk     rt          d          || _        t          | j        | j        d          | _        d| _        dS )zCreate 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 immutabler6   zt must be >= 3Tr   )
r(   r1   
_immutablesetcursorsrx   r   r   sizer/   )r   r   r   s      r   r7   zBTree.__init__h  s      zz$'EE& D !BCCCZDF DI DIII1uu !1222DFdfdlD99DIDIIIr   c                 &    | j         s	d| _         dS dS )zMake 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   s    r   make_immutablezBTree.make_immutable  s#      	#"DOOO	# 	#r   r   c                 ^    | j         rt          | j        D ]}|                                 d S rH   )r   r   r   r   r   cursors     r   _check_mutable_and_parkzBTree._check_mutable_and_park  s;    ? 	Ol 	 	FKKMMMM	 	r   Frg   rW   c                    |                                   | j                            | j                  }|r|| _        | j                                        rH| j        }t          | j        | j        d          | _         | j        j        |                                  | j        	                    ||          }|| xj
        dz  c_
        |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   rI   r1   r:   r/   r   rZ   r[   r\   r   )r   rg   rW   rK   old_rootr^   s         r   insert_elementzBTree.insert_element  s     	$$&&&$$T\22 	DI9!! 	/yHdfdlE::DIDIOX^^--..y''X66<IINIIr   r   c                 6    | j                             |          S )zhGet the element matching *key* from the BTree, or return ``None`` if it
        does not exist.
        )r   rQ   r   r   s     r   get_elementzBTree.get_element  s     y}}S!!!r   rv   c                    |                                   | j                            | j                  }|r|| _        | j                            |d |          }|o| xj        dz  c_        t          | j        j                  dk    rB| j        j        s6t          | j        j	                  dk    sJ | j        j	        d         | _        |S )Nr!   r   )
r   r   rI   r1   ry   r   r9   r3   r2   r4   )r   r   rv   rK   rg   s        r   _deletezBTree._delete  s    $$&&&$$T\22 	DIisD%00?IINII49>""a'' y( 6ty122a7777 $	 21 5DI
r   c                 .    |                      |d          S )zDelete the element matching *key* from the BTree.

        Returns the matching element or ``None`` if it does not exist.
        N)r   r   s     r   
delete_keyzBTree.delete_key  s    
 ||C&&&r   rV   c                 b    |                      |                                |          }||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   rV   delts      r   delete_exactzBTree.delete_exact  s1    
 ||GKKMM733wr   c                     | j         S rH   )r   r   s    r   __len__zBTree.__len__  
    yr   r}   c                 :    | j                             |           dS )zBCall *visit*(element) on all elements in the tree in sorted order.N)r   r   r   r}   s     r   r   zBTree.visit_in_order  s    	  '''''r   c                 :    | j                             |           d S rH   )r   r   r   s     r   r   zBTree._visit_preorder_by_node  s    	))%00000r   c                      t          |           S )zCreate a cursor.)r   r   s    r   r   zBTree.cursor  s    d||r   r   c                 :    | j                             |           dS )z4Register a cursor for the automatic parking service.N)r   addr   s     r   r   zBTree.register_cursor  s         r   c                 :    | j                             |           dS )z7Deregister a cursor from the automatic parking service.N)r   discardr   s     r   r   zBTree.deregister_cursor  s    V$$$$$r   c                 .    |                      |           S )N)r   r`   r   s    r   __copy__zBTree.__copy__  s    ~~t~,,,r   c              #      K   |                                  5 }	 |                                }|n|                                V  .	 d d d            d S # 1 swxY w Y   d S rH   )r   r   r   )r   r   rg   s      r   __iter__zBTree.__iter__  s      [[]] 	 f kkmm;ggii	  		  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   0AAAr   )F)r   r   r   r   	DEFAULT_Tr   r   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   r/   r   r   r   r   r   r   r   r   r   r   r   r   e  s6       <<#,D   S 8I    <# # #    "  d    ."r "b4i " " " "2 b4i BI    "'b 'R$Y ' ' ' 'B 29      (HbT4Z$8 (T ( ( ( (1Xugtm-D 1 1 1 1 1r2v    !f ! ! ! ! !% %4 % % % %- - -         r   r   VTc                   F    e Zd ZdZdedefdZdefdZdefdZd Z	d	 Z
d
S )KVz/The BTree element type used in a ``BTreeDict``.r   valuec                 "    || _         || _        d S rH   _key_value)r   r   r   s      r   r7   zKV.__init__  s    	r   r   c                     | j         S rH   r   r   s    r   r   zKV.key  r   r   c                     | j         S rH   )r   r   s    r   r   zKV.value  s
    {r   c                 (    d| j          d| j         dS NzKV(z, )r   r   s    r   r-   z
KV.__str__	      0TY00$+0000r   c                 (    d| j          d| j         dS r   r   r   s    r   __repr__zKV.__repr__  r   r   N)r   r   r   r   r   r   r7   r   r   r-   r  r   r   r   r   r     s        99B r    R    r    1 1 11 1 1 1 1r   r   c                   t     e Zd ZdZeddddededz  def fdZd	e	d
e
fdZd	e	de
d
dfdZd	e	d
dfdZ xZS )	BTreeDictzA MutableMapping implemented with a BTree.

    Unlike a normal Python dict, the BTreeDict may be mutated while iterating.
    NFr   r   rW   r   r   rW   c                \    t                                          ||           || _        d S Nr   superr7   rW   r   r   r   rW   r`   s       r   r7   zBTreeDict.__init__  -     	1x000 r   r   r   c                     |                      |          }|t          t          t          |                                          S rH   )r   KeyErrorr   r   r   )r   r   rg   s      r   __getitem__zBTreeDict.__getitem__   s9    s##;NC==&&(((r   r   c                 \    t          ||          }|                     || j                   d S rH   )r   r   rW   )r   r   r   rg   s       r   __setitem__zBTreeDict.__setitem__'  s-    ennC/////r   c                 >    |                      |          t          d S rH   )r   r  r   s     r   __delitem__zBTreeDict.__delitem__+  s!    ??3'N ('r   )r   r   r   r   r   r   r   r   r7   r   r   r  r  r  __classcell__r   s   @r   r  r    s          !%! ! ! ! $,	!
 ! ! ! ! ! !)r )b ) ) ) )0r 0" 0 0 0 0 0r d        r   r  c                   *    e Zd ZdZdefdZdefdZdS )Memberz.The BTree element type used in a ``BTreeSet``.r   c                     || _         d S rH   r   r   s     r   r7   zMember.__init__3  s    			r   r   c                     | j         S rH   r   r   s    r   r   z
Member.key6  r   r   N)r   r   r   r   r   r7   r   r   r   r   r  r  0  sP        88B    R      r   r  c                   p     e Zd ZdZeddddededz  def fdZd	e	d
efdZ
ded
dfdZded
dfdZ xZS )BTreeSetzyA MutableSet implemented with a BTree.

    Unlike a normal Python set, the BTreeSet may be mutated while iterating.
    NFr  r   r   rW   c                \    t                                          ||           || _        d S r  r  r	  s       r   r7   zBTreeSet.__init__@  r
  r   r   r   c                 0    |                      |          d uS rH   )r   r   s     r   __contains__zBTreeSet.__contains__J  s    $$D00r   r   c                 Z    t          |          }|                     || j                   d S rH   )r  r   rW   )r   r   rg   s      r   r   zBTreeSet.addM  s+    UmmC/////r   c                 0    |                      |           d S rH   )r   )r   r   s     r   r   zBTreeSet.discardQ  s    r   )r   r   r   r   r   r   r   r   r7   r   r  r   r   r   r  r   s   @r   r  r  :  s          !%! ! ! ! $,	!
 ! ! ! ! ! !1 1 1 1 1 10 0 0 0 0 0R D        r   r  N)r   collections.abcr   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r#   r&   r(   r/   r   	Exceptionr   r   r   r   r  r  r  r   r   r   <module>r!     s    7 6 6 6 6 6 6 6 I I I I I I I I I I I I I I I I I I	WT]]" " " " "gbk " " " WT!!!C C    C C    
	 	 	 	 	 	 	 	FD FD FD FD FDGBFO FD FD FDR
a a a a aWRV_ a a aH" " " " "	 " " "Q  Q  Q  Q  Q GBFO Q  Q  Q h WT]]1 1 1 1 1'"b&/ 1 1 1(    Br2b"f:~!6r2v8N   @    Wgbk       ugbk:b>     r   