-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyc


Qc@@sdZddlmZddlZddlmZeedddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZddlmZmZmZdZd	Zd
ZdZdZd
ZdZdZdefdYZdefdYZ defdYZ!dej"fdYZ#de$fdYZ%defdYZ&defdYZ'e%Z(yddlm)Z*e*j+Z(Wn0e,k
rZ-ej.e-ddlm/Z*nXdS( sB+Tree indicesi(tabsolute_importN(tlazy_imports7
import bisect
import math
import tempfile
import zlib
(
tchunk_writertdebugterrorst
fifo_cachetindext	lru_cachetosutilststatic_tuplettracet	transport(t_OPTION_NODE_REFSt_OPTION_KEY_ELEMENTSt_OPTION_LENsB+Tree Graph Index 2
srow_lengths=s
type=leaf
stype=internal
soffset=ixiit_BuilderRowcB@s#eZdZdZedZRS(sThe 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.
    cC@sd|_d|_d|_dS(sCreate a _BuilderRow.iN(tnodestNonetspooltwriter(tself((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt__init__Ds		cC@s$|jj\}}}|jdkrMtj|_|jjdtnC|jdkrtj	dd}|j|jj
||_nd}|r|r|d=|}n|jj||jj|t
}|dkrtd|jj|fn|jd7_d|_dS(Nititprefixsbzr-index-row-isincorrect node length: %d, %d(RtfinishRt	cStringIOtStringIORtwritet_RESERVED_HEADER_BYTESttempfilet
TemporaryFiletgetvaluet
writelinesttellt
_PAGE_SIZEtAssertionErrorR(Rtpadt
byte_linest_tpaddingRt
skipped_bytest	remainder((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pytfinish_nodeJs&
	(t__name__t
__module__t__doc__RtTrueR*(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR<s	t_InternalBuilderRowcB@seZdZedZRS(s=The stored state accumulated while writing out internal rows.cC@s&|stdntj|dS(NsMust pad internal nodes only.(R#RR*(RR$((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR*es(R+R,R-R.R*(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR/bst_LeafBuilderRowcB@seZdZRS(s;The stored state accumulated while writing out a leaf rows.(R+R,R-(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR0kstBTreeBuildercB@seZdZddddZddZdZdZdZd	Zd
Z	dZ
edZed
Z
dZdZdZdZdZdZdZRS(s)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
    iiicC@sMtjj|d|d|||_g|_i|_d|_t|_	dS(sSee GraphIndexBuilder.__init__.

        :param spill_at: Optional parameter controlling the maximum number
            of nodes that BTreeBuilder will hold in memory.
        treference_liststkey_elementsN(
RtGraphIndexBuilderRt	_spill_att_backing_indicest_nodesRt
_nodes_by_keytFalset_optimize_for_size(RR2R3tspill_at((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs				cC@stjj|j}|j|||\}}||jkrWtj||ntj|||j|<|jdk	r|j
dkr|j|||nt|j|j
krdS|jdS(s9Add 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.
        iN(R	tStaticTuplet
from_sequencetinternt_check_key_ref_valueR7RtBadIndexDuplicateKeyR8Rt_key_lengtht_update_nodes_by_keytlenR5t_spill_mem_keys_to_disk(Rtkeytvaluet
referencest	node_refsR&((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pytadd_nodescC@s|jr!|j\}}}n|j\}}ttjdd|}||_|jrt|j|kr|jj	dn||j|<x4t|D]}d|j|<qWn|jj	|i|_d|_
dS(sWrite 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.
        t.s<temp>N(t_combine_backing_indicest_spill_mem_keys_and_combinet!_spill_mem_keys_without_combiningtBTreeGraphIndexRtget_transport_from_patht_fileRCR6tappendRtrangeR7R8(Rtnew_backing_filetsizetbacking_postnew_backing((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRDs
			
	cC@s|j|jdtS(Ntallow_optimize(t_write_nodest_iter_mem_nodesR9(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRMscC@s|jg}d}xJt|jD]9\}}|dkrK|d8}Pn|j|jq%W|d}|j|j|dt\}}|||fS(NiiRW(	RYt	enumerateR6RRQtiter_all_entriesRXt_iter_smallestR9(Rtiterators_to_combinetpostbackingRURSRT((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRLs

cC@sd|jr9xT|D]"\}}}|j|||qWn'x$|D]\}}|j||q@WdS(snAdd nodes to the index.

        :param nodes: An iterable of (key, node_refs, value) entries to add.
        N(R2RI(RRRERFRH((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt	add_nodess
	cc@s|j}|jrMxmt|D]'}||\}}||||fVqWn5x2t|D]$}||\}}|||fVqZWdS(s&Iterate over the nodes held in memory.N(R7R2tsorted(RRRERGRF((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRYs		c
c@st|dkr0x|dD]}|VqWdSg}xF|D]>}y|j|jWq=tk
rz|jdq=Xq=Wd}xtrgt|D]*}|ddk	r|dd|f^q}t|sdSt|}|d}||ddkrtj	||n|dd}|f|ddV|d}	y||	j||	<Wqtk
r{d||	<qXqWdS(Nii(
RCRQtnextt
StopIterationRR.RZtminRR@(
RR]RFtcurrent_valuestiteratortlasttitemt
candidatestselectedR^((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR\s6	

	:


cC@st}|djd	kr<t}xt|d D]\}}|jd	kr0t}|jdkrm|t8}n|r|j}	nt}	t	j
|dd|	|_|jjt|jjt
t||djdq0q0Wt}|djdkr|t8}nt	j
|d|j|d_|djjtn|djj|r|rjtj|n|dj|d}
t}x>t|d D],}|jj|
r|jqt}PqW|r{dtjkrtjdnt}d}
|jd|t	j
tt|
d|j|_|jjt|jjt
t|djdd|jj|
n|j|||d|nd	S(
sDAdd 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.
        iitoptimize_for_sizeis
RsInserting new global row.RWN(R9RRR.RZR"RRR:RtChunkWriterRt_INTERNAL_FLAGt_INTERNAL_OFFSETtstrt
_LEAF_FLAGRtBadIndexKeyR*treversedRtdebug_flagsR
tmutterR/tinsertt_add_key(Rt
string_keytlinetrowsRWtnew_leafR^tinternal_rowtlengthRktkey_linetnew_rowtrowtreserved_bytes((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRv"s`	
	'


		 cC@sg}d}g|_xk|D]c}|dkrA|jtn|d7}tj||j\}}|j|||d|qWx6t|D](}t|tk}	|j	d|	qWt
g}
|
jtt|jd|
jt
t|jd|
jtt|dg|D]}|j^q#}|
jtdjtt|d|r|ddkrtjdd	}ntj}|j|
ttt|
}
t}|
tkrtd
|
tfnx|D]}t}|jj|jj d|jj!t"}|j#||t|t"kr`|j#d||
nd}
t$j%|j|}||jdt"krt|tkrtd|jdt"|fqqqW|j|j&}|j d||fS(
sWrite 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.
        iiRWR$s
t,iRs
bzr-index-s7Could not fit the header in the reserved space: %d > %dRs5Incorrect amount of data copied expected: %d, got: %d('trow_lengthsRQR0t_btree_serializert
_flatten_nodeR2RvRrttypeR*t_BTSIGNATURERRoR
RARRt_OPTION_ROW_LENGTHStjointmapRtNamedTemporaryFileRRR tsumRCR.RR#RtflushtseektreadR"RRtpumpfileR!(Rt
node_iteratorRWRyt	key_counttnodeRwRxRR$tlinesRtresulttpositiontroot_rowtreservedt
copied_lenRT((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRXns^
	

		'




cC@s|j|jdS(sFinalise the index.

        :return: A file handle for a temporary file containing the nodes added
            to the index.
        i(RXR[(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRscC@sdtjkr"tjddn|jg}x3|jD](}|dk	r;|j|jq;q;Wt	|dkr|dS|j
|S(sIterate 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).
        tevilis-iter_all_entries scales with size of history.iiN(RRsR
tmutter_callsiteRYR6RRQR[RCR\(Rt	iteratorsR_((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR[s	
cc@s0t|}|j}g|D]}||kr|^q}|jrzxa|D])}||}|||d|dfVqJWn-x*|D]"}||}|||dfVqW|jsdS|j|xh|jD]]}|dkrqn|sdSx8|j|D]'}|j|d|f|dVqWqWdS(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).
        iiN(tsetR7R2R6tdifference_updateRtiter_entriestremove(RtkeysRREt
local_keysRR_((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs*	%	

 

	
c
c@st|}|sdSxM|jD]B}|dkr8q nx'|j|D]}|f|dVqHWq W|jdkr2x|D]}|ddkrtj|nt||jkrtj|ny|j|}Wnt	k
rq|nX|j
r|||d|dfVq||||dfVq|WdSxq|D]i}|ddkratj|nt||jkrtj|n|j}t|}yBx;t|r|ddk	r||d}|j
dqWWnt	k
rq9nXt|r|g}x|r|j
d}|jj\}}	t|	tkrf|j|jqx&|jD]}	|ft|	VqsWqWq9|f|Vq9WdS(slIterate 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.
        Niii(RR6Rtiter_entries_prefixRARRqRCR7tKeyErrorR2t_get_nodes_by_keytlisttpopt	iteritemsRbRtdicttextendt
itervaluesttuple(
RRR_RREtkey_dicttelementstdictsRhRF((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRsZ

	

		cC@s|jdkri}|jrx|jjD]V\}\}}|}x$|d D]}|j|i}qQW|||f||d<q.Wngxd|jjD]S\}\}}|}x$|d D]}|j|i}qW||f||d<qW||_n|jS(Ni(R8RR2R7Rt
setdefault(Rtnodes_by_keyRERGRFRtsubkey((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRLs	""cC@s$t|jtd|jDS(swReturn an estimate of the number of keys in this index.

        For InMemoryGraphIndex the estimate is exact.
        cs@s'|]}|dk	r|jVqdS(N(RR(t.0R_((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pys	<genexpr>cs(RCR7RR6(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR^scC@sdS(s9In memory index's have no known corruption at the moment.N((R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pytvalidatefs((R+R,R-RRIRDRMRLR`RYR\R.RvRXRR[RRRRR(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR1os$	#					 LM			)	L		t	_LeafNodecB@s/eZdZdZdZdZdZRS(s*A leaf node for a serialised B+Tree index.tmin_keytmax_keyt_keyscC@sytj|||}|r@|dd|_|dd|_nd|_|_tt|j|t||_	dS(s)Parse bytes to create a leaf node object.iiN(
Rt_parse_leaf_linesRRRtsuperRRRR(Rtbytest
key_lengthtref_list_lengthtkey_list((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRos	cC@s|j}|j|S(s2Return a sorted list of (key, (value, refs)) items(titemstsort(RR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt	all_items|s
cC@s|j}|j|S(s!Return a sorted list of all keys.(RR(RR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pytall_keyss
(smin_keysmax_keys_keys(R+R,R-t	__slots__RRR(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRjs
	
	t
_InternalNodecB@s&eZdZdZdZdZRS(s/An internal node for a serialised B+Tree index.RtoffsetcC@s|j|jd|_dS(s.Parse bytes to create an internal node object.s
N(t_parse_linestsplitR(RR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRscC@s}g}t|dd|_tjj}xM|dD]A}|dkrJPn|j|tt|jdjq4W|S(NiiitR(	tintRR	R<R=RQRR>R(RRRtas_stRx((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs/(skeyssoffset(R+R,R-RRR(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs	RNcB@seZdZeddZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZedZdZdZdZdZdZdZdZdZdZ dZ!RS(sAccess 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.
    icC@s||_||_||_d|_|j|_d|_||_t	|_
d|_|rri|_i|_
n$tjt|_tjd|_
d|_d|_d|_dS(s^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.
        idN(t
_transportt_namet_sizeRRPt_compute_recommended_pagest_recommended_pagest
_root_nodet_base_offsetRt
_leaf_factoryt_leaf_value_cachet_leaf_node_cachet_internal_node_cacheRtLRUCachet_NODE_CACHE_SIZERt	FIFOCachet
_key_countt_row_lengthst_row_offsets(RRtnameRTtunlimited_cacheR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs"											cC@sLt|t|koK|j|jkoK|j|jkoK|j|jkS(s@Equal when self and other were created with the same parameters.(RRRR(Rtother((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt__eq__scC@s|j|S(N(R(RR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt__ne__scC@si}d}x|jt|D]s\}}|dkrF||_nE|dkrb|jd}n||kr~||j|<n
||j|<|||<q"W|S(sRead 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}
        iiN(Rt_read_nodesRaRRRR(RRtfoundtstart_of_leavestnode_posR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_get_and_cache_nodess
"
cC@s2|jj}ttj|tt}|S(sConvert 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.
        (Rtrecommended_page_sizeRtmathtceiltfloatR"(Rtrecommended_readtrecommended_pages((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRscC@s^|jdkrtdn|jdk	r8|jdSttj|jtt	}|S(sHow 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.
        sJ_compute_total_pages_in_index should not be called when self._size is NoneiN(
RRR#RRRRRRR"(Rttotal_pages((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_compute_total_pages_in_indexs"cC@sdtjkr(tjd|j|nt||jkrodtjkrktjdt||jn|S|jd	krdtjkrtjdn|S|j	}|j
}|t||jkr8|rgt|D]}||kr|^q}nt|}dtjkr4tjd|n|S|j
d	krP|}nkt|j}t||krt|dkrdtjkrtjdn|S|j|||}t|}dtjkrtjd|n|S(
sFind 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
        Rsexpanding: %s	offsets: %ss(  not expanding large request (%s >= %s)s*  not expanding without knowing index sizes  reading all unread pages: %sis  not expanding on first readss
expanded:  %sN(RRsR
RtRRCRRRRt_get_offsets_to_cached_pagestxrangeRRRRt_expand_to_neighborsRa(RtoffsetsRtcached_offsetstxtexpandedt
final_offsetst
tree_depth((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_expand_offsetssD
		$	cC@s-t|}d}}t|}xt||jkr(|r(t}x|D]}	|dkrz|j|	\}}n|	d}
|
dkr|
|kr|
|kr|
|kr|j|
n|	d}||krP||krP||krP||krP|j|qPqPW|j||}q%W|S(sMExpand 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
        iiN(RRRCRt_find_layer_first_and_endtaddtupdate(RRRRRtfirsttendtnew_tipst	next_tipsR^tprevioustafter((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRUs.
	




cC@s|jjdS(sClear 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(Rtclear(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pytclear_cachescC@s|jdkr|jn|d|jkrKtd||jfnt}t}x:|jD],}|j|d|j|d|qjW||S(Nis&No ref list %d, index has %d ref listsi(	RRt_get_root_nodetnode_ref_listst
ValueErrorRR[RR(Rtref_list_numRtrefsR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pytexternal_referencess
		cC@sDd}}x-|jD]"}|}|}||krPqqW||fS(sFind 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
        i(R(RRRRtroffset((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs
cC@sNt|jj}|j|jj|jdk	rJ|jdn|S(s,Determine what nodes we already have cached.iN(RRRRRRRR(RR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs
cC@s)|jdkr"|jdgn|jS(Ni(RRt_get_internal_nodes(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRscC@si}g}xo|D]g}|dkrG|jdk	rG|j|d<qny||||<Wqtk
ry|j|qXqW|s|S|j|}|j|j||S(Ni(RRRRQRRR(Rtcachetnode_indexesRtneededtidx((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt
_get_nodess


cC@s|j|j|S(s\Get a node, from cache or disk.

        After getting it, the node will be cached.
        (RR(RR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR	scC@sj|jdk	rfxT|jD]C}x:|jD],\}}||jkrNPn||j|<q/WqWndS(s5Cache directly from key => value, skipping the btree.N(RRRR(RRRRERF((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_cache_leaf_valuesscC@s&|j|j|}|j||S(s)Get a bunch of nodes, from cache or disk.(RRR(RRR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_get_leaf_nodess
c
c@sdtjkr"tjddn|js2dS|jddkr|jrxk|jjD]#\}\}}||||fVq^Wn4x1|jjD] \}\}}|||fVqWdS|jd}|jd}t	||}|dgkr
d|jfg}n|j
|}|jrsx|D]@\}}	x1|	jD]#\}\}}||||fVqEWq,WnHxE|D]=\}}	x.|	jD] \}\}}|||fVqWqzWdS(	sIterate 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.
        Ris-iter_all_entries scales with size of history.Niiii(RRsR
RRRRRRRRR(
RRERFRRt
end_of_leavestneeded_offsetsRR&R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR[s2		
	""

	cC@s|s
gS|sd|fgSt|dkrLtj||d|fgSt|}t|}|j}|j\}}dtfdY}dtfdY}g}	g}
yxtr||kr>g}||f}
|	j|
xJ||kr:|j|y|j}Wqt	k
r6|qXqWnx@||kry|j\}}WqAt	k
r||qAXqAWqWWnV|k
rnF|k
r|g}|j
|t||f}
|	j|
nX|	S(soFind 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.
        iit	InputDonecB@seZRS((R+R,(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR3st	FixedDonecB@seZRS((R+R,(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR4s(RCtbisecttbisect_righttiterRZRbt	ExceptionR.RQRcR(tin_keyst
fixed_keystin_keys_itertfixed_keys_itert
cur_in_keytcur_fixed_offsett
cur_fixed_keyRRtoutputtcur_outtcur_keys((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_multi_bisect_rightsN
	





	
cC@s!dt|fg}xt|jdd!D]\}}g|D]\}}|^q?}|j|}g}	xp|D]h\}
}||
}|j||j}
||j}|	jg|
D]\}}|||f^qqsW|	}q,Wg|D]\}}|^q}|j|}||fS(s6Take 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])]
        iii(	RaRZRR	R#RRRR(RRt
keys_at_indextrow_postnext_row_startR
ts_keysRRtnext_nodes_and_keyst
node_indextsub_keysRt	positionstnode_offsetR^((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_walk_through_internal_nodes^s#

	+
c
c@stt|}|sdS|js&dSg}|jdkrD|}nyxv|D]n}|jj|d}|dk	r|\}}|jr||||fVq|||fVqK|j|qKWd}|}|sdS|j|\}}x|D]}\}	}
|
sqn||	}xX|
D]P}||kr||\}}|jrW||||fVqh|||fVqqWqWdS(sHIterate 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(t	frozensetRRRtgetRRQR-(
RRtneeded_keysRERFRtlast_keyRtnodes_and_keysR)R*Rtnext_sub_key((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs>	
	

	cC@s|js |j|tS||jkrKtd||jfn|j|\}}t}xa|D]Y\}}	|	sqpn||}
t}x[|	D]S}||
kr|j|q|
|\}
}||}|||<|j|qW|j|}x|rt}x|D]}||
krg|
|\}
}||}|||<|j|q!||
jkr|j|q!||
j	kr|j|q!|j|q!W|j|}qWqpW|j|j|}|S(s8Find 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
        s&No ref list %d, index has %d ref lists(
RRRRRR-Rt
differenceRR(RRRt
parent_maptmissing_keysRR2tparents_not_on_pageR)R*Rtparents_to_checkR3RFRtparent_keystnext_parents_to_checkREtsearch_keys((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_find_ancestorssL
	
	


		



cc@stt|}|sdS|jdkr8|jni}|jr|jdkrx|jD]"\}}}}||f||<qcWqi}x|jD]\\}}}}|||f}|}	x$|d D]}
|	j|
i}	qW||	|d<qWn|jdkr>x|jD]\}}}|||<qWnmi}xd|jD]V\}}}||f}|}	x$|d D]}
|	j|
i}	q}W||	|d<qQW|jdkrox|D]}|ddkrt	j
|nt||jkrt	j
|nyC|jr@||\}}||||fVn||||fVWqtk
rfqXqWdSxe|D]]}|ddkrt	j
|nt||jkrt	j
|n|}	t
|}yBx;t|r|ddk	r|	|d}	|jdqWWntk
r/qvnXt|r|	g}
x|
r|
jd}	|	jj\}}t|tkr|
j|	jqHx |	jD]}|f|VqWqHWqv|f|	VqvWdS(sIterate 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.
        Niii(RaRRRRRRAR[RRRqRCRRRRRbRRRR(RRRt_1RERFRRt	key_valueRRRHRRRh((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR5s
	
	


		cC@s#|jdkr|jn|jS(sReturn an estimate of the number of keys in this index.

        For BTreeGraphIndex the estimate is exact as it is contained in the
        header.
        N(RRR(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRs
cC@sQg}d}x(|jD]}|j|||7}qW|j|||_dS(s:Fill out the _row_offsets attribute based on _row_lengths.iN(RRQR(RRt
row_offsetR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_compute_row_offsetss

cC@sx|dt|j!}||jksCtj|jtn|t|jj}|d}|jtstj	|nyt
|tt|_Wn tk
rtj	|nX|d}|jt
stj	|nyt
|tt
|_Wn tk
r4tj	|nX|d}|jts`tj	|nyt
|tt|_Wn tk
rtj	|nX|d}|jtstj	|nyHtt
g|ttjdD]}t|r|^q|_Wn tk
r5tj	|nX|jt|ttt|dd!d}|||fS(sParse 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).
        iiiiRi(RCt
_signatureRtBadIndexFormatSignatureRRNt
splitlinest
startswithRtBadIndexOptionsRRRR
RARRRRRRR@R(RRt	signatureRtoptions_lineR|t
header_end((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt_parse_header_from_bytessJ






	"

*c
c@sd}g}|j}x
|D]}|t}t}|dkr|jr\tt|j}q|jj|j}t|}|||_gt	||tD]}	|	tt||	f^q}PnA||jkrt
d||jfnt||j|}|j|||fqW|s,dS|dk	rkg|D]#\}	}|	||	|	|!f^q?}
nv|jdkr|jj
|j|}
nLg}
xC|D];\}}|jj||
j||jj|fqWx|
D]\}}||8}|dkr:|j|\}}t|dkr:qq:ntj|}|jtrv|j||j|j}n.|jtrt|}nt
d||t|fVqWdS(sRead 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
        is.tried to read past the end of the file %s > %sNsUnknown node type for %r(RRR"RRdRt	get_bytesRRCRR#RQRPtreadvRRRItzlibt
decompressRDRpRRARRmR(
RRRtrangestbase_offsetRRRTt	num_byteststarttdata_rangestdataR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRsZ	

	
50#
	cC@stS(s'The file signature for this index type.(R(R((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRA/scC@si|jt|jdkr/|jd}nd}|jd}x |jt||D]}q[WdS(s6Validate that everything in the index can be accessed.iiN(RRCRRRRR(Rt
start_nodetnode_endR((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyR3s

("R+R,R-R9RRRRRRRRRRRRRRR	RRR[tstaticmethodR#R-RR<RRR@RIRRAR(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyRNs>'						E	,	
	
								+R	!	8	~	p	
	
	/	G	(t_btree_serializer_pyx(t_btree_serializer_py(0R-t
__future__RRtbzrlib.lazy_importRtglobalstbzrlibRRRRRRRR	R
Rtbzrlib.indexRR
RRRRpRmRnRR"RtobjectRR/R0R4R1RRRRNt_gcchk_factoryRWRt_parse_into_chktImportErrortetfailed_to_load_extensionRX(((s6/usr/lib/python2.7/dist-packages/bzrlib/btree_index.pyt<module>sB	F&	



Copyright © 2017 || Recoded By Mr.Bumblebee