§
    cÌcŽ< ã                   óZ  — d Z g d¢ZddlmZ ddlmZ ddlZddlmZ  e e¦   «         d¦  «         dd	l	m
Z
mZmZ d
dlmZ dZdZdZdZdZ G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z ej        d¦  «        Z ej        d¦  «        Zd„ Zd „ Z  G d!„ d"¦  «        Z! G d#„ d$¦  «        Z" G d%„ d&¦  «        Z# G d'„ d(e!¦  «        Z$ G d)„ d*¦  «        Z%d+„ Z&d,„ Z'dS )-zIndexing facilities.)ÚCombinedGraphIndexÚ
GraphIndexÚGraphIndexBuilderÚGraphIndexPrefixAdapterÚInMemoryGraphIndexé    )Úbisect_right)ÚBytesIONé   )Úlazy_importzX
from breezy import (
    bisect_multi,
    revision as _mod_revision,
    trace,
    )
)ÚdebugÚerrorsÚ	transporté   )ÚStaticTuple)r   éÈ   s   key_elements=s   len=s   node_ref_lists=s   Bazaar Graph Index 1
c                   ó   — e Zd ZdZd„ ZdS )ÚBadIndexFormatSignaturez,%(value)s is not an index of type %(_type)s.c                 ó`   — t           j                             | ¦  «         || _        || _        d S ©N)r   ÚBzrErrorÚ__init__ÚvalueÚ_type)Úselfr   r   s      ú2/usr/lib/python3/dist-packages/breezy/bzr/index.pyr   z BadIndexFormatSignature.__init__9   s*   € ÝŒ× Ò  Ñ&Ô&Ð&ØˆŒ
ØˆŒ
ˆ
ˆ
ó    N©Ú__name__Ú
__module__Ú__qualname__Ú_fmtr   © r   r   r   r   5   s(   € € € € € à9€Dðð ð ð ð r   r   c                   ó   — e Zd ZdZd„ ZdS )ÚBadIndexDataz"Error in data for index %(value)s.c                 óR   — t           j                             | ¦  «         || _        d S r   ©r   r   r   r   ©r   r   s     r   r   zBadIndexData.__init__C   ó#   € ÝŒ× Ò  Ñ&Ô&Ð&ØˆŒ
ˆ
ˆ
r   Nr   r"   r   r   r$   r$   ?   s(   € € € € € à/€Dðð ð ð ð r   r$   c                   ó   — e Zd ZdZd„ ZdS )ÚBadIndexDuplicateKeyz2The key '%(key)s' is already in index '%(index)s'.c                 ó`   — t           j                             | ¦  «         || _        || _        d S r   )r   r   r   ÚkeyÚindex)r   r,   r-   s      r   r   zBadIndexDuplicateKey.__init__L   s*   € ÝŒ× Ò  Ñ&Ô&Ð&ØˆŒØˆŒ
ˆ
ˆ
r   Nr   r"   r   r   r*   r*   H   s(   € € € € € à?€Dðð ð ð ð r   r*   c                   ó   — e Zd ZdZd„ ZdS )ÚBadIndexKeyz%The key '%(key)s' is not a valid key.c                 óR   — t           j                             | ¦  «         || _        d S r   )r   r   r   r,   ©r   r,   s     r   r   zBadIndexKey.__init__V   s#   € ÝŒ× Ò  Ñ&Ô&Ð&ØˆŒˆˆr   Nr   r"   r   r   r/   r/   R   s(   € € € € € à2€Dðð ð ð ð r   r/   c                   ó   — e Zd ZdZd„ ZdS )ÚBadIndexOptionsz,Could not parse options for index %(value)s.c                 óR   — t           j                             | ¦  «         || _        d S r   r&   r'   s     r   r   zBadIndexOptions.__init___   r(   r   Nr   r"   r   r   r3   r3   [   s(   € € € € € à9€Dðð ð ð ð r   r3   c                   ó   — e Zd ZdZd„ ZdS )ÚBadIndexValuez+The value '%(value)s' is not a valid value.c                 óR   — t           j                             | ¦  «         || _        d S r   r&   r'   s     r   r   zBadIndexValue.__init__h   r(   r   Nr   r"   r   r   r6   r6   d   s(   € € € € € à8€Dðð ð ð ð r   r6   s	   [	
  ]s   [
 ]c                 ó2   — ||                       |g¦  «        v S )z˜Check if this index has one key.

    If it's possible to check for multiple keys at once through
    calling get_parent_map that should be faster.
    )Úget_parent_mapr1   s     r   Ú_has_key_from_parent_mapr:   q   s   € ð �4×&Ò&¨ uÑ-Ô-Ð-Ð.r   c                 óf   — t          |¦  «        t          |                      |¦  «        ¦  «        z
  S r   )Úsetr9   ©r   Úkeyss     r   Ú_missing_keys_from_parent_mapr?   z   s)   € Ýˆt‰9Œ9•s˜4×.Ò.¨tÑ4Ô4Ñ5Ô5Ñ5Ð5r   c                   óZ   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd	„ Z	dd„Z
d„ Zd„ Zdd„Zd„ ZdS )r   aÚ  A builder that can build a GraphIndex.

    The resulting graph has the structure::

      _SIGNATURE OPTIONS NODES NEWLINE
      _SIGNATURE     := 'Bazaar Graph Index 1' NEWLINE
      OPTIONS        := 'node_ref_lists=' DIGITS NEWLINE
      NODES          := NODE*
      NODE           := KEY NULL ABSENT? NULL REFERENCES NULL VALUE NEWLINE
      KEY            := Not-whitespace-utf8
      ABSENT         := 'a'
      REFERENCES     := REFERENCE_LIST (TAB REFERENCE_LIST){node_ref_lists - 1}
      REFERENCE_LIST := (REFERENCE (CR REFERENCE)*)?
      REFERENCE      := DIGITS  ; digits is the byte offset in the index of the
                                ; referenced key.
      VALUE          := no-newline-no-null-bytes
    r   r   c                 ó€   — || _         i | _        t          ¦   «         | _        d| _        || _        d| _        d| _        dS )zÊCreate a GraphIndex builder.

        :param reference_lists: The number of node references lists for each
            entry.
        :param key_elements: The number of bytestrings in each key.
        NFT)Úreference_listsÚ_nodesr<   Ú_absent_keysÚ_nodes_by_keyÚ_key_lengthÚ_optimize_for_sizeÚ_combine_backing_indices)r   rB   Úkey_elementss      r   r   zGraphIndexBuilder.__init__‘   sE   € ð  /ˆÔàˆŒå™EœEˆÔØ!ˆÔØ'ˆÔØ"'ˆÔØ(,ˆÔ%Ð%Ð%r   c                 ó<  — t          |¦  «        t          t          fvrt          |¦  «        ‚| j        t          |¦  «        k    rt          |¦  «        ‚|D ]E}|r2t          |¦  «        t          k    st                               |¦  «        �t          |¦  «        ‚ŒFdS )z;Raise BadIndexKey if key is not a valid key for this index.N)	ÚtypeÚtupler   r/   rF   ÚlenÚbytesÚ_whitespace_reÚsearch)r   r,   Úelements      r   Ú
_check_keyzGraphIndexBuilder._check_key¢   s    € å�‰9Œ9�U¥KÐ0Ð0Ð0Ý˜cÑ"Ô"Ð"ØÔ�s 3™xœxÒ'Ð'Ý˜cÑ"Ô"Ð"Øð 	'ð 	'ˆGØð '�d 7™mœm­uÒ4Ð4½×8MÒ8MÈgÑ8VÔ8VÐ8bÝ! #Ñ&Ô&Ð&ð 9cð	'ð 	'r   c                 ó  — t          ¦   «         }t          ¦   «         }| j        dk    rX|                      ¦   «         D ]>}|                     |d         ¦  «         |                     |d         d         ¦  «         Œ?||z
  S t          ¦   «         S )ú>Return references that are not present in this index.
        r   é   )r<   rB   Úiter_all_entriesÚaddÚupdate)r   r>   ÚrefsÚnodes       r   Ú_external_referencesz&GraphIndexBuilder._external_references¬   s‰   € õ ‰uŒuˆÝ‰uŒuˆð Ô !Ò#Ð#Ø×-Ò-Ñ/Ô/ð (ð (�Ø—’˜˜aœÑ!Ô!Ð!Ø—’˜D œG AœJÑ'Ô'Ð'Ð'Ø˜$‘;Ðõ
 ‘5”5ˆLr   c                 ó¢  — | j         €Âi }| j        rZ| j                             ¦   «         D ]?\  }\  }}}|rŒ|}|d d…         D ]}|                     |i ¦  «        }Œ|||f||d         <   Œ@nX| j                             ¦   «         D ]>\  }\  }}}|rŒ|}|d d…         D ]}|                     |i ¦  «        }Œ||f||d         <   Œ?|| _         | j         S ©Néÿÿÿÿ)rE   rB   rC   ÚitemsÚ
setdefault)r   Únodes_by_keyr,   ÚabsentÚ
referencesr   Úkey_dictÚsubkeys           r   Ú_get_nodes_by_keyz#GraphIndexBuilder._get_nodes_by_keyÂ   s2  € ØÔÐ%ØˆLØÔ#ð 3Ø8<¼×8IÒ8IÑ8KÔ8Kð ?ð ?Ñ4�CÑ4˜& *¨eØð !Ø Ø+�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(+¨U°JÐ(>�H˜S œWÑ%Ð%ð?ð 9=¼×8IÒ8IÑ8KÔ8Kð 3ð 3Ñ4�CÑ4˜& *¨eØð !Ø Ø+�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(+¨U¨
�H˜S œWÑ%Ð%Ø!-ˆDÔØÔ!Ð!r   c                 óÔ   — | j         €dS | j         }| j        rt          |||¦  «        }nt          ||¦  «        }|dd…         D ]}|                     |i ¦  «        }Œ|||d         <   dS )z”Update the _nodes_by_key dict with a new key.

        For a key of (foo, bar, baz) create
        _nodes_by_key[foo][bar][baz] = key_value
        Nr^   )rE   rB   r   r`   )r   r,   r   Ú	node_refsrd   Ú	key_valuere   s          r   Ú_update_nodes_by_keyz&GraphIndexBuilder._update_nodes_by_keyØ   s‰   € ð ÔÐ%ØˆFØÔ%ˆØÔð 	0Ý# C¨°	Ñ:Ô:ˆIˆIå# C¨Ñ/Ô/ˆIØ˜#˜2˜#”hð 	7ð 	7ˆFØ×*Ò*¨6°2Ñ6Ô6ˆHˆHØ%ˆ��R”ÑÐÐr   c                 óÚ  ‡— t           j        Š|                      |¦  «         t                               |¦  «        �t          |¦  «        ‚t          |¦  «        | j        k    rt          |¦  «        ‚g }g }|D ]f}|D ]5}|| j        vr*|                      |¦  «         | 	                    |¦  «         Œ6 ‰ˆfd„|D ¦   «         ¦  «        }| 	                    |¦  «         Œg ‰|¦  «        |fS )a9  Check that 'key' and 'references' are all valid.

        :param key: A key tuple. Must conform to the key interface (be a tuple,
            be of the right length, not have any whitespace or nulls in any key
            element.)
        :param references: An iterable of reference lists. Something like
            [[(ref, key)], [(ref, key), (other, key)]]
        :param value: The value associate with this key. Must not contain
            newlines or null characters.
        :return: (node_refs, absent_references)

            * node_refs: basically a packed form of 'references' where all
              iterables are tuples
            * absent_references: reference keys that are not in self._nodes.
              This may contain duplicates if the same key is referenced in
              multiple lists.
        Nc                 óJ   •— g | ]} ‰|¦  «                              ¦   «         ‘Œ S r"   )Úintern)Ú.0ÚrefÚas_sts     €r   ú
<listcomp>z:GraphIndexBuilder._check_key_ref_value.<locals>.<listcomp>
  s=   ø€ ð $?ð $?ð $?Ø(+ð %* E¨#¡J¤J×$5Ò$5Ñ$7Ô$7ð $?ð $?ð $?r   )
r   Úfrom_sequencerR   Ú_newline_null_rerP   r6   rM   rB   rC   Úappend)	r   r,   rc   r   rh   Úabsent_referencesÚreference_listÚ	referencerp   s	           @r   Ú_check_key_ref_valuez&GraphIndexBuilder._check_key_ref_valueé   s(  ø€ õ$ Ô)ˆØ�Š˜ÑÔÐÝ×"Ò" 5Ñ)Ô)Ð5Ý Ñ&Ô&Ð&Ýˆz‰?Œ?˜dÔ2Ò2Ð2Ý 
Ñ+Ô+Ð+Øˆ	ØÐØ(ð 		-ð 		-ˆNØ+ð 8ð 8�	ð  D¤KÐ/Ð/Ø—O’O IÑ.Ô.Ð.Ø%×,Ò,¨YÑ7Ô7Ð7øØ"˜Uð $?ð $?ð $?ð $?Ø/=ð$?ñ $?ô $?ñ @ô @ˆNà×Ò˜^Ñ,Ô,Ð,Ð,Øˆu�YÑÔÐ!2Ð2Ð2r   r"   c                 ó”  — |                       |||¦  «        \  }}|| j        v r'| j        |         d         dk    rt          || ¦  «        ‚|D ]}d| j        |<   Œ| j                             |¦  «         | j                             |¦  «         d||f| j        |<   | j        �$| j        dk    r|                      |||¦  «         dS dS dS )aÀ  Add a node to the index.

        :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.
        r   ó   a)rz   r"   r   r   Nr   )	rx   rC   r*   rD   rX   ÚdiscardrE   rF   rj   )r   r,   r   rc   rh   ru   rw   s          r   Úadd_nodezGraphIndexBuilder.add_node  sú   € ð #×7Ò7¸¸ZÈÑOÔOñ	ˆØ	Ø�$”+ÐÐ $¤+¨cÔ"2°1Ô"5¸Ò"=Ð"=Ý& s¨DÑ1Ô1Ð1Ø*ð 	5ð 	5ˆIð &5ˆDŒK˜	Ñ"Ð"ØÔ× Ò Ð!2Ñ3Ô3Ð3ØÔ×!Ò! #Ñ&Ô&Ð&Ø ¨EÐ2ˆŒ�CÑØÔÐ)¨dÔ.>ÀÒ.BÐ.BØ×%Ò% c¨5°)Ñ<Ô<Ð<Ð<Ð<ð *Ð)Ð.BÐ.Br   c                 ó   — dS )zˆSee GraphIndex.clear_cache()

        This is a no-op, but we need the api to conform to a generic 'Index'
        abstraction.
        Nr"   ©r   s    r   Úclear_cachezGraphIndexBuilder.clear_cache(  ó   € € € r   c           	      óN  — t           g}|                     dt          | j        fz  ¦  «         |                     dt          | j        fz  ¦  «         t          | j        ¦  «        t          | j        ¦  «        z
  }|                     dt          |fz  ¦  «         t          d„ |D ¦   «         ¦  «        }t          | j                             ¦   «         ¦  «        }d}| j        �r	g }|}d}|D ]·\  }	\  }
}}|                     |	||f¦  «         |t          d„ |	D ¦   «         ¦  «        z  }| j        dk    r|| j        dz
  z  }|t          |¦  «        dz   dz   z  }|
r|dz  }Œu| j        r;|| j        dz
  z  }|D ]+}|t          |¦  «        z  }|r|t          |¦  «        dz
  z  }Œ,Œ¸d}|||z  z   }d|z  |k     r|dz  }|||z  z   }d|z  |k     °|dz   }i }|D ]\  }	}}|||z  z   ||	<   Œd	|z  }|D ]¡\  }	\  }
}}g }|D ]O}g }|D ] }|                     |||         z  ¦  «         Œ!|                     d
                     |¦  «        ¦  «         ŒPd                     |	¦  «        }|                     d||
d                     |¦  «        |fz  ¦  «         Œ¢|                     d¦  «         t          d                     |¦  «        ¦  «        }|r]t          |                     ¦   «         ¦  «        |k    r8t!          j        dt          |                     ¦   «         ¦  «        |fz  ¦  «        ‚|S )z…Finish the index.

        :returns: cBytesIO holding the full context of the index as it
        should be written to disk.
        s   %s%d
c              3   ó4   K  — | ]}t          |¦  «        V — Œd S r   ©rM   )rn   Úxs     r   ú	<genexpr>z+GraphIndexBuilder.finish.<locals>.<genexpr>:  s(   è è € Ð2Ð2 q�C ™FœFÐ2Ð2Ð2Ð2Ð2Ð2r   Nr   c              3   ó4   K  — | ]}t          |¦  «        V — Œd S r   rƒ   ©rn   rQ   s     r   r…   z+GraphIndexBuilder.finish.<locals>.<genexpr>Z  s(   è è € Ð$EÐ$E°g¥S¨¡\¤\Ð$EÐ$EÐ$EÐ$EÐ$EÐ$Er   r   rU   é
   s   %%0%ddó   ó    s   %s %s %s %s
ó   	ó   
r   zZFailed index creation. Internal error: mismatched output length and expected length: %d %d)Ú
_SIGNATURErt   Ú_OPTION_NODE_REFSrB   Ú_OPTION_KEY_ELEMENTSrF   rM   rC   rD   Ú_OPTION_LENÚsumÚsortedr_   Újoinr	   Úgetvaluer   r   )r   ÚlinesÚ	key_countÚprefix_lengthÚnodesÚexpected_bytesÚkey_offset_infoÚnon_ref_bytesÚtotal_referencesr,   rb   rc   r   Úref_listÚdigitsÚpossible_total_bytesÚkey_addressesÚformat_stringÚflattened_referencesÚref_addressesrw   Ú
string_keyÚresults                          r   ÚfinishzGraphIndexBuilder.finish/  s  € õ �ˆØ�Š�YÕ"3°TÔ5IÐ!JÑJÑKÔKÐKØ�Š�YÕ"6¸Ô8HÐ!IÑIÑJÔJÐJÝ˜œÑ$Ô$¥s¨4Ô+<Ñ'=Ô'=Ñ=ˆ	Ø�Š�Y¥+¨yÐ!9Ñ9Ñ:Ô:Ð:ÝÐ2Ð2¨EÐ2Ñ2Ô2Ñ2Ô2ˆõ  �t”{×(Ò(Ñ*Ô*Ñ+Ô+ˆàˆàÔñ *	/Ø ˆOØ)ˆMØ Ðà49ð ?ð ?Ñ0�Ñ0�f˜j¨%ð  ×&Ò&¨¨]Ð<LÐ'MÑNÔNÐNð ¥Ð$EÐ$EÀÐ$EÑ$EÔ$EÑ!EÔ!EÑE�ØÔ# aÒ'Ð'Ø! TÔ%5¸Ñ%9Ñ9�Mà¥ U¡¤¨a¡°!Ñ!3Ñ3�àð ?Ø! QÑ&�M�MØÔ)ð 	?à! TÔ%9¸AÑ%=Ñ=�Mà$.ð ?ð ?˜à(­C°©M¬MÑ9Ð(à#ð ?Ø)­S°©]¬]¸QÑ->Ñ>˜MøøàˆFØ#0Ð3CÀfÑ3LÑ#LÐ Ø˜‘,Ð!5Ò5Ð5Ø˜!‘�Ø'4Ð7GÈ&Ñ7PÑ'PÐ$ð ˜‘,Ð!5Ò5Ð5ð 2°AÑ5ˆNàˆMØ8Gð Oð OÑ4��]Ð$4Ø%2Ð5EÈÑ5NÑ%N�˜cÑ"Ð"à%¨Ñ.ˆMØ05ð 
	`ð 
	`Ñ,ˆCÑ,�&˜* eØ#%Ð Ø&ð Gð G�Ø "�Ø!)ð Cð C�IØ!×(Ò(¨Ø)6°yÔ)Añ*Bñ Cô Cð Cð Cà$×+Ò+¨E¯JªJ°}Ñ,EÔ,EÑFÔFÐFÐFØ Ÿš cÑ*Ô*ˆJØ�LŠLÐ2°jÀ&Ø6;·j²jÐAUÑ6VÔ6VÐX]ð6_ñ _ñ `ô `ð `ð `à�Š�UÑÔÐÝ˜Ÿš %™œÑ)Ô)ˆØð 	L�c &§/¢/Ñ"3Ô"3Ñ4Ô4¸ÒFÐFÝ”/ð #Yå#& v§¢Ñ'8Ô'8Ñ#9Ô#9¸>Ð"Jñ#Kñ Lô Lð Lð ˆr   Nc                 ó.   — |�|| _         |�	|| _        dS dS )aó  Change how the builder tries to optimize the result.

        :param for_size: Tell the builder to try and make the index as small as
            possible.
        :param combine_backing_indices: If the builder spills to disk to save
            memory, should the on-disk indices be combined. Set to True if you
            are going to be probing the index, but to False if you are not. (If
            you are not querying, then the time spent combining is wasted.)
        :return: None
        N)rG   rH   )r   Úfor_sizeÚcombine_backing_indicess      r   Úset_optimizezGraphIndexBuilder.set_optimizeŒ  s.   € ð ÐØ&.ˆDÔ#Ø"Ð.Ø,CˆDÔ)Ð)Ð)ð /Ð.r   c                 óX  ‡— t          |¦  «        }i Št          ¦   «         }|r…t          ¦   «         }|                      |¦  «        D ]]\  }}}}	|	|         }
|
‰|<   |                     ˆfd„|
D ¦   «         ¦  «         |                     |                     ‰¦  «        ¦  «         Œ^|}|°…‰|fS )z&See CombinedGraphIndex.find_ancestry()c                 ó   •— g | ]}|‰v¯|‘Œ	S r"   r"   )rn   ÚpÚ
parent_maps     €r   rq   z3GraphIndexBuilder.find_ancestry.<locals>.<listcomp>¨  s9   ø€ ð %1ð %1ð %1¨1¸qØ%/ð@0ð @0 Qð @0ð @0ð @0r   )r<   Úiter_entriesrX   Ú
difference)r   r>   Úref_list_numÚpendingÚmissing_keysÚnext_pendingÚ_r,   r   Ú	ref_listsÚparent_keysr®   s              @r   Úfind_ancestryzGraphIndexBuilder.find_ancestryž  sæ   ø€ å�d‘)”)ˆØˆ
Ý‘u”uˆØð 	#Ý™5œ5ˆLØ,0×,=Ò,=¸gÑ,FÔ,Fð Dð DÑ(��3˜˜yØ'¨Ô5�Ø"-�
˜3‘Ø×#Ò#ð %1ð %1ð %1ð %1°ð %1ñ %1ô %1ñ 2ô 2ð 2à×#Ò# G×$6Ò$6°zÑ$BÔ$BÑCÔCÐCÐCØ"ˆGð ð 	#ð ˜<Ð'Ð'r   )r   r   ©r"   )NN)r   r   r    Ú__doc__r   rR   r[   rf   rj   rx   r|   r   r¦   rª   r¸   r"   r   r   r   r   ~   sÛ   € € € € € ðð ð$-ð -ð -ð -ð"'ð 'ð 'ðð ð ð,"ð "ð "ð,&ð &ð &ð"$3ð $3ð $3ðL=ð =ð =ð =ð2ð ð ð[ð [ð [ðzDð Dð Dð Dð$(ð (ð (ð (ð (r   r   c                   óà   — e Zd ZdZd$d„Zd„ Zd„ Zd„ Zd„ Zd	„ Z	d%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„ Zd„ Zd„ Zd „ Z d!„ Z!d"„ Z"d#„ Z#d
S )&r   a>  An index for data with embedded graphs.

    The index maps keys to a list of key reference lists, and a value.
    Each node has the same number of key reference lists. Each key reference
    list can be empty or an arbitrary length. The value is an opaque NULL
    terminated string without any newlines. The storage of the index is
    hidden in the interface: keys and key references are always tuples of
    bytestrings, never the internal representation (e.g. dictionary offsets).

    It is presumed that the index will not be mutated - it is static data.

    Successive iter_all_entries calls will read the entire index each time.
    Additionally, iter_entries calls will read the index linearly until the
    desired keys are found. XXX: This must be fixed before the index is
    suitable for production use. :XXX
    Fr   c                 ó®   — || _         || _        d| _        d| _        g | _        g | _        d| _        d| _        d| _        || _	        d| _
        || _        dS )a  Open an index called name on transport.

        :param transport: A breezy.transport.Transport.
        :param name: A path to provide to transport API calls.
        :param size: The size of the index in bytes. This is used for bisection
            logic to perform partial index reads. While the size could be
            obtained by statting the file this introduced an additional round
            trip as well as requiring stat'able transports, both of which are
            avoided by having it supplied. If size is None, then bisection
            support will be disabled and accessing the index will just stream
            all the data.
        :param offset: Instead of starting the index data at offset 0, start it
            at an arbitrary offset.
        Nr   )Ú
_transportÚ_nameÚ_bisect_nodesrC   Ú_parsed_byte_mapÚ_parsed_key_mapÚ
_key_countÚ_keys_by_offsetrE   Ú_sizeÚ_bytes_readÚ_base_offset)r   r   ÚnameÚsizeÚunlimited_cacheÚoffsets         r   r   zGraphIndex.__init__Á  sm   € ð $ˆŒØˆŒ
ð "ˆÔð ˆŒð !#ˆÔð  "ˆÔØˆŒØ#ˆÔØ!ˆÔØˆŒ
àˆÔØ"ˆÔÐÐ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.)Ú
isinstancerK   r½   r¾   rÄ   ©r   Úothers     r   Ú__eq__zGraphIndex.__eq__ç  sR   € õ �t�T %™[œ[Ñ)Ô)ð &ØŒO˜uÔ/Ò/ð&àŒJ˜%œ+Ò%ð&ð ŒJ˜%œ+Ò%ð		'r   c                 ó.   — |                       |¦  «         S r   )rÏ   rÍ   s     r   Ú__ne__zGraphIndex.__ne__ï  s   € Ø—;’;˜uÑ%Ô%Ð%Ð%r   c                 ó´   — t          |t          ¦  «        s$t          |t          ¦  «        st          |¦  «        ‚t	          | ¦  «        t	          |¦  «        k     S r   ©rÌ   r   r   Ú	TypeErrorÚhashrÍ   s     r   Ú__lt__zGraphIndex.__lt__ò  óL   € å˜5¥*Ñ-Ô-ð 	#Ý˜uÕ&8Ñ9Ô9ð	#å˜EÑ"Ô"Ð"Ý�D‰zŒz�D ™KœKÒ'Ð'r   c                 ó`   — t          t          | ¦  «        | j        | j        | j        f¦  «        S r   )rÕ   rK   r½   r¾   rÄ   r~   s    r   Ú__hash__zGraphIndex.__hash__ù  s%   € Ý•T˜$‘Z”Z ¤°$´*¸d¼jÐIÑJÔJÐJr   c                 ó|   — d                      | j        j        | j                             | j        ¦  «        ¦  «        S )Nz{}({!r}))ÚformatÚ	__class__r   r½   Úabspathr¾   r~   s    r   Ú__repr__zGraphIndex.__repr__ü  s9   € Ø× Ò  ¤Ô!8Øœ?×2Ò2°4´:Ñ>Ô>ñ@ô @ð 	@r   Nc                 óª  — | j         �dS dt          j        v r8t                               d| j                             | j        ¦  «        ¦  «         |€X| j                             | j        ¦  «        }| j	        dk    r.t          |                     ¦   «         | j	        d…         ¦  «        }	 |                      |¦  «         d| j        z   | _        d}i | _        i | _         d| _        d}|                     ¦   «         }|                     ¦   «                              d¦  «        }|                     ¦   «          n# |                     ¦   «          w xY w|d= |                      ||¦  «        \  }}}}| j                             ¦   «         D ]5\  }}}	}
|rŒ
| j        r|
|                      |	¦  «        f}n|
}|| j         |<   Œ6|dk    rt1          | ¦  «        ‚dS )	zYBuffer all the index data.

        Mutates self._nodes and self.keys_by_offset.
        Nr-   zReading entire index %sr   rU   rŒ   r^   r   )rC   r   Údebug_flagsÚtraceÚmutterr½   rÝ   r¾   ÚgetrÆ   r	   ÚreadÚ_read_prefixrF   Ú_expected_elementsrÃ   rE   ÚtellÚsplitÚcloseÚ_parse_linesÚvaluesÚnode_ref_listsÚ_resolve_referencesr$   )r   ÚstreamÚ
line_countÚtrailersÚposr•   rµ   r,   rb   rc   r   Ú
node_values               r   Ú_buffer_allzGraphIndex._buffer_all   sÝ  € ð
 Œ;Ð"àˆFØ•eÔ'Ð'Ð'Ý�LŠLÐ2Øœ×0Ò0°´Ñ<Ô<ñ>ô >ð >àˆ>Ø”_×(Ò(¨¬Ñ4Ô4ˆFØÔ  AÒ%Ð%õ ! §¢¡¤¨tÔ/@Ð/AÐ/AÔ!BÑCÔC�ð	Ø×Ò˜fÑ%Ô%Ð%Ø&'¨$Ô*:Ñ&:ˆDÔ#ØˆJà#%ˆDÔ àˆDŒKØ!%ˆDÔØˆHØ—+’+‘-”-ˆCØ—K’K‘M”M×'Ò'¨Ñ.Ô.ˆEà�LŠL‰NŒNˆNˆNøˆF�LŠL‰NŒNˆNˆNøøøØ�"ˆIØ ×-Ò-¨e°SÑ9Ô9Ñˆˆ1ˆa�Ø.2Ô.B×.IÒ.IÑ.KÔ.Kð 	*ð 	*Ñ*ˆC�˜ UØð ØàÔ"ð #Ø# T×%=Ò%=¸jÑ%IÔ%IÐJ�
�
à"�
Ø)ˆDŒK˜ÑÐà�qŠ=ˆ=å˜tÑ$Ô$Ð$ð ˆ=s   Â+A8D8 Ä8Ec                 ó   — 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.
        Nr"   r~   s    r   r   zGraphIndex.clear_cache/  r€   r   c                 ó4  ‡— |                       ¦   «          |dz   | j        k    rt          d|| j        fz  ¦  «        ‚t          ¦   «         }| j        Š‰                     ¦   «         D ]1\  }\  }}||         }|                     ˆfd„|D ¦   «         ¦  «         Œ2|S )rT   r   z&No ref list %d, index has %d ref listsc                 ó   •— g | ]}|‰v¯|‘Œ	S r"   r"   )rn   ro   r˜   s     €r   rq   z2GraphIndex.external_references.<locals>.<listcomp>B  s#   ø€ ÐEÐEÐE °C¸uÐ4DÐ4D˜Ð4DÐ4DÐ4Dr   )ró   rì   Ú
ValueErrorr<   rC   r_   rX   )r   r±   rY   r,   r   r¶   r�   r˜   s          @r   Úexternal_referenceszGraphIndex.external_references7  s¿   ø€ ð 	×ÒÑÔÐØ˜!Ñ˜dÔ1Ò1Ð1ÝÐEØ ,¨dÔ.AÐBñCñ Dô Dð Då‰uŒuˆØ”ˆØ',§{¢{¡}¤}ð 	Gð 	GÑ#ˆCÑ#�%˜Ø  Ô.ˆHØ�KŠKÐEÐEÐEÐE¨ÐEÑEÔEÑFÔFÐFÐFØˆr   c                 óŒ  — | j         €·i }| j        rV| j                             ¦   «         D ];\  }\  }}|}|d d…         D ]}|                     |i ¦  «        }Œ|||f||d         <   Œ<nQ| j                             ¦   «         D ]7\  }}|}|d d…         D ]}|                     |i ¦  «        }Œ||f||d         <   Œ8|| _         | j         S r]   )rE   rì   rC   r_   r`   )r   ra   r,   r   rc   rd   re   s          r   rf   zGraphIndex._get_nodes_by_keyE  s  € ØÔÐ%ØˆLØÔ"ð 3Ø04´×0AÒ0AÑ0CÔ0Cð ?ð ?Ñ,�CÑ,˜% Ø+�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(+¨U°JÐ(>�H˜S œWÑ%Ð%ð	?ð #'¤+×"3Ò"3Ñ"5Ô"5ð 3ð 3‘J�C˜Ø+�HØ"% c r c¤(ð Cð C˜Ø#+×#6Ò#6°v¸rÑ#BÔ#B˜˜Ø(+¨U¨
�H˜S œWÑ%Ð%Ø!-ˆDÔØÔ!Ð!r   c              #   óD  K  — dt           j        v rt                               dd¦  «         | j        €|                      ¦   «          | j        r,| j                             ¦   «         D ]\  }\  }}| |||fV — ŒdS | j                             ¦   «         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.
        ÚevilrU   ú-iter_all_entries scales with size of history.N)r   rà   rá   Úmutter_callsiterC   ró   rì   r_   )r   r,   r   rì   s       r   rV   zGraphIndex.iter_all_entriesW  sç   è è € ð •UÔ&Ð&Ð&Ý×!Ò! !Ø"QñSô Sð SàŒ;ÐØ×ÒÑÔÐØÔð 	'Ø04´×0AÒ0AÑ0CÔ0Cð 7ð 7Ñ,�Ñ,�e˜^Ø˜C ¨Ð6Ð6Ð6Ð6Ð6ð7ð 7ð #œk×/Ò/Ñ1Ô1ð 'ð '‘
��UØ˜C Ð&Ð&Ð&Ð&Ð&ð'ð 'r   c                 ó  — |                      t          |                      ¦   «         ¦  «        ¦  «        }||                      ¦   «         k    st          | j        t
          ¦  «        ‚|                     ¦   «         }|                     t          ¦  «        st          | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n# t          $ r t          | ¦  «        ‚w xY w|                     ¦   «         }|                     t          ¦  «        st          | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n# t          $ r t          | ¦  «        ‚w xY w|                     ¦   «         }|                     t          ¦  «        st          | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        d S # t          $ r t          | ¦  «        ‚w xY wr]   )rä   rM   Ú
_signaturer   r¾   r   ÚreadlineÚ
startswithrŽ   r3   Úintrì   r÷   r�   rF   r�   rÂ   )r   rî   Ú	signatureÚoptions_lines       r   rå   zGraphIndex._read_prefixl  sâ  € Ø—K’K¥ D§O¢OÑ$5Ô$5Ñ 6Ô 6Ñ7Ô7ˆ	Ø˜DŸOšOÑ-Ô-Ò-Ð-Ý)¨$¬*µjÑAÔAÐAØ—’Ñ(Ô(ˆØ×&Ò&Õ'8Ñ9Ô9ð 	(Ý! $Ñ'Ô'Ð'ð	(Ý"% lµ3Õ7HÑ3IÔ3IÈ"Ð3LÔ&MÑ"NÔ"NˆDÔÐøÝð 	(ð 	(ð 	(Ý! $Ñ'Ô'Ð'ð	(øøøà—’Ñ(Ô(ˆØ×&Ò&Õ';Ñ<Ô<ð 	(Ý! $Ñ'Ô'Ð'ð	(Ý" <µÕ4HÑ0IÔ0IÈ"Ð0LÔ#MÑNÔNˆDÔÐøÝð 	(ð 	(ð 	(Ý! $Ñ'Ô'Ð'ð	(øøøà—’Ñ(Ô(ˆØ×&Ò&¥{Ñ3Ô3ð 	(Ý! $Ñ'Ô'Ð'ð	(Ý! ,­sµ;Ñ/?Ô/?ÀÐ/BÔ"CÑDÔDˆDŒOˆOˆOøÝð 	(ð 	(ð 	(Ý! $Ñ'Ô'Ð'ð	(øøøs$   Â%.C ÃC.Ä/.E ÅE8Æ9.G) Ç)Hc                 óŒ   ‡ — g }|D ]0}|                      t          ˆ fd„|D ¦   «         ¦  «        ¦  «         Œ1t          |¦  «        S )aq  Return the resolved key references for references.

        References are resolved by looking up the location of the key in the
        _keys_by_offset map and substituting the key name, preserving ordering.

        :param references: An iterable of iterables of key locations. e.g.
            [[123, 456], [123]]
        :return: A tuple of tuples of keys.
        c                 ó6   •— g | ]}‰j         |         d          ‘ŒS )r   )rÃ   )rn   ro   r   s     €r   rq   z2GraphIndex._resolve_references.<locals>.<listcomp>“  s&   ø€ ÐHÐHÐH¸�tÔ+¨CÔ0°Ô3ÐHÐHÐHr   )rt   rL   )r   rc   rh   r�   s   `   r   rí   zGraphIndex._resolve_references†  sj   ø€ ð ˆ	Ø"ð 	Kð 	KˆHØ×ÒÝÐHÐHÐHÐH¸xÐHÑHÔHÑIÔIñKô Kð Kð Kå�YÑÔÐr   c                 ó˜   — t          | |¦  «        dz
  }|dz   t          | ¦  «        k     r | |dz            d         |d         k    r|dz   S |S )zúHelper for the _parsed_*_index calls.

        Given a range map - [(start, end), ...], finds the index of the range
        in the map for key if it is in the map, and if it is not there, the
        immediately preceeding range in the map.
        r   r   )r   rM   )Ú	range_mapr,   r¥   s      r   Ú_find_indexzGraphIndex._find_index–  sY   € õ ˜i¨Ñ-Ô-°Ñ1ˆØ�A‰:�˜I™œÒ&Ð&à˜ !™Ô$ QÔ'¨3¨q¬6Ò1Ð1Ø ‘zÐ!Øˆr   c                 ó@   — |df}|                       | j        |¦  «        S )ag  Return the index of the entry immediately before offset.

        e.g. if the parsed map has regions 0,10 and 11,12 parsed, meaning that
        there is one unparsed byte (the 11th, addressed as[10]). then:
        asking for 0 will return 0
        asking for 10 will return 0
        asking for 11 will return 1
        asking for 12 will return 1
        r   )r	  rÀ   )r   rÊ   r,   s      r   Ú_parsed_byte_indexzGraphIndex._parsed_byte_index¥  s&   € ð �qˆkˆØ×Ò Ô 5°sÑ;Ô;Ð;r   c                 ó@   — |df}|                       | j        |¦  «        S )aŽ  Return the index of the entry immediately before key.

        e.g. if the parsed map has regions (None, 'a') and ('b','c') parsed,
        meaning that keys from None to 'a' inclusive, and 'b' to 'c' inclusive
        have been parsed, then:
        asking for '' will return 0
        asking for 'a' will return 0
        asking for 'b' will return 1
        asking for 'e' will return 1
        r   )r	  rÁ   )r   r,   Ú
search_keys      r   Ú_parsed_key_indexzGraphIndex._parsed_key_index²  s&   € ð ˜3�Zˆ
Ø×Ò Ô 4°jÑAÔAÐAr   c                 óÈ   — |                       |¦  «        }|t          | j        ¦  «        k    r|| j        |dz
           d         k     S | j        |         \  }}||k    o||k     S )z'Returns True if offset has been parsed.r   )r  rM   rÀ   )r   rÊ   r-   ÚstartÚends        r   Ú
_is_parsedzGraphIndex._is_parsedÀ  sk   € à×'Ò'¨Ñ/Ô/ˆØ•C˜Ô-Ñ.Ô.Ò.Ð.Ø˜DÔ1°%¸!±)Ô<¸QÔ?Ò?Ð?ØÔ*¨5Ô1‰
ˆˆsØ˜ŠÐ/ 6¨C¢<Ð/r   c              #   óœ   ‡K  — | j         Šˆfd„|D ¦   «         }| j        r|D ]}‰|         \  }}| |||fV — ŒdS |D ]}| |‰|         fV — ŒdS )z2Iterate over keys when the entire index is parsed.c                 ó   •— g | ]}|‰v ¯|‘Œ	S r"   r"   ©rn   r,   r˜   s     €r   rq   z>GraphIndex._iter_entries_from_total_buffer.<locals>.<listcomp>Í  ó   ø€ Ð4Ð4Ð4˜ s¨e | |� | | |r   N)rC   rì   )r   r>   r,   r   rh   r˜   s        @r   Ú_iter_entries_from_total_bufferz*GraphIndex._iter_entries_from_total_bufferÈ  s¨   øè è € ð ”ˆØ4Ð4Ð4Ð4˜tÐ4Ñ4Ô4ˆØÔð 	,Øð 2ð 2�Ø#(¨¤:Ñ ��yØ˜C ¨	Ð1Ð1Ð1Ð1Ð1ð2ð 2ð ð ,ð ,�Ø˜C  s¤Ð+Ð+Ð+Ð+Ð+ð,ð ,r   c                 óŠ  — t          |¦  «        }|sg S | j        €| j        €|                      ¦   «          | j        €<t	          |¦  «        dz  |                      ¦   «         k    r|                      ¦   «          | j        �|                      |¦  «        S d„ t                               | j	        | j        |¦  «        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é   c              3   ó&   K  — | ]}|d          V — ŒdS )r   Nr"   )rn   r¥   s     r   r…   z*GraphIndex.iter_entries.<locals>.<genexpr>ð  s>   è è € ð Cð C &�F˜1”Ið Cð Cð Cð Cð Cð Cr   )
r<   rÄ   rC   ró   rM   r–   r  Úbisect_multiÚbisect_multi_bytesÚ_lookup_keys_via_locationr=   s     r   r¯   zGraphIndex.iter_entriesÖ  s×   € õ �4‰yŒyˆØð 	ØˆIØŒ:Ð $¤+Ð"5Ø×ÒÑÔÐð Œ;Ð¥3 t¡9¤9¨r¡>°D·N²NÑ4DÔ4DÒ#DÐ#DØ×ÒÑÔÐØŒ;Ð"Ø×7Ò7¸Ñ=Ô=Ð=ðCð C­L×,KÒ,KØÔ.°´
¸Dñ-Bô -Bð Cñ Cô Cð Cr   c              #   ód  K  — t          |¦  «        }|sdS | j        €|                      ¦   «          | j        dk    rI|D ]D}t	          | |¦  «         | j        r| j        |         \  }}| |||fV — Œ2| || j        |         fV — ŒEdS |                      ¦   «         }t          | ||¦  «        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<   rC   ró   rF   Ú_sanity_check_keyrì   rf   Ú_iter_entries_prefix)r   r>   r,   r   rh   ra   s         r   Úiter_entries_prefixzGraphIndex.iter_entries_prefixó  sø   è è € õ, �4‰yŒyˆØð 	ØˆFàŒ;ÐØ×ÒÑÔÐØÔ˜qÒ Ð Øð 6ð 6�Ý! $¨Ñ,Ô,Ð,ØÔ&ð 6Ø'+¤{°3Ô'7Ñ$�E˜9Ø  U¨IÐ5Ð5Ð5Ð5Ð5à  T¤[°Ô%5Ð5Ð5Ð5Ð5Ð5ØˆFØ×-Ò-Ñ/Ô/ˆÝ'¨¨l¸DÑAÔAÐAÐAÐAÐAÐAÐAÐAÐAÐAr   c                 óz  — t          ¦   «         }t          ¦   «         }|                      |¦  «        D ]>\  }}}	}
|
|         }|                     |¦  «         |||<   |                     |¦  «         Œ?|                     t          |¦  «                             |¦  «        ¦  «         |                     |¦  «        }|S )zSee BTreeIndex._find_ancestors.)r<   r¯   rW   rX   r°   )r   r>   r±   r®   r³   Ú
found_keysÚsearch_keysr-   r,   r   rY   r·   s               r   Ú_find_ancestorszGraphIndex._find_ancestors  s¹   € õ
 ‘U”Uˆ
Ý‘e”eˆØ'+×'8Ò'8¸Ñ'>Ô'>ð 	,ð 	,Ñ#ˆE�3˜˜tØ˜|Ô,ˆKØ�NŠN˜3ÑÔÐØ)ˆJ�s‰OØ×Ò˜{Ñ+Ô+Ð+Ð+à×Ò�C ™IœI×0Ò0°Ñ<Ô<Ñ=Ô=Ð=Ø!×,Ò,¨ZÑ8Ô8ˆØÐr   c                 óT   — | j         €|                      t          g¦  «         | j         S )zoReturn an estimate of the number of keys in this index.

        For GraphIndex the estimate is exact.
        )rÂ   Ú_read_and_parseÚ_HEADER_READVr~   s    r   r–   zGraphIndex.key_count,  s*   € ð
 Œ?Ð"Ø× Ò ¥- Ñ1Ô1Ð1ØŒÐr   c           
      óè  — g }|D �]\  }}| j         r
|| j         v rŒ|                      |¦  «        }t          | j        ¦  «        rK| j        |         d         |k    r4| j        |         d         |k    s| j        |         d         | j        k    rŒ‹|                      |¦  «        }t          | j        ¦  «        r/| j        |         d         |k    r| j        |         d         |k    rŒãd}||z   | j        k    r
| j        |z
  }|dk    r|                     ||f¦  «         �Œ| j         €|                     t          ¦  «         |  	                    |¦  «         g }| j
        �‰|D ]„\  }}|| j
        vr|                     ||fdf¦  «         Œ(| j        r.| j
        |         \  }}	|                     ||f| |||	ff¦  «         Œ]|                     ||f| || j
        |         ff¦  «         Œ…|S g }
t          ¦   «         }|D �]œ\  }}|| j         v rÉ| j        rš| j         |         \  }}	g }|	D ]%}|D ] }|| j        vr|                     |¦  «         Œ!Œ&|r-|                     |¦  «         |
                     ||f¦  «         Œ|                     ||f| |||                      |	¦  «        ff¦  «         n'|                     ||f| || j         |         ff¦  «         ŒØ|                      |¦  «        }| j        |         d         |k    rN| j        |         d         |k    s| j        |         d         | j        k    r|                     ||fdf¦  «         �ŒR|                      |¦  «        }|| j        |         d         k     rd}nd}|                     ||f|f¦  «         �Œžg }|D ]9}d}||z   | j        k    r
| j        |z
  }|dk    r|                     ||f¦  «         Œ:|  	                    |¦  «         | j
        �7|
D ]2\  }}| j
        |         \  }}	|                     ||f| |||	ff¦  «         Œ3|S |
D ]E\  }}| j         |         \  }}	|                     ||f| |||                      |	¦  «        ff¦  «         ŒF|S )a   Public interface for implementing bisection.

        If _buffer_all has been called, then all the data for the index is in
        memory, and this method should not be called, as it uses a separate
        cache because it cannot pre-resolve all indices, which buffer_all does
        for performance.

        :param location_keys: A list of location(byte offset), key tuples.
        :return: A list of (location_key, result) tuples as expected by
            breezy.bisect_multi.bisect_multi_bytes.
        r   r   i   NFr^   )r¿   r  rM   rÁ   rÀ   rÄ   r  rt   r(  r'  rC   rì   r<   rÃ   rX   rí   )r   Úlocation_keysÚreadv_rangesÚlocationr,   r-   Úlengthr¥   r   rY   Úpending_referencesÚpending_locationsÚwanted_locationsr�   ro   Ú	directions                   r   r  z$GraphIndex._lookup_keys_via_location5  sÉ  € ð. ˆØ*ð 	8ñ 	8‰MˆH�càÔ!ð  c¨TÔ-?Ð&?Ð&?àØ×*Ò*¨3Ñ/Ô/ˆEÝ�DÔ(Ñ)Ô)ð ØÔ$ UÔ+¨AÔ.°#Ò5Ð5ØÔ% eÔ,¨QÔ/°3Ò6Ð6àÔ& uÔ-¨aÔ0°D´JÒ>Ð>ð à×+Ò+¨HÑ5Ô5ˆEÝ�DÔ)Ñ*Ô*ð ØÔ% eÔ,¨QÔ/°8Ò;Ð;ØÔ)¨%Ô0°Ô3°hÒ>Ð>àØˆFØ˜&Ñ  4¤:Ò-Ð-Øœ hÑ.�à˜ŠzˆzØ×#Ò# X¨vÐ$6Ñ7Ô7Ð7ùàÔÐ%Ø×Ò¥Ñ.Ô.Ð.Ø×Ò˜\Ñ*Ô*Ð*ØˆØŒ;Ð"ð "/ð 	Cð 	C‘�˜#Ø˜dœkÐ)Ð)Ø—M’M H¨c ?°EÐ":Ñ;Ô;Ð;Ð;ØÔ(ð CØ"&¤+¨cÔ"2‘K�E˜4Ø—M’M H¨c ?Ø$(¨#¨u°dÐ#;ð#=ñ >ô >ð >ð >ð —M’M H¨c ?Ø$(¨#¨t¬{¸3Ô/?Ð#@ð#Bñ Cô Cð Cð CàˆMð
  ÐÝ™EœEÐØ*ð '	8ñ '	8‰MˆH�cà�dÔ(Ð(Ð(àÔ&ð Jà"&Ô"4°SÔ"9‘K�E˜4Ø')Ð$Ø$(ð =ð =˜Ø#+ð =ð =˜CØ"¨$Ô*>Ð>Ð>Ø 0× 7Ò 7¸Ñ <Ô <Ð <øð=ð (ð !Ø)×0Ò0Ð1AÑBÔBÐBØ*×1Ò1°8¸S°/ÑBÔBÐBØ Ø—M’M H¨c ?°T¸3Ø5:¸D×<TÒ<TÐUYÑ<ZÔ<Zð5\ð #]ñ ^ô ^ð ^ð ^ð —M’M H¨c ?Ø$(¨#¨tÔ/AÀ#Ô/FÐ#Gð#Iñ Jô Jð Jàð ×.Ò.¨sÑ3Ô3�ØÔ(¨Ô/°Ô2°cÒ9Ð9ØÔ)¨%Ô0°Ô3°sÒ:Ð:àÔ*¨5Ô1°!Ô4¸¼
ÒBÐBØ—M’M H¨c ?°EÐ":Ñ;Ô;Ð;Ùð ×+Ò+¨HÑ5Ô5ˆEà�TÔ)¨%Ô0°Ô3Ò3Ð3Ø�	�	à�	Ø�MŠM˜H c˜?¨IÐ6Ñ7Ô7Ð7Ñ7Øˆà)ð 	8ð 	8ˆHØˆFØ˜&Ñ  4¤:Ò-Ð-Øœ hÑ.�ð ˜ŠzˆzØ×#Ò# X¨vÐ$6Ñ7Ô7Ð7øØ×Ò˜\Ñ*Ô*Ð*ØŒ;Ð"ð "4ð Kð K‘�˜#Ø"œk¨#Ô.‘��tØ—’ ¨#˜°°s¸EÀ4Ð0HÐIÑJÔJÐJÐJØˆMØ/ð 	Vð 	V‰MˆH�càÔ,¨SÔ1‰KˆE�4Ø�MŠM˜H c˜?¨T°3Ø-2°D×4LÒ4LÈTÑ4RÔ4Rð-Tð Uñ Vô Vð Vð Vàˆr   c                 óL  — |dt          |                      ¦   «         ¦  «        …         }||                      ¦   «         k    st          | j        t          ¦  «        ‚|t          |                      ¦   «         ¦  «        d…                              ¦   «         }|d         }|                     t          ¦  «        st          | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _
        n# t          $ r t          | ¦  «        ‚w xY w|d         }|                     t          ¦  «        st          | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n# t          $ r t          | ¦  «        ‚w xY w|d         }|                     t          ¦  «        st          | ¦  «        ‚	 t          |t          t          ¦  «        d…         ¦  «        | _        n# t          $ r t          | ¦  «        ‚w xY wt          |¦  «        t          |d         ¦  «        z   t          |d         ¦  «        z   t          |d         ¦  «        z   dz   }|                      dd|d¦  «         d| j        z   | _        i | _        i | _        |||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 length 0).
        r   Nr   r
   rU   r"   )rM   rÿ   r   r¾   r   Ú
splitlinesr  rŽ   r3   r  rì   r÷   r�   rF   r�   rÂ   Ú_parsed_bytesræ   rÃ   r¿   )r   rN   r  r•   r  Ú
header_ends         r   Ú_parse_header_from_bytesz#GraphIndex._parse_header_from_bytesÃ  s’  € ð ˜!�C §¢Ñ 1Ô 1Ñ2Ô2Ð2Ô3ˆ	Ø˜DŸOšOÑ-Ô-Ò-Ð-Ý)¨$¬*µjÑAÔAÐAØ•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øÝð 	(ð 	(ð 	(Ý! $Ñ'Ô'Ð'ð	(øøøõ ˜)‘n”n¥s¨5°¬8¡}¤}Ñ4µs¸5À¼8±}´}ÑDÝ˜% œ(‘m”mñ$Ø&'ñ(ˆ
à×Ò˜1˜b *¨bÑ1Ô1Ð1à"# dÔ&6Ñ"6ˆÔà!ˆÔàˆÔØ˜5   Ô-Ð-Ð-s$   Ã	.C8 Ã8DÅ.E6 Å6FÇ.G4 Ç4Hc                 óÈ   — |t          |¦  «        z   }|}	 |                      |¦  «        }|| j        |         d         k     rdS |                      ||||¦  «        \  }}|rdS ŒN)z�Parse node data returned from a readv operation.

        :param offset: The byte offset the data starts at.
        :param data: The data to parse.
        Tr   N)rM   r  rÀ   Ú_parse_segment)r   rÊ   Údatar  Úhigh_parsedr-   Úlast_segments          r   Ú_parse_regionzGraphIndex._parse_regionï  s‡   € ð •s˜4‘y”yÑ ˆØˆð	ð ×+Ò+¨KÑ8Ô8ˆEØ�TÔ*¨5Ô1°!Ô4Ò4Ð4Ø�ð )-×(;Ò(;Ø˜˜c 5ñ)*ô )*Ñ%ˆK˜àð Ø�ð	r   c           
      ó¢  — d}|| j         |         d         k     r| j         |         d         |z
  }d}n || j         |         d         k    rd}d}nd}d}|| j        k    rd}d}d}	n™|dz   t          | j         ¦  «        k    rd}d}d}	nw|| j         |dz            d         k    rd}d}d}	nV|| j         |dz            d         k    r6| j         |dz            d         |z
  }d}|| j         |dz            d         k     }	nd}d}d}	|sI|€|                     d¦  «        dz   }n|                     d|¦  «        dz   }|dk    st	          d¦  «        ‚|sJ|€|                     d¦  «        dz   }n|                     dd|¦  «        dz   }|dk    st	          d¦  «        ‚|||…         }
|
s&t	          d||||t          |¦  «        z   fz  ¦  «        ‚|r||z  }|
                     d¦  «        }|d	= |}|                      ||¦  «        \  }}}}|D ]\  }}|| j        |<   Œ|  	                    |||t          |
¦  «        z   |¦  «         |t          |
¦  «        z   |	fS )
aY  Parse one segment of data.

        :param offset: Where 'data' begins in the file.
        :param data: Some data to parse a segment of.
        :param end: Where data ends
        :param index: The current index into the parsed bytes map.
        :return: True if the parsed segment is the last possible one in the
            range of data.
        :return: high_parsed_byte, last_segment.
            high_parsed_byte is the location of the highest parsed byte in this
            segment, last_segment is True if the parsed segment is the last
            possible one in the data block.
        Nr   TFr   rŒ   zno 
 was presentz'read unneeded data [%d:%d] from [%d:%d]r^   )
rÀ   rÄ   rM   ÚfindÚAssertionErrorÚrfindrè   rê   r¿   r4  )r   rÊ   r9  r  r-   Útrim_endÚ
trim_startÚstart_adjacentÚend_adjacentr;  Útrimmed_datar•   rñ   Ú	first_keyÚlast_keyr˜   rµ   r,   r   s                      r   r8  zGraphIndex._parse_segment  s  € ð ˆà�DÔ)¨%Ô0°Ô3Ò3Ð3ð Ô.¨uÔ5°aÔ8¸6ÑAˆJà!ˆNˆNØ�tÔ,¨UÔ3°AÔ6Ò6Ð6ð ˆJà!ˆNˆNð ˆJà"ˆNØ�$”*ÒÐð ˆHàˆLØˆLˆLØ�Q‰Y�#˜dÔ3Ñ4Ô4Ò4Ð4ð ˆHà ˆLØˆLˆLØ�DÔ)¨%°!©)Ô4°QÔ7Ò7Ð7ð ˆHàˆLØˆLˆLØ�4Ô(¨°©Ô3°AÔ6Ò6Ð6ð Ô,¨U°Q©YÔ7¸Ô:¸VÑCˆHàˆLØ Ô!6°u¸q±yÔ!AÀ!Ô!DÒDˆLˆLð ˆHà ˆLØˆLàð 	:àÐ!Ø!ŸYšY uÑ-Ô-°Ñ1�
�
à!ŸYšY u¨jÑ9Ô9¸AÑ=�
Ø !’O�OÝ$Ð%8Ñ9Ô9Ð9àð 	:àÐØŸ:š: eÑ,Ô,¨qÑ0��àŸ:š: e¨T°8Ñ<Ô<¸qÑ@�Ø ’M�MÝ$Ð%8Ñ9Ô9Ð9ð ˜J xÐ/Ô0ˆØð 	WÝ Ð!JØ$.°¸&À&Í3ÈtÉ9Ì9ÑBTÐ#Uñ"Vñ Wô Wð Wàð 	!Ø�jÑ ˆFð ×"Ò" 5Ñ)Ô)ˆØ�"ˆIØˆØ(,×(9Ò(9¸%ÀÑ(EÔ(EÑ%ˆ	�8˜U AØð 	,ð 	,‰JˆC�Ø&+ˆDÔ˜sÑ#Ð#Ø×Ò˜6 9Ø!¥C¨Ñ$5Ô$5Ñ5°xñ	Aô 	Að 	Aà�˜LÑ)Ô)Ñ)¨<Ð7Ð7r   c           
      ó  — d }d }d}g }|D �]t}|dk    rC| j         r6| j         |dz   k    s(t          d                     | j         |¦  «        ¦  «        ‚|dz  }ŒL|                     d¦  «        }t	          |¦  «        | j        k    rt          | ¦  «        ‚t          d„ |d | j        …         D ¦   «         ¦  «        }|€|}|dd …         \  }	}
}g }|
                     d¦  «        D ]A}| 	                    t          d	„ |                     d
¦  «        D ¦   «         ¦  «        ¦  «         ŒBt          |¦  «        }||	||f| j
        |<   |t	          |¦  «        dz   z  }|	r�ŒO| j        r||f}n|}| 	                    ||f¦  «         �Œv||||fS )Nr   r   r   z{} {}rŠ   c                 ó   — g | ]}|‘ŒS r"   r"   r‡   s     r   rq   z+GraphIndex._parse_lines.<locals>.<listcomp>„  s   € ÐLÐLÐL W˜ÐLÐLÐLr   éýÿÿÿr‹   c                 ó0   — g | ]}|¯t          |¦  «        ‘ŒS r"   )r  )rn   ro   s     r   rq   z+GraphIndex._parse_lines.<locals>.<listcomp>Š  s3   € ð (ð (ð (Ø!$À3ð(Ý˜‘H”Hð(ð (ð (r   r‰   )rÄ   r?  rÛ   rè   rM   ræ   r$   rL   rF   rt   rÃ   rì   )r   r•   rñ   r,   rF  rð   r˜   ÚlineÚelementsrb   rc   r   r¶   Ú
ref_stringrò   s                  r   rê   zGraphIndex._parse_linesr  sð  € ØˆØˆ	ØˆØˆØð 	,ñ 	,ˆDØ�sŠ{ˆ{à”:ð NØ œJ¨#°©'Ò1Ð1Ý,¨W¯^ª^¸D¼JÈÑ-LÔ-LÑMÔMÐMØ˜A‘�ØØ—z’z %Ñ(Ô(ˆHÝ�8‰}Œ} Ô 7Ò7Ð7Ý" 4Ñ(Ô(Ð(õ ÐLÐL°Ð9J¸$Ô:JÐ9JÔ0KÐLÑLÔLÑMÔMˆCØÐ Ø�	Ø(0°°°¬Ñ%ˆF�J ØˆIØ(×.Ò.¨uÑ5Ô5ð ð �
Ø× Ò ¥ð (ð (Ø(2×(8Ò(8¸Ñ(?Ô(?ð(ñ (ô (ñ "ô "ñ ô ð ð õ ˜iÑ(Ô(ˆIØ),¨f°iÀÐ(GˆDÔ  Ñ%Ø•3�t‘9”9˜q‘=Ñ ˆCØð ÙØÔ"ð #Ø# YÐ/�
�
à"�
Ø�LŠL˜#˜zÐ*Ñ+Ô+Ð+Ñ+à˜#˜u hÐ.Ð.r   c                 ó`  — |                       |¦  «        }||f}||f}|dk    r8| j                             ||¦  «         | j                             ||¦  «         dS |dz   t	          | j        ¦  «        k     r«| j        |         d         |k    r”| j        |dz            d         |k    rz| j        |         d         | j        |dz            d         f| j        |<   | j        |         d         | j        |dz            d         f| j        |<   | j        |dz   = | j        |dz   = dS | j        |         d         |k    r<| j        |         d         |f| j        |<   | j        |         d         |f| j        |<   dS |dz   t	          | j        ¦  «        k     rb| j        |dz            d         |k    rH|| j        |dz            d         f| j        |dz   <   || j        |dz            d         f| j        |dz   <   dS | j                             |dz   |¦  «         | j                             |dz   |¦  «         dS )a  Mark the bytes from start to end as parsed.

        Calling self._parsed_bytes(1,2) will mark one byte (the one at offset
        1) as parsed.

        :param start: The start of the parsed region.
        :param end: The end of the parsed region.
        r^   Nr   r   )r  rÀ   ÚinsertrÁ   rM   )r   r  Ú	start_keyr  Úend_keyr-   Ú	new_valueÚnew_keys           r   r4  zGraphIndex._parsed_bytesš  s~  € ð ×'Ò'¨Ñ.Ô.ˆØ˜C�Lˆ	Ø˜gÐ&ˆØ�BŠ;ˆ;àÔ!×(Ò(¨°	Ñ:Ô:Ð:ØÔ ×'Ò'¨¨wÑ7Ô7Ð7ØˆFð �A‰I�˜DÔ1Ñ2Ô2Ò2Ð2ØÔ! %Ô(¨Ô+¨uÒ4Ð4ØÔ% e¨a¡iÔ0°Ô3°sÒ:Ð:à,0Ô,AÀ%Ô,HÈÔ,KØ,0Ô,AÀ%È!Á)Ô,LÈQÔ,Oð,QˆDÔ! %Ñ(à+/Ô+?ÀÔ+FÀqÔ+IØ+/Ô+?ÀÈÁ	Ô+JÈ1Ô+Mð+OˆDÔ  Ñ'àÔ% e¨a¡iÐ0ØÔ$ U¨Q¡YÐ/Ð/Ð/ØÔ" 5Ô)¨!Ô,°Ò5Ð5ð Ô% eÔ,¨QÔ/°ð,6ˆDÔ! %Ñ(ð Ô$ UÔ+¨AÔ.°ð+9ˆDÔ  Ñ'Ð'Ð'à�a‰i�#˜dÔ3Ñ4Ô4Ò4Ð4ØÔ# E¨A¡IÔ.¨qÔ1°SÒ8Ð8ð �tÔ,¨U°Q©YÔ7¸Ô:ð0<ˆDÔ! %¨!¡)Ñ,ð ˜4Ô/°¸±	Ô:¸1Ô=ð/?ˆDÔ  ¨¡Ñ+Ð+Ð+ð Ô!×(Ò(¨°©°IÑ>Ô>Ð>ØÔ ×'Ò'¨°©	°7Ñ;Ô;Ð;Ð;Ð;r   c                 ó–  ‡— |sdS | j         €)| j        dz  | j        k    r|                      ¦   «          dS | j        Š‰dk    rˆfd„|D ¦   «         }| j                             | j        |d| j        | j        z   ¦  «        }|D ]Æ\  }}|‰z  }| xj        t          |¦  «        z  c_        |dk     r|| d…         }d}|dk    r=t          |¦  «        | j        k    r%|                      t          |¦  «        ¦  «          dS | j
        €,|dk    st          ¦   «         ‚|                      |¦  «        \  }}|                      ||¦  «         ŒÇdS )zqRead the ranges and parse the resulting data.

        :param readv_ranges: A prepared readv range list.
        Nr
   r   c                 ó$   •— g | ]\  }}|‰z   |f‘ŒS r"   r"   )rn   r  rÈ   Úbase_offsets      €r   rq   z.GraphIndex._read_and_parse.<locals>.<listcomp>Ü  s7   ø€ ð =ð =ð =Ù +  tð # [Ñ0°$Ð7ð =ð =ð =r   T)rC   rÅ   rÄ   ró   rÆ   r½   Úreadvr¾   rM   r	   r¿   r?  r6  r<  )r   r+  Ú
readv_datarÊ   r9  rW  s        @r   r'  zGraphIndex._read_and_parseÌ  sž  ø€ ð
 ð 	ØˆFØŒ;Ð 4Ô#3°aÑ#7¸4¼:Ò#EÐ#Eð ×ÒÑÔÐØˆFàÔ'ˆØ˜!ÒÐð=ð =ð =ð =Ø/;ð=ñ =ô =ˆLà”_×*Ò*¨4¬:°|ÀTØ+/¬:¸Ô8IÑ+IñKô Kˆ
ð 'ð 	-ð 	-‰LˆF�DØ�kÑ!ˆFØÐÔ¥ D¡	¤	Ñ)ÐÔØ˜Šzˆzð ˜V˜G˜H˜H”~�Ø�Ø˜Š{ˆ{�s 4™yœy¨D¬JÒ6Ð6ð × Ò ¥¨¡¤Ñ/Ô/Ð/Ø��ØÔ!Ð)à !š˜Ý(Ñ*Ô*Ð*Ø#×<Ò<¸TÑBÔB‘�˜à×Ò˜v tÑ,Ô,Ð,Ð,ð)	-ð 	-r   c                 ó   — t           S )z'The file signature for this index type.)r�   r~   s    r   rÿ   zGraphIndex._signature÷  s   € åÐr   c                 ó4   — |                       ¦   «         D ]}ŒdS )ú6Validate that everything in the index can be accessed.N)rV   )r   rZ   s     r   ÚvalidatezGraphIndex.validateû  s,   € ð ×)Ò)Ñ+Ô+ð 	ð 	ˆDØð	ð 	r   )Fr   r   )$r   r   r    rº   r   rÏ   rÑ   rÖ   rÙ   rÞ   ró   r   rø   rf   rV   rå   rí   Ústaticmethodr	  r  r  r  r  r¯   r!  r%  r–   r  r6  r<  r8  rê   r4  r'  rÿ   r]  r"   r   r   r   r   ¯  s#  € € € € € ðð ð"$#ð $#ð $#ð $#ðL'ð 'ð 'ð&ð &ð &ð(ð (ð (ðKð Kð Kð@ð @ð @ð-%ð -%ð -%ð -%ð^ð ð ðð ð ð"ð "ð "ð$'ð 'ð 'ð*(ð (ð (ð4 ð  ð  ð  ðð ñ „\ðð<ð <ð <ðBð Bð Bð0ð 0ð 0ð,ð ,ð ,ðCð Cð Cð:&Bð &Bð &BðPð ð ð"ð ð ðLð Lð Lð\*.ð *.ð *.ðXð ð ð.j8ð j8ð j8ðX&/ð &/ð &/ðP0<ð 0<ð 0<ðd)-ð )-ð )-ðVð ð ðð ð ð ð r   r   c                   ó~   — e Zd ZdZdd„Zd„ Zd„ Zd„ ZeZ	dd„Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ ZeZd„ Zd„ Zd„ ZdS )r   aä  A GraphIndex made up from smaller GraphIndices.

    The backing indices must implement GraphIndex, and are presumed to be
    static data.

    Queries against the combined index will be made against the first index,
    and then the second and so on. The order of indices can thus influence
    performance significantly. For example, if one index is on local disk and a
    second on a remote server, the local disk index should be before the other
    in the index list.

    Also, queries tend to need results from the same indices as previous
    queries.  So the indices will be reordered after every query to put the
    indices that had the result(s) of that query first (while otherwise
    preserving the relative ordering).
    Nc                 ój   — || _         || _        g | _        dgt          | j         ¦  «        z  | _        dS )aN  Create a CombinedGraphIndex backed by indices.

        :param indices: An ordered list of indices to query for data.
        :param reload_func: A function to call if we find we are missing an
            index. Should have the form reload_func() => True/False to indicate
            if reloading actually changed anything.
        N)Ú_indicesÚ_reload_funcÚ_sibling_indicesrM   Ú_index_names)r   ÚindicesÚreload_funcs      r   r   zCombinedGraphIndex.__init__  s>   € ð  ˆŒØ'ˆÔð !#ˆÔð "˜F¥S¨¬Ñ%7Ô%7Ñ7ˆÔÐÐr   c           	      ó˜   — d                      | j        j        d                     t	          t
          | j        ¦  «        ¦  «        ¦  «        S )Nz{}({})z, )rÛ   rÜ   r   r“   ÚmapÚreprra  r~   s    r   rÞ   zCombinedGraphIndex.__repr__&  s;   € Ø�ŠØŒNÔ#Ø�IŠI•c�$ ¤Ñ.Ô.Ñ/Ô/ñ1ô 1ð 	1r   c                 óB   — | j         D ]}|                     ¦   «          ŒdS )zSee GraphIndex.clear_cache()N)ra  r   )r   r-   s     r   r   zCombinedGraphIndex.clear_cache+  s2   € à”]ð 	 ð 	 ˆEØ×ÒÑÔÐÐð	 ð 	 r   c                 ó  — t          |¦  «        }t          j        |v r.|                     t          j        ¦  «         t          j        g i}ni }|                      |¦  «        D ]#\  }}}}|d         }|st          j        f}|||<   Œ$|S )z/See graph.StackedParentsProvider.get_parent_mapr   )r<   Ú_mod_revisionÚNULL_REVISIONr{   r¯   )	r   r>   r$  Úfound_parentsr-   r,   r   rY   Úparentss	            r   r9   z!CombinedGraphIndex.get_parent_map0  s›   € å˜$‘i”iˆÝÔ&¨+Ð5Ð5Ø×Ò¥Ô ;Ñ<Ô<Ð<Ý*Ô8¸"Ð=ˆMˆMàˆMØ'+×'8Ò'8¸Ñ'EÔ'Eð 	)ð 	)Ñ#ˆE�3˜˜tØ˜1”gˆGØð 9Ý(Ô6Ð8�Ø!(ˆM˜#ÑÐØÐr   c                 ór   — | j                              ||¦  «         | j                             ||¦  «         dS )a†  Insert a new index in the list of indices to query.

        :param pos: The position to insert the index.
        :param index: The index to insert.
        :param name: a name for this index, e.g. a pack name.  These names can
            be used to reflect index reorderings to related CombinedGraphIndex
            instances that use the same names.  (see set_sibling_indices)
        N)ra  rP  rd  )r   rñ   r-   rÇ   s       r   Úinsert_indexzCombinedGraphIndex.insert_indexA  s;   € ð 	Œ×Ò˜S %Ñ(Ô(Ð(ØÔ× Ò   dÑ+Ô+Ð+Ð+Ð+r   c              #   ó$  K  — t          ¦   «         }	 	 | j        D ]B}|                     ¦   «         D ]+}|d         |vr|V — |                     |d         ¦  «         Œ,ŒCdS # t          j        $ r }|                      |¦  «        s‚ Y d}~nd}~ww xY wŒ€)an  Iterate over all keys within the index

        Duplicate keys across child indices are presumed to have the same
        value and are only reported once.

        :return: An iterable of (index, key, reference_lists, value).
            There is no defined order for the result iteration - it will be in
            the most efficient order for the index.
        Tr   N)r<   ra  rV   rW   Ú_mod_transportÚ
NoSuchFileÚ_try_reload)r   Ú	seen_keysr-   rZ   Úes        r   rV   z#CombinedGraphIndex.iter_all_entriesM  sÛ   è è € õ ‘E”Eˆ	ð
	ð	Ø!œ]ð 3ð 3�EØ %× 6Ò 6Ñ 8Ô 8ð 3ð 3˜Ø œ7¨)Ð3Ð3Ø"&˜J˜J˜JØ%ŸMšM¨$¨q¬'Ñ2Ô2Ð2øð3ð �øÝ!Ô,ð ð ð Ø×'Ò'¨Ñ*Ô*ð Øðð ð ð ð øøøøðøøøð
	s   “A
A ÁBÁ.B	Â	Bc              #   ó‚  K  — t          |¦  «        }g }	 	 | j        D ]X}|s nSd}|                     |¦  «        D ]#}|                     |d         ¦  «         |V — d}Œ$|r|                     |¦  «         ŒYn3# t
          j        $ r }|                      |¦  «        s‚ Y d}~nd}~ww xY wŒ•|                      |¦  «         dS )a°  Iterate over keys within the index.

        Duplicate keys across child indices are presumed to have the same
        value and are only reported once.

        :param keys: An iterable providing the keys to be retrieved.
        :return: An iterable of (index, key, reference_lists, value). There is
            no defined order for the result iteration - it will be in the most
            efficient order for the index.
        TFr   N)	r<   ra  r¯   Úremovert   rs  rt  ru  Ú_move_to_front)r   r>   Úhit_indicesr-   Ú	index_hitrZ   rw  s          r   r¯   zCombinedGraphIndex.iter_entriesd  s  è è € õ �4‰yŒyˆØˆð	ðØ!œ]ð 	2ð 	2�EØð Ø˜Ø %�IØ %× 2Ò 2°4Ñ 8Ô 8ð )ð )˜ØŸš D¨¤GÑ,Ô,Ð,Ø"˜
˜
˜
Ø$(˜	˜	Ø ð 2Ø#×*Ò*¨5Ñ1Ô1Ð1øØøÝ!Ô,ð ð ð Ø×'Ò'¨Ñ*Ô*ð Øðð ð ð ð øøøøðøøøð	ð  	×Ò˜KÑ(Ô(Ð(Ð(Ð(s   –A A7 Á7B&ÂB!Â!B&c              #   ó´  K  — t          |¦  «        }|sdS t          ¦   «         }g }	 	 | j        D ]_}d}|                     |¦  «        D ].}|d         |v rŒ|                     |d         ¦  «         |V — d}Œ/|r|                     |¦  «         Œ`n3# t
          j        $ r }|                      |¦  «        s‚ Y d}~nd}~ww xY wŒœ|                      |¦  «         dS )aá  Iterate over keys within the index using prefix matching.

        Duplicate keys across child indices are presumed to have the same
        value and are only reported once.

        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.
        NTFr   )	r<   ra  r!  rW   rt   rs  rt  ru  rz  )r   r>   rv  r{  r-   r|  rZ   rw  s           r   r!  z&CombinedGraphIndex.iter_entries_prefixƒ  s8  è è € õ( �4‰yŒyˆØð 	ØˆFÝ‘E”Eˆ	Øˆð	ðØ!œ]ð 	2ð 	2�EØ %�IØ %× 9Ò 9¸$Ñ ?Ô ?ð )ð )˜Ø œ7 iÐ/Ð/Ø$Ø!Ÿš d¨1¤gÑ.Ô.Ð.Ø"˜
˜
˜
Ø$(˜	˜	Ø ð 2Ø#×*Ò*¨5Ñ1Ô1Ð1øØøÝ!Ô,ð ð ð Ø×'Ò'¨Ñ*Ô*ð Øðð ð ð ð øøøøðøøøð	ð  	×Ò˜KÑ(Ô(Ð(Ð(Ð(s   ¨A'B ÂB?ÂB:Â:B?c                 ó²   — | j         dt          |¦  «        …         |k    rdS |                      |¦  «        }| j        D ]}|                     |¦  «         ŒdS )a±  Rearrange self._indices so that hit_indices are first.

        Order is maintained as much as possible, e.g. the first unhit index
        will be the first index in _indices after the hit_indices, and the
        hit_indices will be present in exactly the order they are passed to
        _move_to_front.

        _move_to_front propagates to all objects in self._sibling_indices by
        calling _move_to_front_by_name.
        N)ra  rM   Ú_move_to_front_by_indexrc  Ú_move_to_front_by_name)r   r{  Ú	hit_namesÚsibling_idxs       r   rz  z!CombinedGraphIndex._move_to_front®  sq   € ð Œ=Ð*�#˜kÑ*Ô*Ð*Ô+¨{Ò:Ð:ð ˆFØ×0Ò0°Ñ=Ô=ˆ	ØÔ0ð 	:ð 	:ˆKØ×.Ò.¨yÑ9Ô9Ð9Ð9ð	:ð 	:r   c                 óú  — t          | j        | j        ¦  «        }dt          j        v r+t          |¦  «        }t                               d||¦  «         g }g }g }g }t          |¦  «        D ]Í\  }\  }}	|	|v r—| 	                    |¦  «         | 	                    |	¦  «         t          |¦  «        t          |¦  «        k    rL|                     | j        |dz   d…         ¦  «         |                     | j        |dz   d…         ¦  «          n,Œ£| 	                    |¦  «         | 	                    |	¦  «         ŒÎ||z   | _        ||z   | _        dt          j        v r t                               d| j        ¦  «         |S )zpCore logic for _move_to_front.

        Returns a list of names corresponding to the hit_indices param.
        r-   z9CombinedGraphIndex reordering: currently %r, promoting %rr   Nz CombinedGraphIndex reordered: %r)Úziprd  ra  r   rà   Úlistrá   râ   Ú	enumeratert   rM   Úextend)
r   r{  Úindices_infor�  Úunhit_namesÚnew_hit_indicesÚunhit_indicesrÊ   rÇ   Úidxs
             r   r  z*CombinedGraphIndex._move_to_front_by_indexÁ  sœ  € õ
 ˜4Ô,¨d¬mÑ<Ô<ˆØ•eÔ'Ð'Ð'Ý Ñ-Ô-ˆLÝ�LŠLð (Ø)5°{ñDô Dð Dàˆ	ØˆØˆØˆå#,¨\Ñ#:Ô#:ð 	*ð 	*ÑˆF‘K�T˜3Ø�kÐ!Ð!Ø× Ò  Ñ&Ô&Ð&Ø×&Ò& sÑ+Ô+Ð+Ý�Ñ'Ô'­3¨{Ñ+;Ô+;Ò;Ð;ð  ×&Ò& tÔ'8¸À!¹¸¸Ô'EÑFÔFÐFØ!×(Ò(¨¬°vÀ±z°{°{Ô)CÑDÔDÐDØ�Eð <ð ×"Ò" 4Ñ(Ô(Ð(Ø×$Ò$ SÑ)Ô)Ð)Ð)à'¨-Ñ7ˆŒØ%¨Ñ3ˆÔØ•eÔ'Ð'Ð'Ý�LŠLÐ;¸T¼]ÑKÔKÐKØÐr   c                 óª   — t          | j        | j        ¦  «        }g }|D ]\  }}||v r|                     |¦  «         Œ|                      |¦  «         dS )zqMoves indices named by 'hit_names' to front of the search order, as
        described in _move_to_front.
        N)r„  rd  ra  rt   r  )r   r�  rˆ  r{  rÇ   rŒ  s         r   r€  z)CombinedGraphIndex._move_to_front_by_nameä  sj   € õ ˜4Ô,¨d¬mÑ<Ô<ˆØˆØ%ð 	(ð 	(‰IˆD�#Ø�yÐ Ð Ø×"Ò" 3Ñ'Ô'Ð'øØ×$Ò$ [Ñ1Ô1Ð1Ð1Ð1r   c                 óÞ  — t          ¦   «         }i }t          |¦  «        }d}|rÇ|dz  }d}t          | j        ¦  «        D ]e\  }}	t          ¦   «         }
|}d}|r|dz  }|	                     ||||
¦  «        }|°|
}|€t          |
¦  «        }n|                     |
¦  «         |s nŒf|€|                     |¦  «         d}n*|                     |¦  «         |                     |¦  «         |°Ç||fS )ae  Find the complete ancestry for the given set of keys.

        Note that this is a whole-ancestry request, so it should be used
        sparingly.

        :param keys: An iterable of keys to look for
        :param ref_list_num: The reference list which references the parents
            we care about.
        :return: (parent_map, missing_keys)
        r   r   N)r<   r†  ra  r%  Úintersection_updaterX   Údifference_update)r   r>   r±   r³   r®   Úkeys_to_lookupÚ
generationÚall_index_missingÚ	index_idxr-   Úindex_missing_keysr$  Úsub_generations                r   r¸   z CombinedGraphIndex.find_ancestryñ  s`  € õ ‘u”uˆØˆ
Ý˜T™œˆØˆ
Øð -	Dà˜!‰OˆJØ $Ðõ
 %.¨d¬mÑ$<Ô$<ð ð Ñ �	˜5õ &)¡U¤UÐ"ð -�Ø!"�ð "ð fØ" aÑ'�Nð #(×"7Ò"7¸Ø8DÀjÐRdñ#fô #f�Kð "ð fð "4�Ø$Ð,Ý(+Ð,>Ñ(?Ô(?Ð%Ð%à%×9Ò9Ð:LÑMÔMÐMØ%ð Ø�Eðà Ð(à×#Ò# NÑ3Ô3Ð3Ø!%��à×#Ò#Ð$5Ñ6Ô6Ð6Ø×0Ò0Ð1BÑCÔCÐCð[ ð -	Dð\ ˜<Ð'Ð'r   c                 óª   — 	 	 t          d„ | j        D ¦   «         d¦  «        S # t          j        $ r }|                      |¦  «        s‚ Y d}~nd}~ww xY wŒS)aG  Return an estimate of the number of keys in this index.

        For CombinedGraphIndex this is approximated by the sum of the keys of
        the child indices. As child indices may have duplicate keys this can
        have a maximum error of the number of child indices * largest number of
        keys in any index.
        Tc              3   ó>   K  — | ]}|                      ¦   «         V — Œd S r   )r–   )rn   r-   s     r   r…   z/CombinedGraphIndex.key_count.<locals>.<genexpr>;  s,   è è € ÐIÐI°%˜EŸOšOÑ-Ô-ÐIÐIÐIÐIÐIÐIr   r   N)r‘   ra  rs  rt  ru  )r   rw  s     r   r–   zCombinedGraphIndex.key_count1  s†   € ð	ðÝÐIÐI¸4¼=ÐIÑIÔIÈ1ÑMÔMÐMøÝ!Ô,ð ð ð Ø×'Ò'¨Ñ*Ô*ð Øðð ð ð ð øøøøðøøøð	s   ƒ" ¢A±AÁAc                 óÈ   — | j         €dS t                               dt          |¦  «        ¦  «         |                       ¦   «         st                               d¦  «         dS dS )z‡We just got a NoSuchFile exception.

        Try to reload the indices, if it fails, just raise the current
        exception.
        NFz,Trying to reload after getting exception: %szG_reload_func indicated nothing has changed. Raising original exception.T)rb  rá   râ   Ústr)r   Úerrors     r   ru  zCombinedGraphIndex._try_reloadB  so   € ð ÔÐ$Ø�5Ý�ŠØ:½CÀ¹J¼Jñ	Hô 	Hð 	Hà× Ò Ñ"Ô"ð 	å�LŠLð 8ñ 9ô 9ð 9à�5Øˆtr   c                 ó   — || _         dS )zMSet the CombinedGraphIndex objects to reorder after reordering self.
        N)rc  )r   Úsibling_combined_graph_indicess     r   Úset_sibling_indicesz&CombinedGraphIndex.set_sibling_indicesS  s   € ð !?ˆÔÐÐr   c                 ó¬   — 	 	 | j         D ]}|                     ¦   «          ŒdS # t          j        $ r }|                      |¦  «        s‚ Y d}~nd}~ww xY wŒT)r\  TN)ra  r]  rs  rt  ru  )r   r-   rw  s      r   r]  zCombinedGraphIndex.validateX  sŽ   € ð	ðØ!œ]ð %ð %�EØ—N’NÑ$Ô$Ð$Ð$Ø�øÝ!Ô,ð ð ð Ø×'Ò'¨Ñ*Ô*ð Øðð ð ð ð øøøøðøøøð	s   ƒ# £A²AÁAr   )r   r   r    rº   r   rÞ   r   r9   r:   Ú__contains__rq  rV   r¯   r!  rz  r  r€  r¸   r–   r?   r³   ru  rž  r]  r"   r   r   r   r     s)  € € € € € ðð ð"8ð 8ð 8ð 8ð$1ð 1ð 1ð
 ð  ð  ð
ð ð ð ,€Lð
,ð 
,ð 
,ð 
,ðð ð ð.)ð )ð )ð>))ð ))ð ))ðV:ð :ð :ð&!ð !ð !ðF2ð 2ð 2ð>(ð >(ð >(ð@ð ð ð 1€Lðð ð ð"?ð ?ð ?ð
	ð 	ð 	ð 	ð 	r   r   c                   ó<   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	S )
r   a  A GraphIndex which operates entirely out of memory and is mutable.

    This is designed to allow the accumulation of GraphIndex entries during a
    single write operation, where the accumulated entries need to be immediately
    available - for example via a CombinedGraphIndex.
    c                 ó”   — | j         r"|D ]\  }}}|                      |||¦  «         ŒdS |D ]\  }}|                      ||¦  «         ŒdS )únAdd nodes to the index.

        :param nodes: An iterable of (key, node_refs, value) entries to add.
        N)rB   r|   )r   r˜   r,   r   rh   s        r   Ú	add_nodeszInMemoryGraphIndex.add_nodesl  s~   € ð
 Ôð 	*Ø+0ð 5ð 5Ñ'��e˜YØ—’˜c 5¨)Ñ4Ô4Ð4Ð4ð5ð 5ð !&ð *ð *‘��eØ—’˜c 5Ñ)Ô)Ð)Ð)ð*ð *r   c              #   ó   K  — dt           j        v rt                               dd¦  «         | j        r/| j                             ¦   «         D ]\  }\  }}}|s| |||fV — ŒdS | j                             ¦   «         D ]\  }\  }}}|s| ||fV — ŒdS )a  Iterate over all keys within the index

        :return: An iterable of (index, key, reference_lists, value). 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).
        rû   rU   rü   N)r   rà   rá   rý   rB   rC   r_   )r   r,   rb   rc   r   s        r   rV   z#InMemoryGraphIndex.iter_all_entriesx  sã   è è € ð •UÔ&Ð&Ð&Ý×!Ò! !Ø"QñSô Sð SàÔð 	+Ø48´K×4EÒ4EÑ4GÔ4Gð 7ð 7Ñ0�Ñ0�f˜j¨%Øð 7Ø  U¨JÐ6Ð6Ð6Ð6øð7ð 7ð 59´K×4EÒ4EÑ4GÔ4Gð +ð +Ñ0�Ñ0�f˜j¨%Øð +Ø  UÐ*Ð*Ð*Ð*øð+ð +r   c              #   óÞ   ‡K  — | j         Šˆfd„|D ¦   «         }| j        r+|D ]&}‰|         }|d         s| ||d         |d         fV — Œ'dS |D ]}‰|         }|d         s| ||d         fV — Œ dS )á_  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  s     €r   rq   z3InMemoryGraphIndex.iter_entries.<locals>.<listcomp>–  r  r   r   r
   r   N)rC   rB   )r   r>   r,   rZ   r˜   s       @r   r¯   zInMemoryGraphIndex.iter_entries‹  sÈ   øè è € ð ”ˆØ4Ð4Ð4Ð4˜tÐ4Ñ4Ô4ˆØÔð 		-Øð 6ð 6�Ø˜S”z�Ø˜A”wð 6Ø  T¨!¤W¨d°1¬gÐ5Ð5Ð5Ð5øð6ð 6ð
 ð -ð -�Ø˜S”z�Ø˜A”wð -Ø  T¨!¤WÐ,Ð,Ð,Ð,øð-ð -r   c              #   óH  K  — t          |¦  «        }|sdS | j        dk    rV|D ]Q}t          | |¦  «         | j        |         }|d         rŒ(| j        r| ||d         |d         fV — ŒD| ||d         fV — ŒRdS |                      ¦   «         }t          | ||¦  «        E d{V —† dS )ál  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
   )r<   rF   r  rC   rB   rf   r   )r   r>   r,   rZ   ra   s        r   r!  z&InMemoryGraphIndex.iter_entries_prefix¢  sí   è è € õ" �4‰yŒyˆØð 	ØˆFØÔ˜qÒ Ð Øð -ð -�Ý! $¨Ñ,Ô,Ð,Ø”{ 3Ô'�Ø˜”7ð ØØÔ'ð -Ø  T¨!¤W¨d°1¬gÐ5Ð5Ð5Ð5Ð5à  T¨!¤WÐ,Ð,Ð,Ð,Ð,ØˆFØ×-Ò-Ñ/Ô/ˆÝ'¨¨l¸DÑAÔAÐAÐAÐAÐAÐAÐAÐAÐAÐAr   c                 óT   — t          | j        ¦  «        t          | j        ¦  «        z
  S )zwReturn an estimate of the number of keys in this index.

        For InMemoryGraphIndex the estimate is exact.
        )rM   rC   rD   r~   s    r   r–   zInMemoryGraphIndex.key_countÄ  s$   € õ
 �4”;ÑÔ¥# dÔ&7Ñ"8Ô"8Ñ8Ð8r   c                 ó   — dS )z9In memory index's have no known corruption at the moment.Nr"   r~   s    r   r]  zInMemoryGraphIndex.validateË  r€   r   c                 ó´   — t          |t          ¦  «        s$t          |t          ¦  «        st          |¦  «        ‚t	          | ¦  «        t	          |¦  «        k     S r   rÓ   rÍ   s     r   rÖ   zInMemoryGraphIndex.__lt__Î  r×   r   N)r   r   r    rº   r¤  rV   r¯   r!  r–   r]  rÖ   r"   r   r   r   r   d  sŽ   € € € € € ðð ð
*ð 
*ð 
*ð+ð +ð +ð&-ð -ð -ð. Bð  Bð  BðD9ð 9ð 9ðHð Hð Hð(ð (ð (ð (ð (r   r   c                   óN   — e Zd ZdZ	 dd„Zd„ Zdd„Zd„ Zd„ Zd	„ Z	d
„ Z
d„ Zd„ ZdS )r   a³  An adapter between GraphIndex with different key lengths.

    Queries against this will emit queries against the adapted Graph with the
    prefix added, queries for all items use iter_entries_prefix. The returned
    nodes will have their keys and node references adjusted to remove the
    prefix. Finally, an add_nodes_callback can be supplied - when called the
    nodes and references being added will have prefix prepended.
    Nc                 ór   — || _         |d|z  z   | _        || _        t          |¦  «        | _        || _        dS )z1Construct an adapter against adapted with prefix.r   N)ÚadaptedÚ
prefix_keyÚprefixrM   Ú
prefix_lenÚadd_nodes_callback)r   r°  r²  Úmissing_key_lengthr´  s        r   r   z GraphIndexPrefixAdapter.__init__à  s?   € ð ˆŒØ  7Ð-?Ñ#?Ñ?ˆŒØˆŒÝ˜f™+œ+ˆŒØ"4ˆÔÐÐr   c                 óN  ‡ — t          |¦  «        }g }	 |D ]A\  }}}t          ˆ fd„|D ¦   «         ¦  «        }|                     ‰ j        |z   ||f¦  «         ŒBn7# t          $ r* |D ]$\  }}|                     ‰ j        |z   |f¦  «         Œ%Y nw xY w‰                      |¦  «         dS )r£  c              3   óN   •K  — | ]}t          ˆfd „|D ¦   «         ¦  «        V — Œ dS )c              3   ó,   •K  — | ]}‰j         |z   V — Œd S r   ©r²  ©rn   Úref_noder   s     €r   r…   z>GraphIndexPrefixAdapter.add_nodes.<locals>.<genexpr>.<genexpr>ö  s*   øè è € ÐPÐP¸8 ¤¨hÑ 6ÐPÐPÐPÐPÐPÐPr   N©rL   ©rn   r�   r   s     €r   r…   z4GraphIndexPrefixAdapter.add_nodes.<locals>.<genexpr>ö  sT   øè è € ð 5ð 5Ø&õ  ÐPÐPÐPÐPÀxÐPÑPÔPÑPÔPð 5ð 5ð 5ð 5ð 5ð 5r   N)rL   rt   r²  r÷   r´  )r   r˜   Útranslated_nodesr,   r   rh   Úadjusted_referencess   `      r   r¤  z!GraphIndexPrefixAdapter.add_nodesé  s'  ø€ õ �e‘”ˆØÐð	Dð ,1ð ?ð ?Ñ'��e˜Yåð 5ð 5ð 5ð 5Ø*3ð5ñ 5ô 5ñ 5ô 5ð $ð !×'Ò'¨¬°sÑ):¸EØ)<ð)>ñ ?ô ?ð ?ð ?ð	?øõ ð 	Dð 	Dð 	Dð !&ð Dð D‘��eØ ×'Ò'¨¬°sÑ):¸EÐ(BÑCÔCÐCÐCðDð Dð		Døøøð 	×ÒÐ 0Ñ1Ô1Ð1Ð1Ð1s   ”AA Á1BÂBr"   c                 ó8   — |                       |||ff¦  «         dS )a¾  Add a node to the index.

        :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   or 
.
        N)r¤  )r   r,   r   rc   s       r   r|   z GraphIndexPrefixAdapter.add_node  s&   € ð 	�Š˜˜e ZÐ0Ð3Ñ4Ô4Ð4Ð4Ð4r   c           	   #   ój  ‡ K  — |D ]¬}|d         d‰ j         …         ‰ j        k    rt          ‰ ¦  «        ‚|d         D ].}|D ])}|d‰ j         …         ‰ j        k    rt          ‰ ¦  «        ‚Œ*Œ/|d         |d         ‰ j         d…         |d         t          ˆ fd„|d         D ¦   «         ¦  «        fV — Œ­dS )z+Strip prefix data from nodes and return it.r   NrU   r   r
   c              3   óN   •K  — | ]}t          ˆfd „|D ¦   «         ¦  «        V — Œ dS )c              3   ó6   •K  — | ]}|‰j         d …         V — Œd S r   )r³  rº  s     €r   r…   zBGraphIndexPrefixAdapter._strip_prefix.<locals>.<genexpr>.<genexpr>  s0   øè è € ÐPÐP¸8˜H T¤_Ð%5Ð%5Ô6ÐPÐPÐPÐPÐPÐPr   Nr¼  r½  s     €r   r…   z8GraphIndexPrefixAdapter._strip_prefix.<locals>.<genexpr>  sT   øè è € ð /ð /Ø"õ ÐPÐPÐPÐPÀxÐPÑPÔPÑPÔPð /ð /ð /ð /ð /ð /r   )r³  r²  r$   rL   )r   Úan_iterrZ   r�   r»  s   `    r   Ú_strip_prefixz%GraphIndexPrefixAdapter._strip_prefix  s  øè è € àð 
	0ð 
	0ˆDà�AŒwÐ'˜œÐ'Ô(¨D¬KÒ7Ð7Ý" 4Ñ(Ô(Ð(Ø  œGð 1ð 1�Ø (ð 1ð 1�HØÐ 0 ¤Ð 0Ô1°T´[Ò@Ð@Ý*¨4Ñ0Ô0Ð0ð Að1ð �q”'˜4 œ7 4¤?Ð#3Ð#3Ô4°d¸1´gÝð /ð /ð /ð /Ø&*¨1¤gð/ñ /ô /ñ /ô /ð0ð 0ð 0ð 0ð 0ð
	0ð 
	0r   c                 óh   — |                       | j                             | j        g¦  «        ¦  «        S )a„  Iterate over all keys within the index

        iter_all_entries is implemented against the adapted index using
        iter_entries_prefix.

        :return: An iterable of (index, key, reference_lists, value). 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).
        )rÅ  r°  r!  r±  r~   s    r   rV   z(GraphIndexPrefixAdapter.iter_all_entries  s-   € ð ×!Ò! $¤,×"BÒ"BÀDÄOÐCTÑ"UÔ"UÑVÔVÐVr   c                 óv   ‡ — ‰                       ‰ j                             ˆ fd„|D ¦   «         ¦  «        ¦  «        S )r§  c              3   ó,   •K  — | ]}‰j         |z   V — Œd S r   r¹  ©rn   r,   r   s     €r   r…   z7GraphIndexPrefixAdapter.iter_entries.<locals>.<genexpr>1  s;   øè è € ð </ð </Ø"%ˆDŒK˜#Ñð</ð </ð </ð </ð </ð </r   )rÅ  r°  r¯   r=   s   ` r   r¯   z$GraphIndexPrefixAdapter.iter_entries)  sW   ø€ ð ×!Ò! $¤,×";Ò";ð </ð </ð </ð </Ø)-ð</ñ </ô </ñ #/ô #/ñ 0ô 0ð 	0r   c                 óv   ‡ — ‰                       ‰ j                             ˆ fd„|D ¦   «         ¦  «        ¦  «        S )rª  c              3   ó,   •K  — | ]}‰j         |z   V — Œd S r   r¹  rÉ  s     €r   r…   z>GraphIndexPrefixAdapter.iter_entries_prefix.<locals>.<genexpr>E  sC   øè è € ð C/ð C/Ø"%ˆDŒK˜#ÑðC/ð C/ð C/ð C/ð C/ð C/r   )rÅ  r°  r!  r=   s   ` r   r!  z+GraphIndexPrefixAdapter.iter_entries_prefix4  s^   ø€ ð" ×!Ò! $¤,×"BÒ"Bð C/ð C/ð C/ð C/Ø)-ðC/ñ C/ô C/ñ #/ô #/ñ 0ô 0ð 	0r   c                 ó^   — t          t          |                      ¦   «         ¦  «        ¦  «        S )z³Return an estimate of the number of keys in this index.

        For GraphIndexPrefixAdapter this is relatively expensive - key
        iteration with the prefix is done.
        )rM   r…  rV   r~   s    r   r–   z!GraphIndexPrefixAdapter.key_countH  s&   € õ •4˜×-Ò-Ñ/Ô/Ñ0Ô0Ñ1Ô1Ð1r   c                 ó8   — | j                              ¦   «          dS )zCall the adapted's validate.N)r°  r]  r~   s    r   r]  z GraphIndexPrefixAdapter.validateP  s   € àŒ×ÒÑÔÐÐÐr   r   r¹   )r   r   r    rº   r   r¤  r|   rÅ  rV   r¯   r!  r–   r]  r"   r   r   r   r   Ö  s·   € € € € € ðð ð %)ð5ð 5ð 5ð 5ð2ð 2ð 2ð25ð 5ð 5ð 5ð0ð 0ð 0ð
Wð 
Wð 
Wð	0ð 	0ð 	0ð0ð 0ð 0ð(2ð 2ð 2ð ð  ð  ð  ð  r   r   c                 ó‚   — |d         €t          |¦  «        ‚t          |¦  «        | j        k    rt          |¦  «        ‚dS )z<Raise BadIndexKey if key cannot be used for prefix matching.r   N)r/   rM   rF   )Úindex_or_builderr,   s     r   r  r  U  sD   € à
ˆ1„v€~Ý˜#ÑÔÐÝ
ˆ3�x„xÐ#Ô/Ò/Ð/Ý˜#ÑÔÐð 0Ð/r   c              #   óT  K  — |D �]!}t          | |¦  «         |}t          |¦  «        }	 t          |¦  «        rB|d         �:||d                  }|                     d¦  «         t          |¦  «        r|d         ­:n# t          $ r Y Œƒw xY wt          |¦  «        rƒ|g}|r||                     ¦   «                              ¦   «         }t          t          |¦  «        ¦  «        }t          |t          ¦  «        r| 
                    |¦  «         n|D ]
}| f|z   V — Œ|°|�Œ| f|z   V — �Œ#dS )z2Helper for implementing prefix matching iterators.r   N)r  r…  rM   ÚpopÚKeyErrorrë   ÚnextÚiterrÌ   Údictr‡  )	rÏ  ra   r>   r,   rd   rM  ÚdictsÚvalues_viewr   s	            r   r   r   ]  sw  è è € àð 2ñ 2ˆÝÐ*¨CÑ0Ô0Ð0àˆÝ˜‘9”9ˆð	Ý�h‘-”-ð   H¨Q¤KÐ$;Ø# H¨Q¤KÔ0�Ø—’˜Q‘”�õ �h‘-”-ð   H¨Q¤KÐ$;øøõ ð 	ð 	ð 	àˆHð	øøøõ ˆx‰=Œ=ð 	2Ø�JˆEØð ;Ø#Ÿiši™kœk×0Ò0Ñ2Ô2�å�T +Ñ.Ô.Ñ/Ô/�Ý˜e¥TÑ*Ô*ð ;à—L’L Ñ-Ô-Ð-Ð-ð "-ð ;ð ;˜ð  0Ð2°UÑ:Ð:Ð:Ð:Ð:ð ð ;ùð $Ð&¨Ñ1Ð1Ð1Ð1Ñ1ð=2ð 2s   ªAA<Á<
B	ÂB	)(rº   Ú__all__Úbisectr   Úior	   Úrer   ÚglobalsÚ r   r   r   rs  Ústatic_tupler   r(  r�   r�   rŽ   r�   r   r   r$   r*   r/   r3   r6   ÚcompilerO   rs   r:   r?   r   r   r   r   r   r  r   r"   r   r   ú<module>rà     sM  ðð" Ð ðð ð €ð  Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 	€	€	€	à %Ð %Ð %Ð %Ð %Ð %Ø €ˆGˆG‰IŒIð ñ ô ð ðð ð ð ð ð ð ð ð ð ð
 &Ð %Ð %Ð %Ð %Ð %à€Ø'Ð Ø€Ø&Ð Ø&€
ðð ð ð ð ˜fœoñ ô ð ðð ð ð ð �6”?ñ ô ð ðð ð ð ð ˜6œ?ñ ô ð ðð ð ð ð �&”/ñ ô ð ðð ð ð ð �f”oñ ô ð ðð ð ð ð �F”Oñ ô ð ð �”Ð4Ñ5Ô5€Ø�2”:˜iÑ(Ô(Ð ð/ð /ð /ð6ð 6ð 6ðn(ð n(ð n(ð n(ð n(ñ n(ô n(ð n(ðb	Pð Pð Pð Pð Pñ Pô Pð Pðf_ð _ð _ð _ð _ñ _ô _ð _ðDo(ð o(ð o(ð o(ð o(Ð*ñ o(ô o(ð o(ðd| ð | ð | ð | ð | ñ | ô | ð | ð~ð ð ð 2ð  2ð  2ð  2ð  2r   