
    h%x              
          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y!)"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y)Elementz+All items stored in the BTree are Elements.returnc                     t         )zFThe key for this element; the returned type must implement comparison.)NotImplementedErrorselfs    G/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/dns/btree.pykeyzElement.key   s    !!    N)__name__
__module____qualname____doc__r   r    r   r   r   r      s    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y)_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(1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$y)*_NodezFA Node in the BTree.

    A Node (leaf or internal) of the BTree.
    r   creatoris_leafeltschildrenr   r0   r1   c                 X    |dk\  sJ || _         || _        || _        g | _        g | _        y )N   r/   )r   r   r0   r1   s       r   __init__z_Node.__init__<   s0    Avv 	-/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?)lenr2   r&   r   r   s    r   
is_maximalz_Node.is_maximalD   ;    499~dff---499~dff--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?)r8   r2   r#   r   r   s    r   
is_minimalz_Node.is_minimalI   r:   r   r   c                 h   t        | j                        }|dkD  r'|| j                  |dz
     j                         kD  r|dfS d}t        | j                        }|dz
  }d}||k  rK||z   dz  }| j                  |   j                         }||k(  r	|}d}	 ||fS ||k  r|}|dz
  }n|dz   }||k  r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)r8   r2   r   )r   r   lirequalmks           r   search_in_nodez_Node.search_in_nodeN   s     		Nq5S499QU+//11e8O		NE1fQ1A		!  "Aax %x qEE 1f %xr   indexz_Node[KT, ET]c                     | j                   rJ | j                  |   }|j                  | j                        }|r|| j                  |<   |S |S N)r1   r3   	maybe_cowr0   )r   rE   childcloneds       r   maybe_cow_childz_Node.maybe_cow_childk   sJ    <<e$.#)DMM% MLr   c                     | j                  |      \  }}|r| |fS | j                  ry| j                  |      }|j                  |      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   )rD   r1   rK   	_get_node)r   r   r?   rA   rI   s        r   rN   z_Node._get_nodeu   sN     &&s+5!9\\((+E??3''r   Nc                     | j                  |      \  }}|r| j                  |   S | j                  ry| j                  |   j	                  |      S )z8Get the element associated with *key* or return ``None``N)rD   r2   r1   r3   get)r   r   r?   rA   s       r   rP   z	_Node.get   sK    &&s+599Q<\\==#'',,r   c                    |dk(  ry| j                   |dz
     }t        |j                        t        | j                        k(  ry| j                  |dz
        }t        |j                        t        | j                        k  rC|j                  | |dz
        syt        |j                        t        | j                        k  rByy)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!   )r3   r8   r2   r&   r   rK   try_right_steal)r   rE   lefts      r   optimize_in_order_insertionz!_Node.optimize_in_order_insertion   s     A:}}UQY'tyy>T$&&\)##EAI.$))ntDFF|+''eai8 $))ntDFF|+r   elementin_orderc                    | j                         rJ 	 |j                         }| j                  |      \  }}|r | j                  |   }|| j                  |<   |S | j                  r| j                  j                  ||       y | j                  |      }|j                         r | j                  |j                           |j                  ||      }|r| j                  |       |S rG   )r9   r   rD   r2   r1   insertrK   adoptsplitinsert_nonfullrT   )	r   rU   rV   r   r?   rA   oldrI   oelts	            r   r[   z_Node.insert_nonfull   s    ??$$$++-C**3/HAuiil&		!
		  G,,,Q/##%DJJ. ++GX>44Q7r   c                    | j                         sJ | j                  | j                  | j                  | j                        }t        | j                  t        | j                        dz   d       |_        | j                  t        | j                           }t        | j                  dt        | j                               | _        | j                  sft        | 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)	r9   	__class__r   r0   r1   listr2   r#   r3   )r   rightmiddles      r   rZ   z_Node.split   s       tvvt||T\\B$))DL1$4$678
4<(>T$&&\23	||!$--TVVq0@0B"CDEN /Adff1A!BCDMVU""r   parentc                    |dk7  r|j                   |dz
     }|j                         s|j                  |dz
        }|j                  |dz
     }|j                  j	                         |j                  |dz
  <   | j                  j                  d|       |j                  sD| j                  rJ |j                   j	                         }| j                   j                  d|       yy)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)r3   r<   rK   r2   poprX   r1   )r   rc   rE   rS   eltrI   s         r   try_left_stealz_Node.try_left_steal   s    
 A:??519-D??$--eai8kk%!),)-EAI&		  C(||#||++ MM--/EMM((E2r   c                    |dz   t        |j                        k  r|j                  |dz      }|j                         s|j                  |dz         }|j                  |   }|j                  j                  d      |j                  |<   | j                  j                  |       |j                  sD| j                  rJ |j                  j                  d      }| j                  j                  |       yy)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)r8   r3   r<   rK   r2   re   appendr1   )r   rc   rE   ra   rf   rI   s         r   rR   z_Node.try_right_steal   s    
 19s6??++OOEAI.E##%..uqy9kk%(%*ZZ^^A%6E"		  %}}#||++!NN..q1EMM((/r   rS   rb   ra   c                 v   | j                         rJ | j                  rJ |j                         }| j                  |      \  }}|rJ | j                  j                  ||       t        | j                        dk(  r
||g| _        y| j                  |   |k(  sJ | j                  j                  |dz   |       y)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)r9   r1   r   rD   r2   rX   r8   r3   )r   rS   rb   ra   r   r?   rA   s          r   rY   z_Node.adopt   s     ??$$$<<jjl&&s+5y		F#t}}"!5MDM==#t+++MM  Q.r   c                 V   |j                   j                  |dz         }| j                  j                  |j                  j                  |             | j                  j	                  |j                         | j
                  s&| j                   j	                  |j                          yy)z>Merge this node's parent and its right sibling into this node.r!   N)r3   re   r2   ri   extendr1   )r   rc   rE   ra   s       r   mergez_Node.merge   sq    ##EAI.		/0		$||MM  0 r   c                 r    | j                   r| j                  d   S | j                  d   j                         S )z"The least element in this subtree.r   )r1   r2   r3   minimumr   s    r   ro   z_Node.minimum  s/    <<99Q<==#++--r   c                 r    | j                   r| j                  d   S | j                  d   j                         S )z%The greatest element in this subtree.)r1   r2   r3   maximumr   s    r   rr   z_Node.maximum  s/    <<99R= ==$,,..r   c                     |j                   rJ | j                  ||      ry| j                  ||      ry|dk(  r| j                  ||       y|j	                  |dz
        }|j                  ||dz
         y)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!   )r1   rg   rR   rm   rK   )r   rc   rE   rS   s       r   balancez_Node.balance  st     >>!!vu-.A:JJvu% ))%!)4DJJvuqy)r   exactc                    || j                         rJ | j                  |      \  }}d}|r~|| j                  |   |urt        d      | j                  r| j                  j                  |      S d}|}| j                  |dz      j                         }|j                         }|dz   }| j                  r|t        d      y| j                  |      }|j                         rK|j                  | |       | j                  |      \  }}|rJ | j                  |   }|j                         rJ |j                  || |      }	|<| j                  |      \  }
}|
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<   rD   r2   
ValueErrorr1   re   r3   ro   r   rK   rt   deleterN   )r   r   rc   ru   r?   rA   original_keyleast_successorrI   rf   noder]   s               r   rx   z_Node.delete&  s    ~T__%666&&s+5 TYYq\%> !JKK||yy}}Q'' EL"mmAE2::<O!%%'CAA<<  !<==$$Q'MM$"**3/HAu9MM!$E'')))ll3e,#nn\2GD!###?"?99Q<DDIIaLC
r   visitc                     t        | j                        D ]7  \  }}| j                  s| j                  |   j	                  |        ||       9 | j                  s| j                  d   j	                  |       yy)z-Call *visit* on all of the elements in order.rq   N)	enumerater2   r1   r3   visit_in_order)r   r|   r?   rf   s       r   r   z_Node.visit_in_orderU  sh    		* 	FAs<<a //6#J	 ||MM",,U3 r   c                 r     ||        | j                   s#| j                  D ]  }|j                  |        yy)z?Visit nodes in preorder.  This method is only used for testing.N)r1   r3   _visit_preorder_by_node)r   r|   rI   s      r   r   z_Node._visit_preorder_by_node^  s6    d|| 5--e45 r   c                 B    | j                   |ur| j                  |      S y)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)r0   clone)r   r0   s     r   rH   z_Node.maybe_cowe  s"     <<w&::g&&r   c                     | j                  | j                  || j                        }|j                  j	                  | j                         | j                  s%|j
                  j	                  | j
                         |S )z+Make a shallow-copy duplicate of this node.)r_   r   r1   r2   rl   r3   )r   r0   rJ   s      r   r   z_Node.clonem  sT    >499%||OO""4==1r   c           	          | j                   s8ddj                  | j                  D cg c]  }t        |      d c}      z   }nd}t        |       dd| j                   d| j
                   | S c c}w )N r*    )r1   joinr3   r+   r0   r2   )r   cr3   s      r   r,   z_Node.__str__u  si    ||SXXT]]&K"Q%|&KLLHHT(1Qt||nAdii[
CC 'Ls   A1
)%r   r   r   r   	__slots__intr(   boolr6   r9   r<   r   tuplerD   rK   r	   r   rN   r   rP   rT   r[   rZ   rg   rR   rY   rm   ro   rr   rt   rx   r   r   r   rH   r   r,   r   r   r   r.   r.   4   s7   
 @I0# 0 04 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. ./ /*o *c *d *&--'8-ACd-	d-^4HbT4Z$8 4T 45X6G6M-N 5SW 5 h.G X / 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y)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.
    c                     || _         d | _        d| _        d| _        d| _        g | _        d| _        d | _        d| _        y )Nr   FT)	btreecurrent_nodecurrent_indexrecurse
increasingparentsparkedparking_keyparking_key_read)r   r   s     r   r6   zCursor.__init__  sG    
*. #$02&* %r   r   Nc                 X   | j                   J | j                   j                  s| j                  j                  | j                   | j                  f       | j                   j
                  | j                     | _         | j                   J d| _        | j                   j                  sy y rM   )r   r1   r   ri   r   r3   r   s    r   _seek_leastzCursor._seek_least  s       ,,,##++LL!2!2D4F4F GH $ 1 1 : :4;M;M ND$$000!"D	 ##++r   c                    | j                   J | j                   j                  s| j                  j                  | j                   | j                  f       | j                   j
                  | j                     | _         | j                   J t        | j                   j                        | _        | j                   j                  sy y rG   )r   r1   r   ri   r   r3   r8   r2   r   s    r   _seek_greatestzCursor._seek_greatest  s       ,,,##++LL!2!2D4F4F GH $ 1 1 : :4;M;M ND$$000!$T%6%6%;%;!<D	 ##++r   c                 ,    | j                   sd| _         yy)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     {{DK r   c                     | j                   rp| j                  U| j                  }| j                  r| j                   }n| j                  }| j	                  | j                  |       || _        d| _         d | _        y y NF)r   r   r   r   seek)r   r   befores      r   _maybe_unparkzCursor._maybe_unpark  so    ;;+!__
(( "&0F
 "__F		$**F3",DK#D! r   c                 P   | j                          d| _        | j                  z| j                  dk(  ry| j                  dk(  sJ | j                  j
                  | _        t        | j                  j
                  j                        | _        | j                          	 | j                  r#| j                  s| j                          d| _	        d| _
        | xj                  dz  c_        | j                  dk\  r^| j                  j                  | j                     }| j                  j                  sd| _	        |j                         | _        d| _        |S t        | j                        dkD  r(| j                  j                         \  | _        | _        nd| _        d| _        y	)zAGet the previous element, or return None if on the left boundary.Nr   r!   TF)r   r   r   r   r   rootr8   r2   r   r   r   r1   r   r   r   re   r   rf   s     r   prevzCursor.prev  s_   $!!Q&))Q... %)JJOO!%()=)=%>"##%|| '')$#DO!#!!Q&'',,T-?-?@((00#'DL#&779 (,%
t||$q(<@LL<L<L<N9D%t'9(,D%)*D&- r   c                 <   | j                          d| _        | j                  S| j                  dk(  ry| j                  dk(  sJ | j                  j
                  | _        d| _        | j                          	 | j                  r#| j                  r| j                          d| _        d| _        | j                  t        | j                  j                        k  rs| j                  j                  | j                     }| xj                  dz  c_        | j                  j                  sd| _        |j                         | _        d| _        |S t        | j                        dkD  r(| j                  j                         \  | _        | _        nd| _        d| _        y&)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   r8   r2   r1   r   r   r   re   r   s     r   nextzCursor.next  s]   $!!Q&))Q... %)JJOO!%&"  "||?? $$&$"DO!!C(9(9(>(>$??'',,T-?-?@""a'"((00#'DL#&779 (,%
t||$q(<@LL<L<L<N9D%t'9(,D%)*D&- r   r   r?   c                 ,    |r|| _         y |dz   | _         y )Nr!   )r   )r   r   r?   s      r   _adjust_for_beforezCursor._adjust_for_before  s    !"D!"QDr   r   c                    | j                   j                  | _        | j                  J d| _        g | _        || _        d| _        || _        d| _        | j                  j                  s| j                  j                  |      \  }}|r6| j                  ||       |r| j                          y| j                          y| j                  j                  | j                  |f       | j                  j                  |   | _        | j                  J | j                  j                  s| j                  j                  |      \  }}|r| j                  ||       y|| _        y)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   r1   rD   r   r   r   ri   r3   r   )r   r   r   r?   rA   s        r   r   zCursor.seek  sC    !JJOO  ,,,  %##++((77<HAu''2'')  $$&LL!2!2A 67 $ 1 1 : :1 =D$$000 ##++ $$33C85##FA.!"Dr   c                 f    d| _         d| _        d| _        d| _        g | _        d| _        d| _        y)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?  s8     !r   c                 f    d| _         d| _        d| _        d| _        g | _        d| _        d| _        y)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  s8    
 !r   c                 <    | j                   j                  |        | S rG   )r   register_cursorr   s    r   	__enter__zCursor.__enter__X  s    

""4(r   c                 :    | j                   j                  |        yr   )r   deregister_cursor)r   exc_type	exc_value	tracebacks       r   __exit__zCursor.__exit__\  s    

$$T*r   )r   zBTree[KT, ET]r   N)T)r   r   r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   }  s    &#=
$&& b4i & P& b4i & P' '# '$ '!# !#D !#D !#F
  r   r   c                       e Zd ZdZy)	ImmutablezThe BTree is immutable.N)r   r   r   r   r   r   r   r   r   a  s    !r   r   c                   :   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y) BTreez2An in-memory BTree with copy-on-write and cursors.Nr   originalr   r   c                |   t               | _        d| _        |  |  |  t               | _        |K|j                  st        d      |j                  | _        |j                  | _        |j                  | _        y|dk  rt        d      || _        t        | j                  | j                  d      | _        d| _        y)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 immutabler5   zt must be >= 3Tr   )
r(   r0   
_immutablesetcursorsrw   r   r   sizer.   )r   r   r   s      r   r6   zBTree.__init__h  s      z$'E&& !BCCZZDF DI DI1u !122DFdffdllD9DIDIr   c                 ,    | j                   sd| _         yy)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     "DO r   r   c                 j    | j                   rt        | j                  D ]  }|j                           y rG   )r   r   r   r   r   cursors     r   _check_mutable_and_parkzBTree._check_mutable_and_park  s*    ??Oll 	FKKM	r   rf   rV   c                    | j                          | j                  j                  | j                        }|r|| _        | j                  j	                         rY| j                  }t        | j                  | j                  d      | _         | j                  j                  |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``.
        Fr!   )r   r   rH   r0   r9   r.   r   rY   rZ   r[   r   )r   rf   rV   rJ   old_rootr]   s         r   insert_elementzBTree.insert_element  s     	$$&$$T\\2DI99!yyHdffdllE:DIDIIOOX^^-.yy''X6<IINIr   r   c                 8    | j                   j                  |      S )zhGet the element matching *key* from the BTree, or return ``None`` if it
        does not exist.
        )r   rP   r   r   s     r   get_elementzBTree.get_element  s     yy}}S!!r   ru   c                    | j                          | j                  j                  | j                        }|r|| _        | j                  j	                  |d |      }|| xj
                  dz  c_        t        | j                  j                        dk(  rX| j                  j                  sBt        | j                  j                        dk(  sJ | j                  j                  d   | _        |S )Nr!   r   )
r   r   rH   r0   rx   r   r8   r2   r1   r3   )r   r   ru   rJ   rf   s        r   _deletezBTree._delete  s    $$&$$T\\2DIiisD%0?IINI499>>"a' yy((tyy112a777 $		 2 21 5DI
r   c                 &    | j                  |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   rU   c                 R    | j                  |j                         |      }||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   rU   delts      r   delete_exactzBTree.delete_exact  s+    
 ||GKKM73wr   c                     | j                   S rG   )r   r   s    r   __len__zBTree.__len__      yyr   r|   c                 :    | j                   j                  |       y)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                   j                  |       y rG   )r   r   r   s     r   r   zBTree._visit_preorder_by_node  s    		))%0r   c                     t        |       S )zCreate a cursor.)r   r   s    r   r   zBTree.cursor  s    d|r   r   c                 :    | j                   j                  |       y)z4Register a cursor for the automatic parking service.N)r   addr   s     r   r   zBTree.register_cursor  s     r   c                 :    | j                   j                  |       y)z7Deregister a cursor from the automatic parking service.N)r   discardr   s     r   r   zBTree.deregister_cursor  s    V$r   c                 &    | j                  |       S )N)r   r_   r   s    r   __copy__zBTree.__copy__  s    ~~t~,,r   c              #      K   | j                         5 }	 |j                         }|n|j                          &	 d d d        y # 1 sw Y   y xY wwrG   )r   r   r   )r   r   rf   s      r   __iter__zBTree.__iter__  sP     [[] 	 fkkm;ggi	  		  	  	 s   A(A	AA
Ar   )F)r   r   r   r   	DEFAULT_Tr   r   r6   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r2v !f ! !% %4 %- r   r   VTc                   D    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
y
)KVz/The BTree element type used in a ``BTreeDict``.r   valuec                      || _         || _        y rG   _key_value)r   r   r   s      r   r6   zKV.__init__  s    	r   r   c                     | j                   S rG   r   r   s    r   r   zKV.key  r   r   c                     | j                   S rG   )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__	      TYYKr$++a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   r6   r   r   r,   r   r   r   r   r   r     s:    9B r R r 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   rV   r   r   rV   c                6    t         |   ||       || _        y Nr   superr6   rV   r   r   r   rV   r_   s       r   r6   zBTreeDict.__init__       	1x0 r   r   r   c                 p    | j                  |      }|t        t        t        |      j	                         S rG   )r   KeyErrorr   r   r   )r   r   rf   s      r   __getitem__zBTreeDict.__getitem__   s1    s#;NC=&&((r   r   c                 T    t        ||      }| j                  || j                         y rG   )r   r   rV   )r   r   r   rf   s       r   __setitem__zBTreeDict.__setitem__'  s!    enC/r   c                 2    | j                  |      t        y rG   )r   r  r   s     r   __delitem__zBTreeDict.__delitem__+  s    ??3'N (r   )r   r   r   r   r   r   r   r   r6   r   r   r  r
  r  __classcell__r   s   @r   r   r     sz     !%! ! $,	!
 !)r )b )0r 0" 0 0r d r   r   c                   (    e Zd ZdZdefdZdefdZy)Memberz.The BTree element type used in a ``BTreeSet``.r   c                     || _         y rG   r   r   s     r   r6   zMember.__init__3  s	    	r   r   c                     | j                   S rG   r   r   s    r   r   z
Member.key6  r   r   N)r   r   r   r   r   r6   r   r   r   r   r  r  0  s    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   rV   c                6    t         |   ||       || _        y r  r  r  s       r   r6   zBTreeSet.__init__@  r  r   r   r   c                 (    | j                  |      d uS rG   )r   r   s     r   __contains__zBTreeSet.__contains__J  s    $D00r   r   c                 R    t        |      }| j                  || j                         y rG   )r  r   rV   )r   r   rf   s      r   r   zBTreeSet.addM  s    UmC/r   c                 &    | j                  |       y rG   )r   )r   r   s     r   r   zBTreeSet.discardQ  s    r   )r   r   r   r   r   r   r   r   r6   r   r  r   r   r   r  r   s   @r   r  r  :  ss     !%! ! $,	!
 !1 1 1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     sE   7 I I I	T]"gbk " T!C C C C 
	 	FDGBFO FDR
aWRV_ aH"	 "Q GBFO Q h T]1'"b&/ 1(Br2b"f:~!6r2v8N @Wgbk ugbk:b> r   