Ë
    ¶�/j%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    úKC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\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   € ð ˆq‰5€Lr   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   € àˆq‰5�1‰9Ðr   c                   ó   — e Zd ZdZd„ Zy)Ú_CreatorzÓA _Creator class instance is used as a unique id for the BTree which created
    a node.

    We use a dedicated creator rather than just a BTree reference to avoid circularity
    that would complicate GC.
    c                 ó   — 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   € Ø�AŠvˆˆ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   ó;   € ä�4—9‘9‹~¤ d§f¡f£Ò-Ð-Ð-Ü�4—9‘9‹~¤ d§f¡f£Ñ-Ð-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 )z×Get the index of the ``Element`` matching ``key`` or the index of its
        least successor.

        Returns a tuple of the index and an ``equal`` boolean that is ``True`` iff.
        the key was found.
        r   r!   Fr%   T)r8   r2   r   )r   r   ÚlÚiÚrÚequalÚmÚks           r   Úsearch_in_nodez_Node.search_in_nodeN   sÛ   € ô �—	‘	‹NˆØˆqŠ5�S˜4Ÿ9™9 Q¨¡UÑ+×/Ñ/Ó1Ò1à�e�8ˆOØˆÜ�—	‘	‹NˆØ�‰EˆØˆØ�1ŠfØ�Q‘˜1‘ˆAØ—	‘	˜!‘× Ñ Ó"ˆAØ�aŠxØ�Ø�Øð �%ˆxˆð �q’Ø�Ø˜‘E‘à˜‘E�ð �1‹fð �%ˆ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Ñ$ˆØ—‘ §¡Ó.ˆÙØ#)ˆD�M‰M˜%Ñ ØˆMàˆLr   c                 ó”   — | j                  |«      \  }}|r| |fS | j                  ry| j                  |«      }|j                  |«      S )zÜGet the node associated with key and its index, doing
        copy-on-write if we have to descend.

        Returns a tuple of the node and the index, or the tuple ``(None, 0)``
        if the key was not found.
        ©Nr   )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ÙØ—9‘9˜Q‘<ÐØ�\Š\Øà—=‘= Ñ#×'Ñ'¨Ó,Ð,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Š:ØØ�}‰}˜U Q™YÑ'ˆÜˆt�y‰y‹>œT $§&¡&›\Ò)ØØ×#Ñ# E¨A¡IÓ.ˆÜ�$—)‘)‹nœt D§F¡F›|Ò+Ø×'Ñ'¨¨e°a©iÔ8Øô �$—)‘)‹nœt D§F¡F›|Õ+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Ó/‰HˆAˆuÙà—i‘i ‘l�Ø&�—	‘	˜!‘Ø�
Ø—’Ø—	‘	× Ñ   GÔ,Øà×,Ñ,¨QÓ/�Ø×#Ñ#Ô%Ø�D—J‘J §¡£Ñ.ð Ø×+Ñ+¨G°XÓ>�ÙØ×4Ñ4°QÔ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è   € à�‰Ô Ð Ð Ø—‘˜tŸv™v t§|¡|°T·\±\ÓBˆÜ˜$Ÿ)™)¤D¨¯©£L°1Ñ$4Ð$6Ð7Ó8ˆŒ
Ø—‘œ4 §¡›<Ñ(ˆÜ˜Ÿ™ >¤T¨$¯&©&£\Ð2Ó3ˆŒ	Ø�|Š|Ü! $§-¡-´°T·V±V³¸qÑ0@Ð0BÐ"CÓDˆEŒNÜ  §¡Ð/A´°d·f±f³ÀÑ1AÐ!BÓCˆDŒMØ�V˜UÐ"Ð"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)z—Try to steal from this Node's left sibling for balancing purposes.

        Returns ``True`` if the theft was successful, or ``False`` if not.
        r   r!   TF)r3   r<   rK   r2   ÚpoprX   r1   )r   rc   rE   rS   ÚeltrI   s         r   Útry_left_stealz_Node.try_left_stealÆ   s½   € ð
 �AŠ:Ø—?‘? 5¨1¡9Ñ-ˆDØ—?‘?Ô$Ø×-Ñ-¨e°a©iÓ8�Ø—k‘k %¨!¡)Ñ,�Ø)-¯©¯©«�—‘˜E A™IÑ&Ø—	‘	× Ñ   CÔ(Ø—|’|Ø#Ÿ|š|Ð+Ð+Ø ŸM™M×-Ñ-Ó/�EØ—M‘M×(Ñ(¨¨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)z˜Try to steal from this Node's right sibling for balancing purposes.

        Returns ``True`` if the theft was successful, or ``False`` if not.
        r!   r   TF)r8   r3   r<   rK   r2   re   Úappendr1   )r   rc   rE   ra   rf   rI   s         r   rR   z_Node.try_right_stealÙ   sÆ   € ð
 �1‰9”s˜6Ÿ?™?Ó+Ò+Ø—O‘O E¨A¡IÑ.ˆEØ×#Ñ#Ô%Ø×.Ñ.¨u°q©yÓ9�Ø—k‘k %Ñ(�Ø%*§Z¡Z§^¡^°AÓ%6�—‘˜EÑ"Ø—	‘	× Ñ  Ô%Ø—}’}Ø#Ÿ|š|Ð+Ð+Ø!ŸN™N×.Ñ.¨qÓ1�EØ—M‘M×(Ñ(¨Ô/ØØ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)zÒAdopt left, middle, and right into our Node (which must not be maximal,
        and which must not be a leaf).  In the case were we are not the new root,
        then the left child must already be in the Node.r   r!   N)r9   r1   r   rD   r2   rX   r8   r3   )r   rS   rb   ra   r   r?   rA   s          r   rY   z_Node.adoptì   s§   € ð —?‘?Ô$Ð$Ð$Ø—<’<ÐÐØ�j‰j‹lˆØ×&Ñ& sÓ+‰ˆˆ5ÙÐˆyØ�	‰	×Ñ˜˜FÔ#Üˆt�}‰}Ó Ò"à! 5˜MˆD�Mà—=‘= Ñ# tÒ+Ð+Ð+Ø�M‰M× Ñ   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   € à—‘×#Ñ# E¨A¡IÓ.ˆØ�	‰	×Ñ˜Ÿ™Ÿ™¨Ó/Ô0Ø�	‰	×Ñ˜Ÿ™Ô$Ø�|Š|Ø�M‰M× Ñ  §¡Õ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/   € à�<Š<Ø—9‘9˜Q‘<Ðà—=‘= Ñ#×+Ñ+Ó-Ð-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/   € à�<Š<Ø—9‘9˜R‘=Ð à—=‘= Ñ$×,Ñ,Ó.Ð.r   c                 óî   — |j                   rJ ‚| j                  ||«      ry| j                  ||«      ry|dk(  r| j                  ||«       y|j	                  |dz
  «      }|j                  ||dz
  «       y)z¶This Node is minimal, and we want to make it non-minimal so we can delete.
        We try to steal from our siblings, and if that doesn't work we will merge
        with one of them.Nr   r!   )r1   rg   rR   rm   rK   )r   rc   rE   rS   s       r   Úbalancez_Node.balance  st   € ð —>’>Ð!Ð!Ø×Ñ˜v uÔ-ØØ×Ñ ¨Ô.Øà�AŠ:à�J‰J�v˜uÕ%ð ×)Ñ)¨%°!©)Ó4ˆDØ�J‰J�v˜u q™yÕ)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 )zÁDelete an element matching *key* if it exists.  If *exact* is not ``None``
        then it must be an exact match with that element.  The Node must not be
        minimal unless it is the root.Nz'exact delete did not match existing eltr!   zexact delete had no match)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ØˆÙàÐ  T§Y¡Y¨q¡\¸Ñ%>Ü Ð!JÓKÐKØ�|Š|Ø—y‘y—}‘} QÓ'Ð'ð ˆEØˆLØ"Ÿm™m¨A°©EÑ2×:Ñ:Ó<ˆOØ!×%Ñ%Ó'ˆCØ�A‘ˆAØ�<Š<àÐ Ü Ð!<Ó=Ð=Øà×$Ñ$ QÓ'ˆØ×ÑÔØ�M‰M˜$ Ô"à×*Ñ*¨3Ó/‰HˆAˆuÙÐ�9Ø—M‘M !Ñ$ˆEØ×'Ñ'Ô)Ð)Ð)Ø�l‰l˜3  eÓ,ˆØÐ#Ø—n‘n \Ó2‰GˆD�!ØÐ#Ð#Ð#Ø�?Ð"�?Ø—9‘9˜Q‘<ˆDØˆD�I‰I�a‰LØˆ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  sc   € ä §	¡	Ö*‰FˆAˆsØ—<’<Ø—‘˜aÑ ×/Ñ/°Ô6Ù�#�Jð +ð �|Š|Ø�M‰M˜"Ñ×,Ñ,¨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^  s1   € áˆdŒØ�|Š|ØŸœ�Ø×-Ñ-¨eÕ4ñ 'ð r   c                 óB   — | j                   |ur| j                  |«      S y)zœReturn a clone of this Node if it was not created by *creator*, or ``None``
        otherwise (i.e. copy for copy-on-write if we haven't already copied it).N)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   € à—‘ §¡¨°·±Ó>ˆØ�‰×Ñ˜4Ÿ9™9Ô%Ø�|Š|Ø�O‰O×"Ñ" 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  sm   € Ø�|Š|Ø˜SŸX™X¸T¿]º]Ó&K¹]¸¬"¨Q«%°¨¡|¸]Ñ&KÓLÑL‰HàˆHÜ�T“(˜1�˜Q˜tŸ|™|˜n¨A¨d¯i©i¨[¸¸
Ð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¨ð 0¸4ó 0ð.˜Dó .ð
.˜Dó .ð
 "ð ¨¨s°D¨yÑ)9ó ð: Sð ¨_ó ð(˜Rð ( E¨(°?Ñ*CÀSÐ*HÑ$Ió (ð -�rð -˜b 4™ió -ð°ð ¸ó ð$ bð °Dð ¸RÀ$¹Yó ð2
#�u˜_¨b°/ÐAÑBó 
#ð _ð ¸Sð ÀTó ð& oð ¸cð Àdó ð&/˜/ð /°2ð /¸oð /ÐRVó /ð"1˜Oð 1°Cð 1¸Dó 1ð.˜ó .ð/˜ó /ð*˜oð *°cð *¸dó *ð&-Øð-Ø'¨Ñ8ð-ØACÀdÁð-à	ˆd‰ó-ð^4 H¨b¨T°4¨ZÑ$8ð 4¸Tó 4ð5¨X°Ð6GÈÐ6MÑ-Nð 5ÐSWó 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)ÚCursorzÍA seekable cursor for a BTree.

    If you are going to use a cursor on a mutable BTree, you should use it
    in a ``with`` block so that any mutations of the BTree automatically park
    the cursor.
    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’   € ð × Ñ Ð,Ð,Ð,Ø×#Ñ#×+Ò+Ø�L‰L×Ñ ×!2Ñ!2°D×4FÑ4FÐ GÔHØ $× 1Ñ 1× :Ñ :¸4×;MÑ;MÑ NˆDÔØ×$Ñ$Ð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£   € ð × Ñ Ð,Ð,Ð,Ø×#Ñ#×+Ò+Ø�L‰L×Ñ ×!2Ñ!2°D×4FÑ4FÐ GÔHØ $× 1Ñ 1× :Ñ :¸4×;MÑ;MÑ NˆDÔØ×$Ñ$Ð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   € ð �{Š{ØˆD�Kð 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   € Ø�;Š;Ø×ÑÐ+à!Ÿ_™_�
Ø×(Ò(ð "&§¡Ð0‘Fð
 "Ÿ_™_�FØ—	‘	˜$×*Ñ*¨FÔ3Ø",�”ØˆDŒKØ#ˆ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Ò.Ð.Ð.ð %)§J¡J§O¡O�Ô!Ü%(¨¯©¯©×)=Ñ)=Ó%>�Ô"Ø×#Ñ#Ô%ØØ�|Š|Ø—’ð ×'Ñ'Ô)Ø$�”Ø#ˆDŒOØ×Ò !Ñ#ÕØ×!Ñ! QÒ&Ø×'Ñ'×,Ñ,¨T×-?Ñ-?Ñ@�Ø×(Ñ(×0Ò0Ø#'�D”LØ#&§7¡7£9�Ô Ø(,�Ô%Ø�
ä�t—|‘|Ó$ qÒ(Ø<@¿L¹L×<LÑ<LÓ<NÑ9�DÔ% 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Ò.Ð.Ð.ð %)§J¡J§O¡O�Ô!Ø%&�Ô"Ø× Ñ Ô"ØØ�|Š|Ø—?’?ð ×$Ñ$Ô&Ø$�”Ø"ˆDŒOØ×!Ñ!¤C¨×(9Ñ(9×(>Ñ(>Ó$?Ò?Ø×'Ñ'×,Ñ,¨T×-?Ñ-?Ñ@�Ø×"Ò" aÑ'Õ"Ø×(Ñ(×0Ò0Ø#'�D”LØ#&§7¡7£9�Ô Ø(,�Ô%Ø�
ä�t—|‘|Ó$ qÒ(Ø<@¿L¹L×<LÑ<LÓ<NÑ9�DÔ% 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  € ð !ŸJ™JŸO™OˆÔØ× Ñ Ð,Ð,Ð,ØˆŒØˆŒØ ˆŒØˆŒØˆÔØ %ˆÔØ×#Ñ#×+Ò+Ø×(Ñ(×7Ñ7¸Ó<‰HˆAˆuÙØ×'Ñ'¨°Ô2ÙØ×'Ñ'Ô)ð ð ×$Ñ$Ô&ØØ�L‰L×Ñ ×!2Ñ!2°AÐ 6Ô7Ø $× 1Ñ 1× :Ñ :¸1Ñ =ˆDÔØ×$Ñ$Ð0Ð0Ð0ð ×#Ñ#×+Ó+ð ×$Ñ$×3Ñ3°CÓ8‰ˆˆ5ÙØ×#Ñ# F¨AÕ.à!"ˆDÕr   c                 óf   — d| _         d| _        d| _        d| _        g | _        d| _        d| _        y)z”Seek to the left boundary (i.e. just before the least element).

        A subsequent next() will return the least element if the BTree isn't empty.Nr   FT©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)z£Seek to the right boundary (i.e. just after the greatest element).

        A subsequent prev() will return the greatest element if the BTree isn't empty.
        Nr!   Fr¯   r   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‹   „ ñó&ó#ó=ò
ò$ð&& �b˜4‘ió & ðP& �b˜4‘ió & ð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)zýCreate a BTree.

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

        The BTree is not thread-safe.
        FNzoriginal BTree is not 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Ø—Z‘ZˆDŒFØ Ÿ™ˆDŒIØ Ÿ™ˆD�Ià�1ŠuÜ Ð!1Ó2Ð2ØˆDŒFÜ˜dŸf™f d§l¡l°DÓ9ˆDŒIØˆD�Ir   c                 ó,   — | j                   sd| _         yy)z®Make the BTree immutable.

        Attempts to alter the BTree after making it immutable will raise an
        Immutable exception.  This operation cannot be undone.
        TN)rÄ   r   s    r   Úmake_immutablezBTree.make_immutable†  s   € ð �ŠØ"ˆD�Oð 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Ø—l”lˆFØ�K‰K�Mñ #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ˆÙØˆDŒIØ�9‰9×ÑÔ!Ø—y‘yˆHÜ˜dŸf™f d§l¡l°EÓ:ˆDŒIØˆD�I‰I�O‰O˜XŸ^™^Ó-Ñ.Ø�y‰y×'Ñ'¨¨XÓ6ˆØˆ<à�IŠI˜‰N�IØˆ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   € ð �y‰y�}‰}˜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ˆÙØˆDŒIØ�i‰i×Ñ˜s D¨%Ó0ˆØˆ?à�IŠI˜‰N�IÜ�4—9‘9—>‘>Ó" aÒ'ð —y‘y×(Ò(Ü˜tŸy™y×1Ñ1Ó2°aÒ7Ð7Ð7Ø $§	¡	× 2Ñ 2°1Ñ 5�D”IØˆ
r   c                 ó&   — | j                  |d«      S )z‚Delete the element matching *key* from the BTree.

        Returns the matching element or ``None`` if it does not exist.
        N)rÕ   rÒ   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+   € ð
 �|‰|˜GŸK™K›M¨7Ó3ˆØ�w‰ÐˆØˆr   c                 ó   — | j                   S rG   )rÇ   r   s    r   Ú__len__zBTree.__len__×  ó   € Ø�y‰yÐ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__ð  sE   è ø€ Ø�[‰[Œ]˜fØØ—k‘k“m�Ø�;ØØ—g‘g“i’ð	 ð ÷	 �]‰]ü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ð " b¨4¡ió "ð˜2ð  b¨4¡ið °B¸±Ió ð"'˜bð ' R¨$¡Yó 'ð Bð ¨2°©9ó òð( H¨b¨T°4¨ZÑ$8ð (¸Tó (ð1¨X°u°g¸t°mÑ-Dð 1Èó 1ð˜˜r 2˜v™ó ð! 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__	  ó   € Ø�T—Y‘Y�K˜r $§+¡+ ¨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__  ó   ø€ ô 	‰Ñ˜1 xÐÔ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!   € Ü��e‹nˆØ×Ñ˜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ó )ð0˜rð 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   € Ü�U‹mˆØ×Ñ˜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ƒ]€ô"ˆg�b‰kô "ñ ˆT˜Ô!€ðˆCð �Có ðˆCð �Có ÷
	ñ 	ôFDˆG�B˜�F‰Oô FDôR
aˆW�R˜�V‰_ô aôH"�	ô "ôQ ˆG�B˜�F‰Oô Q ñh ˆTƒ]€ô1ˆ�'˜"˜b˜&‘/ô 1ô(�˜˜B˜‘  r¨2¨b°"¨f©: ~Ñ!6¸ÀrÈ2ÀvÑ8Nô ô@ˆW�g˜b‘kô ôˆu�g˜b‘k :¨b¡>õ r   