17
17
"""Implementation of Graph algorithms when we have already loaded everything.
20
from __future__ import absolute_import
22
20
cdef extern from "python-compat.h":
25
from cpython.bytes cimport (
28
from cpython.dict cimport (
36
from cpython.list cimport (
43
from cpython.object cimport (
46
PyObject_RichCompareBool,
48
from cpython.ref cimport (
51
from cpython.tuple cimport (
23
cdef extern from "Python.h":
24
ctypedef int Py_ssize_t
25
ctypedef struct PyObject:
28
int PyString_CheckExact(object)
30
int PyObject_RichCompareBool(object, object, int)
33
int PyTuple_CheckExact(object)
34
object PyTuple_New(Py_ssize_t n)
35
Py_ssize_t PyTuple_GET_SIZE(object t)
36
PyObject * PyTuple_GET_ITEM(object t, Py_ssize_t o)
37
void PyTuple_SET_ITEM(object t, Py_ssize_t o, object v)
39
int PyList_CheckExact(object)
40
Py_ssize_t PyList_GET_SIZE(object l)
41
PyObject * PyList_GET_ITEM(object l, Py_ssize_t o)
42
int PyList_SetItem(object l, Py_ssize_t o, object l) except -1
43
int PyList_Append(object l, object v) except -1
45
int PyDict_CheckExact(object d)
46
Py_ssize_t PyDict_Size(object d) except -1
47
PyObject * PyDict_GetItem(object d, object k)
48
int PyDict_SetItem(object d, object k, object v) except -1
49
int PyDict_DelItem(object d, object k) except -1
50
int PyDict_Next(object d, Py_ssize_t *pos, PyObject **k, PyObject **v)
52
void Py_INCREF(object)
54
from collections import deque
62
from . import errors, revision
57
from bzrlib import errors, revision
64
59
cdef object NULL_REVISION
65
60
NULL_REVISION = revision.NULL_REVISION
269
264
- all nodes found will also have child_keys populated with all known
272
cdef PyObject *temp_key
273
cdef PyObject *temp_parent_keys
274
cdef PyObject *temp_node
267
cdef PyObject *temp_key, *temp_parent_keys, *temp_node
275
268
cdef Py_ssize_t pos
276
269
cdef _KnownGraphNode node
277
270
cdef _KnownGraphNode parent_node
405
398
# We use a deque rather than a simple list stack, to go for BFD rather
406
399
# than DFD. So that if a longer path is possible, we walk it before we
407
400
# get to the final child
408
pending = collections.deque([node])
401
pending = deque([node])
409
402
pending_popleft = pending.popleft
410
403
pending_append = pending.append
645
638
# shown a specific impact, yet.
646
639
sorter = _MergeSorter(self, tip_key)
647
640
return sorter.topo_order()
649
642
def get_parent_keys(self, key):
650
643
"""Get the parents for a key
652
Returns a list containing the parents keys. If the key is a ghost,
645
Returns a list containg the parents keys. If the key is a ghost,
653
646
None is returned. A KeyError will be raised if the key is not in
656
649
:param keys: Key to check (eg revision_id)
657
650
:return: A list of parents
659
return self._nodes[key].parent_keys
652
return self._nodes[key].parent_keys
661
654
def get_child_keys(self, key):
662
655
"""Get the children for a key
664
Returns a list containing the children keys. A KeyError will be raised
657
Returns a list containg the children keys. A KeyError will be raised
665
658
if the key is not in the graph.
667
660
:param keys: Key to check (eg revision_id)
668
661
:return: A list of children
670
return self._nodes[key].child_keys
663
return self._nodes[key].child_keys
673
666
cdef class _MergeSortNode:
934
927
cdef _MergeSortNode ms_node
935
928
cdef _KnownGraphNode node
936
929
cdef Py_ssize_t pos
937
cdef PyObject *temp_key
938
cdef PyObject *temp_node
930
cdef PyObject *temp_key, *temp_node
940
932
# Note: allocating a _MergeSortNode and deallocating it for all nodes
941
933
# costs approx 8.52ms (21%) of the total runtime