13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
# cython: language_level=3
19
17
"""Implementation of Graph algorithms when we have already loaded everything.
20
from __future__ import absolute_import
22
22
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 (
25
cdef extern from "Python.h":
26
ctypedef int Py_ssize_t
27
ctypedef struct PyObject:
30
int PyString_CheckExact(object)
32
int PyObject_RichCompareBool(object, object, int)
35
int PyTuple_CheckExact(object)
36
object PyTuple_New(Py_ssize_t n)
37
Py_ssize_t PyTuple_GET_SIZE(object t)
38
PyObject * PyTuple_GET_ITEM(object t, Py_ssize_t o)
39
void PyTuple_SET_ITEM(object t, Py_ssize_t o, object v)
41
int PyList_CheckExact(object)
42
Py_ssize_t PyList_GET_SIZE(object l)
43
PyObject * PyList_GET_ITEM(object l, Py_ssize_t o)
44
int PyList_SetItem(object l, Py_ssize_t o, object l) except -1
45
int PyList_Append(object l, object v) except -1
47
int PyDict_CheckExact(object d)
48
Py_ssize_t PyDict_Size(object d) except -1
49
PyObject * PyDict_GetItem(object d, object k)
50
int PyDict_SetItem(object d, object k, object v) except -1
51
int PyDict_DelItem(object d, object k) except -1
52
int PyDict_Next(object d, Py_ssize_t *pos, PyObject **k, PyObject **v)
54
void Py_INCREF(object)
56
from collections import deque
62
59
from . import errors, revision
405
400
# We use a deque rather than a simple list stack, to go for BFD rather
406
401
# than DFD. So that if a longer path is possible, we walk it before we
407
402
# get to the final child
408
pending = collections.deque([node])
403
pending = deque([node])
409
404
pending_popleft = pending.popleft
410
405
pending_append = pending.append
645
640
# shown a specific impact, yet.
646
641
sorter = _MergeSorter(self, tip_key)
647
642
return sorter.topo_order()
649
644
def get_parent_keys(self, key):
650
645
"""Get the parents for a key
652
Returns a list containing the parents keys. If the key is a ghost,
647
Returns a list containg the parents keys. If the key is a ghost,
653
648
None is returned. A KeyError will be raised if the key is not in
656
651
:param keys: Key to check (eg revision_id)
657
652
:return: A list of parents
659
return self._nodes[key].parent_keys
654
return self._nodes[key].parent_keys
661
656
def get_child_keys(self, key):
662
657
"""Get the children for a key
664
Returns a list containing the children keys. A KeyError will be raised
659
Returns a list containg the children keys. A KeyError will be raised
665
660
if the key is not in the graph.
667
662
:param keys: Key to check (eg revision_id)
668
663
:return: A list of children
670
return self._nodes[key].child_keys
665
return self._nodes[key].child_keys
673
668
cdef class _MergeSortNode: