+
    ni%x              
       <   R t ^ RIHtHt ^ RIHtHtHtHtH	t	H
t
Ht ^t]
! R4      t ! R R]],          4      t]
! R]R7      tR R	 ltR
 R lt ! R R4      t ! R R]]]3,          4      t ! R R]]]3,          4      t ! R R]4      t ! R R]]]3,          4      t]
! R4      t ! R R]]]]3,          4      t ! R R]]]3,          ]]]]]3,          3,          ]]]3,          4      t ! R R]]],          4      t ! R R]]],          ]],          4      tR# ) 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                   6   a  ] tR t^t o RtV 3R lR ltRtV tR# )Elementz+All items stored in the BTree are Elements.c                    < V ^8  d   QhRS[ /#    returnr   )format__classdict__s   "cC:\Users\petid\OneDrive\Desktop\Maestro\MAESTRO\maestro-backend\venv\Lib\site-packages\dns/btree.py__annotate__Element.__annotate__   s     " "R "    c                    \         h)zFThe key for this element; the returned type must implement comparison.)NotImplementedErrorselfs   &r   keyElement.key   s    !!r    N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classdictcell__r   s   @r   r   r      s     5" "r   r   ET)boundc                0    V ^8  d   QhR\         R\         /# r   tr   int)r   s   "r   r   r      s      C C r   c                    V ^,
          # )zSThe minimum number of keys in a non-root node for a BTree with the specified
``t``
r   r,   s   &r   _MINr1      s     q5Lr   c                0    V ^8  d   QhR\         R\         /# r+   r-   )r   s   "r   r   r   #   s      C C r   c                "    ^V ,          ^,
          # )zGThe maximum number of keys in node for a BTree with the specified ``t``r   r0   s   &r   _MAXr4   #   s    q519r   c                   *   a  ] tR t^(t o RtR tRtV tR# )_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                    \        V 4      R  # )x)idr   s   &r   __str___Creator.__str__0   s    T(1r   r   N)r    r!   r"   r#   r$   r:   r%   r&   r'   s   @r   r6   r6   (   s      r   r6   c                     a  ] tR t^4t o Rt. R1OtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 lt	V 3R
 lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R  lR! ltV 3R" lR# ltV 3R$ lR% ltV 3R& lR' ltV 3R( lR) ltV 3R* lR+ ltV 3R, lR- ltR. tR/tV tR0# )2_Nodez>A Node in the BTree.

A Node (leaf or internal) of the BTree.
c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   r,   creatoris_leaf)r.   r6   bool)r   r   s   "r   r   _Node.__annotate__<   s"     0 0# 0 04 0r   c                X    V^8  g   Q hWn         W n        W0n        . V n        . V n        R# )   Nr,   r?   r@   eltschildren)r   r,   r?   r@   s   &&&&r   __init___Node.__init__<   s*    Avv 	-/r   c                    < V ^8  d   QhRS[ /# r   rA   )r   r   s   "r   r   rB   D        . .D .r   c                    \        V P                  4      \        V P                  4      8:  g   Q h\        V P                  4      \        V P                  4      8H  # )z/Does this node have the maximal number of keys?)lenrF   r4   r,   r   s   &r   
is_maximal_Node.is_maximalD   ;    499~dff---499~dff--r   c                    < V ^8  d   QhRS[ /# r   rK   )r   r   s   "r   r   rB   I   rL   r   c                    \        V P                  4      \        V P                  4      8  g   Q h\        V P                  4      \        V P                  4      8H  # )z/Does this node have the minimal number of keys?)rN   rF   r1   r,   r   s   &r   
is_minimal_Node.is_minimalI   rQ   r   c                <   < V ^8  d   QhRS[ RS[S[S[3,          /# r   r   r   )r   tupler.   rA   )r   r   s   "r   r   rB   N   s$      " sDy)9 r   c                   \        V P                  4      pV^ 8  d1   WP                  V^,
          ,          P                  4       8  d   VR3# ^ p\        V P                  4      pV^,
          pRpW$8:  d]   W$,           ^,          pV P                  V,          P                  4       pW8X  d	   TpRp W53# W8  d   TpV^,
          pKW  V^,           pKb  W53# )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.
FT)rN   rF   r   )r   r   lirequalmks   &&      r   search_in_node_Node.search_in_nodeN   s     		Nq5S99QU+//11e8O		NEf1A		!  "Ax x EExr   c                $   < V ^8  d   QhRS[ RR/# )r   indexr   _Node[KT, ET]r-   )r   r   s   "r   r   rB   k   s      S _ r   c                    V P                   '       d   Q hV P                  V,          pVP                  V P                  4      pV'       d   W0P                  V&   V# V# N)r@   rG   	maybe_cowr?   )r   rc   childcloneds   &&  r   maybe_cow_child_Node.maybe_cow_childk   sJ    <<<e$.#)MM% MLr   c                J   < V ^8  d   QhRS[ RS[S[R,          S[3,          /# )r   r   r   rd   )r   r   r   r.   )r   r   s   "r   r   rB   u   s*     ( (R (E(?*CS*H$I (r   c                    V P                  V4      w  r#V'       d   W3# V P                  '       d   R# V P                  V4      pVP                  V4      # )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.
)N    )r`   r@   rj   	_get_node)r   r   r[   r]   rh   s   &&   r   ro   _Node._get_nodeu   sO     &&s+9\\\((+E??3''r   c                4   < V ^8  d   QhRS[ RS[R,          /# r   r   r   Nr   r(   )r   r   s   "r   r   rB      s     - -r -b4i -r   c                    V P                  V4      w  r#V'       d   V P                  V,          # V P                  '       d   R# V P                  V,          P	                  V4      # )z8Get the element associated with *key* or return ``None``N)r`   rF   r@   rG   get)r   r   r[   r]   s   &&  r   ru   	_Node.get   sK    &&s+99Q<\\\==#'',,r   c                $   < V ^8  d   QhRS[ RR/# )r   rc   r   Nr-   )r   r   s   "r   r   rB      s        r   c                x   V^ 8X  d   R# V P                   V^,
          ,          p\        VP                  4      \        V P                  4      8X  d   R# V P                  V^,
          4      p\        VP                  4      \        V P                  4      8  d#   VP                  W^,
          4      '       d   KM  R# R# )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.
N)rG   rN   rF   r4   r,   rj   try_right_steal)r   rc   lefts   && r   optimize_in_order_insertion!_Node.optimize_in_order_insertion   s     A:}}UQY'tyy>T$&&\)##EAI.$))ntDFF|+''ai88 ,r   c                :   < V ^8  d   QhRS[ RS[RS[ R,          /# )r   elementin_orderr   Nr(   rA   )r   r   s   "r   r   rB      s&      b D R$Y r   c                   V P                  4       '       d   Q h VP                  4       pV P                  V4      w  rEV'       d$   V P                  V,          pWP                  V&   V# V P                  '       d   V P                  P                  WA4       R# V P                  V4      pVP                  4       '       d!   V P                  ! VP                  4       !   K  VP                  W4      pV'       d   V P                  V4       V# TN)rO   r   r`   rF   r@   insertrj   adoptsplitinsert_nonfullr{   )	r   r~   r   r   r[   r]   oldrh   oelts	   &&&      r   r   _Node.insert_nonfull   s    ??$$$$++-C**3/HAiil&		!
		  ,,,Q/##%%JJ. ++G>44Q7r   c                6   < V ^8  d   QhRS[ RS[R3,          /# )r   r   rd   )rX   r(   )r   r   s   "r   r   rB      s      
# 
#u_b/AB 
#r   c                   V P                  4       '       g   Q hV P                  V P                  V P                  V P                  4      p\        V P                  \        V P                  4      ^,           R 4      Vn        V P                  \        V P                  4      ,          p\        V P                  R\        V P                  4       4      V n        V P                  '       go   \        V P                  \        V P                  4      ^,           R 4      Vn        \        V P                  R\        V P                  4      ^,            4      V n        WV3# )zASplit a maximal node into two minimal ones and a central element.N)	rO   	__class__r,   r?   r@   listrF   r1   rG   )r   rightmiddles   &  r   r   _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U""r   c                *   < V ^8  d   QhRRRS[ RS[/# r   parentrd   rc   r   r.   rA   )r   r   s   "r   r   rB      s"      _ S T r   c                *   V^ 8w  Ed   VP                   V^,
          ,          pVP                  4       '       g   VP                  V^,
          4      pVP                  V^,
          ,          pVP                  P	                  4       VP                  V^,
          &   V P                  P                  ^ V4       VP                  '       gK   V P                  '       d   Q hVP                   P	                  4       pV P                   P                  ^ V4       R# R# )zTry to steal from this Node's left sibling for balancing purposes.

Returns ``True`` if the theft was successful, or ``False`` if not.
TF)rG   rT   rj   rF   popr   r@   )r   r   rc   rz   eltrh   s   &&&   r   try_left_steal_Node.try_left_steal   s    
 A:??519-D??$$--eai8kk%!),)-EAI&		  C(|||#|||++ MM--/EMM((E2r   c                *   < V ^8  d   QhRRRS[ RS[/# r   r   )r   r   s   "r   r   rB      s"      o c d r   c                @   V^,           \        VP                  4      8  d   VP                  V^,           ,          pVP                  4       '       g   VP                  V^,           4      pVP                  V,          pVP                  P                  ^ 4      VP                  V&   V P                  P                  V4       VP                  '       gK   V P                  '       d   Q hVP                  P                  ^ 4      pV P                  P                  V4       R# R# )zTry to steal from this Node's right sibling for balancing purposes.

Returns ``True`` if the theft was successful, or ``False`` if not.
TF)rN   rG   rT   rj   rF   r   appendr@   )r   r   rc   r   r   rh   s   &&&   r   ry   _Node.try_right_steal   s    
 19s6??++OOEAI.E##%%..uqy9kk%(%*ZZ^^A%6E"		  %}}}#|||++!NN..q1EMM((/r   c                ,   < V ^8  d   QhRRRS[ RRRR/# )r   rz   rd   r   r   r   Nr(   )r   r   s   "r   r   rB      s*     / // /2 /o /RV /r   c                   V P                  4       '       d   Q hV P                  '       d   Q hVP                  4       pV P                  V4      w  rVV'       d   Q hV P                  P                  WR4       \        V P                  4      ^ 8X  d   W.V n        R# V P                  V,          V8X  g   Q hV P                  P                  V^,           V4       R# )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.N)rO   r@   r   r`   rF   r   rN   rG   )r   rz   r   r   r   r[   r]   s   &&&&   r   r   _Node.adopt   s     ??$$$$<<<jjl&&s+y		#t}}"!MDM==#t+++MM  Q.r   c                (   < V ^8  d   QhRRRS[ RR/# r   r   rd   rc   r   Nr-   )r   r   s   "r   r   rB      s"     1 1O 1C 1D 1r   c                n   VP                   P                  V^,           4      pV P                  P                  VP                  P                  V4      4       V P                  P	                  VP                  4       V P
                  '       g(   V P                   P	                  VP                   4       R# R# )z>Merge this node's parent and its right sibling into this node.N)rG   r   rF   r   extendr@   )r   r   rc   r   s   &&& r   merge_Node.merge   ss    ##EAI.		/0		$|||MM  0 r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   rB     s     . . .r   c                    V P                   '       d   V P                  ^ ,          # V P                  ^ ,          P                  4       # )z"The least element in this subtree.)r@   rF   rG   minimumr   s   &r   r   _Node.minimum  s1    <<<99Q<==#++--r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   rB     s     / / /r   c                    V P                   '       d   V P                  R,          # V P                  R,          P                  4       # )z%The greatest element in this subtree.)r@   rF   rG   maximumr   s   &r   r   _Node.maximum  s1    <<<99R= ==$,,..r   c                (   < V ^8  d   QhRRRS[ RR/# r   r-   )r   r   s   "r   r   rB     s"     * *o *c *d *r   c                &   VP                   '       d   Q hV P                  W4      '       d   R# V P                  W4      '       d   R# V^ 8X  d   V P                  W4       R# VP	                  V^,
          4      pVP                  W^,
          4       R# )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.N)r@   r   ry   r   rj   )r   r   rc   rz   s   &&& r   balance_Node.balance  st     >>>!!v--..A:JJv% ))%!)4DJJvqy)r   c          	      \   < V ^8  d   QhRS[ RS[R,          RS[R,          RS[R,          /# )r   r   r   rd   exactNr   )r   r   r(   )r   r   s   "r   r   rB   &  s:     - --'8-ACd-	d-r   c                   Ve   V P                  4       '       d   Q hV P                  V4      w  rERpV'       d   Ve#   V P                  V,          VJd   \        R4      hV P                  '       d   V P                  P                  V4      # RpTpV P                  V^,           ,          P                  4       pVP                  4       pV^,           pV P                  '       d   Ve   \        R4      hR# V P                  V4      pVP                  4       '       dZ   VP                  W4       V P                  V4      w  rEV'       d   Q hV P                  V,          pVP                  4       '       d   Q hVP                  WV4      p	VeC   V P                  V4      w  rV
f   Q hV	f   Q hV
P                  V,          pWP                  V&   Tp	V	# )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 eltzexact delete had no match)rT   r`   rF   
ValueErrorr@   r   rG   r   r   rj   r   deletero   )r   r   r   r   r[   r]   original_keyleast_successorrh   r   noder   s   &&&&        r   r   _Node.delete&  s    ~T__%6%666&&s+ TYYq\%> !JKK|||yy}}Q'' EL"mmAE2::<O!%%'CAA<<<  !<==$$Q'MM$"**3/HA9MM!$E''))))ll3e,#nn\2GD###?"?99Q<DIIaLC
r   c                :   < V ^8  d   QhRS[ S[.R3,          RR/# r   visitNr   r   r(   )r   r   s   "r   r   rB   U  s&     4 4HbT4Z$8 4T 4r   c                &   \        V P                  4       FA  w  r#V P                  '       g#   V P                  V,          P	                  V4       V! V4       KC  	  V P                  '       g%   V P                  R,          P	                  V4       R# R# )z-Call *visit* on all of the elements in order.Nr   )	enumeraterF   r@   rG   visit_in_order)r   r   r[   r   s   &&  r   r   _Node.visit_in_orderU  se    		*FA<<<a //6#J + |||MM",,U3 r   c                8   < V ^8  d   QhRS[ R.R3,          RR/# )r   r   rd   Nr   )r   )r   r   s   "r   r   rB   ^  s)     5 5X6G6M-N 5SW 5r   c                    V! V 4       V P                   '       g'   V P                   F  pVP                  V4       K  	  R# R# )z?Visit nodes in preorder.  This method is only used for testing.N)r@   rG   _visit_preorder_by_node)r   r   rh   s   && r   r   _Node._visit_preorder_by_node^  s3    d|||--e4 ' r   c                4   < V ^8  d   QhRS[ RS[R,          /# r   r?   r   rd   )r6   r   )r   r   s   "r   r   rB   e  s        h.G r   c                H    V P                   VJd   V P                  V4      # R# )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)r?   clone)r   r?   s   &&r   rg   _Node.maybe_cowe  s"     <<w&::g&&r   c                $   < V ^8  d   QhRS[ RR/# r   )r6   )r   r   s   "r   r   rB   m  s      X / r   c                
   V P                  V P                  WP                  4      pVP                  P	                  V P                  4       V P                  '       g&   VP
                  P	                  V P
                  4       V# )z+Make a shallow-copy duplicate of this node.)r   r,   r@   rF   r   rG   )r   r?   ri   s   && r   r   _Node.clonem  sT    >499%|||OO""4==1r   c           	        V P                   '       g?   R R P                  V P                   Uu. uF  p\        V4      R NK  	  up4      ,           pMRp\        V 4      R R V P                   R V P
                   V 2# u upi ) r8    )r@   joinrG   r9   r?   rF   )r   crG   s   &  r   r:   _Node.__str__u  so    |||SXXT]]&K]"Q%|]&KLLHHT(1Qt||nAdii[
CC 'Ls   A=
)rG   r?   rF   r@   r,   NrE   )r    r!   r"   r#   r$   	__slots__rH   rO   rT   r`   rj   ro   ru   r{   r   r   r   ry   r   r   r   r   r   r   r   r   rg   r   r:   r%   r&   r'   s   @r   r=   r=   4   s     
 @I0 0. .
. .
 : ( ( - - $ 2
# 
# & &/ /"1 1. ./ /* *&- -^4 45 5  D Dr   r=   c                      a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltR	 tR
 t	V 3R lR lt
V 3R lR ltV 3R lR ltRV 3R lR lltV 3R lR ltV 3R lR ltR tR tRtV tR# )Cursori}  zA 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                   < V ^8  d   QhRR/# )r   btreezBTree[KT, ET]r   )r   r   s   "r   r   Cursor.__annotate__  s     & &o &r   c                    Wn         R V n        ^ V n        RV n        RV n        . V n        RV n        R V n        RV n        R # )NFT)	r   current_nodecurrent_indexrecurse
increasingparentsparkedparking_keyparking_key_read)r   r   s   &&r   rH   Cursor.__init__  sE    
*. #$02&* %r   c                   < V ^8  d   QhRR/# r   r   Nr   )r   r   s   "r   r   r     s     # #T #r   c                J   V P                   f   Q hV P                   P                  '       gw   V P                  P                  V P                   V P                  34       V P                   P
                  V P                  ,          V n         V P                   f   Q h^ V n        K  R # rf   )r   r@   r   r   r   rG   r   s   &r   _seek_leastCursor._seek_least  s       ,,,##+++LL!2!2D4F4F GH $ 1 1 : :4;M;M ND$$000!"D	 ,r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     = = =r   c                   V P                   f   Q hV P                   P                  '       g   V P                  P                  V P                   V P                  34       V P                   P
                  V P                  ,          V n         V P                   f   Q h\        V P                   P                  4      V n        K  R # rf   )r   r@   r   r   r   rG   rN   rF   r   s   &r   _seek_greatestCursor._seek_greatest  s       ,,,##+++LL!2!2D4F4F GH $ 1 1 : :4;M;M ND$$000!$T%6%6%;%;!<D	 ,r   c                <    V P                   '       g
   RV n         R# R# )aw  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   parkCursor.park  s     {{{DK r   c                "   V P                   '       d}   V P                  e_   V P                  pV P                  '       d   V P                  '       * pMV P                  pV P	                  V P                  V4       Wn        RV n         R V n        R # R # )NF)r   r   r   r   seek)r   r   befores   &  r   _maybe_unparkCursor._maybe_unpark  sr    ;;;+!__
((( "&0F
 "__F		$**F3",DK#D! r   c                .   < V ^8  d   QhRS[ R,          /# r   r   )r   r   s   "r   r   r          &  & b4i & r   c                   V P                  4        RV n        V P                  f   V P                  ^ 8X  d   R# V P                  ^8X  g   Q hV P                  P
                  V n        \        V P                  P
                  P                  4      V n        V P                  4         V P                  '       d*   V P                  '       g   V P                  4        RV n	        RV n
        V ;P                  ^,          un        V P                  ^ 8  di   V P                  P                  V P                  ,          pV P                  P                  '       g   RV n	        VP                  4       V n        RV n        V# \        V P                  4      ^ 8  d+   V P                  P                  4       w  V n        V n        EK  RV n        ^ V n        R# )zAGet the previous element, or return None if on the left boundary.NTF)r   r   r   r   r   rootrN   rF   r   r   r   r@   r   r   r   r   r   r   s   & r   prevCursor.prev  sa   $!!Q&))Q... %)JJOO!%()=)=%>"##%||| '')$#DO!#!!Q&'',,T-?-?@((000#'DL#&779 (,%
t||$q(<@LL<L<L<N9D%t'9(,D%)*D&r   c                .   < V ^8  d   QhRS[ R,          /# r   r   )r   r   s   "r   r   r     r   r   c                   V P                  4        RV n        V P                  fY   V P                  ^8X  d   R# V P                  ^ 8X  g   Q hV P                  P
                  V n        ^ V n        V P                  4         V P                  '       d*   V P                  '       d   V P                  4        RV n        RV n        V P                  \        V P                  P                  4      8  d   V P                  P                  V P                  ,          pV ;P                  ^,          un        V P                  P                  '       g   RV n        VP                  4       V n        RV n        V# \        V P                  4      ^ 8  d+   V P                  P                  4       w  V n        V n        EK6  RV n        ^V n        R# )z>Get the next element, or return None if on the right boundary.NTF)r   r   r   r   r   r   r   r   r   rN   rF   r@   r   r   r   r   r   s   & r   nextCursor.next  s_   $!!Q&))Q... %)JJOO!%&"  "|||??? $$&$"DO!!C(9(9(>(>$??'',,T-?-?@""a'"((000#'DL#&779 (,%
t||$q(<@LL<L<L<N9D%t'9(,D%)*D&r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   r   r[   r   N)rA   r.   )r   r   s   "r   r   r     s"     ' ' '# '$ 'r   c                B    V'       d	   W n         R# V^,           V n         R# )   N)r   )r   r   r[   s   &&&r   _adjust_for_beforeCursor._adjust_for_before  s    !"!"QDr   c                *   < V ^8  d   QhRS[ RS[RR/# )r   r   r   r   N)r   rA   )r   r   s   "r   r   r     s"     !# !# !#D !#D !#r   c                   V P                   P                  V n        V P                  f   Q hRV n        . V n        W n        RV n        Wn        RV n        V P                  P                  '       g   V P                  P                  V4      w  r4V'       d>   V P                  W#4       V'       d   V P                  4        R# V P                  4        R# V P                  P                  V P                  V34       V P                  P                  V,          V n        V P                  e   K  Q hV P                  P                  V4      w  r4V'       d   V P                  W#4       R# W0n        R# )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   r@   r`   r  r   r   r   rG   r   )r   r   r   r[   r]   s   &&&  r   r   Cursor.seek  s%    !JJOO  ,,,  %##+++((77<HA''2'')  $$&LL!2!2A 67 $ 1 1 : :1 =D$$000$$33C8##F.!"r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   ?  s     
  
 D 
 r   c                h    RV n         ^ V n        RV n        RV n        . V n        RV n        RV n        R# )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.NFTr   r   r   r   r   r   r   r   s   &r   
seek_firstCursor.seek_first?  s8     !r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   K  s        4  r   c                h    RV n         ^V n        RV n        RV n        . V n        RV n        RV n        R# )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.
NFr  r   s   &r   	seek_lastCursor.seek_lastK  s8    
 !r   c                <    V P                   P                  V 4       V # rf   )r   register_cursorr   s   &r   	__enter__Cursor.__enter__X  s    

""4(r   c                <    V P                   P                  V 4       R # F)r   deregister_cursor)r   exc_type	exc_value	tracebacks   &&&&r   __exit__Cursor.__exit__\  s    

$$T*r   )	r   r   r   r   r   r   r   r   r   N)T)r    r!   r"   r#   r$   rH   r   r   r   r   r   r  r  r   r  r  r  r  r%   r&   r'   s   @r   r   r   }  s     & &# #= =
$&&  & P&  & P' '!# !#F
  
     r   r   c                       ] tR tRtRtRtR# )	Immutableia  zThe BTree is immutable.r   N)r    r!   r"   r#   r$   r%   r   r   r   r"  r"  a  s    !r   r"  c                   $  a  ] tR tRt o RtR]RR/V 3R lR lltR tV 3R	 lR
 ltR#V 3R lR llt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltR tV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltR  tR! tR"tV tR# )$BTreeie  z2An in-memory BTree with copy-on-write and cursors.r,   originalNc                4   < V ^8  d   QhRS[ RS[R,          /# )r   r,   r%  r$  )r.   r   )r   r   s   "r   r   BTree.__annotate__h  s       S 8I r   c                  \        4       V n        RV n        V  V  V  \        4       V n        VeS   VP                  '       g   \        R4      hVP                  V n        VP                  V n        VP                  V n        R# V^8  d   \        R4      hWn        \        V P                  V P                  R4      V n        ^ V n        R# )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 immutablezt must be >= 3T)
r6   r?   
_immutablesetcursorsr   r,   r   sizer=   )r   r,   r%  s   &$$r   rH   BTree.__init__h  s      z$'E&&& !BCCZZDF DI DI1u !122FdffdllD9DIDIr   c                <    V P                   '       g
   RV n         R# R# )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_immutableBTree.make_immutable  s     "DO r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r'    s       r   c                |    V P                   '       d   \        hV P                   F  pVP                  4        K  	  R # rf   )r)  r"  r+  r   r   cursors   & r   _check_mutable_and_parkBTree._check_mutable_and_park  s'    ???OllFKKM #r   c                :   < V ^8  d   QhRS[ RS[RS[ R,          /# )r   r   r   r   Nr   )r   r   s   "r   r   r'    s&      "  d r   c                   V P                  4        V P                  P                  V P                  4      pV'       d   W0n        V P                  P	                  4       '       d[   V P                  p\        V P                  V P                  R4      V n        V P                  P                  ! VP                  4       !   V P                  P                  W4      pVf   V ;P                  ^,          un
        V# )a  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``.
F)r5  r   rg   r?   rO   r=   r,   r   r   r   r,  )r   r   r   ri   old_rootr   s   &&&   r   insert_elementBTree.insert_element  s     	$$&$$T\\2I99!!yyHdffdllE:DIIIOOX^^-.yy''6<IINIr   c                4   < V ^8  d   QhRS[ RS[R,          /# rr   rs   )r   r   s   "r   r   r'    s     " "r "b4i "r   c                8    V P                   P                  V4      # )zXGet the element matching *key* from the BTree, or return ``None`` if it
does not exist.
)r   ru   r   r   s   &&r   get_elementBTree.get_element  s     yy}}S!!r   c                H   < V ^8  d   QhRS[ RS[R,          RS[R,          /# )r   r   r   Nr   rs   )r   r   s   "r   r   r'    s*      2 b4i BI r   c                   V P                  4        V P                  P                  V P                  4      pV'       d   W0n        V P                  P	                  VR V4      pVe   V ;P
                  ^,          un        \        V P                  P                  4      ^ 8X  de   V P                  P                  '       gI   \        V P                  P                  4      ^8X  g   Q hV P                  P                  ^ ,          V n        V# rf   )
r5  r   rg   r?   r   r,  rN   rF   r@   rG   )r   r   r   ri   r   s   &&&  r   _deleteBTree._delete  s    $$&$$T\\2IiisD%0?IINI499>>"a' yy(((tyy112a777 $		 2 21 5DI
r   c                4   < V ^8  d   QhRS[ RS[R,          /# rr   rs   )r   r   s   "r   r   r'    s     ' 'b 'R$Y 'r   c                &    V P                  VR4      # )zrDelete the element matching *key* from the BTree.

Returns the matching element or ``None`` if it does not exist.
N)rC  r>  s   &&r   
delete_keyBTree.delete_key  s    
 ||C&&r   c                4   < V ^8  d   QhRS[ RS[ R,          /# )r   r~   r   Nr   )r   r   s   "r   r   r'    s      B 29 r   c                T    V P                  VP                  4       V4      pW!J g   Q hV# )zgDelete *element* from the BTree.

Returns the matching element or ``None`` if it was not in the BTree.
)rC  r   )r   r~   delts   && r   delete_exactBTree.delete_exact  s)    
 ||GKKM73r   c                    V P                   # rf   )r,  r   s   &r   __len__BTree.__len__      yyr   c                :   < V ^8  d   QhRS[ S[.R3,          RR/# r   r   )r   r   s   "r   r   r'    s&     ( (HbT4Z$8 (T (r   c                <    V P                   P                  V4       R# )zBCall *visit*(element) on all elements in the tree in sorted order.N)r   r   r   r   s   &&r   r   BTree.visit_in_order  s    		  'r   c                :   < V ^8  d   QhRS[ S[.R3,          RR/# r   )r   r=   )r   r   s   "r   r   r'    s&     1 1Xugtm-D 1 1r   c                <    V P                   P                  V4       R # rf   )r   r   rT  s   &&r   r   BTree._visit_preorder_by_node  s    		))%0r   c                6   < V ^8  d   QhRS[ S[S[3,          /# r   )r   r   r(   )r   r   s   "r   r   r'    s      r2v r   c                    \        V 4      # )zCreate a cursor.r   r   s   &r   r4  BTree.cursor  s    d|r   c                $   < V ^8  d   QhRS[ RR/# r   r4  r   Nr[  )r   r   s   "r   r   r'    s     ! !f ! !r   c                <    V P                   P                  V4       R# )z4Register a cursor for the automatic parking service.N)r+  addr3  s   &&r   r  BTree.register_cursor  s     r   c                $   < V ^8  d   QhRS[ RR/# r^  r[  )r   r   s   "r   r   r'    s     % % %4 %r   c                <    V P                   P                  V4       R# )z7Deregister a cursor from the automatic parking service.N)r+  discardr3  s   &&r   r  BTree.deregister_cursor  s    V$r   c                &    V P                  V R 7      # ))r%  )r   r   s   &r   __copy__BTree.__copy__  s    ~~t~,,r   c              #     "   V P                  4       ;_uu_ 4       p VP                  4       pVf   MVP                  4       x  K*  RRR4       R#   + '       g   i     R# ; i5ir   )r4  r  r   )r   r4  r   s   &  r   __iter__BTree.__iter__  s>     [[]]fkkm;ggi ]]]s   A$+A
A$A!		A$)r)  r?   r+  r   r,  r,   r  )r    r!   r"   r#   r$   	DEFAULT_TrH   r/  r5  r:  r?  rC  rG  rL  rO  r   r   r4  r  r  rg  rj  r%   r&   r'   s   @r   r$  r$  e  s     <9 D  <#  ." " "' ' ( (1 1 ! !% %-   r   r$  VTc                   f   a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltR	 tR
 t	Rt
V tR# )KVi  z/The BTree element type used in a ``BTreeDict``.c                &   < V ^8  d   QhRS[ RS[/# )r   r   valuer   rm  )r   r   s   "r   r   KV.__annotate__  s      B r r   c                    Wn         W n        R # rf   _key_value)r   r   rq  s   &&&r   rH   KV.__init__  s    	r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   rs          R r   c                    V P                   # rf   rv  r   s   &r   r   KV.key  rQ  r   c                    < V ^8  d   QhRS[ /# r   )rm  )r   r   s   "r   r   rs    s      r r   c                    V P                   # rf   )rw  r   s   &r   rq  KV.value  s    {{r   c                <    R V P                    RV P                   R2# zKV(z, )ru  r   s   &r   r:   
KV.__str__	      TYYKr$++a00r   c                <    R V P                    RV P                   R2# r  ru  r   s   &r   __repr__KV.__repr__  r  r   ru  N)r    r!   r"   r#   r$   rH   r   rq  r:   r  r%   r&   r'   s   @r   ro  ro    s5     9   11 1r   ro  c                      a a ] tR tRt oRtR]RRRR/V3R lV 3R	 llltV3R
 lR ltV3R lR ltV3R lR lt	Rt
VtV ;t# )	BTreeDicti  zwA MutableMapping implemented with a BTree.

Unlike a normal Python dict, the BTreeDict may be mutated while iterating.
r,   r%  Nr   Fc                :   < V ^8  d   QhRS[ RS[R,          RS[/# r   r,   r%  Nr   r.   r$  rA   )r   r   s   "r   r   BTreeDict.__annotate__  /     ! ! ! $,	!
 !r   c               4   < \         SV `  WR 7       W0n        R# )r,   r%  NsuperrH   r   r   r,   r%  r   r   s   &$$$r   rH   BTreeDict.__init__       	10 r   c                &   < V ^8  d   QhRS[ RS[/# rW   rr  )r   r   s   "r   r   r     s     ) )r )b )r   c                t    V P                  V4      pVf   \        h\        \        V4      P	                  4       # rf   )r?  KeyErrorr
   ro  rq  )r   r   r   s   && r   __getitem__BTreeDict.__getitem__   s1    s#;NC=&&((r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   r   rq  r   Nrr  )r   r   s   "r   r   r  '  s"     0 0r 0" 0 0r   c                R    \        W4      pV P                  W0P                  4       R # rf   )ro  r:  r   )r   r   rq  r   s   &&& r   __setitem__BTreeDict.__setitem__'  s    nC/r   c                $   < V ^8  d   QhRS[ RR/# rr   r   )r   r   s   "r   r   r  +  s      r d r   c                8    V P                  V4      f   \        hR # rf   )rG  r  r>  s   &&r   __delitem__BTreeDict.__delitem__+  s    ??3'N (r   r   )r    r!   r"   r#   r$   rl  rH   r  r  r  r%   r&   __classcell__r   r   s   @@r   r  r    sU     
! ! "&	!
 ! !) )0 0  r   r  c                   H   a  ] tR tRt o RtV 3R lR ltV 3R lR ltRtV tR# )	Memberi0  z.The BTree element type used in a ``BTreeSet``.c                    < V ^8  d   QhRS[ /# )r   r   r   )r   r   s   "r   r   Member.__annotate__3  s      B r   c                    Wn         R # rf   r|  r>  s   &&r   rH   Member.__init__3  s    	r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r  6  rz  r   c                    V P                   # rf   r|  r   s   &r   r   
Member.key6  rQ  r   r|  N)	r    r!   r"   r#   r$   rH   r   r%   r&   r'   s   @r   r  r  0  s     8  r   r  c                      a a ] tR tRt oRtR]RRRR/V3R lV 3R	 llltV3R
 lR ltV3R lR ltV3R lR lt	Rt
VtV ;t# )BTreeSeti:  zqA MutableSet implemented with a BTree.

Unlike a normal Python set, the BTreeSet may be mutated while iterating.
r,   r%  Nr   Fc                :   < V ^8  d   QhRS[ RS[R,          RS[/# r  r  )r   r   s   "r   r   BTreeSet.__annotate__@  r  r   c               4   < \         SV `  WR 7       W0n        R# r  r  r  s   &$$$r   rH   BTreeSet.__init__@  r  r   c                &   < V ^8  d   QhRS[ RS[/# rW   )r   rA   )r   r   s   "r   r   r  J  s     1 1 1 1r   c                (    V P                  V4      R J# rf   )r?  r>  s   &&r   __contains__BTreeSet.__contains__J  s    $D00r   c                $   < V ^8  d   QhRS[ RR/# r   rq  r   Nr   )r   r   s   "r   r   r  M  s     0 0 0 0r   c                R    \        V4      pV P                  W P                  4       R # rf   )r  r:  r   )r   rq  r   s   && r   r`  BTreeSet.addM  s    UmC/r   c                $   < V ^8  d   QhRS[ RR/# r  r   )r   r   s   "r   r   r  Q  s      R D r   c                (    V P                  V4       R # rf   )rG  )r   rq  s   &&r   rd  BTreeSet.discardQ  s    r   r  )r    r!   r"   r#   r$   rl  rH   r  r`  rd  r%   r&   r  r  s   @@r   r  r  :  sU     
! ! "&	!
 ! !1 10 0  r   r  N)r$   collections.abcr   r   typingr   r   r   r   r   r	   r
   rl  r   r   r(   r1   r4   r6   r=   r   	Exceptionr"  r$  rm  ro  r  r  r  r   r   r   <module>r     s)   7 I I I	T]"gbk " T!
	 	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   