b.i.GraphIndexBuilder(object) : class documentation

Part of bzrlib.index View In Hierarchy

Known subclasses: bzrlib.btree_index.BTreeBuilder, bzrlib.index.InMemoryGraphIndex

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
Method __init__ Create a GraphIndex builder.
Method add_node Add a node to the index.
Method clear_cache See GraphIndex.clear_cache()
Method finish Finish the index.
Method set_optimize Change how the builder tries to optimize the result.
Method find_ancestry See CombinedGraphIndex.find_ancestry()
Method _check_key Raise BadIndexKey if key is not a valid key for this index.
Method _external_references Return references that are not present in this index.
Method _get_nodes_by_key Undocumented
Method _update_nodes_by_key Update the _nodes_by_key dict with a new key.
Method _check_key_ref_value Check that 'key' and 'references' are all valid.
def __init__(self, reference_lists=0, key_elements=1):
Create a GraphIndex builder.
Parametersreference_listsThe number of node references lists for each entry.
key_elementsThe number of bytestrings in each key.
def _check_key(self, key):
Raise BadIndexKey if key is not a valid key for this index.
def _external_references(self):
Return references that are not present in this index.
def _get_nodes_by_key(self):
Undocumented
def _update_nodes_by_key(self, key, value, node_refs):
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

def _check_key_ref_value(self, key, references, value):
Check that 'key' and 'references' are all valid.
ParameterskeyA 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.)
referencesAn iterable of reference lists. Something like [[(ref, key)], [(ref, key), (other, key)]]
valueThe value associate with this key. Must not contain newlines or null characters.
Returns

(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.
def add_node(self, key, value, references=()):
Add a node to the index.
ParameterskeyThe key. keys are non-empty tuples containing as many whitespace-free utf8 bytestrings as the key length defined for this index.
referencesAn iterable of iterables of keys. Each is a reference to another key.
valueThe value to associate with the key. It may be any bytes as long as it does not contain 0 or n.
def clear_cache(self):
See GraphIndex.clear_cache()

This is a no-op, but we need the api to conform to a generic 'Index' abstraction.

def finish(self):
Finish the index.

:returns: cStringIO holding the full context of the index as it 
should be written to disk.
def set_optimize(self, for_size=None, combine_backing_indices=None):
Change how the builder tries to optimize the result.
Parametersfor_sizeTell the builder to try and make the index as small as possible.
combine_backing_indicesIf 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.)
ReturnsNone
def find_ancestry(self, keys, ref_list_num):
See CombinedGraphIndex.find_ancestry()
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.