§
    cÌc  ã                   óì  — d Z ddlmZ ddlmZ  e e¦   «         d¦  «         ddlmZmZmZm	Z	m
Z
mZmZ ddlmZmZ dd	lmZmZmZ d
ZdZdZdZdZdZdZdZ G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ dej        ¦  «        Z G d„ de¦  «        Z  G d„ d¦  «        Z! G d„ d¦  «        Z"e Z#	 dd lm$Z% e%j&        Z#d"S # e'$ r!Z( e
j)        e(¦  «         dd!lm*Z% Y d"Z([(d"S d"Z([(ww xY w)#zB+Tree indicesé    )ÚBytesIOé   )Úlazy_importz7
import bisect
import math
import tempfile
import zlib
)Úchunk_writerÚdebugÚ
fifo_cacheÚ	lru_cacheÚosutilsÚtraceÚ	transporté   )ÚindexÚstatic_tuple)Ú_OPTION_NODE_REFSÚ_OPTION_KEY_ELEMENTSÚ_OPTION_LENs   B+Tree Graph Index 2
s   row_lengths=s
   type=leaf
s   type=internal
s   offset=éx   i   iè  c                   ó    — e Zd ZdZd„ Zdd„ZdS )Ú_BuilderRowzÙThe stored state accumulated while writing out a row in the index.

    :ivar spool: A temporary file used to accumulate nodes for this row
        in the tree.
    :ivar nodes: The count of nodes emitted so far.
    c                 ó0   — d| _         d| _        d| _        dS )zCreate a _BuilderRow.r   N)ÚnodesÚspoolÚwriter©Úselfs    ú8/usr/lib/python3/dist-packages/breezy/bzr/btree_index.pyÚ__init__z_BuilderRow.__init__C   s   € àˆŒ
ØˆŒ
ØˆŒˆˆó    Tc                 ó–  — | j                              ¦   «         \  }}}| j        dk    r6t          ¦   «         | _        | j                             dt          z  ¦  «         nY| j        dk    rNt                               d¬¦  «        }|                     | j         	                    ¦   «         ¦  «         || _        d}|s|r|d= |}| j         
                    |¦  «         | j                             ¦   «         |z   t          z  }|dk    r+t          d| j                             ¦   «         |fz  ¦  «        ‚| xj        dz  c_        d | _         d S )Nr   ó    r   zbzr-index-row-©Úprefixéÿÿÿÿzincorrect node length: %d, %d)r   Úfinishr   r   r   ÚwriteÚ_RESERVED_HEADER_BYTESÚtempfileÚTemporaryFileÚgetvalueÚ
writelinesÚtellÚ
_PAGE_SIZEÚAssertionError)r   ÚpadÚ
byte_linesÚ_Úpaddingr   Úskipped_bytesÚ	remainders           r   Úfinish_nodez_BuilderRow.finish_nodeI   s@  € Ø!%¤×!3Ò!3Ñ!5Ô!5Ñˆ
�A�wØŒ:˜Š?ˆ?Ý ™œˆDŒJàŒJ×Ò˜WÕ'=Ñ=Ñ>Ô>Ð>Ð>ØŒZ˜1Š_ˆ_å×*Ò*Ð2BÐ*ÑCÔCˆEØ�KŠK˜œ
×+Ò+Ñ-Ô-Ñ.Ô.Ð.ØˆDŒJØˆØð 	$�wð 	$Ø˜2�Ø#ˆMØŒ
×Ò˜jÑ)Ô)Ð)Ø”Z—_’_Ñ&Ô&¨Ñ6½*ÑDˆ	Ø˜Š>ˆ>Ý Ð!@Ø$(¤J§O¢OÑ$5Ô$5°yÐ#Añ"Bñ Cô Cð Càˆ
Œ
�a‰ˆ
Œ
ØˆŒˆˆr   N©T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r4   © r   r   r   r   ;   sA   € € € € € ðð ðð ð ðð ð ð ð ð r   r   c                   ó   — e Zd ZdZdd„ZdS )Ú_InternalBuilderRowz=The stored state accumulated while writing out internal rows.Tc                 ó\   — |st          d¦  «        ‚t                               | ¦  «         d S )NzMust pad internal nodes only.)r-   r   r4   )r   r.   s     r   r4   z_InternalBuilderRow.finish_noded   s4   € Øð 	BÝ Ð!@ÑAÔAÐAÝ×Ò Ñ%Ô%Ð%Ð%Ð%r   Nr5   )r6   r7   r8   r9   r4   r:   r   r   r<   r<   a   s.   € € € € € ØGÐGð&ð &ð &ð &ð &ð &r   r<   c                   ó   — e Zd ZdZdS )Ú_LeafBuilderRowz;The stored state accumulated while writing out a leaf rows.N)r6   r7   r8   r9   r:   r   r   r?   r?   j   s   € € € € € ØEÐEÐEÐEr   r?   c                   ó†   — e Zd ZdZdd„Zdd„Zd„ Zd	„ Zd
„ Zd„ Z	d„ Z
d„ Zdd„Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚBTreeBuildera)  A Builder for B+Tree based Graph indices.

    The resulting graph has the structure:

    _SIGNATURE OPTIONS NODES
    _SIGNATURE     := 'B+Tree Graph Index 1' NEWLINE
    OPTIONS        := REF_LISTS KEY_ELEMENTS LENGTH
    REF_LISTS      := 'node_ref_lists=' DIGITS NEWLINE
    KEY_ELEMENTS   := 'key_elements=' DIGITS NEWLINE
    LENGTH         := 'len=' DIGITS NEWLINE
    ROW_LENGTHS    := 'row_lengths' DIGITS (COMMA DIGITS)*
    NODES          := NODE_COMPRESSED*
    NODE_COMPRESSED:= COMPRESSED_BYTES{4096}
    NODE_RAW       := INTERNAL | LEAF
    INTERNAL       := INTERNAL_FLAG POINTERS
    LEAF           := LEAF_FLAG ROWS
    KEY_ELEMENT    := Not-whitespace-utf8
    KEY            := KEY_ELEMENT (NULL KEY_ELEMENT)*
    ROWS           := ROW*
    ROW            := KEY NULL ABSENT? NULL REFERENCES NULL VALUE NEWLINE
    ABSENT         := 'a'
    REFERENCES     := REFERENCE_LIST (TAB REFERENCE_LIST){node_ref_lists - 1}
    REFERENCE_LIST := (REFERENCE (CR REFERENCE)*)?
    REFERENCE      := KEY
    VALUE          := no-newline-no-null-bytes
    r   r   é † c                 ó�   — t           j                             | ||¬¦  «         || _        g | _        i | _        d| _        d| _        dS )z°See GraphIndexBuilder.__init__.

        :param spill_at: Optional parameter controlling the maximum number
            of nodes that BTreeBuilder will hold in memory.
        )Úreference_listsÚkey_elementsNF)r   ÚGraphIndexBuilderr   Ú	_spill_atÚ_backing_indicesÚ_nodesÚ_nodes_by_keyÚ_optimize_for_size)r   rD   rE   Úspill_ats       r   r   zBTreeBuilder.__init__Š   sZ   € õ 	Ô×(Ò(¨¸Ø6Bð 	)ñ 	Dô 	Dð 	Dà!ˆŒØ "ˆÔàˆŒà!ˆÔØ"'ˆÔÐÐr   r:   c                 óÊ  — t           j                             |¦  «                             ¦   «         }|                      |||¦  «        \  }}|| j        v rt          j        || ¦  «        ‚t          j        ||¦  «        | j        |<   | j        �"| j	        dk    r|  
                    |||¦  «         t          | j        ¦  «        | j        k     rdS |                      ¦   «          dS )a9  Add a node to the index.

        If adding the node causes the builder to reach its spill_at threshold,
        disk spilling will be triggered.

        :param key: The key. keys are non-empty tuples containing
            as many whitespace-free utf8 bytestrings as the key length
            defined for this index.
        :param references: An iterable of iterables of keys. Each is a
            reference to another key.
        :param value: The value to associate with the key. It may be any
            bytes as long as it does not contain \0 or \n.
        Nr   )r   ÚStaticTupleÚfrom_sequenceÚinternÚ_check_key_ref_valuerI   r   ÚBadIndexDuplicateKeyrJ   Ú_key_lengthÚ_update_nodes_by_keyÚlenrG   Ú_spill_mem_keys_to_disk)r   ÚkeyÚvalueÚ
referencesÚ	node_refsr0   s         r   Úadd_nodezBTreeBuilder.add_nodeš   sÜ   € õ Ô&×4Ò4°SÑ9Ô9×@Ò@ÑBÔBˆà×0Ò0°°jÀ%ÑHÔH‰ˆ	�1Ø�$”+ÐÐÝÔ,¨S°$Ñ7Ô7Ð7Ý'Ô3°I¸uÑEÔEˆŒ�CÑØÔÐ)¨dÔ.>ÀÒ.BÐ.BØ×%Ò% c¨5°)Ñ<Ô<Ð<ÝˆtŒ{ÑÔ˜dœnÒ,Ð,ØˆFØ×$Ò$Ñ&Ô&Ð&Ð&Ð&r   c                 óØ  — | j         r|                      ¦   «         \  }}}n|                      ¦   «         \  }}t          t	          j        d¦  «        d|¦  «        }||_        | j         rYt          | j        ¦  «        |k    r| j         	                    d¦  «         || j        |<   t          |¦  «        D ]}d| j        |<   Œn| j         	                    |¦  «         i | _        d| _        dS )aö  Write the in memory keys down to disk to cap memory consumption.

        If we already have some keys written to disk, we will combine them so
        as to preserve the sorted order.  The algorithm for combining uses
        powers of two.  So on the first spill, write all mem nodes into a
        single index. On the second spill, combine the mem nodes with the nodes
        on disk to create a 2x sized disk index and get rid of the first index.
        On the third spill, create a single new disk index, which will contain
        the mem nodes, and preserve the existing 2x sized index.  On the fourth,
        combine mem with the first and second indexes, creating a new one of
        size 4x. On the fifth create a single new one, etc.
        ú.z<temp>N)Ú_combine_backing_indicesÚ_spill_mem_keys_and_combineÚ!_spill_mem_keys_without_combiningÚBTreeGraphIndexr   Úget_transport_from_pathÚ_filerU   rH   ÚappendÚrangerI   rJ   )r   Únew_backing_fileÚsizeÚbacking_posÚnew_backings        r   rV   z$BTreeBuilder._spill_mem_keys_to_diskµ   s  € ð Ô(ð 	Nà ×<Ò<Ñ>Ô>ñÐ˜tØˆ[à%)×%KÒ%KÑ%MÔ%MÑ"Ð˜dõ &¥iÔ&GÈÑ&LÔ&LØ&.°ñ6ô 6ˆð -ˆÔØÔ(ð 	6Ý�4Ô(Ñ)Ô)¨[Ò8Ð8ØÔ%×,Ò,¨TÑ2Ô2Ð2Ø1<ˆDÔ! +Ñ.Ý$ [Ñ1Ô1ð :ð :�Ø59�Ô% kÑ2Ð2ð:ð Ô!×(Ò(¨Ñ5Ô5Ð5ØˆŒØ!ˆÔÐÐr   c                 óT   — |                       |                      ¦   «         d¬¦  «        S )NF©Úallow_optimize)Ú_write_nodesÚ_iter_mem_nodesr   s    r   r`   z.BTreeBuilder._spill_mem_keys_without_combiningØ   s'   € Ø× Ò  ×!5Ò!5Ñ!7Ô!7ÈÐ ÑNÔNÐNr   c                 ó2  — |                       ¦   «         g}d}t          | j        ¦  «        D ]5\  }}|€|dz  } n(|                     |                     ¦   «         ¦  «         Œ6|dz   }|                      |                      |¦  «        d¬¦  «        \  }}|||fS )Nr#   r   Frk   )rn   Ú	enumeraterH   rd   Úiter_all_entriesrm   Ú_iter_smallest)r   Úiterators_to_combineÚposÚbackingrh   rf   rg   s          r   r_   z(BTreeBuilder._spill_mem_keys_and_combineÛ   sÀ   € Ø $× 4Ò 4Ñ 6Ô 6Ð7ÐØˆÝ% dÔ&;Ñ<Ô<ð 	Dð 	D‰LˆC�ØˆØ�q‘�Ø�Ø ×'Ò'¨×(@Ò(@Ñ(BÔ(BÑCÔCÐCÐCØ˜A‘gˆà×Ò˜d×1Ò1Ð2FÑGÔGØ-2ð ñ 4ô 4ñ 	Ð˜$ð    {Ð2Ð2r   c                 ó”   — | j         r"|D ]\  }}}|                      |||¦  «         ŒdS |D ]\  }}|                      ||¦  «         ŒdS )znAdd nodes to the index.

        :param nodes: An iterable of (key, node_refs, value) entries to add.
        N)rD   r[   )r   r   rW   rX   rZ   s        r   Ú	add_nodeszBTreeBuilder.add_nodesé   s~   € ð
 Ôð 	*Ø+0ð 5ð 5Ñ'��e˜YØ—’˜c 5¨)Ñ4Ô4Ð4Ð4ð5ð 5ð !&ð *ð *‘��eØ—’˜c 5Ñ)Ô)Ð)Ð)ð*ð *r   c              #   ó¼   K  — | j         }| j        r't          |¦  «        D ]}||         \  }}| |||fV — ŒdS t          |¦  «        D ]}||         \  }}| ||fV — ŒdS )z&Iterate over the nodes held in memory.N)rI   rD   Úsorted)r   r   rW   rY   rX   s        r   rn   zBTreeBuilder._iter_mem_nodesõ   s¢   è è € à”ˆØÔð 	'Ý˜e‘}”}ð 3ð 3�Ø$)¨#¤JÑ!�
˜EØ˜C ¨
Ð2Ð2Ð2Ð2Ð2ð3ð 3õ ˜e‘}”}ð 'ð '�Ø$)¨#¤JÑ!�
˜EØ˜C Ð&Ð&Ð&Ð&Ð&ð'ð 'r   c              #   óx  K  — t          |¦  «        dk    r|d         E d {V —† d S g }|D ]J}	 |                     t          |¦  «        ¦  «         Œ&# t          $ r |                     d ¦  «         Y ŒGw xY wd }	 d„ t	          |¦  «        D ¦   «         }t          |¦  «        sd S t          |¦  «        }|d         }||d         d         k    rt          j        || ¦  «        ‚|d         d         }| f|d         dd …         z   V — |d         }	 t          ||         ¦  «        ||<   n# t          $ r d ||<   Y nw xY wŒÄ)Nr   r   Tc                 ó>   — g | ]}|d          ®
|d          d          |f‘ŒS )r   r:   )Ú.0Úitems     r   ú
<listcomp>z/BTreeBuilder._iter_smallest.<locals>.<listcomp>  s;   € ð Oð Oð O°Ø:>¸q¼'Ð:Mð   œ7 1œ: tÐ,Ø:MÐ:MÐ:Mr   )rU   rd   ÚnextÚStopIterationrp   Úminr   rR   )r   rs   Úcurrent_valuesÚiteratorÚlastÚ
candidatesÚselectedrt   s           r   rr   zBTreeBuilder._iter_smallest  s®  è è € ÝÐ#Ñ$Ô$¨Ò)Ð)Ø+¨AÔ.Ð.Ð.Ð.Ð.Ð.Ð.Ð.ØˆFØˆØ,ð 	,ð 	,ˆHð,Ø×%Ò%¥d¨8¡n¤nÑ5Ô5Ð5Ð5øÝ ð ,ð ,ð ,Ø×%Ò% dÑ+Ô+Ð+Ð+Ð+ð,øøøàˆð	+ðOð OÝ& ~Ñ6Ô6ðOñ Oô OˆJå�z‘?”?ð Ø�Ý˜:‘”ˆHà ”{ˆHØ�x ”{ 1”~Ò%Ð%ÝÔ0°°tÑ<Ô<Ð<Ø˜A”;˜q”>ˆDà�'˜H QœK¨¨¨œOÑ+Ð+Ð+Ð+Ø˜1”+ˆCð+Ý&*Ð+?ÀÔ+DÑ&EÔ&E�˜sÑ#Ð#øÝ ð +ð +ð +Ø&*�˜sÑ#Ð#Ð#ð+øøøð#	+s#   ­"AÁA2Á1A2ÄD& Ä&D8Ä7D8Tc                 ó¼  — d}|d         j         �€)d}t          |dd…         ¦  «        D ]¢\  }}|j         €–t          }|j        dk    r
|t          z  }|r| j        }	nd}	t          j        |d|	¬¦  «        |_         |j                              t          ¦  «         |j                              t          d||dz            j        z  z   ¦  «         Œ£t          }|d         j        dk    r
|t          z  }t          j        || j        ¬¦  «        |d         _         |d         j                              t          ¦  «         |d         j                              |¦  «        �r�|rt          j        |¦  «        ‚|d                              ¦   «          |d	z   }
d}t          |dd…         ¦  «        D ]3}|j                              |
¦  «        r|                     ¦   «          Œ1d} |râd
t           j        v rt%          j        d¦  «         t)          ¦   «         }d}|                     d|¦  «         t          j        t          t          z
  || j        ¬¦  «        |_         |j                              t          ¦  «         |j                              t          d|d         j        dz
  z  z   ¦  «         |j                              |
¦  «         |                      ||||¬¦  «         dS dS )aD  Add a key to the current chunk.

        :param string_key: The key to add.
        :param line: The fully serialised key and value.
        :param allow_optimize: If set to False, prevent setting the optimize
            flag when writing out. This is used by the _spill_mem_keys_to_disk
            functionality.
        Fr#   NTr   )Úoptimize_for_sizes   %d
r   ó   
r   zInserting new global row.rk   )r   rp   r,   r   r&   rK   r   ÚChunkWriterr%   Ú_INTERNAL_FLAGÚ_INTERNAL_OFFSETÚ
_LEAF_FLAGr   ÚBadIndexKeyr4   Úreversedr   Údebug_flagsr   Úmutterr<   ÚinsertÚ_add_key)r   Ú
string_keyÚlineÚrowsrl   Únew_leafrt   Úinternal_rowÚlengthrˆ   Úkey_lineÚnew_rowÚrowÚreserved_bytess                 r   r“   zBTreeBuilder._add_key   s)  € ð ˆØ�Œ8Œ?Ñ"àˆHÝ%.¨t°C°R°C¬yÑ%9Ô%9ð Oð OÑ!��\ð  Ô&Ð.Ý'�FØ#Ô)¨QÒ.Ð.ØÕ"8Ñ8˜Ø%ð 2Ø,0Ô,CÐ)Ð)à,1Ð)Ý*6Ô*BØ Ð5Fð+Hñ +Hô +H�LÔ'à Ô'×-Ò-­nÑ=Ô=Ð=Ø Ô'×-Ò-Õ.>Ø07¸$¸sÀQ¹w¼-Ô:MÑ0Mñ/Nñ Oô Oð Oøõ  ˆFØ�BŒxŒ~ Ò"Ð"ØÕ0Ñ0�Ý*Ô6Ø¨$Ô*AðCñ Cô CˆD�ŒHŒOà�ŒHŒO×!Ò!¥*Ñ-Ô-Ð-Ø�Œ8Œ?× Ò  Ñ&Ô&ñ '	9ð ð 4ÝÔ'¨
Ñ3Ô3Ð3à�ŒH× Ò Ñ"Ô"Ð"Ø! EÑ)ˆHØˆGÝ  S b S¤	Ñ*Ô*ð 	ð 	�ð ”:×#Ò# HÑ-Ô-ð Ø—O’OÑ%Ô%Ð%Ð%ð $�GØð ð /à�eÔ/Ð/Ð/Ý”LÐ!<Ñ=Ô=Ð=Ý-Ñ/Ô/�Ø!"�Ø—’˜A˜wÑ'Ô'Ð'å!-Ô!9ÝÕ!7Ñ7Ø"Ø&*Ô&=ð"?ñ "?ô "?�”ð ”×$Ò$¥^Ñ4Ô4Ð4Ø”×$Ò$Õ%5Ø'.°$°q´'´-À!Ñ2CÑ'Dñ&Eñ Fô Fð Fà”×$Ò$ XÑ.Ô.Ð.Ø�MŠM˜* d¨DØ)7ð ñ 9ô 9ð 9ð 9ð 9ðM'	9ð '	9r   c           	      óè  — g }d}g | _         |D ]d}|dk    r!|                     t          ¦   «         ¦  «         |dz  }t          j        || j        ¦  «        \  }}|                      ||||¬¦  «         Œet          |¦  «        D ].}t          |t          ¦  «         }	| 	                    |	¬¦  «         Œ/t          g}
|
                     dt          | j        fz  ¦  «         |
                     dt          | j        fz  ¦  «         |
                     dt          |fz  ¦  «         d„ |D ¦   «         }|
                     t          d                     t#          t$          |¦  «        ¦  «                             d¦  «        z   d	z   ¦  «         |r(|d
         dk    rt(                               d¬¦  «        }nt-          ¦   «         }|                     |
¦  «         t1          t#          t2          |
¦  «        ¦  «        }|t4          k    rt7          d|t4          fz  ¦  «        ‚|D �]}t4          }|j                             ¦   «          |j                             d¦  «         |j                             t@          ¦  «        }| !                    ||d…         ¦  «         t3          |¦  «        t@          k    r| !                    d||z
  z  ¦  «         d}tE          j#        |j        |¦  «        }||j$        dz
  t@          z  k    r9t          |t          ¦  «        s$t7          d|j$        dz
  t@          z  |fz  ¦  «        ‚�Œ|                     ¦   «          | %                    ¦   «         }|                     d¦  «         ||fS )aÌ  Write node_iterator out as a B+Tree.

        :param node_iterator: An iterator of sorted nodes. Each node should
            match the output given by iter_all_entries.
        :param allow_optimize: If set to False, prevent setting the optimize
            flag when writing out. This is used by the _spill_mem_keys_to_disk
            functionality.
        :return: A file handle for a temporary file containing a B+Tree for
            the nodes.
        r   r   rk   )r.   s   %s%d
c                 ó   — g | ]	}|j         ‘Œ
S r:   )r   )r|   rœ   s     r   r~   z-BTreeBuilder._write_nodes.<locals>.<listcomp>–  s   € Ð1Ð1Ð1 S�s”yÐ1Ð1Ð1r   ú,Úasciir‰   r#   z
bzr-index-r!   z7Could not fit the header in the reserved space: %d > %dNr    z5Incorrect amount of data copied expected: %d, got: %d)&Úrow_lengthsrd   r?   Ú_btree_serializerÚ_flatten_noderD   r“   r�   Ú
isinstancer4   Ú_BTSIGNATUREr   r   rS   r   Ú_OPTION_ROW_LENGTHSÚjoinÚmapÚstrÚencoder'   ÚNamedTemporaryFiler   r*   ÚsumrU   r&   r-   r   ÚflushÚseekÚreadr,   r%   r
   Úpumpfiler   r+   )r   Únode_iteratorrl   r–   Ú	key_countÚnoder”   r•   rœ   r.   Úlinesr¢   ÚresultÚpositionÚreservedÚ
copied_lenrg   s                    r   rm   zBTreeBuilder._write_nodesm  sv  € ð ˆð ˆ	ð ˆÔð
 "ð 	9ð 	9ˆDØ˜AŠ~ˆ~à—’�OÑ-Ô-Ñ.Ô.Ð.Ø˜‰NˆIÝ0Ô>Ø�dÔ*ñ ,ô  ,ÑˆJ˜à�MŠM˜* d¨DØ)7ð ñ 9ô 9ð 9ð 9å˜D‘>”>ð 	%ð 	%ˆCÝ! #¥Ñ7Ô7Ð7ˆCØ�OŠO ˆOÑ$Ô$Ð$Ð$Ý�ˆØ�Š�YÕ"3°TÔ5IÐ!JÑJÑKÔKÐKØ�Š�YÕ"6¸Ô8HÐ!IÑIÑJÔJÐJØ�Š�Y¥+¨yÐ!9Ñ9Ñ:Ô:Ð:Ø1Ð1¨DÐ1Ñ1Ô1ˆØ�ŠÕ(¨3¯8ª8Ý•�[Ñ!Ô!ñ,#ô ,#ß#)¢6¨'¡?¤?ñ3Ø5:ñ;ñ 	<ô 	<ð 	<àð 	˜; rœ?¨QÒ.Ð.Ý×0Ò0¸Ð0ÑEÔEˆFˆFå‘Y”YˆFØ×Ò˜%Ñ Ô Ð Ý•s�3 ‘”Ñ'Ô'ˆØÕ,Ò,Ð,Ý ð "<à$,Õ.DÐ#Eñ"Fñ Gô Gð Gð ð 	9ñ 	9ˆCÝ-ˆHØŒI�OŠOÑÔÐØŒI�NŠN˜1ÑÔÐð ”9—>’>¥*Ñ-Ô-ˆDØ�LŠL˜˜h˜i˜iœÑ)Ô)Ð)Ý�4‰yŒy�JÒ&Ð&Ø—’˜W¨°8Ñ(;Ñ<Ñ=Ô=Ð=ØˆHÝ Ô)¨#¬)°VÑ<Ô<ˆJØ˜cœi¨!™m­zÑ9Ò9Ð9Ý! #¥Ñ7Ô7ð 9Ý(ð *Bà-0¬Y¸©]½jÑ,HØ,6ð,8ñ*8ñ 9ô 9ð 9ùð 	�Š‰ŒˆØ�{Š{‰}Œ}ˆØ�Š�A‰ŒˆØ�tˆ|Ðr   c                 ó\   — |                       |                      ¦   «         ¦  «        d         S )z†Finalise the index.

        :return: A file handle for a temporary file containing the nodes added
            to the index.
        r   )rm   rq   r   s    r   r$   zBTreeBuilder.finish»  s)   € ð × Ò  ×!6Ò!6Ñ!8Ô!8Ñ9Ô9¸!Ô<Ð<r   c                 ó8  — dt           j        v rt          j        dd¦  «         |                      ¦   «         g}| j        D ]+}|�'|                     |                     ¦   «         ¦  «         Œ,t          |¦  «        dk    r|d         S |  	                    |¦  «        S )a  Iterate over all keys within the index

        :return: An iterable of (index, key, value, reference_lists). There is
            no defined order for the result iteration - it will be in the most
            efficient order for the index (in this case dictionary hash order).
        Úevilé   ú-iter_all_entries scales with size of history.Nr   r   )
r   r�   r   Úmutter_callsitern   rH   rd   rq   rU   rr   )r   Ú	iteratorsru   s      r   rq   zBTreeBuilder.iter_all_entriesÃ  s®   € ð •UÔ&Ð&Ð&ÝÔ!ØÐBñDô Dð Dð ×)Ò)Ñ+Ô+Ð,ˆ	ØÔ,ð 	=ð 	=ˆGØÐ"Ø× Ò  ×!9Ò!9Ñ!;Ô!;Ñ<Ô<Ð<øÝˆy‰>Œ>˜QÒÐØ˜Q”<ÐØ×"Ò" 9Ñ-Ô-Ð-r   c              #   óÀ  ‡K  — t          |¦  «        }| j        Šˆfd„|D ¦   «         }| j        r"|D ]}‰|         }| ||d         |d         fV — Œn|D ]}‰|         }| ||d         fV — Œ| j        sdS |                     |¦  «         | j        D ]M}|€Œ|s dS |                     |¦  «        D ]-}|                     |d         ¦  «         | f|dd…         z   V — Œ.ŒNdS )a_  Iterate over keys within the index.

        :param keys: An iterable providing the keys to be retrieved.
        :return: An iterable of (index, key, value, reference_lists). There is
            no defined order for the result iteration - it will be in the most
            efficient order for the index (keys iteration order in this case).
        c                 ó   •— g | ]}|‰v ¯|‘Œ	S r:   r:   )r|   rW   r   s     €r   r~   z-BTreeBuilder.iter_entries.<locals>.<listcomp>è  s   ø€ Ð:Ð:Ð:˜c¨S°E¨\¨\�c¨\¨\¨\r   r   r   N)ÚsetrI   rD   rH   Údifference_updateÚiter_entriesÚremove)r   ÚkeysÚ
local_keysrW   r´   ru   r   s         @r   rÅ   zBTreeBuilder.iter_entries×  sa  øè è € õ �4‰yŒyˆð ”ˆØ:Ð:Ð:Ð: TÐ:Ñ:Ô:ˆ
ØÔð 	)Ø!ð 2ð 2�Ø˜S”z�Ø˜C  a¤¨$¨q¬'Ð1Ð1Ð1Ð1Ð1ð2ð "ð )ð )�Ø˜S”z�Ø˜C  a¤Ð(Ð(Ð(Ð(Ð(ð Ô$ð 	ØˆFà×Ò˜zÑ*Ô*Ð*ØÔ,ð 	)ð 	)ˆGØˆØØð Ø��Ø×,Ò,¨TÑ2Ô2ð )ð )�Ø—’˜D œGÑ$Ô$Ð$Ø�g  Q R R¤Ñ(Ð(Ð(Ð(Ð(ð)ð	)ð 	)r   c              #   óØ  K  — t          |¦  «        }|sdS | j        D ]-}|€Œ|                     |¦  «        D ]}| f|dd…         z   V — ŒŒ.| j        dk    rd|D ]_}t	          j        | |¦  «         	 | j        |         }n# t          $ r Y Œ2w xY w| j        r| ||d         |d         fV — ŒR| ||d         fV — Œ`dS |  	                    ¦   «         }t	          j
        | ||¦  «        E d{V —† dS )al  Iterate over keys within the index using prefix matching.

        Prefix matching is applied within the tuple of a key, not to within
        the bytestring of each key element. e.g. if you have the keys ('foo',
        'bar'), ('foobar', 'gam') and do a prefix search for ('foo', None) then
        only the former key is returned.

        :param keys: An iterable providing the key prefixes to be retrieved.
            Each key prefix takes the form of a tuple the length of a key, but
            with the last N elements 'None' rather than a regular bytestring.
            The first element cannot be 'None'.
        :return: An iterable as per iter_all_entries, but restricted to the
            keys with a matching prefix to those supplied. No additional keys
            will be returned, and every match that is in the index will be
            returned.
        Nr   r   )rÃ   rH   Úiter_entries_prefixrS   r   Ú_sanity_check_keyrI   ÚKeyErrorrD   Ú_get_nodes_by_keyÚ_iter_entries_prefix)r   rÇ   ru   r´   rW   Únodes_by_keys         r   rÊ   z BTreeBuilder.iter_entries_prefix   se  è è € õ" �4‰yŒyˆØð 	ØˆFØÔ,ð 	)ð 	)ˆGØˆØØ×3Ò3°DÑ9Ô9ð )ð )�Ø�g  Q R R¤Ñ(Ð(Ð(Ð(Ð(ð)àÔ˜qÒ Ð Øð 	-ð 	-�ÝÔ'¨¨cÑ2Ô2Ð2ðØœ; sÔ+�D�DøÝð ð ð Ø�HðøøøàÔ'ð -Ø  T¨!¤W¨d°1¬gÐ5Ð5Ð5Ð5Ð5à  T¨!¤WÐ,Ð,Ð,Ð,Ð,ØˆFØ×-Ò-Ñ/Ô/ˆÝÔ-¨d°LÀ$ÑGÔGÐGÐGÐGÐGÐGÐGÐGÐGÐGs   Á0A>Á>
BÂ
Bc                 ó’  — | j         €ºi }| j        rV| j                             ¦   «         D ];\  }\  }}|}|d d…         D ]}|                     |i ¦  «        }Œ|||f||d         <   Œ<nT| j                             ¦   «         D ]:\  }\  }}|}|d d…         D ]}|                     |i ¦  «        }Œ||f||d         <   Œ;|| _         | j         S )Nr#   )rJ   rD   rI   ÚitemsÚ
setdefault)r   rÏ   rW   rY   rX   Úkey_dictÚsubkeys          r   rÍ   zBTreeBuilder._get_nodes_by_key(  s  € ØÔÐ%ØˆLØÔ#ð 3Ø04´×0AÒ0AÑ0CÔ0Cð ?ð ?Ñ,�CÑ,˜* eØ+�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(+¨U°JÐ(>�H˜S œWÑ%Ð%ð	?ð 15´×0AÒ0AÑ0CÔ0Cð 3ð 3Ñ,�CÑ,˜* eØ+�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(+¨U¨
�H˜S œWÑ%Ð%Ø!-ˆDÔØÔ!Ð!r   c                 óh   — t          | j        ¦  «        t          d„ | j        D ¦   «         ¦  «        z   S )zwReturn an estimate of the number of keys in this index.

        For InMemoryGraphIndex the estimate is exact.
        c              3   óB   K  — | ]}|®|                      ¦   «         V — Œd S ©N)r³   )r|   ru   s     r   ú	<genexpr>z)BTreeBuilder.key_count.<locals>.<genexpr>?  s@   è è € ð &$ð &$àØÐ"ð ×ÒÑÔà"Ð"Ð"Ð"ð&$ð &$r   )rU   rI   r­   rH   r   s    r   r³   zBTreeBuilder.key_count:  sF   € õ
 �4”;ÑÔ¥#ð &$ð &$àÔ0ð&$ñ &$ô &$ñ #$ô #$ñ $ð 	$r   c                 ó   — dS )z9In memory index's have no known corruption at the moment.Nr:   r   s    r   ÚvalidatezBTreeBuilder.validateD  s   € € € r   c                 ó˜   — t          |t          | ¦  «        ¦  «        r| j        |j        k     S t          |t          ¦  «        rdS t          ‚)NF)r¥   ÚtyperI   ra   Ú	TypeError©r   Úothers     r   Ú__lt__zBTreeBuilder.__lt__G  sE   € Ý�e�T $™ZœZÑ(Ô(ð 	.Ø”; ¤Ò-Ð-å�e�_Ñ-Ô-ð 	Ø�5Ýˆr   N)r   r   rB   )r:   r5   )r6   r7   r8   r9   r   r[   rV   r`   r_   rw   rn   rr   r“   rm   r$   rq   rÅ   rÊ   rÍ   r³   rÚ   rà   r:   r   r   rA   rA   n   sV  € € € € € ðð ð6(ð (ð (ð (ð 'ð 'ð 'ð 'ð6!"ð !"ð !"ðFOð Oð Oð3ð 3ð 3ð
*ð 
*ð 
*ð
'ð 
'ð 
'ð+ð +ð +ð>K9ð K9ð K9ð K9ðZLð Lð Lð Lð\=ð =ð =ð.ð .ð .ð(')ð ')ð ')ðR&Hð &Hð &HðP"ð "ð "ð$$ð $ð $ðHð Hð Hðð ð ð ð r   rA   c                   ó2   ‡ — e Zd ZdZdZˆ fd„Zd„ Zd„ Zˆ xZS )Ú	_LeafNodez*A leaf node for a serialised B+Tree index.)Úmin_keyÚmax_keyÚ_keysc                 ó  •— t          j        |||¦  «        }|r'|d         d         | _        |d         d         | _        ndx| _        | _        t	          ¦   «                              |¦  «         t          | ¦  «        | _        dS )z)Parse bytes to create a leaf node object.r   r#   N)r£   Ú_parse_leaf_linesrã   rä   Úsuperr   Údictrå   )r   ÚbytesÚ
key_lengthÚref_list_lengthÚkey_listÚ	__class__s        €r   r   z_LeafNode.__init__U  s}   ø€ õ %Ô6Ø�:˜ñ0ô 0ˆàð 	/Ø# Aœ; qœ>ˆDŒLØ# Bœ<¨œ?ˆDŒLˆLà*.Ð.ˆDŒL˜4œ<Ý‰Œ×Ò˜Ñ"Ô"Ð"Ý˜$‘Z”ZˆŒ
ˆ
ˆ
r   c                 óH   — t          |                      ¦   «         ¦  «        }|S )z2Return a sorted list of (key, (value, refs)) items)ry   rÑ   )r   rÑ   s     r   Ú	all_itemsz_LeafNode.all_itemsb  s   € å�t—z’z‘|”|Ñ$Ô$ˆØˆr   c                 óH   — t          |                      ¦   «         ¦  «        }|S )z!Return a sorted list of all keys.)ry   rÇ   )r   rÇ   s     r   Úall_keysz_LeafNode.all_keysg  s   € å�d—i’i‘k”kÑ"Ô"ˆØˆr   )	r6   r7   r8   r9   Ú	__slots__r   rð   rò   Ú__classcell__)rî   s   @r   râ   râ   P  sa   ø€ € € € € Ø4Ð4à/€Ið ð  ð  ð  ð  ðð ð ð
ð ð ð ð ð ð r   râ   c                   ó"   — e Zd ZdZdZd„ Zd„ ZdS )Ú_InternalNodez/An internal node for a serialised B+Tree index.)rÇ   Úoffsetc                 ó`   — |                       |                     d¦  «        ¦  «        | _        dS )z.Parse bytes to create an internal node object.r‰   N)Ú_parse_linesÚsplitrÇ   )r   rê   s     r   r   z_InternalNode.__init__r  s)   € ð ×%Ò% e§k¢k°%Ñ&8Ô&8Ñ9Ô9ˆŒ	ˆ	ˆ	r   c                 ó   — g }t          |d         dd …         ¦  «        | _        t          j        j        }|dd …         D ]M}|dk    r nD|                      ||                     d¦  «        ¦  «                             ¦   «         ¦  «         ŒN|S )Nr   é   r   r   r    )Úintr÷   r   rN   rO   rd   rú   rP   )r   rµ   r   Úas_str•   s        r   rù   z_InternalNode._parse_linesw  s�   € ØˆÝ˜% œ( 1 2 2œ,Ñ'Ô'ˆŒÝÔ(Ô6ˆØ˜!˜"˜"”Ið 	<ð 	<ˆDØ�sŠ{ˆ{Ø�ð �LŠL˜˜˜tŸzšz¨%Ñ0Ô0Ñ1Ô1×8Ò8Ñ:Ô:Ñ;Ô;Ð;Ð;Øˆr   N)r6   r7   r8   r9   ró   r   rù   r:   r   r   rö   rö   m  s=   € € € € € Ø9Ð9à"€Ið:ð :ð :ð

ð 
ð 
ð 
ð 
r   rö   c                   óâ   — e Zd ZdZ	 	 d$d„Zd„ Zd„ Zd„ Zd„ Zd	„ Z	d
„ Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zed„ ¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d „ Z!d!„ Z"d"„ Z#d#S )%ra   zÅAccess to nodes via the standard GraphIndex interface for B+Tree's.

    Individual nodes are held in a LRU cache. This holds the root node in
    memory except when very large walks are done.
    Fr   c                 ól  — || _         || _        || _        d| _        |                      ¦   «         | _        d| _        || _        t          | _	        d| _
        |ri | _        i | _        n7t          j        t          ¦  «        | _        t!          j        d¦  «        | _        d| _        d| _        d| _        dS )a^  Create a B+Tree index object on the index name.

        :param transport: The transport to read data for the index from.
        :param name: The file name of the index on transport.
        :param size: Optional size of the index in bytes. This allows
            compatibility with the GraphIndex API, as well as ensuring that
            the initial read (to read the root node header) can be done
            without over-reading even on empty indices, and on small indices
            allows single-IO to read the entire index.
        :param unlimited_cache: If set to True, then instead of using an
            LRUCache with size _NODE_CACHE_SIZE, we will use a dict and always
            cache all leaf nodes.
        :param offset: The start of the btree index data isn't byte 0 of the
            file. Instead it starts at some point later.
        Néd   )Ú
_transportÚ_nameÚ_sizerc   Ú_compute_recommended_pagesÚ_recommended_pagesÚ
_root_nodeÚ_base_offsetrâ   Ú_leaf_factoryÚ_leaf_value_cacheÚ_leaf_node_cacheÚ_internal_node_cacher	   ÚLRUCacheÚ_NODE_CACHE_SIZEr   Ú	FIFOCacheÚ
_key_countÚ_row_lengthsÚ_row_offsets)r   r   Únamerg   Úunlimited_cacher÷   s         r   r   zBTreeGraphIndex.__init__‹  sµ   € ð" $ˆŒØˆŒ
ØˆŒ
ØˆŒ
Ø"&×"AÒ"AÑ"CÔ"CˆÔØˆŒØ"ˆÔÝ&ˆÔà!%ˆÔØð 	BØ$&ˆDÔ!Ø(*ˆDÔ%Ð%å$-Ô$6Õ7GÑ$HÔ$HˆDÔ!õ )3Ô(<¸SÑ(AÔ(AˆDÔ%ØˆŒØ ˆÔØ ˆÔÐÐr   c                 ó    — t          | ¦  «        S r×   )Úidr   s    r   Ú__hash__zBTreeGraphIndex.__hash__³  s   € Ý�$‰xŒxˆr   c                 óœ   — t          | t          |¦  «        ¦  «        o/| j        |j        k    o| j        |j        k    o| j        |j        k    S )z@Equal when self and other were created with the same parameters.)r¥   rÜ   r  r  r  rÞ   s     r   Ú__eq__zBTreeGraphIndex.__eq__¶  sR   € õ �t�T %™[œ[Ñ)Ô)ð *Ø” 5Ô#3Ò3ð*à”
˜eœkÒ)ð*ð ”
˜eœkÒ)ð		+r   c                 ó´   — t          |t          | ¦  «        ¦  «        r| j        | j        f|j        |j        fk     S t          |t          ¦  «        rdS t
          ‚)NT)r¥   rÜ   r  r  rA   rÝ   rÞ   s     r   rà   zBTreeGraphIndex.__lt__¾  sT   € Ý�e�T $™ZœZÑ(Ô(ð 	KØ”Z ¤Ð,°´¸U¼[Ð/IÒIÐJå�e�\Ñ*Ô*ð 	Ø�4Ýˆr   c                 ó.   — |                       |¦  «         S r×   )r  rÞ   s     r   Ú__ne__zBTreeGraphIndex.__ne__Æ  s   € Ø—;’;˜uÑ%Ô%Ð%Ð%r   c                 óØ   — i }d}|                       t          |¦  «        ¦  «        D ]B\  }}|dk    r|| _        n*|€| j        d         }||k     r|| j        |<   n
|| j        |<   |||<   ŒC|S )aÍ  Read nodes and cache them in the lru.

        The nodes list supplied is sorted and then read from disk, each node
        being inserted it into the _node_cache.

        Note: Asking for more nodes than the _node_cache can contain will
        result in some of the results being immediately discarded, to prevent
        this an assertion is raised if more nodes are asked for than are
        cachable.

        :return: A dict of {node_pos: node}
        Nr   éþÿÿÿ)Ú_read_nodesry   r  r  r  r  )r   r   ÚfoundÚstart_of_leavesÚnode_posr´   s         r   Ú_get_and_cache_nodesz$BTreeGraphIndex._get_and_cache_nodesÉ  s’   € ð ˆØˆØ"×.Ò.­v°e©}¬}Ñ=Ô=ð 
	#ð 
	#‰NˆH�dØ˜1Š}ˆ}Ø"&�”�à"Ð*Ø&*Ô&7¸Ô&;�OØ˜oÒ-Ð-Ø:>�DÔ-¨hÑ7Ð7à6:�DÔ)¨(Ñ3Ø"ˆE�(‰OˆOØˆr   c                 ó–   — | j                              ¦   «         }t          t                               |t
          z  ¦  «        ¦  «        }|S )z¶Convert transport's recommended_page_size into btree pages.

        recommended_page_size is in bytes, we want to know how many _PAGE_SIZE
        pages fit in that length.
        )r  Úrecommended_page_sizerý   ÚmathÚceilr,   )r   Úrecommended_readÚrecommended_pagess      r   r  z*BTreeGraphIndex._compute_recommended_pageså  s>   € ð  œ?×@Ò@ÑBÔBÐÝ¥§	¢	Ð*:½ZÑ*GÑ HÔ HÑIÔIÐØ Ð r   c                 óÂ   — | j         €t          d¦  «        ‚| j        �| j        d         S t	          t
                               | j         t          z  ¦  «        ¦  «        }|S )z¹How many pages are in the index.

        If we have read the header we will use the value stored there.
        Otherwise it will be computed based on the length of the index.
        NzJ_compute_total_pages_in_index should not be called when self._size is Noner#   )r  r-   r  r  rý   r&  r'  r,   )r   Útotal_pagess     r   Ú_compute_total_pages_in_indexz-BTreeGraphIndex._compute_total_pages_in_indexï  se   € ð Œ:ÐÝ ð "Cñ Dô Dð DàŒ?Ð&àÔ$ RÔ(Ð(õ �$Ÿ)š) D¤JµÑ$;Ñ<Ô<Ñ=Ô=ˆØÐr   c                 óö  ‡— dt           j        v rt          j        d| j        |¦  «         t          |¦  «        | j        k    r8dt           j        v r(t          j        dt          |¦  «        | j        ¦  «         |S | j        €$dt           j        v rt          j        d¦  «         |S |                      ¦   «         }|  	                    ¦   «         Š|t          ‰¦  «        z
  | j        k    r_‰rˆfd„t          |¦  «        D ¦   «         }nt          t          |¦  «        ¦  «        }dt           j        v rt          j        d|¦  «         |S | j        €|}nut          | j        ¦  «        }t          ‰¦  «        |k     r7t          |¦  «        dk    r$dt           j        v rt          j        d	¦  «         |S |                      |‰|¦  «        }t          |¦  «        }dt           j        v rt          j        d
|¦  «         |S )aï  Find extra pages to download.

        The idea is that we always want to make big-enough requests (like 64kB
        for http), so that we don't waste round trips. So given the entries
        that we already have cached and the new pages being downloaded figure
        out what other pages we might want to read.

        See also doc/developers/btree_index_prefetch.txt for more details.

        :param offsets: The offsets to be read
        :return: A list of offsets to download
        r   zexpanding: %s	offsets: %sz(  not expanding large request (%s >= %s)Nz*  not expanding without knowing index sizec                 ó   •— g | ]}|‰v¯|‘Œ	S r:   r:   )r|   ÚxÚcached_offsetss     €r   r~   z3BTreeGraphIndex._expand_offsets.<locals>.<listcomp>"  s-   ø€ ð 8ð 8ð 8 !Ø ¨Ð6Ð6ð Ø6Ð6Ð6r   z  reading all unread pages: %sr   z  not expanding on first readszexpanded:  %s)r   r�   r   r‘   r  rU   r  r  r,  Ú_get_offsets_to_cached_pagesre   Úlistr  r  Ú_expand_to_neighborsry   )r   Úoffsetsr+  ÚexpandedÚfinal_offsetsÚ
tree_depthr0  s         @r   Ú_expand_offsetszBTreeGraphIndex._expand_offsets   s  ø€ ð •eÔ'Ð'Ð'ÝŒLÐ5°t´zÀ7ÑKÔKÐKåˆw‰<Œ<˜4Ô2Ò2Ð2à�%Ô+Ð+Ð+Ý”ÐGÝ  ™\œ\¨4Ô+BñDô Dð DàˆNØŒ:Ðà�%Ô+Ð+Ð+Ý”ÐIÑJÔJÐJØˆNØ×8Ò8Ñ:Ô:ˆØ×:Ò:Ñ<Ô<ˆð �˜^Ñ,Ô,Ñ,°Ô0GÒGÐGàð 4ð8ð 8ð 8ð 8¥u¨[Ñ'9Ô'9ð 8ñ 8ô 8��õ  ¥ kÑ 2Ô 2Ñ3Ô3�Ø�%Ô+Ð+Ð+Ý”Ð=¸xÑHÔHÐHØˆOàŒ?Ð"ð $ˆMˆMå˜TÔ.Ñ/Ô/ˆJÝ�>Ñ"Ô" ZÒ/Ð/µC¸±L´LÀAÒ4EÐ4Eð �eÔ/Ð/Ð/Ý”LÐ!AÑBÔBÐBØ�Ø ×5Ò5°g¸~Ø6AñCô CˆMõ ˜}Ñ-Ô-ˆØ•eÔ'Ð'Ð'ÝŒL˜¨-Ñ8Ô8Ð8ØÐr   c                 óò  — t          |¦  «        }dx}}t          |¦  «        }t          |¦  «        | j        k     r¼|rºt          ¦   «         }|D ]x}	|€|                      |	¦  «        \  }}|	dz
  }
|
dk    r#|
|vr|
|vr|
|k    r|                     |
¦  «         |	dz   }||k     r#||vr||vr||k     r|                     |¦  «         Œy|                     |¦  «         |}t          |¦  «        | j        k     r|°º|S )aM  Expand requests to neighbors until we have enough pages.

        This is called from _expand_offsets after policy has determined that we
        want to expand.
        We only want to expand requests within a given layer. We cheat a little
        bit and assume all requests will be in the same layer. This is true
        given the current design, but if it changes this algorithm may perform
        oddly.

        :param offsets: requested offsets
        :param cached_offsets: offsets for pages we currently have cached
        :return: A set() of offsets after expansion
        Nr   r   )rÃ   rU   r  Ú_find_layer_first_and_endÚaddÚupdate)r   r4  r0  r+  r6  ÚfirstÚendÚnew_tipsÚ	next_tipsrt   ÚpreviousÚafters               r   r3  z$BTreeGraphIndex._expand_to_neighborsE  s@  € õ ˜G™œˆØÐˆ�Ý�}Ñ%Ô%ˆÝ�-Ñ Ô  4Ô#:Ò:Ð:¸xÐ:Ý™œˆIØð )ð )�Ø�=Ø!%×!?Ò!?ÀÑ!DÔ!D‘J�E˜3Ø ™7�Ø˜q’L�LØ NÐ2Ð2Ø MÐ1Ð1Ø  EÒ)Ð)Ø—M’M (Ñ+Ô+Ð+Ø˜a™�Ø˜KÒ'Ð'Ø Ð/Ð/Ø Ð.Ð.Ø š˜Ø—M’M %Ñ(Ô(Ð(øð × Ò  Ñ+Ô+Ð+Ø ˆHõ1 �-Ñ Ô  4Ô#:Ò:Ð:¸xÐ:ð2 Ðr   c                 ó8   — | j                              ¦   «          dS )zåClear out any cached/memoized values.

        This can be called at any time, but generally it is used when we have
        extracted some information, but don't expect to be requesting any more
        from this index.
        N)r  Úclearr   s    r   Úclear_cachezBTreeGraphIndex.clear_cacheq  s   € ð 	Ô×#Ò#Ñ%Ô%Ð%Ð%Ð%r   c                 ón  — | j         €|                      ¦   «          |dz   | j        k    rt          d|| j        fz  ¦  «        ‚t	          ¦   «         }t	          ¦   «         }|                      ¦   «         D ]>}|                     |d         ¦  «         |                     |d         |         ¦  «         Œ?||z
  S )Nr   ú&No ref list %d, index has %d ref listsr½   )r  Ú_get_root_nodeÚnode_ref_listsÚ
ValueErrorrÃ   rq   r;  r<  )r   Úref_list_numrÇ   Úrefsr´   s        r   Úexternal_referencesz#BTreeGraphIndex.external_references~  sÃ   € ØŒ?Ð"Ø×ÒÑ!Ô!Ð!Ø˜!Ñ˜dÔ1Ò1Ð1ÝÐEØ ,¨dÔ.AÐBñCñ Dô Dð Då‰uŒuˆÝ‰uŒuˆØ×)Ò)Ñ+Ô+ð 	/ð 	/ˆDØ�HŠH�T˜!”WÑÔÐØ�KŠK˜˜Qœ Ô-Ñ.Ô.Ð.Ð.Ø�d‰{Ðr   c                 ó>   — dx}}| j         D ]}|}|}||k     r nŒ||fS )zÎFind the start/stop nodes for the layer corresponding to offset.

        :return: (first, end)
            first is the first node in this layer
            end is the first node of the next layer
        r   )r  )r   r÷   r=  r>  Úroffsets        r   r:  z)BTreeGraphIndex._find_layer_first_and_end‹  sH   € ð ˆˆ�ØÔ(ð 	ð 	ˆGØˆEØˆCØ˜ÒÐØ�ð  à�cˆzÐr   c                 ó¾   — t          | j        ¦  «        }|                     | j                             ¦   «         ¦  «         | j        �|                     d¦  «         |S )z,Determine what nodes we already have cached.Nr   )rÃ   r  r<  r  rÇ   r  r;  )r   r0  s     r   r1  z,BTreeGraphIndex._get_offsets_to_cached_pagesš  sW   € å˜TÔ6Ñ7Ô7ˆà×Ò˜dÔ3×8Ò8Ñ:Ô:Ñ;Ô;Ð;ØŒ?Ð&Ø×Ò˜qÑ!Ô!Ð!ØÐr   c                 óJ   — | j         €|                      dg¦  «         | j         S ©Nr   )r  Ú_get_internal_nodesr   s    r   rH  zBTreeGraphIndex._get_root_node£  s(   € ØŒ?Ð"à×$Ò$ a SÑ)Ô)Ð)ØŒÐr   c                 ó,  — i }g }|D ]K}|dk    r| j         �| j         |d<   Œ	 ||         ||<   Œ'# t          $ r |                     |¦  «         Y ŒHw xY w|s|S |                      |¦  «        }|                     |                      |¦  «        ¦  «         |S rR  )r  rÌ   rd   r8  r<  r#  )r   ÚcacheÚnode_indexesr   ÚneededÚidxs         r   Ú
_get_nodeszBTreeGraphIndex._get_nodes©  sÅ   € ØˆØˆØð 	#ð 	#ˆCØ�aŠxˆx˜DœOÐ7Øœ?��a‘Øð#Ø" 3œZ��c‘
�
øÝð #ð #ð #Ø—’˜cÑ"Ô"Ð"Ð"Ð"ð#øøøàð 	ØˆLØ×%Ò% fÑ-Ô-ˆØ�Š�T×.Ò.¨vÑ6Ô6Ñ7Ô7Ð7Øˆs   ¢.®AÁAc                 ó8   — |                       | j        |¦  «        S )z\Get a node, from cache or disk.

        After getting it, the node will be cached.
        )rY  r  )r   rV  s     r   rS  z#BTreeGraphIndex._get_internal_nodesº  s   € ð
 �Š˜tÔ8¸,ÑGÔGÐGr   c                 ó¤   — | j         �F|                     ¦   «         D ]3}|                     ¦   «         D ]\  }}|| j         v r n|| j         |<   ŒŒ2dS dS )z5Cache directly from key => value, skipping the btree.N)r
  Úvaluesrð   )r   r   r´   rW   rX   s        r   Ú_cache_leaf_valuesz"BTreeGraphIndex._cache_leaf_valuesÁ  sw   € àÔ!Ð-ØŸš™œð 8ð 8�Ø"&§.¢.Ñ"2Ô"2ð 8ð 8‘J�C˜Ø˜dÔ4Ð4Ð4ð ˜Ø27�DÔ*¨3Ñ/Ð/øð .Ð-ð8ð 8r   c                 óf   — |                       | j        |¦  «        }|                      |¦  «         |S )z)Get a bunch of nodes, from cache or disk.)rY  r  r]  )r   rV  r   s      r   Ú_get_leaf_nodeszBTreeGraphIndex._get_leaf_nodesÌ  s1   € à—’ Ô 5°|ÑDÔDˆØ×Ò Ñ&Ô&Ð&Øˆr   c              #   óØ  K  — dt           j        v rt          j        dd¦  «         |                      ¦   «         sdS | j        d         dk    r]| j        r+| j                             ¦   «         D ]\  }\  }}| |||fV — Œn)| j                             ¦   «         D ]\  }\  }}| ||fV — ŒdS | j        d         }| j        d         }t          t          ||¦  «        ¦  «        }|dgk    rd| j        fg}n|                      |¦  «        }| j        r/|D ]*\  }}	|	                     ¦   «         D ]\  }\  }}| |||fV — ŒŒ+dS |D ])\  }}	|	                     ¦   «         D ]\  }\  }}| ||fV — ŒŒ*dS )	a»  Iterate over all keys within the index.

        :return: An iterable of (index, key, value) or
            (index, key, value, reference_lists).
            The former tuple is used when there are no reference lists in the
            index, making the API compatible with simple key:value index types.
            There is no defined order for the result iteration - it will be in
            the most efficient order for the index.
        r¼   r½   r¾   Nr#   r   r  r   )r   r�   r   r¿   r³   r  rI  r  rð   r2  re   r  )
r   rW   rX   rL  r!  Úend_of_leavesÚneeded_offsetsr   r0   r´   s
             r   rq   z BTreeGraphIndex.iter_all_entriesÒ  s  è è € ð •UÔ&Ð&Ð&ÝÔ!ØÐBñDô Dð Dà�~Š~ÑÔð 	ØˆFØÔ˜RÔ  AÒ%Ð%àÔ"ð -Ø*.¬/×*CÒ*CÑ*EÔ*Eð 3ð 3Ñ&�C™˜% Ø  e¨TÐ2Ð2Ð2Ð2Ð2ð3ð +/¬/×*CÒ*CÑ*EÔ*Eð -ð -Ñ&�C™˜% Ø  eÐ,Ð,Ð,Ð,Ð,ØˆFØÔ+¨BÔ/ˆØÔ)¨"Ô-ˆÝ�e O°]ÑCÔCÑDÔDˆØ˜a˜SÒ Ð ð ˜œÐ)Ð*ˆEˆEà×$Ò$ ^Ñ4Ô4ˆEð Ôð 	-Ø ð 3ð 3‘��4Ø*.¯.ª.Ñ*:Ô*:ð 3ð 3Ñ&�C™˜% Ø  e¨TÐ2Ð2Ð2Ð2Ð2ð3ð3ð 3ð !ð -ð -‘��4Ø*.¯.ª.Ñ*:Ô*:ð -ð -Ñ&�C™˜% Ø  eÐ,Ð,Ð,Ð,Ð,ð-ð-ð -r   c                 ó:  — | sg S |sd| fgS t          | ¦  «        dk    r$t                               || d         ¦  «        | fgS t          | ¦  «        }t	          |¦  «        }t          |¦  «        }t          |¦  «        \  }} G d„ dt          ¦  «        } G d„ dt          ¦  «        }g }	g }
	 	 ||k     rbg }||f}
|	                     |
¦  «         ||k     rA|                     |¦  «         	 t          |¦  «        }n# t          $ r}||‚d}~ww xY w||k     °A||k    r/	 t          |¦  «        \  }}n# t          $ r}||‚d}~ww xY w||k    °/Œž# |$ r Y nH|$ rA |g}| 	                    |¦  «         t          |¦  «        |f}
|	                     |
¦  «         Y nw xY w|	S )	ao  Find the positions where each 'in_key' would fit in fixed_keys.

        This is equivalent to doing "bisect_right" on each in_key into
        fixed_keys

        :param in_keys: A sorted list of keys to match with fixed_keys
        :param fixed_keys: A sorted list of keys to match against
        :return: A list of (integer position, [key list]) tuples.
        r   r   c                   ó   — e Zd ZdS )ú6BTreeGraphIndex._multi_bisect_right.<locals>.InputDoneN©r6   r7   r8   r:   r   r   Ú	InputDonere  %  ó   € € € € € ØˆDr   rg  c                   ó   — e Zd ZdS )ú6BTreeGraphIndex._multi_bisect_right.<locals>.FixedDoneNrf  r:   r   r   Ú	FixedDonerj  (  rh  r   rk  TN)
rU   ÚbisectÚbisect_rightÚiterrp   r   Ú	Exceptionrd   r€   Úextend)Úin_keysÚ
fixed_keysÚin_keys_iterÚfixed_keys_iterÚ
cur_in_keyÚcur_fixed_offsetÚcur_fixed_keyrg  rk  ÚoutputÚcur_outÚcur_keysÚexcs                r   Ú_multi_bisect_rightz#BTreeGraphIndex._multi_bisect_rightþ  so  € ð ð 	ØˆIØð 	"ð ˜�L�>Ð!õ ˆw‰<Œ<˜1ÒÐÝ×(Ò(¨°W¸Q´ZÑ@Ô@À'ÐJÐKÐKõ ˜G‘}”}ˆÝ# JÑ/Ô/ˆÝ˜,Ñ'Ô'ˆ
Ý*.¨Ñ*?Ô*?Ñ'Ð˜-ð	ð 	ð 	ð 	ð 	�	ñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	�	ñ 	ô 	ð 	ð ˆØˆð	#ð1Ø Ò-Ð-Ø!�HØ/°Ð:�GØ—M’M 'Ñ*Ô*Ð*Ø$ }Ò4Ð4Ø Ÿš¨
Ñ3Ô3Ð3ð5Ý)-¨lÑ);Ô);˜J˜JøÝ,ð 5ð 5ð 5Ø"+°Ð4øøøøð5øøøð	 % }Ò4Ð4ð ! MÒ1Ð1ð1Ý:>¸Ñ:OÔ:OÑ7Ð(¨-¨-øÝ(ð 1ð 1ð 1Ø'¨SÐ0øøøøð1øøøð ! MÒ1Ð1ð1øð& ð 	ð 	ð 	àˆDØð 	#ð 	#ð 	#ð #�|ˆHØ�OŠO˜LÑ)Ô)Ð)Ý˜:‘”¨Ð1ˆGØ�MŠM˜'Ñ"Ô"Ð"Ð"Ð"ð	#øøøð ˆsa   Â-=E Ã+C; Ã:E Ã;
DÄDÄDÄE ÄD0 Ä/E Ä0
EÄ:D=Ä=EÅ
E ÅFÅAFÆFc                 ó¬  ‡— dt          |¦  «        fg}t          | j        dd…         ¦  «        D ]€\  }}d„ |D ¦   «         }|                      |¦  «        }g }|D ]S\  }}	||         }
|                      |	|
j        ¦  «        }||
j        z   Š|                     ˆfd„|D ¦   «         ¦  «         ŒT|}Œ�d„ |D ¦   «         }|                      |¦  «        }||fS )a6  Take the given set of keys, and find the corresponding LeafNodes.

        :param keys: An unsorted iterable of keys to search for
        :return: (nodes, index_and_keys)
            nodes is a dict mapping {index: LeafNode}
            keys_at_index is a list of tuples of [(index, [keys for Leaf])]
        r   r   r#   c                 ó   — g | ]\  }}|‘ŒS r:   r:   ©r|   rX  Ús_keyss      r   r~   z@BTreeGraphIndex._walk_through_internal_nodes.<locals>.<listcomp>a  s   € ÐAÐAÐA¡K C¨˜CÐAÐAÐAr   c                 ó$   •— g | ]\  }}‰|z   |f‘ŒS r:   r:   )r|   rt   r€  Únode_offsets      €r   r~   z@BTreeGraphIndex._walk_through_internal_nodes.<locals>.<listcomp>i  s=   ø€ ð ,Jð ,Jð ,JÙ0;°°Vð .9¸3Ñ->ÀÐ,Gð ,Jð ,Jð ,Jr   c                 ó   — g | ]\  }}|‘ŒS r:   r:   r  s      r   r~   z@BTreeGraphIndex._walk_through_internal_nodes.<locals>.<listcomp>m  s   € Ð=Ð=Ð=¡  V˜Ð=Ð=Ð=r   )	ry   rp   r  rS  r|  rÇ   r÷   rp  r_  )r   rÇ   Úkeys_at_indexÚrow_posÚnext_row_startrV  r   Únext_nodes_and_keysÚ
node_indexÚsub_keysr´   Ú	positionsr‚  s               @r   Ú_walk_through_internal_nodesz,BTreeGraphIndex._walk_through_internal_nodesS  s7  ø€ ð �V D™\œ\Ð*Ð+ˆå'0°Ô1BÀ1ÀRÀ4Ô1HÑ'IÔ'Ið 	0ð 	0Ñ#ˆG�^ØAÐA°=ÐAÑAÔAˆLØ×,Ò,¨\Ñ:Ô:ˆEà"$ÐØ(5ð Kð KÑ$�
˜HØ˜ZÔ(�Ø ×4Ò4°X¸t¼yÑIÔI�	Ø,¨t¬{Ñ:�Ø#×*Ò*ð ,Jð ,Jð ,Jð ,JØ?Hð,Jñ ,Jô ,Jñ Kô Kð Kð Kà/ˆMˆMà=Ð=¨}Ð=Ñ=Ô=ˆð ×$Ò$ \Ñ2Ô2ˆØ�mÐ#Ð#r   c              #   óÔ  K  — t          |¦  «        }|sdS |                      ¦   «         sdS g }| j        €|}nT|D ]Q}| j                             |d¦  «        }|�|\  }}| j        r	| |||fV — Œ4| ||fV — Œ<|                     |¦  «         ŒR|}|sdS |                      |¦  «        \  }}|D ];\  }}	|	sŒ||         }
|	D ](}||
v r"|
|         \  }}| j        r	| |||fV — Œ!| ||fV — Œ)Œ<dS )aH  Iterate over keys within the index.

        :param keys: An iterable providing the keys to be retrieved.
        :return: An iterable as per iter_all_entries, but restricted to the
            keys supplied. No additional keys will be returned, and every
            key supplied that is in the index will be returned.
        N)Ú	frozensetr³   r
  ÚgetrI  rd   r‹  )r   rÇ   Úneeded_keysrW   rX   rL  r   Únodes_and_keysrˆ  r‰  r´   Únext_sub_keys               r   rÅ   zBTreeGraphIndex.iter_entriest  s“  è è € õ  ˜‰ŒˆØð 	ØˆFà�~Š~ÑÔð 	ØˆFàˆØÔ!Ð)ØˆKˆKàð 
,ð 
,�ØÔ.×2Ò2°3¸Ñ=Ô=�ØÐ$à"'‘K�E˜4ØÔ*ð 1Ø# S¨%°Ð6Ð6Ð6Ð6Ð6à# S¨%Ð0Ð0Ð0Ð0Ð0à×&Ò& sÑ+Ô+Ð+Ð+àˆØð 	ØˆFØ $× AÒ AÀ+Ñ NÔ NÑˆˆ~Ø$2ð 
	:ð 
	:Ñ ˆJ˜Øð ØØ˜Ô$ˆDØ (ð :ð :�Ø 4Ð'Ð'Ø"& |Ô"4‘K�E˜4ØÔ*ð :Ø# \°5¸$Ð?Ð?Ð?Ð?Ð?à# \°5Ð9Ð9Ð9Ð9øð:ð	
	:ð 
	:r   c                 óÊ  — |                       ¦   «         s#|                     |¦  «         t          ¦   «         S || j        k    rt	          d|| j        fz  ¦  «        ‚|                      |¦  «        \  }}t          ¦   «         }|D �]5\  }}	|	sŒ	||         }
t          ¦   «         }|	D ]I}||
vr|                     |¦  «         Œ|
|         \  }}||         }|||<   |                     |¦  «         ŒJ|                     |¦  «        }|r³t          ¦   «         }|D ]‹}||
v r.|
|         \  }}||         }|||<   |                     |¦  «         Œ4||
j        k     r|                     |¦  «         ŒU||
j	        k    r|                     |¦  «         Œv|                     |¦  «         ŒŒ|                     |¦  «        }|°³�Œ7|                     |¦  «                             |¦  «        }|S )a8  Find the parent_map information for the set of keys.

        This populates the parent_map dict and missing_keys set based on the
        queried keys. It also can fill out an arbitrary number of parents that
        it finds while searching for the supplied keys.

        It is unlikely that you want to call this directly. See
        "CombinedGraphIndex.find_ancestry()" for a more appropriate API.

        :param keys: A keys whose ancestry we want to return
            Every key will either end up in 'parent_map' or 'missing_keys'.
        :param ref_list_num: This index in the ref_lists is the parents we
            care about.
        :param parent_map: {key: parent_keys} for keys that are present in this
            index. This may contain more entries than were in 'keys', that are
            reachable ancestors of the keys requested.
        :param missing_keys: keys which are known to be missing in this index.
            This may include parents that were not directly requested, but we
            were able to determine that they are not present in this index.
        :return: search_keys    parents that were found but not queried to know
            if they are missing or present. Callers can re-query this index for
            those keys, and they will be placed into parent_map or missing_keys
        rG  )
r³   r<  rÃ   rI  rJ  r‹  r;  Ú
differencerã   rä   )r   rÇ   rK  Ú
parent_mapÚmissing_keysr   r�  Úparents_not_on_pagerˆ  r‰  r´   Úparents_to_checkr‘  rX   rL  Úparent_keysÚnext_parents_to_checkrW   Úsearch_keyss                      r   Ú_find_ancestorszBTreeGraphIndex._find_ancestors«  sd  € ð0 �~Š~ÑÔð 	ð ×Ò Ñ%Ô%Ð%Ý‘5”5ˆLØ˜4Ô.Ò.Ð.ÝÐEØ ,¨dÔ.AÐBñCñ Dô Dð Dð !%× AÒ AÀ$Ñ GÔ GÑˆˆ~õ, "™eœeÐà$2ð 8	Pñ 8	PÑ ˆJ˜Øð Øð ˜Ô$ˆDÝ"™uœuÐØ (ð 9ð 9�Ø tÐ+Ð+à ×$Ò$ \Ñ2Ô2Ð2Ð2à"& |Ô"4‘K�E˜4Ø"& |Ô"4�KØ/:�J˜|Ñ,Ø$×+Ò+¨KÑ8Ô8Ð8Ð8à/×:Ò:¸:ÑFÔFÐð
 #ð "PÝ(+©¬Ð%Ø+ð 2ð 2�CØ˜d�{�{Ø&*¨3¤i™˜˜tØ&*¨<Ô&8˜Ø*5˜
 3™Ø-×4Ò4°[ÑAÔAÐAÐAð  ¤Ò-Ð-ð 0×3Ò3°CÑ8Ô8Ð8Ð8Ø  4¤<Ò/Ð/ð 0×3Ò3°CÑ8Ô8Ð8Ð8ð )×,Ò,¨SÑ1Ô1Ð1Ð1Ø#8×#CÒ#CÀJÑ#OÔ#OÐ ðE #ð "PùðN *×4Ò4Øñô ß"š
 <Ñ0Ô0ð 	àÐr   c              #   óŠ  K  — t          t          |¦  «        ¦  «        }|sdS | j        €|                      ¦   «          i }| j        rƒ| j        dk    r$|                      ¦   «         D ]\  }}}}||f||<   ŒnÑi }|                      ¦   «         D ]<\  }}}}|||f}|}	|dd…         D ]}
|	                     |
i ¦  «        }	Œ||	|d         <   Œ=n}| j        dk    r!|                      ¦   «         D ]\  }}}|||<   ŒnQi }|                      ¦   «         D ]:\  }}}||f}|}	|dd…         D ]}
|	                     |
i ¦  «        }	Œ||	|d         <   Œ;| j        dk    rU|D ]P}t          j	        | |¦  «         	 | j        r||         \  }}| |||fV — n| |||         fV — ŒA# t          $ r Y ŒMw xY wdS t          j        | ||¦  «        E d{V —† dS )a  Iterate over keys within the index using prefix matching.

        Prefix matching is applied within the tuple of a key, not to within
        the bytestring of each key element. e.g. if you have the keys ('foo',
        'bar'), ('foobar', 'gam') and do a prefix search for ('foo', None) then
        only the former key is returned.

        WARNING: Note that this method currently causes a full index parse
        unconditionally (which is reasonably appropriate as it is a means for
        thunking many small indices into one larger one and still supplies
        iter_all_entries at the thunk layer).

        :param keys: An iterable providing the key prefixes to be retrieved.
            Each key prefix takes the form of a tuple the length of a key, but
            with the last N elements 'None' rather than a regular bytestring.
            The first element cannot be 'None'.
        :return: An iterable as per iter_all_entries, but restricted to the
            keys with a matching prefix to those supplied. No additional keys
            will be returned, and every match that is in the index will be
            returned.
        Nr   r#   )ry   rÃ   r  rH  rI  rS   rq   rÒ   r   rË   rÌ   rÎ   )r   rÇ   r   Ú_1rW   rX   rL  rÏ   Ú	key_valuerÓ   rÔ   rZ   s               r   rÊ   z#BTreeGraphIndex.iter_entries_prefix*  s¨  è è € õ, •c˜$‘i”iÑ Ô ˆØð 	ØˆFàŒ?Ð"Ø×ÒÑ!Ô!Ð!ð ˆØÔð 	2ØÔ 1Ò$Ð$Ø,0×,AÒ,AÑ,CÔ,Cð -ð -Ñ(�B˜˜U DØ!&¨ �E˜#‘J�Jð-ð  "�Ø,0×,AÒ,AÑ,CÔ,Cð 2ð 2Ñ(�B˜˜U DØ # U¨DÐ 0�Ið  ,�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(1�H˜S œWÑ%Ð%ð2ð Ô 1Ò$Ð$Ø&*×&;Ò&;Ñ&=Ô&=ð 'ð '‘N�B˜˜UØ!&�E˜#‘J�Jð'ð  "�Ø&*×&;Ò&;Ñ&=Ô&=ð 2ð 2‘N�B˜˜UØ # U 
�Ið  ,�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(1�H˜S œWÑ%Ð%ØÔ˜qÒ Ð Øð 	ð 	�ÝÔ'¨¨cÑ2Ô2Ð2ðØÔ*ð 4Ø+0°¬:Ñ(˜˜yØ" C¨°	Ð9Ð9Ð9Ð9Ð9à" C¨¨s¬Ð3Ð3Ð3Ð3øøÝð ð ð Ø�DðøøøàˆFÝÔ-¨d°LÀ$ÑGÔGÐGÐGÐGÐGÐGÐGÐGÐGÐGs   Å,(FÆ
F"Æ!F"c                 óF   — | j         €|                      ¦   «          | j         S )z�Return an estimate of the number of keys in this index.

        For BTreeGraphIndex the estimate is exact as it is contained in the
        header.
        )r  rH  r   s    r   r³   zBTreeGraphIndex.key_countt  s&   € ð Œ?Ð"Ø×ÒÑ!Ô!Ð!ØŒÐr   c                 óŽ   — g }d}| j         D ]}|                     |¦  «         ||z  }Œ|                     |¦  «         || _        dS )z:Fill out the _row_offsets attribute based on _row_lengths.r   N)r  rd   r  )r   r4  Ú
row_offsetrœ   s       r   Ú_compute_row_offsetsz$BTreeGraphIndex._compute_row_offsets~  s\   € àˆØˆ
ØÔ$ð 	ð 	ˆCØ�NŠN˜:Ñ&Ô&Ð&Ø˜#ÑˆJˆJØ�Š�zÑ"Ô"Ð"Ø#ˆÔÐÐr   c           	      óR  — |dt          |                      ¦   «         ¦  «        …         }||                      ¦   «         k    st          j        | j        t
          ¦  «        ‚|t          |                      ¦   «         ¦  «        d…                              ¦   «         }|d         }|                     t          ¦  «        st          j	        | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n"# t          $ r t          j	        | ¦  «        ‚w xY w|d         }|                     t          ¦  «        st          j	        | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n"# t          $ r t          j	        | ¦  «        ‚w xY w|d         }|                     t          ¦  «        st          j	        | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n"# t          $ r t          j	        | ¦  «        ‚w xY w|d         }|                     t"          ¦  «        st          j	        | ¦  «        ‚	 d„ |t          t"          ¦  «        d…                              d¦  «        D ¦   «         | _        n"# t          $ r t          j	        | ¦  «        ‚w xY w|                      ¦   «          t          |¦  «        t+          t-          t           |dd…         ¦  «        ¦  «        z   dz   }|||d…         fS )	z×Parse the header from a region of bytes.

        :param bytes: The data to parse.
        :return: An offset, data tuple such as readv yields, for the unparsed
            data. (which may be of length 0).
        r   Nr   r   r½   c                 ó0   — g | ]}|¯t          |¦  «        ‘ŒS r:   )rý   )r|   r™   s     r   r~   z<BTreeGraphIndex._parse_header_from_bytes.<locals>.<listcomp>¬  s4   € ð !,ð !,ð !,°ð %+ð!,¥ V¡¤ð !,ð !,ð !,r   ó   ,é   )rU   Ú
_signaturer   ÚBadIndexFormatSignaturer  ra   Ú
splitlinesÚ
startswithr   ÚBadIndexOptionsrý   rI  rJ  r   rS   r   r  r§   rú   r  r¢  r­   r©   )r   rê   Ú	signaturerµ   Úoptions_lineÚ
header_ends         r   Ú_parse_header_from_bytesz(BTreeGraphIndex._parse_header_from_bytesˆ  s  € ð ˜!�C §¢Ñ 1Ô 1Ñ2Ô2Ð2Ô3ˆ	Ø˜DŸOšOÑ-Ô-Ò-Ð-ÝÔ/°´
½OÑLÔLÐLØ•c˜$Ÿ/š/Ñ+Ô+Ñ,Ô,Ð-Ð-Ô.×9Ò9Ñ;Ô;ˆØ˜Q”xˆØ×&Ò&Õ'8Ñ9Ô9ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.Ý"% lµ3Õ7HÑ3IÔ3IÐ3JÐ3JÔ&KÑ"LÔ"LˆDÔÐøÝð 	.ð 	.ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.øøøà˜Q”xˆØ×&Ò&Õ';Ñ<Ô<ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.Ý" <µÕ4HÑ0IÔ0IÐ0JÐ0JÔ#KÑLÔLˆDÔÐøÝð 	.ð 	.ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.øøøà˜Q”xˆØ×&Ò&¥{Ñ3Ô3ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.Ý! ,­sµ;Ñ/?Ô/?Ð/@Ð/@Ô"AÑBÔBˆDŒOˆOøÝð 	.ð 	.ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.øøøà˜Q”xˆØ×&Ò&Õ':Ñ;Ô;ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.ð!,ð !,Ø!-­cÕ2EÑ.FÔ.FÐ.GÐ.GÔ!H×!NÒ!NØ%)ñ"+ô "+ð!,ñ !,ô !,ˆDÔÐøõ ð 	.ð 	.ð 	.ÝÔ'¨Ñ-Ô-Ð-ð	.øøøà×!Ò!Ñ#Ô#Ð#õ ˜)‘n”n¥s­3­s°E¸!¸A¸#´JÑ+?Ô+?Ñ'@Ô'@Ñ@À1ÑDˆ
Ø˜5   Ô-Ð-Ð-s0   Ã.D ÄD!Å.F
 Æ
F)Ç#.H ÈH1É+>J* Ê*K	c              #   óä  ‡
‡K  — dŠ
g }| j         }|D ]î}|t          z  }t          }|dk    r~| j        rt          t          | j        ¦  «        }n™| j                             | j        ¦  «        Š
t          ‰
¦  «        Š‰|z
  | _        ˆfd„t          |‰t          ¦  «        D ¦   «         } nX|| j        k    rt          d|›d| j        ›�¦  «        ‚t          || j        |z
  ¦  «        }| 
                    ||z   |f¦  «         Œï|sdS ‰
�ˆ
fd„|D ¦   «         }n{| j        €!| j                             | j        |¦  «        }nSg }|D ]N\  }}| j                             |¦  «         | 
                    || j                             |¦  «        f¦  «         ŒO|D ]Ü\  }}||z  }|dk    r,|                      |¦  «        \  }}t          |¦  «        dk    rŒ<t                                |¦  «        Š
‰
                     t&          ¦  «        r"|                      ‰
| j        | j        ¦  «        }	n<‰
                     t.          ¦  «        rt1          ‰
¦  «        }	nt          d‰
z  ¦  «        ‚|t          z  |	fV — ŒÝdS )a®  Read some nodes from disk into the LRU cache.

        This performs a readv to get the node data into memory, and parses each
        node, then yields it to the caller. The nodes are requested in the
        supplied order. If possible doing sort() on the list before requesting
        a read may improve performance.

        :param nodes: The nodes to read. 0 - first node, 1 - second node etc.
        :return: None
        Nr   c                 óD   •— g | ]}|t          t          ‰|z
  ¦  «        f‘ŒS r:   )r�   r,   )r|   ÚstartÚ	num_bytess     €r   r~   z/BTreeGraphIndex._read_nodes.<locals>.<listcomp>×  sC   ø€ ð Gð Gð GØ"'ð  %¥c­*°iÀ%Ñ6GÑ&HÔ&HÐIð Gð Gð Gr   z'tried to read past the end of the file z > c                 ó4   •— g | ]\  }}|‰|||z   …         f‘ŒS r:   r:   )r|   r²  rg   rê   s      €r   r~   z/BTreeGraphIndex._read_nodes.<locals>.<listcomp>æ  s@   ø€ ð 6ð 6ð 6Ù*˜u dð " 5¨¨u°t©|Ð);Ô#<Ð=ð 6ð 6ð 6r   zUnknown node type for %r)r  r,   r  r�   r  Ú	get_bytesr  rU   re   r-   rd   rc   Úreadvr¯   r°   r¯  ÚzlibÚ
decompressrª  r�   r	  rS   rI  r‹   rö   )r   r   ÚrangesÚbase_offsetr   r÷   rg   Údata_rangesÚdatar´   rê   r³  s             @@r   r  zBTreeGraphIndex._read_nodes¸  sú  øøè è € ð ˆð ˆØÔ'ˆØð 	8ð 	8ˆEØ�jÑ(ˆFÝˆDØ˜Šzˆzà”:ð Ý�z¨4¬:Ñ6Ô6�D�Dð !œO×5Ò5°d´jÑAÔA�EÝ # E¡
¤
�IØ!*¨[Ñ!8�D”JðGð Gð Gð GÝ+0Ø"-¨y½*ñ,Fô ,FðGñ Gô G�Fð �Eà˜DœJÒ&Ð&Ý(˜.à,2¨F¨F°D´J°Jð*@ñ Aô Að Aõ ˜4 ¤¨fÑ!4Ñ5Ô5�Ø�MŠM˜;¨Ñ/°Ð6Ñ7Ô7Ð7Ð7Øð 	DØˆFØÐð6ð 6ð 6ð 6Ø.4ð6ñ 6ô 6ˆKˆKàŒZÐØœ/×/Ò/°´
¸FÑCÔCˆKˆKàˆKØ &ð Dð D‘�˜Ø”
—’ Ñ'Ô'Ð'Ø×"Ò" F¨D¬J¯OªO¸DÑ,AÔ,AÐ#BÑCÔCÐCÐCØ'ð 	-ð 	-‰LˆF�DØ�kÑ!ˆFØ˜Š{ˆ{à#×<Ò<¸TÑBÔB‘�˜Ý�t‘9”9 ’>�>ØÝ—O’O DÑ)Ô)ˆEØ×Ò¥
Ñ+Ô+ð IØ×)Ò)¨%°Ô1AØ*.Ô*=ñ?ô ?��à×!Ò!¥.Ñ1Ô1ð IÝ$ UÑ+Ô+��å$Ð%?À%Ñ%GÑHÔHÐHØ�JÑ&¨Ð,Ð,Ð,Ð,Ð,ð	-ð 	-r   c                 ó   — t           S )z'The file signature for this index type.)r¦   r   s    r   r§  zBTreeGraphIndex._signature   s   € åÐr   c                 óþ   — |                       ¦   «          t          | j        ¦  «        dk    r| j        d         }nd}| j        d         }|                      t          t          ||¦  «        ¦  «        ¦  «        D ]}ŒdS )z6Validate that everything in the index can be accessed.r   r#   N)rH  rU   r  r  r  r2  re   )r   Ú
start_nodeÚnode_endr´   s       r   rÚ   zBTreeGraphIndex.validate  s‹   € ð 	×ÒÑÔÐÝˆtÔ Ñ!Ô! AÒ%Ð%ØÔ*¨1Ô-ˆJˆJð ˆJØÔ$ RÔ(ˆØ×$Ò$¥T­%°
¸HÑ*EÔ*EÑ%FÔ%FÑGÔGð 	ð 	ˆDØð	ð 	r   N)Fr   )$r6   r7   r8   r9   r   r  r  rà   r  r#  r  r,  r8  r3  rE  rM  r:  r1  rH  rY  rS  r]  r_  rq   Ústaticmethodr|  r‹  rÅ   r›  rÊ   r³   r¢  r¯  r  r§  rÚ   r:   r   r   ra   ra   „  s)  € € € € € ðð ð ?DØð&!ð &!ð &!ð &!ðPð ð ð+ð +ð +ðð ð ð&ð &ð &ðð ð ð8!ð !ð !ðð ð ð"Cð Cð CðJ*ð *ð *ðX&ð &ð &ðð ð ðð ð ðð ð ðð ð ðð ð ð"Hð Hð Hð	8ð 	8ð 	8ðð ð ð*-ð *-ð *-ðX ðRð Rñ „\ðRðh$ð $ð $ðB5:ð 5:ð 5:ðn}ð }ð }ð~HHð HHð HHðTð ð ð$ð $ð $ð..ð ..ð ..ð`F-ð F-ð F-ðPð ð ðð ð ð ð r   ra   )Ú_btree_serializer_pyx)Ú_btree_serializer_pyN)+r9   Úior   r   ÚglobalsÚ r   r   r   r	   r
   r   r   r   r   r   r   r   r¦   r§   r�   r‹   rŒ   r&   r,   r  r   r<   r?   rF   rA   ré   râ   rö   ra   Ú_gcchk_factoryrÂ  r£   Ú_parse_into_chkÚImportErrorÚeÚfailed_to_load_extensionrÃ  r:   r   r   ú<module>rÌ     sã  ðð$ Ð à Ð Ð Ð Ð Ð à %Ð %Ð %Ð %Ð %Ð %Ø €ˆGˆG‰IŒIð ñ ô ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð HÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ Gð )€Ø%Ð Ø€
Ø#€ØÐ àÐ Ø€
ð Ð ð#ð #ð #ð #ð #ñ #ô #ð #ðL&ð &ð &ð &ð &˜+ñ &ô &ð &ðFð Fð Fð Fð F�kñ Fô Fð Fð_ð _ð _ð _ð _�5Ô*ñ _ô _ð _ðDð ð ð ð �ñ ô ð ð:ð ð ð ð ñ ô ð ð.Kð Kð Kð Kð Kñ Kô Kð Kð\ €ð<Ø<Ð<Ð<Ð<Ð<Ð<Ø&Ô6€N€N€NøØð <ð <ð <Ø$€GÔ$ QÑ'Ô'Ð'Ø;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;øøøøð<øøøs   Â>C ÃC3ÃC.Ã.C3