/* Generated by Cython 0.23.3 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_23_3"
#include <stddef.h>
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
#define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
#define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
typedef struct {
    unaryfunc am_await;
    unaryfunc am_aiter;
    unaryfunc am_anext;
} __Pyx_PyAsyncMethodsStruct;
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
#else
#define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)

#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif


#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__bzrlib___known_graph_pyx
#define __PYX_HAVE_API__bzrlib___known_graph_pyx
#include "python-compat.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (_MSC_VER) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _abs64(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */

static PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "bzrlib/_known_graph_pyx.pyx",
};

/*--- Type declarations ---*/
struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode;
struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph;
struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode;
struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter;

/* "bzrlib/_known_graph_pyx.pyx":63
 * 
 * 
 * cdef class _KnownGraphNode:             # <<<<<<<<<<<<<<
 *     """Represents a single object in the known graph."""
 * 
 */
struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_vtab;
  PyObject *key;
  PyObject *parents;
  PyObject *children;
  long gdfo;
  int seen;
  PyObject *extra;
};


/* "bzrlib/_known_graph_pyx.pyx":192
 * cdef class _MergeSorter
 * 
 * cdef class KnownGraph:             # <<<<<<<<<<<<<<
 *     """This is a class which assumes we already know the full graph."""
 * 
 */
struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_vtab;
  PyObject *_nodes;
  PyObject *_known_heads;
  int do_cache;
};


/* "bzrlib/_known_graph_pyx.pyx":666
 * 
 * 
 * cdef class _MergeSortNode:             # <<<<<<<<<<<<<<
 *     """Tracks information about a node during the merge_sort operation."""
 * 
 */
struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_vtab;
  PyObject *key;
  long merge_depth;
  PyObject *end_of_merge;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *left_parent;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *left_pending_parent;
  PyObject *pending_parents;
  long _revno_first;
  long _revno_second;
  long _revno_last;
  int is_first_child;
  int seen_by_child;
  int completed;
};


/* "bzrlib/_known_graph_pyx.pyx":190
 * 
 * 
 * cdef class _MergeSorter             # <<<<<<<<<<<<<<
 * 
 * cdef class KnownGraph:
 */
struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_vtab;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *graph;
  PyObject *_depth_first_stack;
  Py_ssize_t _last_stack_item;
  PyObject *_revno_to_branch_count;
  PyObject *_scheduled_nodes;
};



/* "bzrlib/_known_graph_pyx.pyx":63
 * 
 * 
 * cdef class _KnownGraphNode:             # <<<<<<<<<<<<<<
 *     """Represents a single object in the known graph."""
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode {
  PyObject *(*clear_references)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode;


/* "bzrlib/_known_graph_pyx.pyx":724
 * 
 * 
 * cdef class _MergeSorter:             # <<<<<<<<<<<<<<
 *     """This class does the work of computing the merge_sort ordering.
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *(*_get_ms_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *);
  PyObject *(*_push_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, long);
  PyObject *(*_pop_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *);
  PyObject *(*_schedule_stack)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *);
  PyObject *(*topo_order)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter;


/* "bzrlib/_known_graph_pyx.pyx":192
 * cdef class _MergeSorter
 * 
 * cdef class KnownGraph:             # <<<<<<<<<<<<<<
 *     """This is a class which assumes we already know the full graph."""
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *(*_get_or_create_node)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, PyObject *);
  PyObject *(*_populate_parents)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, PyObject *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph;


/* "bzrlib/_known_graph_pyx.pyx":666
 * 
 * 
 * cdef class _MergeSortNode:             # <<<<<<<<<<<<<<
 *     """Tracks information about a node during the merge_sort operation."""
 * 
 */

struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode {
  int (*has_pending_parents)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *);
  PyObject *(*_revno)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *);
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode;

/* --- Runtime support code (head) --- */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name);

static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
    if (it) {
        PyObject* result;
#if CYTHON_COMPILING_IN_PYPY
        PyObject* args;
        args = PyTuple_Pack(1, it);
        if (unlikely(!args))
            return NULL;
        result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL);
        Py_DECREF(args);
        return result;
#else
        if (PyFrozenSet_CheckExact(it)) {
            Py_INCREF(it);
            return it;
        }
        result = PyFrozenSet_New(it);
        if (unlikely(!result))
            return NULL;
        if (likely(PySet_GET_SIZE(result)))
            return result;
        Py_DECREF(result);
#endif
    }
#if CYTHON_COMPILING_IN_CPYTHON
    return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#else
    return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#endif
}

static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject* none = _PyList_Extend((PyListObject*)L, v);
    if (unlikely(!none))
        return -1;
    Py_DECREF(none);
    return 0;
#else
    return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
#endif
}

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);

static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L);
#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ?\
    __Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
#else
#define __Pyx_PyList_Pop(L)  __Pyx__PyObject_Pop(L)
#define __Pyx_PyObject_Pop(L)  __Pyx__PyObject_Pop(L)
#endif

typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    ((likely((cfunc)->func)) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
             ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) : __Pyx__CallUnboundCMethod0(cfunc, self)))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

static int __Pyx_SetVtable(PyObject *dict, void *vtable);

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static int __Pyx_check_binary_version(void);

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_clear_references(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self); /* proto*/
static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__get_or_create_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key); /* proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__populate_parents(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node, PyObject *__pyx_v_parent_keys); /* proto*/
static int __pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_has_pending_parents(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode__revno(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto*/
static struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__get_ms_node(CYTHON_UNUSED struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node); /* proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__push_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node, long __pyx_v_merge_depth); /* proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__pop_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__schedule_stack(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter_topo_order(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self); /* proto*/

/* Module declarations from 'bzrlib._known_graph_pyx' */
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode = 0;
static PyObject *__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = 0;
static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(PyObject *, Py_ssize_t); /*proto*/
static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(PyObject *, Py_ssize_t); /*proto*/
static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(PyObject *, int); /*proto*/
#define __Pyx_MODULE_NAME "bzrlib._known_graph_pyx"
int __pyx_module_is_main_bzrlib___known_graph_pyx = 0;

/* Implementation of 'bzrlib._known_graph_pyx' */
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_RuntimeError;
static char __pyx_k__3[] = "";
static char __pyx_k_gc[] = "gc";
static char __pyx_k_key[] = "key";
static char __pyx_k_pop[] = "pop";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_name[] = "__name__";
static char __pyx_k_node[] = "node";
static char __pyx_k_sort[] = "sort";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_class[] = "__class__";
static char __pyx_k_clear[] = "clear";
static char __pyx_k_deque[] = "deque";
static char __pyx_k_append[] = "append";
static char __pyx_k_bzrlib[] = "bzrlib";
static char __pyx_k_errors[] = "errors";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_get_key[] = "get_key";
static char __pyx_k_popleft[] = "popleft";
static char __pyx_k_reverse[] = "reverse";
static char __pyx_k_tip_key[] = "tip_key";
static char __pyx_k_KeyError[] = "KeyError";
static char __pyx_k_do_cache[] = "do_cache";
static char __pyx_k_revision[] = "revision";
static char __pyx_k_TypeError[] = "TypeError";
static char __pyx_k_find_gdfo[] = "_find_gdfo";
static char __pyx_k_find_tips[] = "_find_tips";
static char __pyx_k_real_node[] = "real_node";
static char __pyx_k_ValueError[] = "ValueError";
static char __pyx_k_child_keys[] = "child_keys";
static char __pyx_k_find_tails[] = "_find_tails";
static char __pyx_k_parent_map[] = "parent_map";
static char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static char __pyx_k_collections[] = "collections";
static char __pyx_k_known_graph[] = "known_graph";
static char __pyx_k_parent_keys[] = "parent_keys";
static char __pyx_k_RuntimeError[] = "RuntimeError";
static char __pyx_k_NULL_REVISION[] = "NULL_REVISION";
static char __pyx_k_GraphCycleError[] = "GraphCycleError";
static char __pyx_k_initialize_nodes[] = "_initialize_nodes";
static char __pyx_k_key_s_not_in_nodes[] = "key %s not in nodes";
static char __pyx_k_Something_wrong_with_s[] = "Something wrong with: %s";
static char __pyx_k_bzrlib__known_graph_pyx[] = "bzrlib._known_graph_pyx";
static char __pyx_k_s_s_gdfo_s_par_s_child_s[] = "%s(%s  gdfo:%s par:%s child:%s)";
static char __pyx_k_home_vila_src_bzr_integration_2[] = "/home/vila/src/bzr/integration/2.7.0-dev/bzrlib/_known_graph_pyx.pyx";
static char __pyx_k_s_s_depth_s_rev_s_s_s_first_s_s[] = "%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)";
static char __pyx_k_Implementation_of_Graph_algorith[] = "Implementation of Graph algorithms when we have already loaded everything.\n";
static char __pyx_k_Parent_key_mismatch_existing_nod[] = "Parent key mismatch, existing node %s has parents of %s not %s";
static char __pyx_k_ghost_nodes_should_not_be_pushed[] = "ghost nodes should not be pushed onto the stack: %s";
static char __pyx_k_lst_or_tpl_must_be_a_list_or_tup[] = "lst_or_tpl must be a list or tuple.";
static char __pyx_k_parent_map_should_be_a_dict_of_k[] = "parent_map should be a dict of {key:parent_keys}";
static PyObject *__pyx_n_s_GraphCycleError;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_n_s_NULL_REVISION;
static PyObject *__pyx_kp_s_Parent_key_mismatch_existing_nod;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_kp_s_Something_wrong_with_s;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s__3;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_bzrlib;
static PyObject *__pyx_n_s_bzrlib__known_graph_pyx;
static PyObject *__pyx_n_s_child_keys;
static PyObject *__pyx_n_s_class;
static PyObject *__pyx_n_s_clear;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_deque;
static PyObject *__pyx_n_s_do_cache;
static PyObject *__pyx_n_s_errors;
static PyObject *__pyx_n_s_find_gdfo;
static PyObject *__pyx_n_s_find_tails;
static PyObject *__pyx_n_s_find_tips;
static PyObject *__pyx_n_s_gc;
static PyObject *__pyx_n_s_get_key;
static PyObject *__pyx_kp_s_ghost_nodes_should_not_be_pushed;
static PyObject *__pyx_kp_s_home_vila_src_bzr_integration_2;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_initialize_nodes;
static PyObject *__pyx_n_s_key;
static PyObject *__pyx_kp_s_key_s_not_in_nodes;
static PyObject *__pyx_n_s_known_graph;
static PyObject *__pyx_kp_s_lst_or_tpl_must_be_a_list_or_tup;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_node;
static PyObject *__pyx_n_s_parent_keys;
static PyObject *__pyx_n_s_parent_map;
static PyObject *__pyx_kp_s_parent_map_should_be_a_dict_of_k;
static PyObject *__pyx_n_s_pop;
static PyObject *__pyx_n_s_popleft;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_real_node;
static PyObject *__pyx_n_s_reverse;
static PyObject *__pyx_n_s_revision;
static PyObject *__pyx_kp_s_s_s_depth_s_rev_s_s_s_first_s_s;
static PyObject *__pyx_kp_s_s_s_gdfo_s_par_s_child_s;
static PyObject *__pyx_n_s_sort;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_tip_key;
static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_2__repr__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_get_key(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_node); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_parent_map, PyObject *__pyx_v_do_cache); /* proto */
static void __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_2__dealloc__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_4_initialize_nodes(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_parent_map); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_find_tails(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8_find_tips(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_10_find_gdfo(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12add_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_parent_keys); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_14heads(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_keys); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_16topo_sort(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_18gc_sort(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_20merge_sort(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_tip_key); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_22get_parent_keys(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_24get_child_keys(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_2__repr__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self); /* proto */
static int __pyx_pf_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, PyObject *__pyx_v_known_graph, PyObject *__pyx_v_tip_key); /* proto */
static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSorter(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx_KnownGraph(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSortNode(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0};
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_codeobj__5;

/* "bzrlib/_known_graph_pyx.pyx":73
 *     cdef object extra
 * 
 *     def __init__(self, key):             # <<<<<<<<<<<<<<
 *         self.key = key
 *         self.parents = None
 */

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_key = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self), __pyx_v_key);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self, PyObject *__pyx_v_key) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":74
 * 
 *     def __init__(self, key):
 *         self.key = key             # <<<<<<<<<<<<<<
 *         self.parents = None
 * 
 */
  __Pyx_INCREF(__pyx_v_key);
  __Pyx_GIVEREF(__pyx_v_key);
  __Pyx_GOTREF(__pyx_v_self->key);
  __Pyx_DECREF(__pyx_v_self->key);
  __pyx_v_self->key = __pyx_v_key;

  /* "bzrlib/_known_graph_pyx.pyx":75
 *     def __init__(self, key):
 *         self.key = key
 *         self.parents = None             # <<<<<<<<<<<<<<
 * 
 *         self.children = []
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->parents);
  __Pyx_DECREF(__pyx_v_self->parents);
  __pyx_v_self->parents = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":77
 *         self.parents = None
 * 
 *         self.children = []             # <<<<<<<<<<<<<<
 *         # Greatest distance from origin
 *         self.gdfo = -1
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->children);
  __Pyx_DECREF(__pyx_v_self->children);
  __pyx_v_self->children = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":79
 *         self.children = []
 *         # Greatest distance from origin
 *         self.gdfo = -1             # <<<<<<<<<<<<<<
 *         self.seen = 0
 *         self.extra = None
 */
  __pyx_v_self->gdfo = -1L;

  /* "bzrlib/_known_graph_pyx.pyx":80
 *         # Greatest distance from origin
 *         self.gdfo = -1
 *         self.seen = 0             # <<<<<<<<<<<<<<
 *         self.extra = None
 * 
 */
  __pyx_v_self->seen = 0;

  /* "bzrlib/_known_graph_pyx.pyx":81
 *         self.gdfo = -1
 *         self.seen = 0
 *         self.extra = None             # <<<<<<<<<<<<<<
 * 
 *     property child_keys:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->extra);
  __Pyx_DECREF(__pyx_v_self->extra);
  __pyx_v_self->extra = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":73
 *     cdef object extra
 * 
 *     def __init__(self, key):             # <<<<<<<<<<<<<<
 *         self.key = key
 *         self.parents = None
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":84
 * 
 *     property child_keys:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef _KnownGraphNode child
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child = 0;
  PyObject *__pyx_v_keys = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":87
 *             cdef _KnownGraphNode child
 * 
 *             keys = []             # <<<<<<<<<<<<<<
 *             for child in self.children:
 *                 PyList_Append(keys, child.key)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_keys = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":88
 * 
 *             keys = []
 *             for child in self.children:             # <<<<<<<<<<<<<<
 *                 PyList_Append(keys, child.key)
 *             return keys
 */
  if (likely(PyList_CheckExact(__pyx_v_self->children)) || PyTuple_CheckExact(__pyx_v_self->children)) {
    __pyx_t_1 = __pyx_v_self->children; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->children); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_child, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":89
 *             keys = []
 *             for child in self.children:
 *                 PyList_Append(keys, child.key)             # <<<<<<<<<<<<<<
 *             return keys
 * 
 */
    __pyx_t_4 = __pyx_v_child->key;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_5 = PyList_Append(__pyx_v_keys, __pyx_t_4); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":88
 * 
 *             keys = []
 *             for child in self.children:             # <<<<<<<<<<<<<<
 *                 PyList_Append(keys, child.key)
 *             return keys
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":90
 *             for child in self.children:
 *                 PyList_Append(keys, child.key)
 *             return keys             # <<<<<<<<<<<<<<
 * 
 *     property parent_keys:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_keys);
  __pyx_r = __pyx_v_keys;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":84
 * 
 *     property child_keys:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef _KnownGraphNode child
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.child_keys.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":93
 * 
 *     property parent_keys:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.parents is None:
 *                 return None
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent = 0;
  PyObject *__pyx_v_keys = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":94
 *     property parent_keys:
 *         def __get__(self):
 *             if self.parents is None:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_1 = (__pyx_v_self->parents == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":95
 *         def __get__(self):
 *             if self.parents is None:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             cdef _KnownGraphNode parent
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "bzrlib/_known_graph_pyx.pyx":94
 *     property parent_keys:
 *         def __get__(self):
 *             if self.parents is None:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":99
 *             cdef _KnownGraphNode parent
 * 
 *             keys = []             # <<<<<<<<<<<<<<
 *             for parent in self.parents:
 *                 PyList_Append(keys, parent.key)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_keys = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":100
 * 
 *             keys = []
 *             for parent in self.parents:             # <<<<<<<<<<<<<<
 *                 PyList_Append(keys, parent.key)
 *             return keys
 */
  if (likely(PyList_CheckExact(__pyx_v_self->parents)) || PyTuple_CheckExact(__pyx_v_self->parents)) {
    __pyx_t_3 = __pyx_v_self->parents; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_self->parents); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        #endif
      }
    } else {
      __pyx_t_6 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_6)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_6);
    }
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_parent, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":101
 *             keys = []
 *             for parent in self.parents:
 *                 PyList_Append(keys, parent.key)             # <<<<<<<<<<<<<<
 *             return keys
 * 
 */
    __pyx_t_6 = __pyx_v_parent->key;
    __Pyx_INCREF(__pyx_t_6);
    __pyx_t_7 = PyList_Append(__pyx_v_keys, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":100
 * 
 *             keys = []
 *             for parent in self.parents:             # <<<<<<<<<<<<<<
 *                 PyList_Append(keys, parent.key)
 *             return keys
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":102
 *             for parent in self.parents:
 *                 PyList_Append(keys, parent.key)
 *             return keys             # <<<<<<<<<<<<<<
 * 
 *     cdef clear_references(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_keys);
  __pyx_r = __pyx_v_keys;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":93
 * 
 *     property parent_keys:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.parents is None:
 *                 return None
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.parent_keys.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_parent);
  __Pyx_XDECREF(__pyx_v_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":104
 *             return keys
 * 
 *     cdef clear_references(self):             # <<<<<<<<<<<<<<
 *         self.parents = None
 *         self.children = None
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_clear_references(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clear_references", 0);

  /* "bzrlib/_known_graph_pyx.pyx":105
 * 
 *     cdef clear_references(self):
 *         self.parents = None             # <<<<<<<<<<<<<<
 *         self.children = None
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->parents);
  __Pyx_DECREF(__pyx_v_self->parents);
  __pyx_v_self->parents = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":106
 *     cdef clear_references(self):
 *         self.parents = None
 *         self.children = None             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->children);
  __Pyx_DECREF(__pyx_v_self->children);
  __pyx_v_self->children = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":104
 *             return keys
 * 
 *     cdef clear_references(self):             # <<<<<<<<<<<<<<
 *         self.parents = None
 *         self.children = None
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":108
 *         self.children = None
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_3__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_3__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_2__repr__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_2__repr__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  PyObject *__pyx_v_parent_keys = NULL;
  PyObject *__pyx_v_child_keys = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":111
 *         cdef _KnownGraphNode node
 * 
 *         parent_keys = []             # <<<<<<<<<<<<<<
 *         if self.parents is not None:
 *             for node in self.parents:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_parent_keys = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":112
 * 
 *         parent_keys = []
 *         if self.parents is not None:             # <<<<<<<<<<<<<<
 *             for node in self.parents:
 *                 parent_keys.append(node.key)
 */
  __pyx_t_2 = (__pyx_v_self->parents != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":113
 *         parent_keys = []
 *         if self.parents is not None:
 *             for node in self.parents:             # <<<<<<<<<<<<<<
 *                 parent_keys.append(node.key)
 *         child_keys = []
 */
    if (likely(PyList_CheckExact(__pyx_v_self->parents)) || PyTuple_CheckExact(__pyx_v_self->parents)) {
      __pyx_t_1 = __pyx_v_self->parents; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->parents); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":114
 *         if self.parents is not None:
 *             for node in self.parents:
 *                 parent_keys.append(node.key)             # <<<<<<<<<<<<<<
 *         child_keys = []
 *         if self.children is not None:
 */
      __pyx_t_6 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_parent_keys, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":113
 *         parent_keys = []
 *         if self.parents is not None:
 *             for node in self.parents:             # <<<<<<<<<<<<<<
 *                 parent_keys.append(node.key)
 *         child_keys = []
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":112
 * 
 *         parent_keys = []
 *         if self.parents is not None:             # <<<<<<<<<<<<<<
 *             for node in self.parents:
 *                 parent_keys.append(node.key)
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":115
 *             for node in self.parents:
 *                 parent_keys.append(node.key)
 *         child_keys = []             # <<<<<<<<<<<<<<
 *         if self.children is not None:
 *             for node in self.children:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_child_keys = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":116
 *                 parent_keys.append(node.key)
 *         child_keys = []
 *         if self.children is not None:             # <<<<<<<<<<<<<<
 *             for node in self.children:
 *                 child_keys.append(node.key)
 */
  __pyx_t_3 = (__pyx_v_self->children != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":117
 *         child_keys = []
 *         if self.children is not None:
 *             for node in self.children:             # <<<<<<<<<<<<<<
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 */
    if (likely(PyList_CheckExact(__pyx_v_self->children)) || PyTuple_CheckExact(__pyx_v_self->children)) {
      __pyx_t_1 = __pyx_v_self->children; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->children); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":118
 *         if self.children is not None:
 *             for node in self.children:
 *                 child_keys.append(node.key)             # <<<<<<<<<<<<<<
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 *             self.__class__.__name__, self.key, self.gdfo,
 */
      __pyx_t_6 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_child_keys, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":117
 *         child_keys = []
 *         if self.children is not None:
 *             for node in self.children:             # <<<<<<<<<<<<<<
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":116
 *                 parent_keys.append(node.key)
 *         child_keys = []
 *         if self.children is not None:             # <<<<<<<<<<<<<<
 *             for node in self.children:
 *                 child_keys.append(node.key)
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":119
 *             for node in self.children:
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (             # <<<<<<<<<<<<<<
 *             self.__class__.__name__, self.key, self.gdfo,
 *             parent_keys, child_keys)
 */
  __Pyx_XDECREF(__pyx_r);

  /* "bzrlib/_known_graph_pyx.pyx":120
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 *             self.__class__.__name__, self.key, self.gdfo,             # <<<<<<<<<<<<<<
 *             parent_keys, child_keys)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->gdfo); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "bzrlib/_known_graph_pyx.pyx":121
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (
 *             self.__class__.__name__, self.key, self.gdfo,
 *             parent_keys, child_keys)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
  __Pyx_INCREF(__pyx_v_self->key);
  __Pyx_GIVEREF(__pyx_v_self->key);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_self->key);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1);
  __Pyx_INCREF(__pyx_v_parent_keys);
  __Pyx_GIVEREF(__pyx_v_parent_keys);
  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_v_parent_keys);
  __Pyx_INCREF(__pyx_v_child_keys);
  __Pyx_GIVEREF(__pyx_v_child_keys);
  PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_child_keys);
  __pyx_t_6 = 0;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":119
 *             for node in self.children:
 *                 child_keys.append(node.key)
 *         return '%s(%s  gdfo:%s par:%s child:%s)' % (             # <<<<<<<<<<<<<<
 *             self.__class__.__name__, self.key, self.gdfo,
 *             parent_keys, child_keys)
 */
  __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_s_gdfo_s_par_s_child_s, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":108
 *         self.children = None
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_parent_keys);
  __Pyx_XDECREF(__pyx_v_child_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":69
 *     cdef object parents
 *     cdef object children
 *     cdef public long gdfo             # <<<<<<<<<<<<<<
 *     cdef int seen
 *     cdef object extra
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->gdfo); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.gdfo.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  long __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_value); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->gdfo = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._KnownGraphNode.gdfo.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":124
 * 
 * 
 * cdef _KnownGraphNode _get_list_node(lst, Py_ssize_t pos):             # <<<<<<<<<<<<<<
 *     cdef PyObject *temp_node
 * 
 */

static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(PyObject *__pyx_v_lst, Py_ssize_t __pyx_v_pos) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_list_node", 0);

  /* "bzrlib/_known_graph_pyx.pyx":127
 *     cdef PyObject *temp_node
 * 
 *     temp_node = PyList_GET_ITEM(lst, pos)             # <<<<<<<<<<<<<<
 *     return <_KnownGraphNode>temp_node
 * 
 */
  __pyx_v_temp_node = PyList_GET_ITEM(__pyx_v_lst, __pyx_v_pos);

  /* "bzrlib/_known_graph_pyx.pyx":128
 * 
 *     temp_node = PyList_GET_ITEM(lst, pos)
 *     return <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":124
 * 
 * 
 * cdef _KnownGraphNode _get_list_node(lst, Py_ssize_t pos):             # <<<<<<<<<<<<<<
 *     cdef PyObject *temp_node
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":131
 * 
 * 
 * cdef _KnownGraphNode _get_tuple_node(tpl, Py_ssize_t pos):             # <<<<<<<<<<<<<<
 *     cdef PyObject *temp_node
 * 
 */

static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(PyObject *__pyx_v_tpl, Py_ssize_t __pyx_v_pos) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_tuple_node", 0);

  /* "bzrlib/_known_graph_pyx.pyx":134
 *     cdef PyObject *temp_node
 * 
 *     temp_node = PyTuple_GET_ITEM(tpl, pos)             # <<<<<<<<<<<<<<
 *     return <_KnownGraphNode>temp_node
 * 
 */
  __pyx_v_temp_node = PyTuple_GET_ITEM(__pyx_v_tpl, __pyx_v_pos);

  /* "bzrlib/_known_graph_pyx.pyx":135
 * 
 *     temp_node = PyTuple_GET_ITEM(tpl, pos)
 *     return <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node)));
  __pyx_r = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_temp_node);
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":131
 * 
 * 
 * cdef _KnownGraphNode _get_tuple_node(tpl, Py_ssize_t pos):             # <<<<<<<<<<<<<<
 *     cdef PyObject *temp_node
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":138
 * 
 * 
 * def get_key(node):             # <<<<<<<<<<<<<<
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_1get_key(PyObject *__pyx_self, PyObject *__pyx_v_node); /*proto*/
static PyMethodDef __pyx_mdef_6bzrlib_16_known_graph_pyx_1get_key = {"get_key", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_1get_key, METH_O, 0};
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_1get_key(PyObject *__pyx_self, PyObject *__pyx_v_node) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_key (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_get_key(__pyx_self, ((PyObject *)__pyx_v_node));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_get_key(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_node) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_real_node = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_key", 0);

  /* "bzrlib/_known_graph_pyx.pyx":140
 * def get_key(node):
 *     cdef _KnownGraphNode real_node
 *     real_node = node             # <<<<<<<<<<<<<<
 *     return real_node.key
 * 
 */
  if (!(likely(((__pyx_v_node) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_node, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __pyx_v_node;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_real_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":141
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 *     return real_node.key             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_real_node->key);
  __pyx_r = __pyx_v_real_node->key;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":138
 * 
 * 
 * def get_key(node):             # <<<<<<<<<<<<<<
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.get_key", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_real_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":144
 * 
 * 
 * cdef object _sort_list_nodes(object lst_or_tpl, int reverse):             # <<<<<<<<<<<<<<
 *     """Sort a list of _KnownGraphNode objects.
 * 
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(PyObject *__pyx_v_lst_or_tpl, int __pyx_v_reverse) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node1 = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node2 = 0;
  int __pyx_v_do_swap;
  int __pyx_v_is_tuple;
  Py_ssize_t __pyx_v_length;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_sort_list_nodes", 0);
  __Pyx_INCREF(__pyx_v_lst_or_tpl);

  /* "bzrlib/_known_graph_pyx.pyx":154
 *     cdef Py_ssize_t length
 * 
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)             # <<<<<<<<<<<<<<
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 */
  __pyx_v_is_tuple = PyTuple_CheckExact(__pyx_v_lst_or_tpl);

  /* "bzrlib/_known_graph_pyx.pyx":155
 * 
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):             # <<<<<<<<<<<<<<
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)
 */
  __pyx_t_2 = (__pyx_v_is_tuple != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (PyList_CheckExact(__pyx_v_lst_or_tpl) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  __pyx_t_2 = ((!__pyx_t_1) != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":156
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')             # <<<<<<<<<<<<<<
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":155
 * 
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):             # <<<<<<<<<<<<<<
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":157
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)             # <<<<<<<<<<<<<<
 *     if length == 0 or length == 1:
 *         return lst_or_tpl
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_lst_or_tpl); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_length = __pyx_t_4;

  /* "bzrlib/_known_graph_pyx.pyx":158
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:             # <<<<<<<<<<<<<<
 *         return lst_or_tpl
 *     if length == 2:
 */
  switch (__pyx_v_length) {
    case 0:
    case 1:

    /* "bzrlib/_known_graph_pyx.pyx":159
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:
 *         return lst_or_tpl             # <<<<<<<<<<<<<<
 *     if length == 2:
 *         if is_tuple:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_lst_or_tpl);
    __pyx_r = __pyx_v_lst_or_tpl;
    goto __pyx_L0;

    /* "bzrlib/_known_graph_pyx.pyx":158
 *         raise TypeError('lst_or_tpl must be a list or tuple.')
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:             # <<<<<<<<<<<<<<
 *         return lst_or_tpl
 *     if length == 2:
 */
    break;
    default: break;
  }

  /* "bzrlib/_known_graph_pyx.pyx":160
 *     if length == 0 or length == 1:
 *         return lst_or_tpl
 *     if length == 2:             # <<<<<<<<<<<<<<
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 */
  __pyx_t_2 = ((__pyx_v_length == 2) != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":161
 *         return lst_or_tpl
 *     if length == 2:
 *         if is_tuple:             # <<<<<<<<<<<<<<
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 */
    __pyx_t_2 = (__pyx_v_is_tuple != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":162
 *     if length == 2:
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)             # <<<<<<<<<<<<<<
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 *         else:
 */
      __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_lst_or_tpl, 0)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":163
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 *             node2 = _get_tuple_node(lst_or_tpl, 1)             # <<<<<<<<<<<<<<
 *         else:
 *             node1 = _get_list_node(lst_or_tpl, 0)
 */
      __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_lst_or_tpl, 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":161
 *         return lst_or_tpl
 *     if length == 2:
 *         if is_tuple:             # <<<<<<<<<<<<<<
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 */
      goto __pyx_L7;
    }

    /* "bzrlib/_known_graph_pyx.pyx":165
 *             node2 = _get_tuple_node(lst_or_tpl, 1)
 *         else:
 *             node1 = _get_list_node(lst_or_tpl, 0)             # <<<<<<<<<<<<<<
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:
 */
    /*else*/ {
      __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_lst_or_tpl, 0)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_node1 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":166
 *         else:
 *             node1 = _get_list_node(lst_or_tpl, 0)
 *             node2 = _get_list_node(lst_or_tpl, 1)             # <<<<<<<<<<<<<<
 *         if reverse:
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 */
      __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_lst_or_tpl, 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_node2 = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
      __pyx_t_3 = 0;
    }
    __pyx_L7:;

    /* "bzrlib/_known_graph_pyx.pyx":167
 *             node1 = _get_list_node(lst_or_tpl, 0)
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:             # <<<<<<<<<<<<<<
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 *         else:
 */
    __pyx_t_2 = (__pyx_v_reverse != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":168
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)             # <<<<<<<<<<<<<<
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 */
      __pyx_t_3 = __pyx_v_node1->key;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_5 = __pyx_v_node2->key;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_v_do_swap = PyObject_RichCompareBool(__pyx_t_3, __pyx_t_5, Py_LT);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":167
 *             node1 = _get_list_node(lst_or_tpl, 0)
 *             node2 = _get_list_node(lst_or_tpl, 1)
 *         if reverse:             # <<<<<<<<<<<<<<
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 *         else:
 */
      goto __pyx_L8;
    }

    /* "bzrlib/_known_graph_pyx.pyx":170
 *             do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)             # <<<<<<<<<<<<<<
 *         if not do_swap:
 *             return lst_or_tpl
 */
    /*else*/ {
      __pyx_t_5 = __pyx_v_node2->key;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_3 = __pyx_v_node1->key;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_v_do_swap = PyObject_RichCompareBool(__pyx_t_5, __pyx_t_3, Py_LT);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_L8:;

    /* "bzrlib/_known_graph_pyx.pyx":171
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 *         if not do_swap:             # <<<<<<<<<<<<<<
 *             return lst_or_tpl
 *         if is_tuple:
 */
    __pyx_t_2 = ((!(__pyx_v_do_swap != 0)) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":172
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 *         if not do_swap:
 *             return lst_or_tpl             # <<<<<<<<<<<<<<
 *         if is_tuple:
 *             return (node2, node1)
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_lst_or_tpl);
      __pyx_r = __pyx_v_lst_or_tpl;
      goto __pyx_L0;

      /* "bzrlib/_known_graph_pyx.pyx":171
 *         else:
 *             do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
 *         if not do_swap:             # <<<<<<<<<<<<<<
 *             return lst_or_tpl
 *         if is_tuple:
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":173
 *         if not do_swap:
 *             return lst_or_tpl
 *         if is_tuple:             # <<<<<<<<<<<<<<
 *             return (node2, node1)
 *         else:
 */
    __pyx_t_2 = (__pyx_v_is_tuple != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":174
 *             return lst_or_tpl
 *         if is_tuple:
 *             return (node2, node1)             # <<<<<<<<<<<<<<
 *         else:
 *             # Swap 'in-place', since lists are mutable
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_node2));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_node2));
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_node2));
      __Pyx_INCREF(((PyObject *)__pyx_v_node1));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_node1));
      PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_node1));
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L0;

      /* "bzrlib/_known_graph_pyx.pyx":173
 *         if not do_swap:
 *             return lst_or_tpl
 *         if is_tuple:             # <<<<<<<<<<<<<<
 *             return (node2, node1)
 *         else:
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":177
 *         else:
 *             # Swap 'in-place', since lists are mutable
 *             Py_INCREF(node1)             # <<<<<<<<<<<<<<
 *             PyList_SetItem(lst_or_tpl, 1, node1)
 *             Py_INCREF(node2)
 */
    /*else*/ {
      Py_INCREF(((PyObject *)__pyx_v_node1));

      /* "bzrlib/_known_graph_pyx.pyx":178
 *             # Swap 'in-place', since lists are mutable
 *             Py_INCREF(node1)
 *             PyList_SetItem(lst_or_tpl, 1, node1)             # <<<<<<<<<<<<<<
 *             Py_INCREF(node2)
 *             PyList_SetItem(lst_or_tpl, 0, node2)
 */
      __pyx_t_6 = PyList_SetItem(__pyx_v_lst_or_tpl, 1, ((PyObject *)__pyx_v_node1)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":179
 *             Py_INCREF(node1)
 *             PyList_SetItem(lst_or_tpl, 1, node1)
 *             Py_INCREF(node2)             # <<<<<<<<<<<<<<
 *             PyList_SetItem(lst_or_tpl, 0, node2)
 *             return lst_or_tpl
 */
      Py_INCREF(((PyObject *)__pyx_v_node2));

      /* "bzrlib/_known_graph_pyx.pyx":180
 *             PyList_SetItem(lst_or_tpl, 1, node1)
 *             Py_INCREF(node2)
 *             PyList_SetItem(lst_or_tpl, 0, node2)             # <<<<<<<<<<<<<<
 *             return lst_or_tpl
 *     # For all other sizes, we just use 'sorted()'
 */
      __pyx_t_6 = PyList_SetItem(__pyx_v_lst_or_tpl, 0, ((PyObject *)__pyx_v_node2)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":181
 *             Py_INCREF(node2)
 *             PyList_SetItem(lst_or_tpl, 0, node2)
 *             return lst_or_tpl             # <<<<<<<<<<<<<<
 *     # For all other sizes, we just use 'sorted()'
 *     if is_tuple:
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_lst_or_tpl);
      __pyx_r = __pyx_v_lst_or_tpl;
      goto __pyx_L0;
    }

    /* "bzrlib/_known_graph_pyx.pyx":160
 *     if length == 0 or length == 1:
 *         return lst_or_tpl
 *     if length == 2:             # <<<<<<<<<<<<<<
 *         if is_tuple:
 *             node1 = _get_tuple_node(lst_or_tpl, 0)
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":183
 *             return lst_or_tpl
 *     # For all other sizes, we just use 'sorted()'
 *     if is_tuple:             # <<<<<<<<<<<<<<
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)
 */
  __pyx_t_2 = (__pyx_v_is_tuple != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":185
 *     if is_tuple:
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)             # <<<<<<<<<<<<<<
 *     lst_or_tpl.sort(key=get_key, reverse=reverse)
 *     return lst_or_tpl
 */
    __pyx_t_3 = PySequence_List(__pyx_v_lst_or_tpl); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_lst_or_tpl, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":183
 *             return lst_or_tpl
 *     # For all other sizes, we just use 'sorted()'
 *     if is_tuple:             # <<<<<<<<<<<<<<
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":186
 *         # Note that sorted() is just list(iterable).sort()
 *         lst_or_tpl = list(lst_or_tpl)
 *     lst_or_tpl.sort(key=get_key, reverse=reverse)             # <<<<<<<<<<<<<<
 *     return lst_or_tpl
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_lst_or_tpl, __pyx_n_s_sort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_key); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_key, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_reverse); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reverse, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":187
 *         lst_or_tpl = list(lst_or_tpl)
 *     lst_or_tpl.sort(key=get_key, reverse=reverse)
 *     return lst_or_tpl             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_lst_or_tpl);
  __pyx_r = __pyx_v_lst_or_tpl;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":144
 * 
 * 
 * cdef object _sort_list_nodes(object lst_or_tpl, int reverse):             # <<<<<<<<<<<<<<
 *     """Sort a list of _KnownGraphNode objects.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._sort_list_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node1);
  __Pyx_XDECREF((PyObject *)__pyx_v_node2);
  __Pyx_XDECREF(__pyx_v_lst_or_tpl);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":199
 *     cdef public int do_cache
 * 
 *     def __init__(self, parent_map, do_cache=True):             # <<<<<<<<<<<<<<
 *         """Create a new KnownGraph instance.
 * 
 */

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph___init__[] = "Create a new KnownGraph instance.\n\n        :param parent_map: A dictionary mapping key => parent_keys\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__;
#endif
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_parent_map = 0;
  PyObject *__pyx_v_do_cache = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_parent_map,&__pyx_n_s_do_cache,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_parent_map)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_do_cache);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_parent_map = values[0];
    __pyx_v_do_cache = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph___init__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), __pyx_v_parent_map, __pyx_v_do_cache);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_parent_map, PyObject *__pyx_v_do_cache) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":205
 *         """
 *         # tests at pre-allocating the node dict actually slowed things down
 *         self._nodes = {}             # <<<<<<<<<<<<<<
 *         # Maps {sorted(revision_id, revision_id): heads}
 *         self._known_heads = {}
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_nodes);
  __Pyx_DECREF(__pyx_v_self->_nodes);
  __pyx_v_self->_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":207
 *         self._nodes = {}
 *         # Maps {sorted(revision_id, revision_id): heads}
 *         self._known_heads = {}             # <<<<<<<<<<<<<<
 *         self.do_cache = int(do_cache)
 *         # TODO: consider disabling gc since we are allocating a lot of nodes
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_known_heads);
  __Pyx_DECREF(__pyx_v_self->_known_heads);
  __pyx_v_self->_known_heads = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":208
 *         # Maps {sorted(revision_id, revision_id): heads}
 *         self._known_heads = {}
 *         self.do_cache = int(do_cache)             # <<<<<<<<<<<<<<
 *         # TODO: consider disabling gc since we are allocating a lot of nodes
 *         #       that won't be collectable anyway. real world testing has not
 */
  __pyx_t_1 = PyNumber_Int(__pyx_v_do_cache); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->do_cache = __pyx_t_2;

  /* "bzrlib/_known_graph_pyx.pyx":212
 *         #       that won't be collectable anyway. real world testing has not
 *         #       shown a specific impact, yet.
 *         self._initialize_nodes(parent_map)             # <<<<<<<<<<<<<<
 *         self._find_gdfo()
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_initialize_nodes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_parent_map); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_INCREF(__pyx_v_parent_map);
    __Pyx_GIVEREF(__pyx_v_parent_map);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_parent_map);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":213
 *         #       shown a specific impact, yet.
 *         self._initialize_nodes(parent_map)
 *         self._find_gdfo()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_find_gdfo); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":199
 *     cdef public int do_cache
 * 
 *     def __init__(self, parent_map, do_cache=True):             # <<<<<<<<<<<<<<
 *         """Create a new KnownGraph instance.
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":215
 *         self._find_gdfo()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode child
 *         cdef Py_ssize_t pos
 */

/* Python wrapper */
static void __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_2__dealloc__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_2__dealloc__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child = 0;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_temp_node;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":220
 *         cdef PyObject *temp_node
 * 
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             child = <_KnownGraphNode>temp_node
 *             child.clear_references()
 */
  while (1) {
    __pyx_t_1 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = (PyDict_Next(__pyx_t_1, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node)) != 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":221
 * 
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             child = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             child.clear_references()
 * 
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_temp_node);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_child, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":222
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             child = <_KnownGraphNode>temp_node
 *             child.clear_references()             # <<<<<<<<<<<<<<
 * 
 *     cdef _KnownGraphNode _get_or_create_node(self, key):
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_v_child->__pyx_vtab)->clear_references(__pyx_v_child); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":215
 *         self._find_gdfo()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode child
 *         cdef Py_ssize_t pos
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("bzrlib._known_graph_pyx.KnownGraph.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_RefNannyFinishContext();
}

/* "bzrlib/_known_graph_pyx.pyx":224
 *             child.clear_references()
 * 
 *     cdef _KnownGraphNode _get_or_create_node(self, key):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

static struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__get_or_create_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_or_create_node", 0);

  /* "bzrlib/_known_graph_pyx.pyx":228
 *         cdef _KnownGraphNode node
 * 
 *         temp_node = PyDict_GetItem(self._nodes, key)             # <<<<<<<<<<<<<<
 *         if temp_node == NULL:
 *             node = _KnownGraphNode(key)
 */
  __pyx_t_1 = __pyx_v_self->_nodes;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_temp_node = PyDict_GetItem(__pyx_t_1, __pyx_v_key);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":229
 * 
 *         temp_node = PyDict_GetItem(self._nodes, key)
 *         if temp_node == NULL:             # <<<<<<<<<<<<<<
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)
 */
  __pyx_t_2 = ((__pyx_v_temp_node == NULL) != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":230
 *         temp_node = PyDict_GetItem(self._nodes, key)
 *         if temp_node == NULL:
 *             node = _KnownGraphNode(key)             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._nodes, key, node)
 *         else:
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":231
 *         if temp_node == NULL:
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)             # <<<<<<<<<<<<<<
 *         else:
 *             node = <_KnownGraphNode>temp_node
 */
    __pyx_t_3 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = PyDict_SetItem(__pyx_t_3, __pyx_v_key, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":229
 * 
 *         temp_node = PyDict_GetItem(self._nodes, key)
 *         if temp_node == NULL:             # <<<<<<<<<<<<<<
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)
 */
    goto __pyx_L3;
  }

  /* "bzrlib/_known_graph_pyx.pyx":233
 *             PyDict_SetItem(self._nodes, key, node)
 *         else:
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *         return node
 * 
 */
  /*else*/ {
    __pyx_t_3 = ((PyObject *)__pyx_v_temp_node);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3);
    __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":234
 *         else:
 *             node = <_KnownGraphNode>temp_node
 *         return node             # <<<<<<<<<<<<<<
 * 
 *     cdef _populate_parents(self, _KnownGraphNode node, parent_keys):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_node));
  __pyx_r = __pyx_v_node;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":224
 *             child.clear_references()
 * 
 *     cdef _KnownGraphNode _get_or_create_node(self, key):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._get_or_create_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":236
 *         return node
 * 
 *     cdef _populate_parents(self, _KnownGraphNode node, parent_keys):             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t num_parent_keys, pos
 *         cdef _KnownGraphNode parent_node
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__populate_parents(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node, PyObject *__pyx_v_parent_keys) {
  Py_ssize_t __pyx_v_num_parent_keys;
  Py_ssize_t __pyx_v_pos;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node = 0;
  PyObject *__pyx_v_parent_nodes = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_populate_parents", 0);

  /* "bzrlib/_known_graph_pyx.pyx":240
 *         cdef _KnownGraphNode parent_node
 * 
 *         num_parent_keys = len(parent_keys)             # <<<<<<<<<<<<<<
 *         # We know how many parents, so we pre allocate the tuple
 *         parent_nodes = PyTuple_New(num_parent_keys)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_parent_keys); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_num_parent_keys = __pyx_t_1;

  /* "bzrlib/_known_graph_pyx.pyx":242
 *         num_parent_keys = len(parent_keys)
 *         # We know how many parents, so we pre allocate the tuple
 *         parent_nodes = PyTuple_New(num_parent_keys)             # <<<<<<<<<<<<<<
 *         for pos from 0 <= pos < num_parent_keys:
 *             # Note: it costs us 10ms out of 40ms to lookup all of these
 */
  __pyx_t_2 = PyTuple_New(__pyx_v_num_parent_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_parent_nodes = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":243
 *         # We know how many parents, so we pre allocate the tuple
 *         parent_nodes = PyTuple_New(num_parent_keys)
 *         for pos from 0 <= pos < num_parent_keys:             # <<<<<<<<<<<<<<
 *             # Note: it costs us 10ms out of 40ms to lookup all of these
 *             #       parents, it doesn't seem to be an allocation overhead,
 */
  __pyx_t_1 = __pyx_v_num_parent_keys;
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_1; __pyx_v_pos++) {

    /* "bzrlib/_known_graph_pyx.pyx":251
 *             #       node.
 *             # We use [] because parent_keys may be a tuple or list
 *             parent_node = self._get_or_create_node(parent_keys[pos])             # <<<<<<<<<<<<<<
 *             # PyTuple_SET_ITEM will steal a reference, so INCREF first
 *             Py_INCREF(parent_node)
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_parent_keys, __pyx_v_pos, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_get_or_create_node(__pyx_v_self, __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":253
 *             parent_node = self._get_or_create_node(parent_keys[pos])
 *             # PyTuple_SET_ITEM will steal a reference, so INCREF first
 *             Py_INCREF(parent_node)             # <<<<<<<<<<<<<<
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)
 *             PyList_Append(parent_node.children, node)
 */
    Py_INCREF(((PyObject *)__pyx_v_parent_node));

    /* "bzrlib/_known_graph_pyx.pyx":254
 *             # PyTuple_SET_ITEM will steal a reference, so INCREF first
 *             Py_INCREF(parent_node)
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)             # <<<<<<<<<<<<<<
 *             PyList_Append(parent_node.children, node)
 *         node.parents = parent_nodes
 */
    PyTuple_SET_ITEM(__pyx_v_parent_nodes, __pyx_v_pos, ((PyObject *)__pyx_v_parent_node));

    /* "bzrlib/_known_graph_pyx.pyx":255
 *             Py_INCREF(parent_node)
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)
 *             PyList_Append(parent_node.children, node)             # <<<<<<<<<<<<<<
 *         node.parents = parent_nodes
 * 
 */
    __pyx_t_3 = __pyx_v_parent_node->children;
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = PyList_Append(__pyx_t_3, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":256
 *             PyTuple_SET_ITEM(parent_nodes, pos, parent_node)
 *             PyList_Append(parent_node.children, node)
 *         node.parents = parent_nodes             # <<<<<<<<<<<<<<
 * 
 *     def _initialize_nodes(self, parent_map):
 */
  __Pyx_INCREF(__pyx_v_parent_nodes);
  __Pyx_GIVEREF(__pyx_v_parent_nodes);
  __Pyx_GOTREF(__pyx_v_node->parents);
  __Pyx_DECREF(__pyx_v_node->parents);
  __pyx_v_node->parents = __pyx_v_parent_nodes;

  /* "bzrlib/_known_graph_pyx.pyx":236
 *         return node
 * 
 *     cdef _populate_parents(self, _KnownGraphNode node, parent_keys):             # <<<<<<<<<<<<<<
 *         cdef Py_ssize_t num_parent_keys, pos
 *         cdef _KnownGraphNode parent_node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._populate_parents", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_XDECREF(__pyx_v_parent_nodes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":258
 *         node.parents = parent_nodes
 * 
 *     def _initialize_nodes(self, parent_map):             # <<<<<<<<<<<<<<
 *         """Populate self._nodes.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_5_initialize_nodes(PyObject *__pyx_v_self, PyObject *__pyx_v_parent_map); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_4_initialize_nodes[] = "Populate self._nodes.\n\n        After this has finished:\n        - self._nodes will have an entry for every entry in parent_map.\n        - ghosts will have a parent_keys = None,\n        - all nodes found will also have child_keys populated with all known\n          child keys,\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_5_initialize_nodes(PyObject *__pyx_v_self, PyObject *__pyx_v_parent_map) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_initialize_nodes (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_4_initialize_nodes(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_parent_map));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_4_initialize_nodes(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_parent_map) {
  PyObject *__pyx_v_temp_key;
  PyObject *__pyx_v_temp_parent_keys;
  Py_ssize_t __pyx_v_pos;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_parent_keys = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_initialize_nodes", 0);

  /* "bzrlib/_known_graph_pyx.pyx":272
 *         cdef _KnownGraphNode parent_node
 * 
 *         if not PyDict_CheckExact(parent_map):             # <<<<<<<<<<<<<<
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')
 *         # for key, parent_keys in parent_map.iteritems():
 */
  __pyx_t_1 = ((!(PyDict_CheckExact(__pyx_v_parent_map) != 0)) != 0);
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":273
 * 
 *         if not PyDict_CheckExact(parent_map):
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')             # <<<<<<<<<<<<<<
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":272
 *         cdef _KnownGraphNode parent_node
 * 
 *         if not PyDict_CheckExact(parent_map):             # <<<<<<<<<<<<<<
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')
 *         # for key, parent_keys in parent_map.iteritems():
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":275
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):
 *             key = <object>temp_key
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":276
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):             # <<<<<<<<<<<<<<
 *             key = <object>temp_key
 *             parent_keys = <object>temp_parent_keys
 */
  while (1) {
    __pyx_t_1 = (PyDict_Next(__pyx_v_parent_map, (&__pyx_v_pos), (&__pyx_v_temp_key), (&__pyx_v_temp_parent_keys)) != 0);
    if (!__pyx_t_1) break;

    /* "bzrlib/_known_graph_pyx.pyx":277
 *         pos = 0
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):
 *             key = <object>temp_key             # <<<<<<<<<<<<<<
 *             parent_keys = <object>temp_parent_keys
 *             node = self._get_or_create_node(key)
 */
    __pyx_t_2 = ((PyObject *)__pyx_v_temp_key);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":278
 *         while PyDict_Next(parent_map, &pos, &temp_key, &temp_parent_keys):
 *             key = <object>temp_key
 *             parent_keys = <object>temp_parent_keys             # <<<<<<<<<<<<<<
 *             node = self._get_or_create_node(key)
 *             self._populate_parents(node, parent_keys)
 */
    __pyx_t_2 = ((PyObject *)__pyx_v_temp_parent_keys);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_parent_keys, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":279
 *             key = <object>temp_key
 *             parent_keys = <object>temp_parent_keys
 *             node = self._get_or_create_node(key)             # <<<<<<<<<<<<<<
 *             self._populate_parents(node, parent_keys)
 * 
 */
    __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_get_or_create_node(__pyx_v_self, __pyx_v_key)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":280
 *             parent_keys = <object>temp_parent_keys
 *             node = self._get_or_create_node(key)
 *             self._populate_parents(node, parent_keys)             # <<<<<<<<<<<<<<
 * 
 *     def _find_tails(self):
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_populate_parents(__pyx_v_self, __pyx_v_node, __pyx_v_parent_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":258
 *         node.parents = parent_nodes
 * 
 *     def _initialize_nodes(self, parent_map):             # <<<<<<<<<<<<<<
 *         """Populate self._nodes.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._initialize_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_parent_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":282
 *             self._populate_parents(node, parent_keys)
 * 
 *     def _find_tails(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_7_find_tails(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_7_find_tails(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_find_tails (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_find_tails(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_find_tails(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_tails = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_find_tails", 0);

  /* "bzrlib/_known_graph_pyx.pyx":287
 *         cdef Py_ssize_t pos
 * 
 *         tails = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_tails = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":288
 * 
 *         tails = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":289
 *         tails = []
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 */
  while (1) {
    __pyx_t_1 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = (PyDict_Next(__pyx_t_1, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node)) != 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":290
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 *                 node.gdfo = 1
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_temp_node);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":291
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:             # <<<<<<<<<<<<<<
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)
 */
    __pyx_t_3 = (__pyx_v_node->parents == Py_None);
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_1 = __pyx_v_node->parents;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_4 = ((PyTuple_GET_SIZE(__pyx_t_1) == 0) != 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_2 = __pyx_t_4;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":292
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 *                 node.gdfo = 1             # <<<<<<<<<<<<<<
 *                 PyList_Append(tails, node)
 *         return tails
 */
      __pyx_v_node->gdfo = 1;

      /* "bzrlib/_known_graph_pyx.pyx":293
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)             # <<<<<<<<<<<<<<
 *         return tails
 * 
 */
      __pyx_t_5 = PyList_Append(__pyx_v_tails, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":291
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is None or PyTuple_GET_SIZE(node.parents) == 0:             # <<<<<<<<<<<<<<
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)
 */
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":294
 *                 node.gdfo = 1
 *                 PyList_Append(tails, node)
 *         return tails             # <<<<<<<<<<<<<<
 * 
 *     def _find_tips(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_tails);
  __pyx_r = __pyx_v_tails;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":282
 *             self._populate_parents(node, parent_keys)
 * 
 *     def _find_tails(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_tails", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_tails);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":296
 *         return tails
 * 
 *     def _find_tips(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_9_find_tips(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_9_find_tips(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_find_tips (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8_find_tips(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8_find_tips(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_tips = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_find_tips", 0);

  /* "bzrlib/_known_graph_pyx.pyx":301
 *         cdef Py_ssize_t pos
 * 
 *         tips = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_tips = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":302
 * 
 *         tips = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":303
 *         tips = []
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:
 */
  while (1) {
    __pyx_t_1 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = (PyDict_Next(__pyx_t_1, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node)) != 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":304
 *         pos = 0
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if PyList_GET_SIZE(node.children) == 0:
 *                 PyList_Append(tips, node)
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_temp_node);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":305
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:             # <<<<<<<<<<<<<<
 *                 PyList_Append(tips, node)
 *         return tips
 */
    __pyx_t_1 = __pyx_v_node->children;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_2 = ((PyList_GET_SIZE(__pyx_t_1) == 0) != 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":306
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:
 *                 PyList_Append(tips, node)             # <<<<<<<<<<<<<<
 *         return tips
 * 
 */
      __pyx_t_3 = PyList_Append(__pyx_v_tips, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":305
 *         while PyDict_Next(self._nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if PyList_GET_SIZE(node.children) == 0:             # <<<<<<<<<<<<<<
 *                 PyList_Append(tips, node)
 *         return tips
 */
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":307
 *             if PyList_GET_SIZE(node.children) == 0:
 *                 PyList_Append(tips, node)
 *         return tips             # <<<<<<<<<<<<<<
 * 
 *     def _find_gdfo(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_tips);
  __pyx_r = __pyx_v_tips;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":296
 *         return tails
 * 
 *     def _find_tips(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _KnownGraphNode node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_tips", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_tips);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":309
 *         return tips
 * 
 *     def _find_gdfo(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 *         cdef _KnownGraphNode child
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_11_find_gdfo(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_11_find_gdfo(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_find_gdfo (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_10_find_gdfo(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_10_find_gdfo(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child = 0;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  long __pyx_v_next_gdfo;
  PyObject *__pyx_v_pending = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_find_gdfo", 0);

  /* "bzrlib/_known_graph_pyx.pyx":318
 *         cdef long next_gdfo
 * 
 *         pending = self._find_tails()             # <<<<<<<<<<<<<<
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_find_tails); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_pending = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":320
 *         pending = self._find_tails()
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *         while last_item >= 0:
 *             # Avoid pop followed by push, instead, peek, and replace
 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "bzrlib/_known_graph_pyx.pyx":321
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:             # <<<<<<<<<<<<<<
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 */
  while (1) {
    __pyx_t_4 = ((__pyx_v_last_item >= 0) != 0);
    if (!__pyx_t_4) break;

    /* "bzrlib/_known_graph_pyx.pyx":324
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *             last_item = last_item - 1
 *             next_gdfo = node.gdfo + 1
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":325
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1             # <<<<<<<<<<<<<<
 *             next_gdfo = node.gdfo + 1
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "bzrlib/_known_graph_pyx.pyx":326
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             next_gdfo = node.gdfo + 1             # <<<<<<<<<<<<<<
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 */
    __pyx_v_next_gdfo = (__pyx_v_node->gdfo + 1);

    /* "bzrlib/_known_graph_pyx.pyx":327
 *             last_item = last_item - 1
 *             next_gdfo = node.gdfo + 1
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):             # <<<<<<<<<<<<<<
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:
 */
    __pyx_t_1 = __pyx_v_node->children;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = PyList_GET_SIZE(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_5; __pyx_v_pos++) {

      /* "bzrlib/_known_graph_pyx.pyx":328
 *             next_gdfo = node.gdfo + 1
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)             # <<<<<<<<<<<<<<
 *                 if next_gdfo > child.gdfo:
 *                     child.gdfo = next_gdfo
 */
      __pyx_t_1 = __pyx_v_node->children;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_1, __pyx_v_pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_child, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":329
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:             # <<<<<<<<<<<<<<
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1
 */
      __pyx_t_4 = ((__pyx_v_next_gdfo > __pyx_v_child->gdfo) != 0);
      if (__pyx_t_4) {

        /* "bzrlib/_known_graph_pyx.pyx":330
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:
 *                     child.gdfo = next_gdfo             # <<<<<<<<<<<<<<
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 */
        __pyx_v_child->gdfo = __pyx_v_next_gdfo;

        /* "bzrlib/_known_graph_pyx.pyx":329
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 *                 if next_gdfo > child.gdfo:             # <<<<<<<<<<<<<<
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":331
 *                 if next_gdfo > child.gdfo:
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1             # <<<<<<<<<<<<<<
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 *                     # This child is populated, queue it to be walked
 */
      __pyx_v_child->seen = (__pyx_v_child->seen + 1);

      /* "bzrlib/_known_graph_pyx.pyx":332
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):             # <<<<<<<<<<<<<<
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1
 */
      __pyx_t_2 = __pyx_v_child->parents;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = ((__pyx_v_child->seen == PyTuple_GET_SIZE(__pyx_t_2)) != 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_4) {

        /* "bzrlib/_known_graph_pyx.pyx":334
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "bzrlib/_known_graph_pyx.pyx":335
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)
 */
        __pyx_t_4 = ((__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending)) != 0);
        if (__pyx_t_4) {

          /* "bzrlib/_known_graph_pyx.pyx":336
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 */
          Py_INCREF(((PyObject *)__pyx_v_child));

          /* "bzrlib/_known_graph_pyx.pyx":337
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)             # <<<<<<<<<<<<<<
 *                     else:
 *                         PyList_Append(pending, child)
 */
          __pyx_t_6 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

          /* "bzrlib/_known_graph_pyx.pyx":335
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)
 */
          goto __pyx_L9;
        }

        /* "bzrlib/_known_graph_pyx.pyx":339
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 *                         PyList_Append(pending, child)             # <<<<<<<<<<<<<<
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 */
        /*else*/ {
          __pyx_t_6 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L9:;

        /* "bzrlib/_known_graph_pyx.pyx":342
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 *                     child.seen = 0             # <<<<<<<<<<<<<<
 * 
 *     def add_node(self, key, parent_keys):
 */
        __pyx_v_child->seen = 0;

        /* "bzrlib/_known_graph_pyx.pyx":332
 *                     child.gdfo = next_gdfo
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):             # <<<<<<<<<<<<<<
 *                     # This child is populated, queue it to be walked
 *                     last_item = last_item + 1
 */
      }
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":309
 *         return tips
 * 
 *     def _find_gdfo(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 *         cdef _KnownGraphNode child
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph._find_gdfo", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_pending);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":344
 *                     child.seen = 0
 * 
 *     def add_node(self, key, parent_keys):             # <<<<<<<<<<<<<<
 *         """Add a new node to the graph.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_13add_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_12add_node[] = "Add a new node to the graph.\n\n        If this fills in a ghost, then the gdfos of all children will be\n        updated accordingly.\n        \n        :param key: The node being added. If this is a duplicate, this is a\n            no-op.\n        :param parent_keys: The parents of the given node.\n        :return: None (should we return if this was a ghost, etc?)\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_13add_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_v_parent_keys = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_node (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_parent_keys,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_parent_keys)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add_node", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_node") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_key = values[0];
    __pyx_v_parent_keys = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add_node", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.add_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12add_node(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), __pyx_v_key, __pyx_v_parent_keys);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12add_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_parent_keys) {
  PyObject *__pyx_v_maybe_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child_node = 0;
  long __pyx_v_parent_gdfo;
  long __pyx_v_next_gdfo;
  PyObject *__pyx_v_existing_parent_keys = NULL;
  PyObject *__pyx_v_pending = NULL;
  PyObject *__pyx_v_pending_popleft = NULL;
  PyObject *__pyx_v_pending_append = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  int __pyx_t_9;
  long __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_node", 0);
  __Pyx_INCREF(__pyx_v_parent_keys);

  /* "bzrlib/_known_graph_pyx.pyx":359
 *         cdef long parent_gdfo, next_gdfo
 * 
 *         maybe_node = PyDict_GetItem(self._nodes, key)             # <<<<<<<<<<<<<<
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node
 */
  __pyx_t_1 = __pyx_v_self->_nodes;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_maybe_node = PyDict_GetItem(__pyx_t_1, __pyx_v_key);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":360
 * 
 *         maybe_node = PyDict_GetItem(self._nodes, key)
 *         if maybe_node != NULL:             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>maybe_node
 *             if node.parents is None:
 */
  __pyx_t_2 = ((__pyx_v_maybe_node != NULL) != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":361
 *         maybe_node = PyDict_GetItem(self._nodes, key)
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node             # <<<<<<<<<<<<<<
 *             if node.parents is None:
 *                 # We are filling in a ghost
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_maybe_node);
    __Pyx_INCREF(__pyx_t_1);
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":362
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node
 *             if node.parents is None:             # <<<<<<<<<<<<<<
 *                 # We are filling in a ghost
 *                 self._populate_parents(node, parent_keys)
 */
    __pyx_t_2 = (__pyx_v_node->parents == Py_None);
    __pyx_t_3 = (__pyx_t_2 != 0);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":364
 *             if node.parents is None:
 *                 # We are filling in a ghost
 *                 self._populate_parents(node, parent_keys)             # <<<<<<<<<<<<<<
 *                 # We can't trust cached heads anymore
 *                 self._known_heads.clear()
 */
      __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_populate_parents(__pyx_v_self, __pyx_v_node, __pyx_v_parent_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":366
 *                 self._populate_parents(node, parent_keys)
 *                 # We can't trust cached heads anymore
 *                 self._known_heads.clear()             # <<<<<<<<<<<<<<
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_known_heads, __pyx_n_s_clear); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":362
 *         if maybe_node != NULL:
 *             node = <_KnownGraphNode>maybe_node
 *             if node.parents is None:             # <<<<<<<<<<<<<<
 *                 # We are filling in a ghost
 *                 self._populate_parents(node, parent_keys)
 */
      goto __pyx_L4;
    }

    /* "bzrlib/_known_graph_pyx.pyx":368
 *                 self._known_heads.clear()
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []             # <<<<<<<<<<<<<<
 *                 for parent_node in node.parents:
 *                     existing_parent_keys.append(parent_node.key)
 */
    /*else*/ {
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_existing_parent_keys = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":369
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []
 *                 for parent_node in node.parents:             # <<<<<<<<<<<<<<
 *                     existing_parent_keys.append(parent_node.key)
 *                 # Make sure we use a list for the comparison, in case it was a
 */
      if (likely(PyList_CheckExact(__pyx_v_node->parents)) || PyTuple_CheckExact(__pyx_v_node->parents)) {
        __pyx_t_1 = __pyx_v_node->parents; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
        __pyx_t_7 = NULL;
      } else {
        __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_node->parents); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      for (;;) {
        if (likely(!__pyx_t_7)) {
          if (likely(PyList_CheckExact(__pyx_t_1))) {
            if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          } else {
            if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          }
        } else {
          __pyx_t_4 = __pyx_t_7(__pyx_t_1);
          if (unlikely(!__pyx_t_4)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_4);
        }
        if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4));
        __pyx_t_4 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":370
 *                 existing_parent_keys = []
 *                 for parent_node in node.parents:
 *                     existing_parent_keys.append(parent_node.key)             # <<<<<<<<<<<<<<
 *                 # Make sure we use a list for the comparison, in case it was a
 *                 # tuple, etc
 */
        __pyx_t_4 = __pyx_v_parent_node->key;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_existing_parent_keys, __pyx_t_4); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":369
 *             else: # Ensure that the parent_key list matches
 *                 existing_parent_keys = []
 *                 for parent_node in node.parents:             # <<<<<<<<<<<<<<
 *                     existing_parent_keys.append(parent_node.key)
 *                 # Make sure we use a list for the comparison, in case it was a
 */
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":373
 *                 # Make sure we use a list for the comparison, in case it was a
 *                 # tuple, etc
 *                 parent_keys = list(parent_keys)             # <<<<<<<<<<<<<<
 *                 if existing_parent_keys == parent_keys:
 *                     # Exact match, nothing more to do
 */
      __pyx_t_1 = PySequence_List(__pyx_v_parent_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_parent_keys, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":374
 *                 # tuple, etc
 *                 parent_keys = list(parent_keys)
 *                 if existing_parent_keys == parent_keys:             # <<<<<<<<<<<<<<
 *                     # Exact match, nothing more to do
 *                     return
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_existing_parent_keys, __pyx_v_parent_keys, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":376
 *                 if existing_parent_keys == parent_keys:
 *                     # Exact match, nothing more to do
 *                     return             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError('Parent key mismatch, existing node %s'
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;

        /* "bzrlib/_known_graph_pyx.pyx":374
 *                 # tuple, etc
 *                 parent_keys = list(parent_keys)
 *                 if existing_parent_keys == parent_keys:             # <<<<<<<<<<<<<<
 *                     # Exact match, nothing more to do
 *                     return
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":378
 *                     return
 *                 else:
 *                     raise ValueError('Parent key mismatch, existing node %s'             # <<<<<<<<<<<<<<
 *                         ' has parents of %s not %s'
 *                         % (key, existing_parent_keys, parent_keys))
 */
      /*else*/ {

        /* "bzrlib/_known_graph_pyx.pyx":380
 *                     raise ValueError('Parent key mismatch, existing node %s'
 *                         ' has parents of %s not %s'
 *                         % (key, existing_parent_keys, parent_keys))             # <<<<<<<<<<<<<<
 *         else:
 *             node = _KnownGraphNode(key)
 */
        __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
        __Pyx_INCREF(__pyx_v_existing_parent_keys);
        __Pyx_GIVEREF(__pyx_v_existing_parent_keys);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_existing_parent_keys);
        __Pyx_INCREF(__pyx_v_parent_keys);
        __Pyx_GIVEREF(__pyx_v_parent_keys);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_parent_keys);
        __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Parent_key_mismatch_existing_nod, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":378
 *                     return
 *                 else:
 *                     raise ValueError('Parent key mismatch, existing node %s'             # <<<<<<<<<<<<<<
 *                         ' has parents of %s not %s'
 *                         % (key, existing_parent_keys, parent_keys))
 */
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    __pyx_L4:;

    /* "bzrlib/_known_graph_pyx.pyx":360
 * 
 *         maybe_node = PyDict_GetItem(self._nodes, key)
 *         if maybe_node != NULL:             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>maybe_node
 *             if node.parents is None:
 */
    goto __pyx_L3;
  }

  /* "bzrlib/_known_graph_pyx.pyx":382
 *                         % (key, existing_parent_keys, parent_keys))
 *         else:
 *             node = _KnownGraphNode(key)             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._nodes, key, node)
 *             self._populate_parents(node, parent_keys)
 */
  /*else*/ {
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_key);
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode), __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":383
 *         else:
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)             # <<<<<<<<<<<<<<
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0
 */
    __pyx_t_1 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_9 = PyDict_SetItem(__pyx_t_1, __pyx_v_key, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":384
 *             node = _KnownGraphNode(key)
 *             PyDict_SetItem(self._nodes, key, node)
 *             self._populate_parents(node, parent_keys)             # <<<<<<<<<<<<<<
 *         parent_gdfo = 0
 *         for parent_node in node.parents:
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self->__pyx_vtab)->_populate_parents(__pyx_v_self, __pyx_v_node, __pyx_v_parent_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":385
 *             PyDict_SetItem(self._nodes, key, node)
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0             # <<<<<<<<<<<<<<
 *         for parent_node in node.parents:
 *             if parent_node.gdfo == -1:
 */
  __pyx_v_parent_gdfo = 0;

  /* "bzrlib/_known_graph_pyx.pyx":386
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0
 *         for parent_node in node.parents:             # <<<<<<<<<<<<<<
 *             if parent_node.gdfo == -1:
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 */
  if (likely(PyList_CheckExact(__pyx_v_node->parents)) || PyTuple_CheckExact(__pyx_v_node->parents)) {
    __pyx_t_1 = __pyx_v_node->parents; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_node->parents); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":387
 *         parent_gdfo = 0
 *         for parent_node in node.parents:
 *             if parent_node.gdfo == -1:             # <<<<<<<<<<<<<<
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1
 */
    __pyx_t_3 = ((__pyx_v_parent_node->gdfo == -1L) != 0);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":389
 *             if parent_node.gdfo == -1:
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1             # <<<<<<<<<<<<<<
 *             if parent_gdfo < parent_node.gdfo:
 *                 parent_gdfo = parent_node.gdfo
 */
      __pyx_v_parent_node->gdfo = 1;

      /* "bzrlib/_known_graph_pyx.pyx":387
 *         parent_gdfo = 0
 *         for parent_node in node.parents:
 *             if parent_node.gdfo == -1:             # <<<<<<<<<<<<<<
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":390
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1
 *             if parent_gdfo < parent_node.gdfo:             # <<<<<<<<<<<<<<
 *                 parent_gdfo = parent_node.gdfo
 *         node.gdfo = parent_gdfo + 1
 */
    __pyx_t_3 = ((__pyx_v_parent_gdfo < __pyx_v_parent_node->gdfo) != 0);
    if (__pyx_t_3) {

      /* "bzrlib/_known_graph_pyx.pyx":391
 *                 parent_node.gdfo = 1
 *             if parent_gdfo < parent_node.gdfo:
 *                 parent_gdfo = parent_node.gdfo             # <<<<<<<<<<<<<<
 *         node.gdfo = parent_gdfo + 1
 *         # Now fill the gdfo to all children
 */
      __pyx_t_10 = __pyx_v_parent_node->gdfo;
      __pyx_v_parent_gdfo = __pyx_t_10;

      /* "bzrlib/_known_graph_pyx.pyx":390
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 *                 parent_node.gdfo = 1
 *             if parent_gdfo < parent_node.gdfo:             # <<<<<<<<<<<<<<
 *                 parent_gdfo = parent_node.gdfo
 *         node.gdfo = parent_gdfo + 1
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":386
 *             self._populate_parents(node, parent_keys)
 *         parent_gdfo = 0
 *         for parent_node in node.parents:             # <<<<<<<<<<<<<<
 *             if parent_node.gdfo == -1:
 *                 # This is a newly introduced ghost, so it gets gdfo of 1
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":392
 *             if parent_gdfo < parent_node.gdfo:
 *                 parent_gdfo = parent_node.gdfo
 *         node.gdfo = parent_gdfo + 1             # <<<<<<<<<<<<<<
 *         # Now fill the gdfo to all children
 *         # Note that this loop is slightly inefficient, in that we may visit the
 */
  __pyx_v_node->gdfo = (__pyx_v_parent_gdfo + 1);

  /* "bzrlib/_known_graph_pyx.pyx":401
 *         # than DFD. So that if a longer path is possible, we walk it before we
 *         # get to the final child
 *         pending = deque([node])             # <<<<<<<<<<<<<<
 *         pending_popleft = pending.popleft
 *         pending_append = pending.append
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_deque); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_node));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_node));
  PyList_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_node));
  __pyx_t_11 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  if (!__pyx_t_11) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_pending = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":402
 *         # get to the final child
 *         pending = deque([node])
 *         pending_popleft = pending.popleft             # <<<<<<<<<<<<<<
 *         pending_append = pending.append
 *         while pending:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_pending, __pyx_n_s_popleft); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_pending_popleft = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":403
 *         pending = deque([node])
 *         pending_popleft = pending.popleft
 *         pending_append = pending.append             # <<<<<<<<<<<<<<
 *         while pending:
 *             node = pending_popleft()
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_pending, __pyx_n_s_append); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_pending_append = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":404
 *         pending_popleft = pending.popleft
 *         pending_append = pending.append
 *         while pending:             # <<<<<<<<<<<<<<
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1
 */
  while (1) {
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_pending); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_3) break;

    /* "bzrlib/_known_graph_pyx.pyx":405
 *         pending_append = pending.append
 *         while pending:
 *             node = pending_popleft()             # <<<<<<<<<<<<<<
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:
 */
    __Pyx_INCREF(__pyx_v_pending_popleft);
    __pyx_t_4 = __pyx_v_pending_popleft; __pyx_t_12 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (__pyx_t_12) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":406
 *         while pending:
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1             # <<<<<<<<<<<<<<
 *             for child_node in node.children:
 *                 if child_node.gdfo < next_gdfo:
 */
    __pyx_v_next_gdfo = (__pyx_v_node->gdfo + 1);

    /* "bzrlib/_known_graph_pyx.pyx":407
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:             # <<<<<<<<<<<<<<
 *                 if child_node.gdfo < next_gdfo:
 *                     # This child is being updated, we need to check its
 */
    if (likely(PyList_CheckExact(__pyx_v_node->children)) || PyTuple_CheckExact(__pyx_v_node->children)) {
      __pyx_t_1 = __pyx_v_node->children; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_node->children); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_4);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_4);
          #endif
        }
      } else {
        __pyx_t_4 = __pyx_t_7(__pyx_t_1);
        if (unlikely(!__pyx_t_4)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_XDECREF_SET(__pyx_v_child_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":408
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:
 *                 if child_node.gdfo < next_gdfo:             # <<<<<<<<<<<<<<
 *                     # This child is being updated, we need to check its
 *                     # children
 */
      __pyx_t_3 = ((__pyx_v_child_node->gdfo < __pyx_v_next_gdfo) != 0);
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":411
 *                     # This child is being updated, we need to check its
 *                     # children
 *                     child_node.gdfo = next_gdfo             # <<<<<<<<<<<<<<
 *                     pending_append(child_node)
 * 
 */
        __pyx_v_child_node->gdfo = __pyx_v_next_gdfo;

        /* "bzrlib/_known_graph_pyx.pyx":412
 *                     # children
 *                     child_node.gdfo = next_gdfo
 *                     pending_append(child_node)             # <<<<<<<<<<<<<<
 * 
 *     def heads(self, keys):
 */
        __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_pending, ((PyObject *)__pyx_v_child_node)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "bzrlib/_known_graph_pyx.pyx":408
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:
 *                 if child_node.gdfo < next_gdfo:             # <<<<<<<<<<<<<<
 *                     # This child is being updated, we need to check its
 *                     # children
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":407
 *             node = pending_popleft()
 *             next_gdfo = node.gdfo + 1
 *             for child_node in node.children:             # <<<<<<<<<<<<<<
 *                 if child_node.gdfo < next_gdfo:
 *                     # This child is being updated, we need to check its
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":344
 *                     child.seen = 0
 * 
 *     def add_node(self, key, parent_keys):             # <<<<<<<<<<<<<<
 *         """Add a new node to the graph.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.add_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_child_node);
  __Pyx_XDECREF(__pyx_v_existing_parent_keys);
  __Pyx_XDECREF(__pyx_v_pending);
  __Pyx_XDECREF(__pyx_v_pending_popleft);
  __Pyx_XDECREF(__pyx_v_pending_append);
  __Pyx_XDECREF(__pyx_v_parent_keys);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":414
 *                     pending_append(child_node)
 * 
 *     def heads(self, keys):             # <<<<<<<<<<<<<<
 *         """Return the heads from amongst keys.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_15heads(PyObject *__pyx_v_self, PyObject *__pyx_v_keys); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_14heads[] = "Return the heads from amongst keys.\n\n        This is done by searching the ancestries of each key.  Any key that is\n        reachable from another key is not returned; all the others are.\n\n        This operation scales with the relative depth between any two keys. It\n        uses gdfo to avoid walking all ancestry.\n\n        :param keys: An iterable of keys.\n        :return: A set of the heads. Note that as a set there is no ordering\n            information. Callers will need to filter their input to create\n            order if they need it.\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_15heads(PyObject *__pyx_v_self, PyObject *__pyx_v_keys) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("heads (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_14heads(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_keys));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_14heads(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_keys) {
  PyObject *__pyx_v_maybe_node;
  PyObject *__pyx_v_maybe_heads;
  PyObject *__pyx_v_temp_node;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  long __pyx_v_min_gdfo;
  PyObject *__pyx_v_heads_key = NULL;
  PyObject *__pyx_v_candidate_nodes = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_cleanup = NULL;
  PyObject *__pyx_v_pending = NULL;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node = NULL;
  PyObject *__pyx_v_heads = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  long __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("heads", 0);

  /* "bzrlib/_known_graph_pyx.pyx":435
 *         cdef long min_gdfo
 * 
 *         heads_key = frozenset(keys)             # <<<<<<<<<<<<<<
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:
 */
  __pyx_t_1 = __Pyx_PyFrozenSet_New(__pyx_v_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_heads_key = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":436
 * 
 *         heads_key = frozenset(keys)
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)             # <<<<<<<<<<<<<<
 *         if maybe_heads != NULL:
 *             return <object>maybe_heads
 */
  __pyx_t_1 = __pyx_v_self->_known_heads;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_maybe_heads = PyDict_GetItem(__pyx_t_1, __pyx_v_heads_key);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":437
 *         heads_key = frozenset(keys)
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:             # <<<<<<<<<<<<<<
 *             return <object>maybe_heads
 *         # Not cached, compute it ourselves
 */
  __pyx_t_2 = ((__pyx_v_maybe_heads != NULL) != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":438
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:
 *             return <object>maybe_heads             # <<<<<<<<<<<<<<
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_maybe_heads));
    __pyx_r = ((PyObject *)__pyx_v_maybe_heads);
    goto __pyx_L0;

    /* "bzrlib/_known_graph_pyx.pyx":437
 *         heads_key = frozenset(keys)
 *         maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
 *         if maybe_heads != NULL:             # <<<<<<<<<<<<<<
 *             return <object>maybe_heads
 *         # Not cached, compute it ourselves
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":440
 *             return <object>maybe_heads
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}             # <<<<<<<<<<<<<<
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_candidate_nodes = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":441
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}
 *         for key in keys:             # <<<<<<<<<<<<<<
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:
 */
  if (likely(PyList_CheckExact(__pyx_v_keys)) || PyTuple_CheckExact(__pyx_v_keys)) {
    __pyx_t_1 = __pyx_v_keys; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_keys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_1);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":442
 *         candidate_nodes = {}
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)             # <<<<<<<<<<<<<<
 *             if maybe_node == NULL:
 *                 raise KeyError('key %s not in nodes' % (key,))
 */
    __pyx_t_5 = __pyx_v_self->_nodes;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_v_maybe_node = PyDict_GetItem(__pyx_t_5, __pyx_v_key);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":443
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:             # <<<<<<<<<<<<<<
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 */
    __pyx_t_2 = ((__pyx_v_maybe_node == NULL) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":444
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:
 *                 raise KeyError('key %s not in nodes' % (key,))             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 */
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_key);
      __Pyx_GIVEREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_key);
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_key_s_not_in_nodes, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":443
 *         for key in keys:
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:             # <<<<<<<<<<<<<<
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":445
 *             if maybe_node == NULL:
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)             # <<<<<<<<<<<<<<
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 *         if maybe_node != NULL:
 */
    __pyx_t_7 = PyDict_SetItem(__pyx_v_candidate_nodes, __pyx_v_key, ((PyObject *)__pyx_v_maybe_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":441
 *         # Not cached, compute it ourselves
 *         candidate_nodes = {}
 *         for key in keys:             # <<<<<<<<<<<<<<
 *             maybe_node = PyDict_GetItem(self._nodes, key)
 *             if maybe_node == NULL:
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":446
 *                 raise KeyError('key %s not in nodes' % (key,))
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)             # <<<<<<<<<<<<<<
 *         if maybe_node != NULL:
 *             # NULL_REVISION is only a head if it is the only entry
 */
  __pyx_t_1 = __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_maybe_node = PyDict_GetItem(__pyx_v_candidate_nodes, __pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":447
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 *         if maybe_node != NULL:             # <<<<<<<<<<<<<<
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)
 */
  __pyx_t_2 = ((__pyx_v_maybe_node != NULL) != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":449
 *         if maybe_node != NULL:
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)             # <<<<<<<<<<<<<<
 *             if not candidate_nodes:
 *                 return frozenset([NULL_REVISION])
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_candidate_nodes, __pyx_n_s_pop); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __Pyx_GIVEREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":450
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)
 *             if not candidate_nodes:             # <<<<<<<<<<<<<<
 *                 return frozenset([NULL_REVISION])
 *             # The keys changed, so recalculate heads_key
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_candidate_nodes); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = ((!__pyx_t_2) != 0);
    if (__pyx_t_9) {

      /* "bzrlib/_known_graph_pyx.pyx":451
 *             candidate_nodes.pop(NULL_REVISION)
 *             if not candidate_nodes:
 *                 return frozenset([NULL_REVISION])             # <<<<<<<<<<<<<<
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __Pyx_GIVEREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
      __pyx_t_6 = __Pyx_PyFrozenSet_New(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;

      /* "bzrlib/_known_graph_pyx.pyx":450
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)
 *             if not candidate_nodes:             # <<<<<<<<<<<<<<
 *                 return frozenset([NULL_REVISION])
 *             # The keys changed, so recalculate heads_key
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":453
 *                 return frozenset([NULL_REVISION])
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)             # <<<<<<<<<<<<<<
 *         if PyDict_Size(candidate_nodes) < 2:
 *             return heads_key
 */
    __pyx_t_6 = __Pyx_PyFrozenSet_New(__pyx_v_candidate_nodes); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF_SET(__pyx_v_heads_key, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":447
 *             PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
 *         maybe_node = PyDict_GetItem(candidate_nodes, NULL_REVISION)
 *         if maybe_node != NULL:             # <<<<<<<<<<<<<<
 *             # NULL_REVISION is only a head if it is the only entry
 *             candidate_nodes.pop(NULL_REVISION)
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":454
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)
 *         if PyDict_Size(candidate_nodes) < 2:             # <<<<<<<<<<<<<<
 *             return heads_key
 * 
 */
  __pyx_t_3 = PyDict_Size(__pyx_v_candidate_nodes); if (unlikely(__pyx_t_3 == -1L)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_9 = ((__pyx_t_3 < 2) != 0);
  if (__pyx_t_9) {

    /* "bzrlib/_known_graph_pyx.pyx":455
 *             heads_key = frozenset(candidate_nodes)
 *         if PyDict_Size(candidate_nodes) < 2:
 *             return heads_key             # <<<<<<<<<<<<<<
 * 
 *         cleanup = []
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_heads_key);
    __pyx_r = __pyx_v_heads_key;
    goto __pyx_L0;

    /* "bzrlib/_known_graph_pyx.pyx":454
 *             # The keys changed, so recalculate heads_key
 *             heads_key = frozenset(candidate_nodes)
 *         if PyDict_Size(candidate_nodes) < 2:             # <<<<<<<<<<<<<<
 *             return heads_key
 * 
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":457
 *             return heads_key
 * 
 *         cleanup = []             # <<<<<<<<<<<<<<
 *         pending = []
 *         # we know a gdfo cannot be longer than a linear chain of all nodes
 */
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_v_cleanup = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":458
 * 
 *         cleanup = []
 *         pending = []             # <<<<<<<<<<<<<<
 *         # we know a gdfo cannot be longer than a linear chain of all nodes
 *         min_gdfo = PyDict_Size(self._nodes) + 1
 */
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_v_pending = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":460
 *         pending = []
 *         # we know a gdfo cannot be longer than a linear chain of all nodes
 *         min_gdfo = PyDict_Size(self._nodes) + 1             # <<<<<<<<<<<<<<
 *         # Build up nodes that need to be walked, note that starting nodes are
 *         # not added to seen()
 */
  __pyx_t_6 = __pyx_v_self->_nodes;
  __Pyx_INCREF(__pyx_t_6);
  __pyx_t_3 = PyDict_Size(__pyx_t_6); if (unlikely(__pyx_t_3 == -1L)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_min_gdfo = (__pyx_t_3 + 1);

  /* "bzrlib/_known_graph_pyx.pyx":463
 *         # Build up nodes that need to be walked, note that starting nodes are
 *         # not added to seen()
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":464
 *         # not added to seen()
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:
 */
  while (1) {
    __pyx_t_9 = (PyDict_Next(__pyx_v_candidate_nodes, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node)) != 0);
    if (!__pyx_t_9) break;

    /* "bzrlib/_known_graph_pyx.pyx":465
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if node.parents is not None:
 *                 pending.extend(node.parents)
 */
    __pyx_t_6 = ((PyObject *)__pyx_v_temp_node);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":466
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:             # <<<<<<<<<<<<<<
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:
 */
    __pyx_t_9 = (__pyx_v_node->parents != Py_None);
    __pyx_t_2 = (__pyx_t_9 != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":467
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:
 *                 pending.extend(node.parents)             # <<<<<<<<<<<<<<
 *             if node.gdfo < min_gdfo:
 *                 min_gdfo = node.gdfo
 */
      __pyx_t_6 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_10 = __Pyx_PyList_Extend(__pyx_v_pending, __pyx_t_6); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":466
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if node.parents is not None:             # <<<<<<<<<<<<<<
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":468
 *             if node.parents is not None:
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:             # <<<<<<<<<<<<<<
 *                 min_gdfo = node.gdfo
 * 
 */
    __pyx_t_2 = ((__pyx_v_node->gdfo < __pyx_v_min_gdfo) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":469
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:
 *                 min_gdfo = node.gdfo             # <<<<<<<<<<<<<<
 * 
 *         # Now do all the real work
 */
      __pyx_t_11 = __pyx_v_node->gdfo;
      __pyx_v_min_gdfo = __pyx_t_11;

      /* "bzrlib/_known_graph_pyx.pyx":468
 *             if node.parents is not None:
 *                 pending.extend(node.parents)
 *             if node.gdfo < min_gdfo:             # <<<<<<<<<<<<<<
 *                 min_gdfo = node.gdfo
 * 
 */
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":472
 * 
 *         # Now do all the real work
 *         last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *         while last_item >= 0:
 *             node = _get_list_node(pending, last_item)
 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "bzrlib/_known_graph_pyx.pyx":473
 *         # Now do all the real work
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:             # <<<<<<<<<<<<<<
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_last_item >= 0) != 0);
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":474
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:
 *             node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *             last_item = last_item - 1
 *             if node.seen:
 */
    __pyx_t_6 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":475
 *         while last_item >= 0:
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1             # <<<<<<<<<<<<<<
 *             if node.seen:
 *                 # node already appears in some ancestry
 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "bzrlib/_known_graph_pyx.pyx":476
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             if node.seen:             # <<<<<<<<<<<<<<
 *                 # node already appears in some ancestry
 *                 continue
 */
    __pyx_t_2 = (__pyx_v_node->seen != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":478
 *             if node.seen:
 *                 # node already appears in some ancestry
 *                 continue             # <<<<<<<<<<<<<<
 *             PyList_Append(cleanup, node)
 *             node.seen = 1
 */
      goto __pyx_L14_continue;

      /* "bzrlib/_known_graph_pyx.pyx":476
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             if node.seen:             # <<<<<<<<<<<<<<
 *                 # node already appears in some ancestry
 *                 continue
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":479
 *                 # node already appears in some ancestry
 *                 continue
 *             PyList_Append(cleanup, node)             # <<<<<<<<<<<<<<
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:
 */
    __pyx_t_7 = PyList_Append(__pyx_v_cleanup, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":480
 *                 continue
 *             PyList_Append(cleanup, node)
 *             node.seen = 1             # <<<<<<<<<<<<<<
 *             if node.gdfo <= min_gdfo:
 *                 continue
 */
    __pyx_v_node->seen = 1;

    /* "bzrlib/_known_graph_pyx.pyx":481
 *             PyList_Append(cleanup, node)
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:             # <<<<<<<<<<<<<<
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 */
    __pyx_t_2 = ((__pyx_v_node->gdfo <= __pyx_v_min_gdfo) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":482
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:
 *                 continue             # <<<<<<<<<<<<<<
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 */
      goto __pyx_L14_continue;

      /* "bzrlib/_known_graph_pyx.pyx":481
 *             PyList_Append(cleanup, node)
 *             node.seen = 1
 *             if node.gdfo <= min_gdfo:             # <<<<<<<<<<<<<<
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":483
 *             if node.gdfo <= min_gdfo:
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:             # <<<<<<<<<<<<<<
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)
 */
    __pyx_t_9 = (__pyx_v_node->parents != Py_None);
    __pyx_t_12 = (__pyx_t_9 != 0);
    if (__pyx_t_12) {
    } else {
      __pyx_t_2 = __pyx_t_12;
      goto __pyx_L19_bool_binop_done;
    }
    __pyx_t_6 = __pyx_v_node->parents;
    __Pyx_INCREF(__pyx_t_6);
    __pyx_t_12 = ((PyTuple_GET_SIZE(__pyx_t_6) > 0) != 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = __pyx_t_12;
    __pyx_L19_bool_binop_done:;
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":484
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):             # <<<<<<<<<<<<<<
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1
 */
      __pyx_t_6 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_3 = PyTuple_GET_SIZE(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_3; __pyx_v_pos++) {

        /* "bzrlib/_known_graph_pyx.pyx":485
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)             # <<<<<<<<<<<<<<
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 */
        __pyx_t_6 = __pyx_v_node->parents;
        __Pyx_INCREF(__pyx_t_6);
        __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_t_6, __pyx_v_pos)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
        __pyx_t_1 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":486
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "bzrlib/_known_graph_pyx.pyx":487
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, parent_node)
 */
        __pyx_t_2 = ((__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending)) != 0);
        if (__pyx_t_2) {

          /* "bzrlib/_known_graph_pyx.pyx":488
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(parent_node) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                         PyList_SetItem(pending, last_item, parent_node)
 *                     else:
 */
          Py_INCREF(((PyObject *)__pyx_v_parent_node));

          /* "bzrlib/_known_graph_pyx.pyx":489
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, parent_node)             # <<<<<<<<<<<<<<
 *                     else:
 *                         PyList_Append(pending, parent_node)
 */
          __pyx_t_7 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

          /* "bzrlib/_known_graph_pyx.pyx":487
 *                     parent_node = _get_tuple_node(node.parents, pos)
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(parent_node) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, parent_node)
 */
          goto __pyx_L23;
        }

        /* "bzrlib/_known_graph_pyx.pyx":491
 *                         PyList_SetItem(pending, last_item, parent_node)
 *                     else:
 *                         PyList_Append(pending, parent_node)             # <<<<<<<<<<<<<<
 *         heads = []
 *         pos = 0
 */
        /*else*/ {
          __pyx_t_7 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L23:;
      }

      /* "bzrlib/_known_graph_pyx.pyx":483
 *             if node.gdfo <= min_gdfo:
 *                 continue
 *             if node.parents is not None and PyTuple_GET_SIZE(node.parents) > 0:             # <<<<<<<<<<<<<<
 *                 for pos from 0 <= pos < PyTuple_GET_SIZE(node.parents):
 *                     parent_node = _get_tuple_node(node.parents, pos)
 */
    }
    __pyx_L14_continue:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":492
 *                     else:
 *                         PyList_Append(pending, parent_node)
 *         heads = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_heads = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":493
 *                         PyList_Append(pending, parent_node)
 *         heads = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_known_graph_pyx.pyx":494
 *         heads = []
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):             # <<<<<<<<<<<<<<
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:
 */
  while (1) {
    __pyx_t_2 = (PyDict_Next(__pyx_v_candidate_nodes, (&__pyx_v_pos), NULL, (&__pyx_v_temp_node)) != 0);
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":495
 *         pos = 0
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node             # <<<<<<<<<<<<<<
 *             if not node.seen:
 *                 PyList_Append(heads, node.key)
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_temp_node);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":496
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:             # <<<<<<<<<<<<<<
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)
 */
    __pyx_t_2 = ((!(__pyx_v_node->seen != 0)) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":497
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:
 *                 PyList_Append(heads, node.key)             # <<<<<<<<<<<<<<
 *         heads = frozenset(heads)
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 */
      __pyx_t_1 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_7 = PyList_Append(__pyx_v_heads, __pyx_t_1); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":496
 *         while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
 *             node = <_KnownGraphNode>temp_node
 *             if not node.seen:             # <<<<<<<<<<<<<<
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)
 */
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":498
 *             if not node.seen:
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)             # <<<<<<<<<<<<<<
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 *             node = _get_list_node(cleanup, pos)
 */
  __pyx_t_1 = __Pyx_PyFrozenSet_New(__pyx_v_heads); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_heads, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":499
 *                 PyList_Append(heads, node.key)
 *         heads = frozenset(heads)
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):             # <<<<<<<<<<<<<<
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0
 */
  __pyx_t_3 = PyList_GET_SIZE(__pyx_v_cleanup);
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_3; __pyx_v_pos++) {

    /* "bzrlib/_known_graph_pyx.pyx":500
 *         heads = frozenset(heads)
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 *             node = _get_list_node(cleanup, pos)             # <<<<<<<<<<<<<<
 *             node.seen = 0
 *         if self.do_cache:
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_cleanup, __pyx_v_pos)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":501
 *         for pos from 0 <= pos < PyList_GET_SIZE(cleanup):
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0             # <<<<<<<<<<<<<<
 *         if self.do_cache:
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 */
    __pyx_v_node->seen = 0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":502
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0
 *         if self.do_cache:             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 *         return heads
 */
  __pyx_t_2 = (__pyx_v_self->do_cache != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":503
 *             node.seen = 0
 *         if self.do_cache:
 *             PyDict_SetItem(self._known_heads, heads_key, heads)             # <<<<<<<<<<<<<<
 *         return heads
 * 
 */
    __pyx_t_1 = __pyx_v_self->_known_heads;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_7 = PyDict_SetItem(__pyx_t_1, __pyx_v_heads_key, __pyx_v_heads); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":502
 *             node = _get_list_node(cleanup, pos)
 *             node.seen = 0
 *         if self.do_cache:             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 *         return heads
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":504
 *         if self.do_cache:
 *             PyDict_SetItem(self._known_heads, heads_key, heads)
 *         return heads             # <<<<<<<<<<<<<<
 * 
 *     def topo_sort(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_heads);
  __pyx_r = __pyx_v_heads;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":414
 *                     pending_append(child_node)
 * 
 *     def heads(self, keys):             # <<<<<<<<<<<<<<
 *         """Return the heads from amongst keys.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.heads", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_heads_key);
  __Pyx_XDECREF(__pyx_v_candidate_nodes);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_cleanup);
  __Pyx_XDECREF(__pyx_v_pending);
  __Pyx_XDECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_XDECREF(__pyx_v_heads);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":506
 *         return heads
 * 
 *     def topo_sort(self):             # <<<<<<<<<<<<<<
 *         """Return the nodes in topological order.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_17topo_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_16topo_sort[] = "Return the nodes in topological order.\n\n        All parents must occur before all children.\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_17topo_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("topo_sort (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_16topo_sort(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_16topo_sort(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_child = 0;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  PyObject *__pyx_v_pending = NULL;
  PyObject *__pyx_v_topo_order = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("topo_sort", 0);

  /* "bzrlib/_known_graph_pyx.pyx":523
 *         cdef Py_ssize_t last_item
 * 
 *         pending = self._find_tails()             # <<<<<<<<<<<<<<
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:
 *             raise errors.GraphCycleError(self._nodes)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_find_tails); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_pending = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":524
 * 
 *         pending = self._find_tails()
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:             # <<<<<<<<<<<<<<
 *             raise errors.GraphCycleError(self._nodes)
 * 
 */
  __pyx_t_5 = ((PyList_GET_SIZE(__pyx_v_pending) == 0) != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_4 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_1 = __pyx_v_self->_nodes;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_6 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((__pyx_t_6 > 0) != 0);
  __pyx_t_4 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_4) {

    /* "bzrlib/_known_graph_pyx.pyx":525
 *         pending = self._find_tails()
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:
 *             raise errors.GraphCycleError(self._nodes)             # <<<<<<<<<<<<<<
 * 
 *         topo_order = []
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_errors); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_GraphCycleError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->_nodes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_INCREF(__pyx_v_self->_nodes);
      __Pyx_GIVEREF(__pyx_v_self->_nodes);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_self->_nodes);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":524
 * 
 *         pending = self._find_tails()
 *         if PyList_GET_SIZE(pending) == 0 and len(self._nodes) > 0:             # <<<<<<<<<<<<<<
 *             raise errors.GraphCycleError(self._nodes)
 * 
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":527
 *             raise errors.GraphCycleError(self._nodes)
 * 
 *         topo_order = []             # <<<<<<<<<<<<<<
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_topo_order = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":529
 *         topo_order = []
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *         while last_item >= 0:
 *             # Avoid pop followed by push, instead, peek, and replace
 */
  __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

  /* "bzrlib/_known_graph_pyx.pyx":530
 * 
 *         last_item = PyList_GET_SIZE(pending) - 1
 *         while last_item >= 0:             # <<<<<<<<<<<<<<
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 */
  while (1) {
    __pyx_t_4 = ((__pyx_v_last_item >= 0) != 0);
    if (!__pyx_t_4) break;

    /* "bzrlib/_known_graph_pyx.pyx":533
 *             # Avoid pop followed by push, instead, peek, and replace
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *             last_item = last_item - 1
 *             if node.parents is not None:
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":534
 *             # timing shows this is 930ms => 770ms for OOo
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1             # <<<<<<<<<<<<<<
 *             if node.parents is not None:
 *                 # We don't include ghost parents
 */
    __pyx_v_last_item = (__pyx_v_last_item - 1);

    /* "bzrlib/_known_graph_pyx.pyx":535
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             if node.parents is not None:             # <<<<<<<<<<<<<<
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)
 */
    __pyx_t_4 = (__pyx_v_node->parents != Py_None);
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "bzrlib/_known_graph_pyx.pyx":537
 *             if node.parents is not None:
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)             # <<<<<<<<<<<<<<
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 */
      __pyx_t_1 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_8 = PyList_Append(__pyx_v_topo_order, __pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":535
 *             node = _get_list_node(pending, last_item)
 *             last_item = last_item - 1
 *             if node.parents is not None:             # <<<<<<<<<<<<<<
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":538
 *                 # We don't include ghost parents
 *                 PyList_Append(topo_order, node.key)
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):             # <<<<<<<<<<<<<<
 *                 child = _get_list_node(node.children, pos)
 *                 if child.gdfo == -1:
 */
    __pyx_t_1 = __pyx_v_node->children;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_6 = PyList_GET_SIZE(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_6; __pyx_v_pos++) {

      /* "bzrlib/_known_graph_pyx.pyx":539
 *                 PyList_Append(topo_order, node.key)
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)             # <<<<<<<<<<<<<<
 *                 if child.gdfo == -1:
 *                     # We know we have a graph cycle because a node has a parent
 */
      __pyx_t_1 = __pyx_v_node->children;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_1, __pyx_v_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_child, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":540
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 *                 if child.gdfo == -1:             # <<<<<<<<<<<<<<
 *                     # We know we have a graph cycle because a node has a parent
 *                     # which we couldn't find
 */
      __pyx_t_5 = ((__pyx_v_child->gdfo == -1L) != 0);
      if (__pyx_t_5) {

        /* "bzrlib/_known_graph_pyx.pyx":543
 *                     # We know we have a graph cycle because a node has a parent
 *                     # which we couldn't find
 *                     raise errors.GraphCycleError(self._nodes)             # <<<<<<<<<<<<<<
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 */
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_errors); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GraphCycleError); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        if (!__pyx_t_1) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_self->_nodes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_INCREF(__pyx_v_self->_nodes);
          __Pyx_GIVEREF(__pyx_v_self->_nodes);
          PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_self->_nodes);
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "bzrlib/_known_graph_pyx.pyx":540
 *             for pos from 0 <= pos < PyList_GET_SIZE(node.children):
 *                 child = _get_list_node(node.children, pos)
 *                 if child.gdfo == -1:             # <<<<<<<<<<<<<<
 *                     # We know we have a graph cycle because a node has a parent
 *                     # which we couldn't find
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":544
 *                     # which we couldn't find
 *                     raise errors.GraphCycleError(self._nodes)
 *                 child.seen = child.seen + 1             # <<<<<<<<<<<<<<
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):
 *                     # All parents of this child have been yielded, queue this
 */
      __pyx_v_child->seen = (__pyx_v_child->seen + 1);

      /* "bzrlib/_known_graph_pyx.pyx":545
 *                     raise errors.GraphCycleError(self._nodes)
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):             # <<<<<<<<<<<<<<
 *                     # All parents of this child have been yielded, queue this
 *                     # one to be yielded as well
 */
      __pyx_t_3 = __pyx_v_child->parents;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_5 = ((__pyx_v_child->seen == PyTuple_GET_SIZE(__pyx_t_3)) != 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_5) {

        /* "bzrlib/_known_graph_pyx.pyx":548
 *                     # All parents of this child have been yielded, queue this
 *                     # one to be yielded as well
 *                     last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 */
        __pyx_v_last_item = (__pyx_v_last_item + 1);

        /* "bzrlib/_known_graph_pyx.pyx":549
 *                     # one to be yielded as well
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)
 */
        __pyx_t_5 = ((__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending)) != 0);
        if (__pyx_t_5) {

          /* "bzrlib/_known_graph_pyx.pyx":550
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 */
          Py_INCREF(((PyObject *)__pyx_v_child));

          /* "bzrlib/_known_graph_pyx.pyx":551
 *                     if last_item < PyList_GET_SIZE(pending):
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)             # <<<<<<<<<<<<<<
 *                     else:
 *                         PyList_Append(pending, child)
 */
          __pyx_t_8 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

          /* "bzrlib/_known_graph_pyx.pyx":549
 *                     # one to be yielded as well
 *                     last_item = last_item + 1
 *                     if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                         Py_INCREF(child) # SetItem steals a ref
 *                         PyList_SetItem(pending, last_item, child)
 */
          goto __pyx_L13;
        }

        /* "bzrlib/_known_graph_pyx.pyx":553
 *                         PyList_SetItem(pending, last_item, child)
 *                     else:
 *                         PyList_Append(pending, child)             # <<<<<<<<<<<<<<
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 */
        /*else*/ {
          __pyx_t_8 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_child)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L13:;

        /* "bzrlib/_known_graph_pyx.pyx":556
 *                     # We have queued this node, we don't need to track it
 *                     # anymore
 *                     child.seen = 0             # <<<<<<<<<<<<<<
 *         # We started from the parents, so we don't need to do anymore work
 *         return topo_order
 */
        __pyx_v_child->seen = 0;

        /* "bzrlib/_known_graph_pyx.pyx":545
 *                     raise errors.GraphCycleError(self._nodes)
 *                 child.seen = child.seen + 1
 *                 if child.seen == PyTuple_GET_SIZE(child.parents):             # <<<<<<<<<<<<<<
 *                     # All parents of this child have been yielded, queue this
 *                     # one to be yielded as well
 */
      }
    }
  }

  /* "bzrlib/_known_graph_pyx.pyx":558
 *                     child.seen = 0
 *         # We started from the parents, so we don't need to do anymore work
 *         return topo_order             # <<<<<<<<<<<<<<
 * 
 *     def gc_sort(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_topo_order);
  __pyx_r = __pyx_v_topo_order;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":506
 *         return heads
 * 
 *     def topo_sort(self):             # <<<<<<<<<<<<<<
 *         """Return the nodes in topological order.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.topo_sort", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_pending);
  __Pyx_XDECREF(__pyx_v_topo_order);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":560
 *         return topo_order
 * 
 *     def gc_sort(self):             # <<<<<<<<<<<<<<
 *         """Return a reverse topological ordering which is 'stable'.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_19gc_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_18gc_sort[] = "Return a reverse topological ordering which is 'stable'.\n\n        There are a few constraints:\n          1) Reverse topological (all children before all parents)\n          2) Grouped by prefix\n          3) 'stable' sorting, so that we get the same result, independent of\n             machine, or extra data.\n        To do this, we use the same basic algorithm as topo_sort, but when we\n        aren't sure what node to access next, we sort them lexicographically.\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_19gc_sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gc_sort (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_18gc_sort(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_18gc_sort(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  PyObject *__pyx_v_temp;
  Py_ssize_t __pyx_v_pos;
  Py_ssize_t __pyx_v_last_item;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node = 0;
  PyObject *__pyx_v_tips = NULL;
  PyObject *__pyx_v_prefix_tips = NULL;
  PyObject *__pyx_v_prefix = NULL;
  PyObject *__pyx_v_tip_nodes = NULL;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_pending = NULL;
  PyObject *__pyx_v_parents = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("gc_sort", 0);

  /* "bzrlib/_known_graph_pyx.pyx":575
 *         cdef _KnownGraphNode node, node2, parent_node
 * 
 *         tips = self._find_tips()             # <<<<<<<<<<<<<<
 *         # Split the tips based on prefix
 *         prefix_tips = {}
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_find_tips); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_tips = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":577
 *         tips = self._find_tips()
 *         # Split the tips based on prefix
 *         prefix_tips = {}             # <<<<<<<<<<<<<<
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_prefix_tips = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":578
 *         # Split the tips based on prefix
 *         prefix_tips = {}
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):             # <<<<<<<<<<<<<<
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:
 */
  __pyx_t_4 = PyList_GET_SIZE(__pyx_v_tips);
  for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_4; __pyx_v_pos++) {

    /* "bzrlib/_known_graph_pyx.pyx":579
 *         prefix_tips = {}
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)             # <<<<<<<<<<<<<<
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:
 *                 prefix = ''
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_tips, __pyx_v_pos)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":580
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:             # <<<<<<<<<<<<<<
 *                 prefix = ''
 *             else:
 */
    __pyx_t_1 = __pyx_v_node->key;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_6 = (PyString_CheckExact(__pyx_t_1) != 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_6) {
    } else {
      __pyx_t_5 = __pyx_t_6;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_1 = __pyx_v_node->key;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_7 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = ((__pyx_t_7 == 1) != 0);
    __pyx_t_5 = __pyx_t_6;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_5) {

      /* "bzrlib/_known_graph_pyx.pyx":581
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:
 *                 prefix = ''             # <<<<<<<<<<<<<<
 *             else:
 *                 prefix = node.key[0]
 */
      __Pyx_INCREF(__pyx_kp_s__3);
      __Pyx_XDECREF_SET(__pyx_v_prefix, __pyx_kp_s__3);

      /* "bzrlib/_known_graph_pyx.pyx":580
 *         for pos from 0 <= pos < PyList_GET_SIZE(tips):
 *             node = _get_list_node(tips, pos)
 *             if PyString_CheckExact(node.key) or len(node.key) == 1:             # <<<<<<<<<<<<<<
 *                 prefix = ''
 *             else:
 */
      goto __pyx_L5;
    }

    /* "bzrlib/_known_graph_pyx.pyx":583
 *                 prefix = ''
 *             else:
 *                 prefix = node.key[0]             # <<<<<<<<<<<<<<
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:
 */
    /*else*/ {
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_node->key, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_prefix, __pyx_t_1);
      __pyx_t_1 = 0;
    }
    __pyx_L5:;

    /* "bzrlib/_known_graph_pyx.pyx":584
 *             else:
 *                 prefix = node.key[0]
 *             temp = PyDict_GetItem(prefix_tips, prefix)             # <<<<<<<<<<<<<<
 *             if temp == NULL:
 *                 prefix_tips[prefix] = [node]
 */
    __pyx_v_temp = PyDict_GetItem(__pyx_v_prefix_tips, __pyx_v_prefix);

    /* "bzrlib/_known_graph_pyx.pyx":585
 *                 prefix = node.key[0]
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:             # <<<<<<<<<<<<<<
 *                 prefix_tips[prefix] = [node]
 *             else:
 */
    __pyx_t_5 = ((__pyx_v_temp == NULL) != 0);
    if (__pyx_t_5) {

      /* "bzrlib/_known_graph_pyx.pyx":586
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:
 *                 prefix_tips[prefix] = [node]             # <<<<<<<<<<<<<<
 *             else:
 *                 tip_nodes = <object>temp
 */
      __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_node));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_node));
      PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_node));
      if (unlikely(PyDict_SetItem(__pyx_v_prefix_tips, __pyx_v_prefix, __pyx_t_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":585
 *                 prefix = node.key[0]
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             if temp == NULL:             # <<<<<<<<<<<<<<
 *                 prefix_tips[prefix] = [node]
 *             else:
 */
      goto __pyx_L8;
    }

    /* "bzrlib/_known_graph_pyx.pyx":588
 *                 prefix_tips[prefix] = [node]
 *             else:
 *                 tip_nodes = <object>temp             # <<<<<<<<<<<<<<
 *                 PyList_Append(tip_nodes, node)
 * 
 */
    /*else*/ {
      __pyx_t_1 = ((PyObject *)__pyx_v_temp);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_tip_nodes, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":589
 *             else:
 *                 tip_nodes = <object>temp
 *                 PyList_Append(tip_nodes, node)             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
      __pyx_t_8 = PyList_Append(__pyx_v_tip_nodes, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L8:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":591
 *                 PyList_Append(tip_nodes, node)
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         for prefix in sorted(prefix_tips):
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":592
 * 
 *         result = []
 *         for prefix in sorted(prefix_tips):             # <<<<<<<<<<<<<<
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL
 */
  __pyx_t_2 = PySequence_List(__pyx_v_prefix_tips); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_9 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_prefix, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":593
 *         result = []
 *         for prefix in sorted(prefix_tips):
 *             temp = PyDict_GetItem(prefix_tips, prefix)             # <<<<<<<<<<<<<<
 *             assert temp != NULL
 *             tip_nodes = <object>temp
 */
    __pyx_v_temp = PyDict_GetItem(__pyx_v_prefix_tips, __pyx_v_prefix);

    /* "bzrlib/_known_graph_pyx.pyx":594
 *         for prefix in sorted(prefix_tips):
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL             # <<<<<<<<<<<<<<
 *             tip_nodes = <object>temp
 *             pending = _sort_list_nodes(tip_nodes, 1)
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_temp != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "bzrlib/_known_graph_pyx.pyx":595
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL
 *             tip_nodes = <object>temp             # <<<<<<<<<<<<<<
 *             pending = _sort_list_nodes(tip_nodes, 1)
 *             last_item = PyList_GET_SIZE(pending) - 1
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_temp);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_tip_nodes, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":596
 *             assert temp != NULL
 *             tip_nodes = <object>temp
 *             pending = _sort_list_nodes(tip_nodes, 1)             # <<<<<<<<<<<<<<
 *             last_item = PyList_GET_SIZE(pending) - 1
 *             while last_item >= 0:
 */
    __pyx_t_1 = __pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(__pyx_v_tip_nodes, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_pending, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":597
 *             tip_nodes = <object>temp
 *             pending = _sort_list_nodes(tip_nodes, 1)
 *             last_item = PyList_GET_SIZE(pending) - 1             # <<<<<<<<<<<<<<
 *             while last_item >= 0:
 *                 node = _get_list_node(pending, last_item)
 */
    __pyx_v_last_item = (PyList_GET_SIZE(__pyx_v_pending) - 1);

    /* "bzrlib/_known_graph_pyx.pyx":598
 *             pending = _sort_list_nodes(tip_nodes, 1)
 *             last_item = PyList_GET_SIZE(pending) - 1
 *             while last_item >= 0:             # <<<<<<<<<<<<<<
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1
 */
    while (1) {
      __pyx_t_5 = ((__pyx_v_last_item >= 0) != 0);
      if (!__pyx_t_5) break;

      /* "bzrlib/_known_graph_pyx.pyx":599
 *             last_item = PyList_GET_SIZE(pending) - 1
 *             while last_item >= 0:
 *                 node = _get_list_node(pending, last_item)             # <<<<<<<<<<<<<<
 *                 last_item = last_item - 1
 *                 if node.parents is None:
 */
      __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_pending, __pyx_v_last_item)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":600
 *             while last_item >= 0:
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1             # <<<<<<<<<<<<<<
 *                 if node.parents is None:
 *                     # Ghost
 */
      __pyx_v_last_item = (__pyx_v_last_item - 1);

      /* "bzrlib/_known_graph_pyx.pyx":601
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1
 *                 if node.parents is None:             # <<<<<<<<<<<<<<
 *                     # Ghost
 *                     continue
 */
      __pyx_t_5 = (__pyx_v_node->parents == Py_None);
      __pyx_t_6 = (__pyx_t_5 != 0);
      if (__pyx_t_6) {

        /* "bzrlib/_known_graph_pyx.pyx":603
 *                 if node.parents is None:
 *                     # Ghost
 *                     continue             # <<<<<<<<<<<<<<
 *                 PyList_Append(result, node.key)
 *                 # Sorting the parent keys isn't strictly necessary for stable
 */
        goto __pyx_L11_continue;

        /* "bzrlib/_known_graph_pyx.pyx":601
 *                 node = _get_list_node(pending, last_item)
 *                 last_item = last_item - 1
 *                 if node.parents is None:             # <<<<<<<<<<<<<<
 *                     # Ghost
 *                     continue
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":604
 *                     # Ghost
 *                     continue
 *                 PyList_Append(result, node.key)             # <<<<<<<<<<<<<<
 *                 # Sorting the parent keys isn't strictly necessary for stable
 *                 # sorting of a given graph. But it does help minimize the
 */
      __pyx_t_1 = __pyx_v_node->key;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_8 = PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":611
 *                 #   4.73ms  no sort
 *                 #   7.73ms  RichCompareBool sort
 *                 parents = _sort_list_nodes(node.parents, 1)             # <<<<<<<<<<<<<<
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):
 */
      __pyx_t_1 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_f_6bzrlib_16_known_graph_pyx__sort_list_nodes(__pyx_t_1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_parents, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":612
 *                 #   7.73ms  RichCompareBool sort
 *                 parents = _sort_list_nodes(node.parents, 1)
 *                 for pos from 0 <= pos < len(parents):             # <<<<<<<<<<<<<<
 *                     if PyTuple_CheckExact(parents):
 *                         parent_node = _get_tuple_node(parents, pos)
 */
      __pyx_t_7 = PyObject_Length(__pyx_v_parents); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      for (__pyx_v_pos = 0; __pyx_v_pos < __pyx_t_7; __pyx_v_pos++) {

        /* "bzrlib/_known_graph_pyx.pyx":613
 *                 parents = _sort_list_nodes(node.parents, 1)
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):             # <<<<<<<<<<<<<<
 *                         parent_node = _get_tuple_node(parents, pos)
 *                     else:
 */
        __pyx_t_6 = (PyTuple_CheckExact(__pyx_v_parents) != 0);
        if (__pyx_t_6) {

          /* "bzrlib/_known_graph_pyx.pyx":614
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):
 *                         parent_node = _get_tuple_node(parents, pos)             # <<<<<<<<<<<<<<
 *                     else:
 *                         parent_node = _get_list_node(parents, pos)
 */
          __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_v_parents, __pyx_v_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
          __pyx_t_3 = 0;

          /* "bzrlib/_known_graph_pyx.pyx":613
 *                 parents = _sort_list_nodes(node.parents, 1)
 *                 for pos from 0 <= pos < len(parents):
 *                     if PyTuple_CheckExact(parents):             # <<<<<<<<<<<<<<
 *                         parent_node = _get_tuple_node(parents, pos)
 *                     else:
 */
          goto __pyx_L16;
        }

        /* "bzrlib/_known_graph_pyx.pyx":616
 *                         parent_node = _get_tuple_node(parents, pos)
 *                     else:
 *                         parent_node = _get_list_node(parents, pos)             # <<<<<<<<<<<<<<
 *                     # TODO: GraphCycle detection
 *                     parent_node.seen = parent_node.seen + 1
 */
        /*else*/ {
          __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_v_parents, __pyx_v_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
          __pyx_t_3 = 0;
        }
        __pyx_L16:;

        /* "bzrlib/_known_graph_pyx.pyx":618
 *                         parent_node = _get_list_node(parents, pos)
 *                     # TODO: GraphCycle detection
 *                     parent_node.seen = parent_node.seen + 1             # <<<<<<<<<<<<<<
 *                     if (parent_node.seen
 *                         == PyList_GET_SIZE(parent_node.children)):
 */
        __pyx_v_parent_node->seen = (__pyx_v_parent_node->seen + 1);

        /* "bzrlib/_known_graph_pyx.pyx":620
 *                     parent_node.seen = parent_node.seen + 1
 *                     if (parent_node.seen
 *                         == PyList_GET_SIZE(parent_node.children)):             # <<<<<<<<<<<<<<
 *                         # All children have been processed, queue up this
 *                         # parent
 */
        __pyx_t_3 = __pyx_v_parent_node->children;
        __Pyx_INCREF(__pyx_t_3);
        __pyx_t_6 = ((__pyx_v_parent_node->seen == PyList_GET_SIZE(__pyx_t_3)) != 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":619
 *                     # TODO: GraphCycle detection
 *                     parent_node.seen = parent_node.seen + 1
 *                     if (parent_node.seen             # <<<<<<<<<<<<<<
 *                         == PyList_GET_SIZE(parent_node.children)):
 *                         # All children have been processed, queue up this
 */
        if (__pyx_t_6) {

          /* "bzrlib/_known_graph_pyx.pyx":623
 *                         # All children have been processed, queue up this
 *                         # parent
 *                         last_item = last_item + 1             # <<<<<<<<<<<<<<
 *                         if last_item < PyList_GET_SIZE(pending):
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 */
          __pyx_v_last_item = (__pyx_v_last_item + 1);

          /* "bzrlib/_known_graph_pyx.pyx":624
 *                         # parent
 *                         last_item = last_item + 1
 *                         if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 *                             PyList_SetItem(pending, last_item, parent_node)
 */
          __pyx_t_6 = ((__pyx_v_last_item < PyList_GET_SIZE(__pyx_v_pending)) != 0);
          if (__pyx_t_6) {

            /* "bzrlib/_known_graph_pyx.pyx":625
 *                         last_item = last_item + 1
 *                         if last_item < PyList_GET_SIZE(pending):
 *                             Py_INCREF(parent_node) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *                             PyList_SetItem(pending, last_item, parent_node)
 *                         else:
 */
            Py_INCREF(((PyObject *)__pyx_v_parent_node));

            /* "bzrlib/_known_graph_pyx.pyx":626
 *                         if last_item < PyList_GET_SIZE(pending):
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 *                             PyList_SetItem(pending, last_item, parent_node)             # <<<<<<<<<<<<<<
 *                         else:
 *                             PyList_Append(pending, parent_node)
 */
            __pyx_t_8 = PyList_SetItem(__pyx_v_pending, __pyx_v_last_item, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

            /* "bzrlib/_known_graph_pyx.pyx":624
 *                         # parent
 *                         last_item = last_item + 1
 *                         if last_item < PyList_GET_SIZE(pending):             # <<<<<<<<<<<<<<
 *                             Py_INCREF(parent_node) # SetItem steals a ref
 *                             PyList_SetItem(pending, last_item, parent_node)
 */
            goto __pyx_L18;
          }

          /* "bzrlib/_known_graph_pyx.pyx":628
 *                             PyList_SetItem(pending, last_item, parent_node)
 *                         else:
 *                             PyList_Append(pending, parent_node)             # <<<<<<<<<<<<<<
 *                         parent_node.seen = 0
 *         return result
 */
          /*else*/ {
            __pyx_t_8 = PyList_Append(__pyx_v_pending, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          __pyx_L18:;

          /* "bzrlib/_known_graph_pyx.pyx":629
 *                         else:
 *                             PyList_Append(pending, parent_node)
 *                         parent_node.seen = 0             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
          __pyx_v_parent_node->seen = 0;

          /* "bzrlib/_known_graph_pyx.pyx":619
 *                     # TODO: GraphCycle detection
 *                     parent_node.seen = parent_node.seen + 1
 *                     if (parent_node.seen             # <<<<<<<<<<<<<<
 *                         == PyList_GET_SIZE(parent_node.children)):
 *                         # All children have been processed, queue up this
 */
        }
      }
      __pyx_L11_continue:;
    }

    /* "bzrlib/_known_graph_pyx.pyx":592
 * 
 *         result = []
 *         for prefix in sorted(prefix_tips):             # <<<<<<<<<<<<<<
 *             temp = PyDict_GetItem(prefix_tips, prefix)
 *             assert temp != NULL
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":630
 *                             PyList_Append(pending, parent_node)
 *                         parent_node.seen = 0
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def merge_sort(self, tip_key):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":560
 *         return topo_order
 * 
 *     def gc_sort(self):             # <<<<<<<<<<<<<<
 *         """Return a reverse topological ordering which is 'stable'.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.gc_sort", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_XDECREF(__pyx_v_tips);
  __Pyx_XDECREF(__pyx_v_prefix_tips);
  __Pyx_XDECREF(__pyx_v_prefix);
  __Pyx_XDECREF(__pyx_v_tip_nodes);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_pending);
  __Pyx_XDECREF(__pyx_v_parents);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":632
 *         return result
 * 
 *     def merge_sort(self, tip_key):             # <<<<<<<<<<<<<<
 *         """Compute the merge sorted graph output."""
 *         cdef _MergeSorter sorter
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_21merge_sort(PyObject *__pyx_v_self, PyObject *__pyx_v_tip_key); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_20merge_sort[] = "Compute the merge sorted graph output.";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_21merge_sort(PyObject *__pyx_v_self, PyObject *__pyx_v_tip_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("merge_sort (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_20merge_sort(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_tip_key));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_20merge_sort(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_tip_key) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_sorter = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge_sort", 0);

  /* "bzrlib/_known_graph_pyx.pyx":639
 *         #       that won't be collectable anyway. real world testing has not
 *         #       shown a specific impact, yet.
 *         sorter = _MergeSorter(self, tip_key)             # <<<<<<<<<<<<<<
 *         return sorter.topo_order()
 * 
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(__pyx_v_tip_key);
  __Pyx_GIVEREF(__pyx_v_tip_key);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_tip_key);
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_sorter = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":640
 *         #       shown a specific impact, yet.
 *         sorter = _MergeSorter(self, tip_key)
 *         return sorter.topo_order()             # <<<<<<<<<<<<<<
 * 
 *     def get_parent_keys(self, key):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_sorter->__pyx_vtab)->topo_order(__pyx_v_sorter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":632
 *         return result
 * 
 *     def merge_sort(self, tip_key):             # <<<<<<<<<<<<<<
 *         """Compute the merge sorted graph output."""
 *         cdef _MergeSorter sorter
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.merge_sort", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_sorter);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":642
 *         return sorter.topo_order()
 * 
 *     def get_parent_keys(self, key):             # <<<<<<<<<<<<<<
 *         """Get the parents for a key
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_23get_parent_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_22get_parent_keys[] = "Get the parents for a key\n        \n        Returns a list containg the parents keys. If the key is a ghost,\n        None is returned. A KeyError will be raised if the key is not in\n        the graph.\n        \n        :param keys: Key to check (eg revision_id)\n        :return: A list of parents\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_23get_parent_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_parent_keys (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_22get_parent_keys(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_key));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_22get_parent_keys(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_parent_keys", 0);

  /* "bzrlib/_known_graph_pyx.pyx":652
 *         :return: A list of parents
 *         """
 *         return self._nodes[key].parent_keys             # <<<<<<<<<<<<<<
 * 
 *     def get_child_keys(self, key):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetItem(__pyx_v_self->_nodes, __pyx_v_key); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_parent_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":642
 *         return sorter.topo_order()
 * 
 *     def get_parent_keys(self, key):             # <<<<<<<<<<<<<<
 *         """Get the parents for a key
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.get_parent_keys", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":654
 *         return self._nodes[key].parent_keys
 * 
 *     def get_child_keys(self, key):             # <<<<<<<<<<<<<<
 *         """Get the children for a key
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_25get_child_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static char __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_24get_child_keys[] = "Get the children for a key\n        \n        Returns a list containg the children keys. A KeyError will be raised\n        if the key is not in the graph.\n        \n        :param keys: Key to check (eg revision_id)\n        :return: A list of children\n        ";
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_25get_child_keys(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_child_keys (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_24get_child_keys(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_key));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_24get_child_keys(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_child_keys", 0);

  /* "bzrlib/_known_graph_pyx.pyx":663
 *         :return: A list of children
 *         """
 *         return self._nodes[key].child_keys             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetItem(__pyx_v_self->_nodes, __pyx_v_key); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_child_keys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":654
 *         return self._nodes[key].parent_keys
 * 
 *     def get_child_keys(self, key):             # <<<<<<<<<<<<<<
 *         """Get the children for a key
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.get_child_keys", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":195
 *     """This is a class which assumes we already know the full graph."""
 * 
 *     cdef public object _nodes             # <<<<<<<<<<<<<<
 *     cdef public object _known_heads
 *     cdef public int do_cache
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_nodes);
  __pyx_r = __pyx_v_self->_nodes;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(__pyx_v_self->_nodes);
  __Pyx_DECREF(__pyx_v_self->_nodes);
  __pyx_v_self->_nodes = __pyx_v_value;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_5__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_5__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_4__del__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__", 0);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_nodes);
  __Pyx_DECREF(__pyx_v_self->_nodes);
  __pyx_v_self->_nodes = Py_None;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":196
 * 
 *     cdef public object _nodes
 *     cdef public object _known_heads             # <<<<<<<<<<<<<<
 *     cdef public int do_cache
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_known_heads);
  __pyx_r = __pyx_v_self->_known_heads;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(__pyx_v_self->_known_heads);
  __Pyx_DECREF(__pyx_v_self->_known_heads);
  __pyx_v_self->_known_heads = __pyx_v_value;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_5__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_5__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_4__del__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__", 0);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_known_heads);
  __Pyx_DECREF(__pyx_v_self->_known_heads);
  __pyx_v_self->_known_heads = Py_None;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":197
 *     cdef public object _nodes
 *     cdef public object _known_heads
 *     cdef public int do_cache             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, parent_map, do_cache=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->do_cache); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.do_cache.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->do_cache = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx.KnownGraph.do_cache.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":686
 *     cdef int completed # Fully Processed
 * 
 *     def __init__(self, key):             # <<<<<<<<<<<<<<
 *         self.key = key
 *         self.merge_depth = -1
 */

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_key = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self), __pyx_v_key);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_key) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":687
 * 
 *     def __init__(self, key):
 *         self.key = key             # <<<<<<<<<<<<<<
 *         self.merge_depth = -1
 *         self.left_parent = None
 */
  __Pyx_INCREF(__pyx_v_key);
  __Pyx_GIVEREF(__pyx_v_key);
  __Pyx_GOTREF(__pyx_v_self->key);
  __Pyx_DECREF(__pyx_v_self->key);
  __pyx_v_self->key = __pyx_v_key;

  /* "bzrlib/_known_graph_pyx.pyx":688
 *     def __init__(self, key):
 *         self.key = key
 *         self.merge_depth = -1             # <<<<<<<<<<<<<<
 *         self.left_parent = None
 *         self.left_pending_parent = None
 */
  __pyx_v_self->merge_depth = -1L;

  /* "bzrlib/_known_graph_pyx.pyx":689
 *         self.key = key
 *         self.merge_depth = -1
 *         self.left_parent = None             # <<<<<<<<<<<<<<
 *         self.left_pending_parent = None
 *         self.pending_parents = None
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->left_parent);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->left_parent));
  __pyx_v_self->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":690
 *         self.merge_depth = -1
 *         self.left_parent = None
 *         self.left_pending_parent = None             # <<<<<<<<<<<<<<
 *         self.pending_parents = None
 *         self._revno_first = -1
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->left_pending_parent);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->left_pending_parent));
  __pyx_v_self->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

  /* "bzrlib/_known_graph_pyx.pyx":691
 *         self.left_parent = None
 *         self.left_pending_parent = None
 *         self.pending_parents = None             # <<<<<<<<<<<<<<
 *         self._revno_first = -1
 *         self._revno_second = -1
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->pending_parents);
  __Pyx_DECREF(__pyx_v_self->pending_parents);
  __pyx_v_self->pending_parents = Py_None;

  /* "bzrlib/_known_graph_pyx.pyx":692
 *         self.left_pending_parent = None
 *         self.pending_parents = None
 *         self._revno_first = -1             # <<<<<<<<<<<<<<
 *         self._revno_second = -1
 *         self._revno_last = -1
 */
  __pyx_v_self->_revno_first = -1L;

  /* "bzrlib/_known_graph_pyx.pyx":693
 *         self.pending_parents = None
 *         self._revno_first = -1
 *         self._revno_second = -1             # <<<<<<<<<<<<<<
 *         self._revno_last = -1
 *         self.is_first_child = 0
 */
  __pyx_v_self->_revno_second = -1L;

  /* "bzrlib/_known_graph_pyx.pyx":694
 *         self._revno_first = -1
 *         self._revno_second = -1
 *         self._revno_last = -1             # <<<<<<<<<<<<<<
 *         self.is_first_child = 0
 *         self.seen_by_child = 0
 */
  __pyx_v_self->_revno_last = -1L;

  /* "bzrlib/_known_graph_pyx.pyx":695
 *         self._revno_second = -1
 *         self._revno_last = -1
 *         self.is_first_child = 0             # <<<<<<<<<<<<<<
 *         self.seen_by_child = 0
 *         self.completed = 0
 */
  __pyx_v_self->is_first_child = 0;

  /* "bzrlib/_known_graph_pyx.pyx":696
 *         self._revno_last = -1
 *         self.is_first_child = 0
 *         self.seen_by_child = 0             # <<<<<<<<<<<<<<
 *         self.completed = 0
 * 
 */
  __pyx_v_self->seen_by_child = 0;

  /* "bzrlib/_known_graph_pyx.pyx":697
 *         self.is_first_child = 0
 *         self.seen_by_child = 0
 *         self.completed = 0             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __pyx_v_self->completed = 0;

  /* "bzrlib/_known_graph_pyx.pyx":686
 *     cdef int completed # Fully Processed
 * 
 *     def __init__(self, key):             # <<<<<<<<<<<<<<
 *         self.key = key
 *         self.merge_depth = -1
 */

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":699
 *         self.completed = 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_2__repr__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_2__repr__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":700
 * 
 *     def __repr__(self):
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (             # <<<<<<<<<<<<<<
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "bzrlib/_known_graph_pyx.pyx":701
 *     def __repr__(self):
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,             # <<<<<<<<<<<<<<
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":702
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,             # <<<<<<<<<<<<<<
 *             self._revno_first, self._revno_second, self._revno_last,
 *             self.is_first_child, self.seen_by_child)
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->merge_depth); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "bzrlib/_known_graph_pyx.pyx":703
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,             # <<<<<<<<<<<<<<
 *             self.is_first_child, self.seen_by_child)
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_first); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_last); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "bzrlib/_known_graph_pyx.pyx":704
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,
 *             self.is_first_child, self.seen_by_child)             # <<<<<<<<<<<<<<
 * 
 *     cdef int has_pending_parents(self): # cannot_raise
 */
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->is_first_child); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->seen_by_child); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "bzrlib/_known_graph_pyx.pyx":701
 *     def __repr__(self):
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,             # <<<<<<<<<<<<<<
 *             self.merge_depth,
 *             self._revno_first, self._revno_second, self._revno_last,
 */
  __pyx_t_8 = PyTuple_New(8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_self->key);
  __Pyx_GIVEREF(__pyx_v_self->key);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_self->key);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 7, __pyx_t_7);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":700
 * 
 *     def __repr__(self):
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (             # <<<<<<<<<<<<<<
 *             self.__class__.__name__, self.key,
 *             self.merge_depth,
 */
  __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_s_s_depth_s_rev_s_s_s_first_s_s, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":699
 *         self.completed = 0
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return '%s(%s depth:%s rev:%s,%s,%s first:%s seen:%s)' % (
 *             self.__class__.__name__, self.key,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":706
 *             self.is_first_child, self.seen_by_child)
 * 
 *     cdef int has_pending_parents(self): # cannot_raise             # <<<<<<<<<<<<<<
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1
 */

static int __pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_has_pending_parents(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("has_pending_parents", 0);

  /* "bzrlib/_known_graph_pyx.pyx":707
 * 
 *     cdef int has_pending_parents(self): # cannot_raise
 *         if self.left_pending_parent is not None or self.pending_parents:             # <<<<<<<<<<<<<<
 *             return 1
 *         return 0
 */
  __pyx_t_2 = (((PyObject *)__pyx_v_self->left_pending_parent) != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_self->pending_parents); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":708
 *     cdef int has_pending_parents(self): # cannot_raise
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "bzrlib/_known_graph_pyx.pyx":707
 * 
 *     cdef int has_pending_parents(self): # cannot_raise
 *         if self.left_pending_parent is not None or self.pending_parents:             # <<<<<<<<<<<<<<
 *             return 1
 *         return 0
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":709
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef object _revno(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":706
 *             self.is_first_child, self.seen_by_child)
 * 
 *     cdef int has_pending_parents(self): # cannot_raise             # <<<<<<<<<<<<<<
 *         if self.left_pending_parent is not None or self.pending_parents:
 *             return 1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("bzrlib._known_graph_pyx._MergeSortNode.has_pending_parents", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":711
 *         return 0
 * 
 *     cdef object _revno(self):             # <<<<<<<<<<<<<<
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode__revno(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_revno", 0);

  /* "bzrlib/_known_graph_pyx.pyx":712
 * 
 *     cdef object _revno(self):
 *         if self._revno_first == -1:             # <<<<<<<<<<<<<<
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 */
  __pyx_t_1 = ((__pyx_v_self->_revno_first == -1L) != 0);
  if (__pyx_t_1) {

    /* "bzrlib/_known_graph_pyx.pyx":713
 *     cdef object _revno(self):
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 *             return (self._revno_last,)
 */
    __pyx_t_1 = ((__pyx_v_self->_revno_second != -1L) != 0);
    if (__pyx_t_1) {

      /* "bzrlib/_known_graph_pyx.pyx":714
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))             # <<<<<<<<<<<<<<
 *             return (self._revno_last,)
 *         else:
 */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
      __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_Something_wrong_with_s, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":713
 *     cdef object _revno(self):
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 *             return (self._revno_last,)
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":715
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 *             return (self._revno_last,)             # <<<<<<<<<<<<<<
 *         else:
 *             return (self._revno_first, self._revno_second, self._revno_last)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_last); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "bzrlib/_known_graph_pyx.pyx":712
 * 
 *     cdef object _revno(self):
 *         if self._revno_first == -1:             # <<<<<<<<<<<<<<
 *             if self._revno_second != -1:
 *                 raise RuntimeError('Something wrong with: %s' % (self,))
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":717
 *             return (self._revno_last,)
 *         else:
 *             return (self._revno_first, self._revno_second, self._revno_last)             # <<<<<<<<<<<<<<
 * 
 *     property revno:
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_first); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_second); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_self->_revno_last); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }

  /* "bzrlib/_known_graph_pyx.pyx":711
 *         return 0
 * 
 *     cdef object _revno(self):             # <<<<<<<<<<<<<<
 *         if self._revno_first == -1:
 *             if self._revno_second != -1:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode._revno", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":720
 * 
 *     property revno:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._revno()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":721
 *     property revno:
 *         def __get__(self):
 *             return self._revno()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self->__pyx_vtab)->_revno(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":720
 * 
 *     property revno:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._revno()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.revno.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":670
 * 
 *     # Public api
 *     cdef public object key             # <<<<<<<<<<<<<<
 *     cdef public long merge_depth
 *     cdef public object end_of_merge # True/False Is this the end of the current merge
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->key);
  __pyx_r = __pyx_v_self->key;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(__pyx_v_self->key);
  __Pyx_DECREF(__pyx_v_self->key);
  __pyx_v_self->key = __pyx_v_value;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_5__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_5__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_4__del__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__", 0);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->key);
  __Pyx_DECREF(__pyx_v_self->key);
  __pyx_v_self->key = Py_None;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":671
 *     # Public api
 *     cdef public object key
 *     cdef public long merge_depth             # <<<<<<<<<<<<<<
 *     cdef public object end_of_merge # True/False Is this the end of the current merge
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->merge_depth); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.merge_depth.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  long __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_value); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->merge_depth = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSortNode.merge_depth.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":672
 *     cdef public object key
 *     cdef public long merge_depth
 *     cdef public object end_of_merge # True/False Is this the end of the current merge             # <<<<<<<<<<<<<<
 * 
 *     # Private api, used while computing the information
 */

/* Python wrapper */
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge___get__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge___get__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->end_of_merge);
  __pyx_r = __pyx_v_self->end_of_merge;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_2__set__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_2__set__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __Pyx_GOTREF(__pyx_v_self->end_of_merge);
  __Pyx_DECREF(__pyx_v_self->end_of_merge);
  __pyx_v_self->end_of_merge = __pyx_v_value;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_5__del__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_5__del__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_4__del__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_4__del__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__", 0);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->end_of_merge);
  __Pyx_DECREF(__pyx_v_self->end_of_merge);
  __pyx_v_self->end_of_merge = Py_None;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":743
 *     cdef object _scheduled_nodes # List of nodes ready to be yielded
 * 
 *     def __init__(self, known_graph, tip_key):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 * 
 */

/* Python wrapper */
static int __pyx_pw_6bzrlib_16_known_graph_pyx_12_MergeSorter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6bzrlib_16_known_graph_pyx_12_MergeSorter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_known_graph = 0;
  PyObject *__pyx_v_tip_key = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_known_graph,&__pyx_n_s_tip_key,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_known_graph)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tip_key)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_known_graph = values[0];
    __pyx_v_tip_key = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__(((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self), __pyx_v_known_graph, __pyx_v_tip_key);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_16_known_graph_pyx_12_MergeSorter___init__(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, PyObject *__pyx_v_known_graph, PyObject *__pyx_v_tip_key) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "bzrlib/_known_graph_pyx.pyx":746
 *         cdef _KnownGraphNode node
 * 
 *         self.graph = known_graph             # <<<<<<<<<<<<<<
 *         # self._ms_nodes = {}
 *         self._revno_to_branch_count = {}
 */
  if (!(likely(((__pyx_v_known_graph) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_known_graph, __pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __pyx_v_known_graph;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->graph);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->graph));
  __pyx_v_self->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":748
 *         self.graph = known_graph
 *         # self._ms_nodes = {}
 *         self._revno_to_branch_count = {}             # <<<<<<<<<<<<<<
 *         self._depth_first_stack = []
 *         self._last_stack_item = -1
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_revno_to_branch_count);
  __Pyx_DECREF(__pyx_v_self->_revno_to_branch_count);
  __pyx_v_self->_revno_to_branch_count = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":749
 *         # self._ms_nodes = {}
 *         self._revno_to_branch_count = {}
 *         self._depth_first_stack = []             # <<<<<<<<<<<<<<
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_depth_first_stack);
  __Pyx_DECREF(__pyx_v_self->_depth_first_stack);
  __pyx_v_self->_depth_first_stack = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":750
 *         self._revno_to_branch_count = {}
 *         self._depth_first_stack = []
 *         self._last_stack_item = -1             # <<<<<<<<<<<<<<
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION
 */
  __pyx_v_self->_last_stack_item = -1L;

  /* "bzrlib/_known_graph_pyx.pyx":751
 *         self._depth_first_stack = []
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []             # <<<<<<<<<<<<<<
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_scheduled_nodes);
  __Pyx_DECREF(__pyx_v_self->_scheduled_nodes);
  __pyx_v_self->_scheduled_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":752
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION             # <<<<<<<<<<<<<<
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 */
  __pyx_t_3 = (__pyx_v_tip_key != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }

  /* "bzrlib/_known_graph_pyx.pyx":753
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):             # <<<<<<<<<<<<<<
 *             node = self.graph._nodes[tip_key]
 *             self._push_node(node, 0)
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_tip_key, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bzrlib/_known_graph_pyx.pyx":752
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION             # <<<<<<<<<<<<<<
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }

  /* "bzrlib/_known_graph_pyx.pyx":753
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):             # <<<<<<<<<<<<<<
 *             node = self.graph._nodes[tip_key]
 *             self._push_node(node, 0)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  __Pyx_GIVEREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  __pyx_t_5 = PyObject_RichCompare(__pyx_v_tip_key, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;

  /* "bzrlib/_known_graph_pyx.pyx":752
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION             # <<<<<<<<<<<<<<
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 */
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":754
 *         if (tip_key is not None and tip_key != NULL_REVISION
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]             # <<<<<<<<<<<<<<
 *             self._push_node(node, 0)
 * 
 */
    __pyx_t_5 = PyObject_GetItem(__pyx_v_self->graph->_nodes, __pyx_v_tip_key); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":755
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 *             self._push_node(node, 0)             # <<<<<<<<<<<<<<
 * 
 *     cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node):
 */
    __pyx_t_5 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_push_node(__pyx_v_self, __pyx_v_node, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":752
 *         self._last_stack_item = -1
 *         self._scheduled_nodes = []
 *         if (tip_key is not None and tip_key != NULL_REVISION             # <<<<<<<<<<<<<<
 *             and tip_key != (NULL_REVISION,)):
 *             node = self.graph._nodes[tip_key]
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":743
 *     cdef object _scheduled_nodes # List of nodes ready to be yielded
 * 
 *     def __init__(self, known_graph, tip_key):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode node
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":757
 *             self._push_node(node, 0)
 * 
 *     cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _MergeSortNode ms_node
 */

static struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__get_ms_node(CYTHON_UNUSED struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_ms_node", 0);

  /* "bzrlib/_known_graph_pyx.pyx":761
 *         cdef _MergeSortNode ms_node
 * 
 *         if node.extra is None:             # <<<<<<<<<<<<<<
 *             ms_node = _MergeSortNode(node.key)
 *             node.extra = ms_node
 */
  __pyx_t_1 = (__pyx_v_node->extra == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":762
 * 
 *         if node.extra is None:
 *             ms_node = _MergeSortNode(node.key)             # <<<<<<<<<<<<<<
 *             node.extra = ms_node
 *         else:
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_node->key);
    __Pyx_GIVEREF(__pyx_v_node->key);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_node->key);
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":763
 *         if node.extra is None:
 *             ms_node = _MergeSortNode(node.key)
 *             node.extra = ms_node             # <<<<<<<<<<<<<<
 *         else:
 *             ms_node = <_MergeSortNode>node.extra
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_ms_node));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ms_node));
    __Pyx_GOTREF(__pyx_v_node->extra);
    __Pyx_DECREF(__pyx_v_node->extra);
    __pyx_v_node->extra = ((PyObject *)__pyx_v_ms_node);

    /* "bzrlib/_known_graph_pyx.pyx":761
 *         cdef _MergeSortNode ms_node
 * 
 *         if node.extra is None:             # <<<<<<<<<<<<<<
 *             ms_node = _MergeSortNode(node.key)
 *             node.extra = ms_node
 */
    goto __pyx_L3;
  }

  /* "bzrlib/_known_graph_pyx.pyx":765
 *             node.extra = ms_node
 *         else:
 *             ms_node = <_MergeSortNode>node.extra             # <<<<<<<<<<<<<<
 *         return ms_node
 * 
 */
  /*else*/ {
    __pyx_t_4 = __pyx_v_node->extra;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_4);
    __pyx_t_4 = 0;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":766
 *         else:
 *             ms_node = <_MergeSortNode>node.extra
 *         return ms_node             # <<<<<<<<<<<<<<
 * 
 *     cdef _push_node(self, _KnownGraphNode node, long merge_depth):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_ms_node));
  __pyx_r = __pyx_v_ms_node;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":757
 *             self._push_node(node, 0)
 * 
 *     cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp_node
 *         cdef _MergeSortNode ms_node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._get_ms_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":768
 *         return ms_node
 * 
 *     cdef _push_node(self, _KnownGraphNode node, long merge_depth):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode parent_node
 *         cdef _MergeSortNode ms_node, ms_parent_node
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__push_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node, long __pyx_v_merge_depth) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_parent_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_parent_node = 0;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_push_node", 0);

  /* "bzrlib/_known_graph_pyx.pyx":773
 *         cdef Py_ssize_t pos
 * 
 *         ms_node = self._get_ms_node(node)             # <<<<<<<<<<<<<<
 *         ms_node.merge_depth = merge_depth
 *         if node.parents is None:
 */
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self, __pyx_v_node)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":774
 * 
 *         ms_node = self._get_ms_node(node)
 *         ms_node.merge_depth = merge_depth             # <<<<<<<<<<<<<<
 *         if node.parents is None:
 *             raise RuntimeError('ghost nodes should not be pushed'
 */
  __pyx_v_ms_node->merge_depth = __pyx_v_merge_depth;

  /* "bzrlib/_known_graph_pyx.pyx":775
 *         ms_node = self._get_ms_node(node)
 *         ms_node.merge_depth = merge_depth
 *         if node.parents is None:             # <<<<<<<<<<<<<<
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))
 */
  __pyx_t_2 = (__pyx_v_node->parents == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":777
 *         if node.parents is None:
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))             # <<<<<<<<<<<<<<
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 *             parent_node = _get_tuple_node(node.parents, 0)
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_v_node));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_node));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_node));
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_ghost_nodes_should_not_be_pushed, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":776
 *         ms_node.merge_depth = merge_depth
 *         if node.parents is None:
 *             raise RuntimeError('ghost nodes should not be pushed'             # <<<<<<<<<<<<<<
 *                                ' onto the stack: %s' % (node,))
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":775
 *         ms_node = self._get_ms_node(node)
 *         ms_node.merge_depth = merge_depth
 *         if node.parents is None:             # <<<<<<<<<<<<<<
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":778
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))
 *         if PyTuple_GET_SIZE(node.parents) > 0:             # <<<<<<<<<<<<<<
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node
 */
  __pyx_t_4 = __pyx_v_node->parents;
  __Pyx_INCREF(__pyx_t_4);
  __pyx_t_3 = ((PyTuple_GET_SIZE(__pyx_t_4) > 0) != 0);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_3) {

    /* "bzrlib/_known_graph_pyx.pyx":779
 *                                ' onto the stack: %s' % (node,))
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 *             parent_node = _get_tuple_node(node.parents, 0)             # <<<<<<<<<<<<<<
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost
 */
    __pyx_t_4 = __pyx_v_node->parents;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_t_4, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":780
 *         if PyTuple_GET_SIZE(node.parents) > 0:
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node             # <<<<<<<<<<<<<<
 *             if parent_node.parents is None: # left-hand ghost
 *                 ms_node.left_pending_parent = None
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_parent_node));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_parent_node));
    __Pyx_GOTREF(__pyx_v_ms_node->left_parent);
    __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_parent));
    __pyx_v_ms_node->left_parent = __pyx_v_parent_node;

    /* "bzrlib/_known_graph_pyx.pyx":781
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost             # <<<<<<<<<<<<<<
 *                 ms_node.left_pending_parent = None
 *                 ms_node.left_parent = None
 */
    __pyx_t_3 = (__pyx_v_parent_node->parents == Py_None);
    __pyx_t_2 = (__pyx_t_3 != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":782
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost
 *                 ms_node.left_pending_parent = None             # <<<<<<<<<<<<<<
 *                 ms_node.left_parent = None
 *             else:
 */
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_GOTREF(__pyx_v_ms_node->left_pending_parent);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_pending_parent));
      __pyx_v_ms_node->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

      /* "bzrlib/_known_graph_pyx.pyx":783
 *             if parent_node.parents is None: # left-hand ghost
 *                 ms_node.left_pending_parent = None
 *                 ms_node.left_parent = None             # <<<<<<<<<<<<<<
 *             else:
 *                 ms_node.left_pending_parent = parent_node
 */
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      __Pyx_GOTREF(__pyx_v_ms_node->left_parent);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_parent));
      __pyx_v_ms_node->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

      /* "bzrlib/_known_graph_pyx.pyx":781
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node
 *             if parent_node.parents is None: # left-hand ghost             # <<<<<<<<<<<<<<
 *                 ms_node.left_pending_parent = None
 *                 ms_node.left_parent = None
 */
      goto __pyx_L5;
    }

    /* "bzrlib/_known_graph_pyx.pyx":785
 *                 ms_node.left_parent = None
 *             else:
 *                 ms_node.left_pending_parent = parent_node             # <<<<<<<<<<<<<<
 *         if PyTuple_GET_SIZE(node.parents) > 1:
 *             ms_node.pending_parents = []
 */
    /*else*/ {
      __Pyx_INCREF(((PyObject *)__pyx_v_parent_node));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_parent_node));
      __Pyx_GOTREF(__pyx_v_ms_node->left_pending_parent);
      __Pyx_DECREF(((PyObject *)__pyx_v_ms_node->left_pending_parent));
      __pyx_v_ms_node->left_pending_parent = __pyx_v_parent_node;
    }
    __pyx_L5:;

    /* "bzrlib/_known_graph_pyx.pyx":778
 *             raise RuntimeError('ghost nodes should not be pushed'
 *                                ' onto the stack: %s' % (node,))
 *         if PyTuple_GET_SIZE(node.parents) > 0:             # <<<<<<<<<<<<<<
 *             parent_node = _get_tuple_node(node.parents, 0)
 *             ms_node.left_parent = parent_node
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":786
 *             else:
 *                 ms_node.left_pending_parent = parent_node
 *         if PyTuple_GET_SIZE(node.parents) > 1:             # <<<<<<<<<<<<<<
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 */
  __pyx_t_1 = __pyx_v_node->parents;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((PyTuple_GET_SIZE(__pyx_t_1) > 1) != 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":787
 *                 ms_node.left_pending_parent = parent_node
 *         if PyTuple_GET_SIZE(node.parents) > 1:
 *             ms_node.pending_parents = []             # <<<<<<<<<<<<<<
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF(__pyx_v_ms_node->pending_parents);
    __Pyx_DECREF(__pyx_v_ms_node->pending_parents);
    __pyx_v_ms_node->pending_parents = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":788
 *         if PyTuple_GET_SIZE(node.parents) > 1:
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):             # <<<<<<<<<<<<<<
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost
 */
    __pyx_t_1 = __pyx_v_node->parents;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_GET_SIZE(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (__pyx_v_pos = 1; __pyx_v_pos < __pyx_t_5; __pyx_v_pos++) {

      /* "bzrlib/_known_graph_pyx.pyx":789
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)             # <<<<<<<<<<<<<<
 *                 if parent_node.parents is None: # ghost
 *                     continue
 */
      __pyx_t_1 = __pyx_v_node->parents;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_tuple_node(__pyx_t_1, __pyx_v_pos)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_parent_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":790
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost             # <<<<<<<<<<<<<<
 *                     continue
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 */
      __pyx_t_2 = (__pyx_v_parent_node->parents == Py_None);
      __pyx_t_3 = (__pyx_t_2 != 0);
      if (__pyx_t_3) {

        /* "bzrlib/_known_graph_pyx.pyx":791
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost
 *                     continue             # <<<<<<<<<<<<<<
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 * 
 */
        goto __pyx_L7_continue;

        /* "bzrlib/_known_graph_pyx.pyx":790
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 *                 parent_node = _get_tuple_node(node.parents, pos)
 *                 if parent_node.parents is None: # ghost             # <<<<<<<<<<<<<<
 *                     continue
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":792
 *                 if parent_node.parents is None: # ghost
 *                     continue
 *                 PyList_Append(ms_node.pending_parents, parent_node)             # <<<<<<<<<<<<<<
 * 
 *         ms_node.is_first_child = 1
 */
      __pyx_t_4 = __pyx_v_ms_node->pending_parents;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_6 = PyList_Append(__pyx_t_4, ((PyObject *)__pyx_v_parent_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_L7_continue:;
    }

    /* "bzrlib/_known_graph_pyx.pyx":786
 *             else:
 *                 ms_node.left_pending_parent = parent_node
 *         if PyTuple_GET_SIZE(node.parents) > 1:             # <<<<<<<<<<<<<<
 *             ms_node.pending_parents = []
 *             for pos from 1 <= pos < PyTuple_GET_SIZE(node.parents):
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":794
 *                 PyList_Append(ms_node.pending_parents, parent_node)
 * 
 *         ms_node.is_first_child = 1             # <<<<<<<<<<<<<<
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 */
  __pyx_v_ms_node->is_first_child = 1;

  /* "bzrlib/_known_graph_pyx.pyx":795
 * 
 *         ms_node.is_first_child = 1
 *         if ms_node.left_parent is not None:             # <<<<<<<<<<<<<<
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:
 */
  __pyx_t_3 = (((PyObject *)__pyx_v_ms_node->left_parent) != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":796
 *         ms_node.is_first_child = 1
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)             # <<<<<<<<<<<<<<
 *             if ms_parent_node.seen_by_child:
 *                 ms_node.is_first_child = 0
 */
    __pyx_t_4 = ((PyObject *)__pyx_v_ms_node->left_parent);
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_4))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":797
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:             # <<<<<<<<<<<<<<
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1
 */
    __pyx_t_2 = (__pyx_v_ms_parent_node->seen_by_child != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":798
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:
 *                 ms_node.is_first_child = 0             # <<<<<<<<<<<<<<
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1
 */
      __pyx_v_ms_node->is_first_child = 0;

      /* "bzrlib/_known_graph_pyx.pyx":797
 *         if ms_node.left_parent is not None:
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:             # <<<<<<<<<<<<<<
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":799
 *             if ms_parent_node.seen_by_child:
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1             # <<<<<<<<<<<<<<
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 */
    __pyx_v_ms_parent_node->seen_by_child = 1;

    /* "bzrlib/_known_graph_pyx.pyx":795
 * 
 *         ms_node.is_first_child = 1
 *         if ms_node.left_parent is not None:             # <<<<<<<<<<<<<<
 *             ms_parent_node = self._get_ms_node(ms_node.left_parent)
 *             if ms_parent_node.seen_by_child:
 */
  }

  /* "bzrlib/_known_graph_pyx.pyx":800
 *                 ms_node.is_first_child = 0
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1             # <<<<<<<<<<<<<<
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 *             Py_INCREF(node) # SetItem steals a ref
 */
  __pyx_v_self->_last_stack_item = (__pyx_v_self->_last_stack_item + 1);

  /* "bzrlib/_known_graph_pyx.pyx":801
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):             # <<<<<<<<<<<<<<
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 */
  __pyx_t_1 = __pyx_v_self->_depth_first_stack;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((__pyx_v_self->_last_stack_item < PyList_GET_SIZE(__pyx_t_1)) != 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "bzrlib/_known_graph_pyx.pyx":802
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 *             Py_INCREF(node) # SetItem steals a ref             # <<<<<<<<<<<<<<
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 *                            node)
 */
    Py_INCREF(((PyObject *)__pyx_v_node));

    /* "bzrlib/_known_graph_pyx.pyx":803
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,             # <<<<<<<<<<<<<<
 *                            node)
 *         else:
 */
    __pyx_t_1 = __pyx_v_self->_depth_first_stack;
    __Pyx_INCREF(__pyx_t_1);

    /* "bzrlib/_known_graph_pyx.pyx":804
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 *                            node)             # <<<<<<<<<<<<<<
 *         else:
 *             PyList_Append(self._depth_first_stack, node)
 */
    __pyx_t_6 = PyList_SetItem(__pyx_t_1, __pyx_v_self->_last_stack_item, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":801
 *             ms_parent_node.seen_by_child = 1
 *         self._last_stack_item = self._last_stack_item + 1
 *         if self._last_stack_item < PyList_GET_SIZE(self._depth_first_stack):             # <<<<<<<<<<<<<<
 *             Py_INCREF(node) # SetItem steals a ref
 *             PyList_SetItem(self._depth_first_stack, self._last_stack_item,
 */
    goto __pyx_L12;
  }

  /* "bzrlib/_known_graph_pyx.pyx":806
 *                            node)
 *         else:
 *             PyList_Append(self._depth_first_stack, node)             # <<<<<<<<<<<<<<
 * 
 *     cdef _pop_node(self):
 */
  /*else*/ {
    __pyx_t_1 = __pyx_v_self->_depth_first_stack;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_6 = PyList_Append(__pyx_t_1, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L12:;

  /* "bzrlib/_known_graph_pyx.pyx":768
 *         return ms_node
 * 
 *     cdef _push_node(self, _KnownGraphNode node, long merge_depth):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode parent_node
 *         cdef _MergeSortNode ms_node, ms_parent_node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._push_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_parent_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_parent_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":808
 *             PyList_Append(self._depth_first_stack, node)
 * 
 *     cdef _pop_node(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp
 *         cdef _MergeSortNode ms_node, ms_parent_node, ms_prev_node
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__pop_node(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self) {
  PyObject *__pyx_v_temp;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_parent_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_prev_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_prev_node = 0;
  long __pyx_v_base_revno;
  PyObject *__pyx_v_branch_count = NULL;
  PyObject *__pyx_v_root_count = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  long __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_pop_node", 0);

  /* "bzrlib/_known_graph_pyx.pyx":813
 *         cdef _KnownGraphNode node, parent_node, prev_node
 * 
 *         node = _get_list_node(self._depth_first_stack, self._last_stack_item)             # <<<<<<<<<<<<<<
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1
 */
  __pyx_t_1 = __pyx_v_self->_depth_first_stack;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_1, __pyx_v_self->_last_stack_item)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":814
 * 
 *         node = _get_list_node(self._depth_first_stack, self._last_stack_item)
 *         ms_node = <_MergeSortNode>node.extra             # <<<<<<<<<<<<<<
 *         self._last_stack_item = self._last_stack_item - 1
 *         if ms_node.left_parent is not None:
 */
  __pyx_t_2 = __pyx_v_node->extra;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_v_ms_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":815
 *         node = _get_list_node(self._depth_first_stack, self._last_stack_item)
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1             # <<<<<<<<<<<<<<
 *         if ms_node.left_parent is not None:
 *             # Assign the revision number from the left-hand parent
 */
  __pyx_v_self->_last_stack_item = (__pyx_v_self->_last_stack_item - 1);

  /* "bzrlib/_known_graph_pyx.pyx":816
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1
 *         if ms_node.left_parent is not None:             # <<<<<<<<<<<<<<
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra
 */
  __pyx_t_3 = (((PyObject *)__pyx_v_ms_node->left_parent) != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "bzrlib/_known_graph_pyx.pyx":818
 *         if ms_node.left_parent is not None:
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra             # <<<<<<<<<<<<<<
 *             if ms_node.is_first_child:
 *                 # First child just increments the final digit
 */
    __pyx_t_2 = __pyx_v_ms_node->left_parent->extra;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_v_ms_parent_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":819
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra
 *             if ms_node.is_first_child:             # <<<<<<<<<<<<<<
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first
 */
    __pyx_t_4 = (__pyx_v_ms_node->is_first_child != 0);
    if (__pyx_t_4) {

      /* "bzrlib/_known_graph_pyx.pyx":821
 *             if ms_node.is_first_child:
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = ms_parent_node._revno_second
 *                 ms_node._revno_last = ms_parent_node._revno_last + 1
 */
      __pyx_t_5 = __pyx_v_ms_parent_node->_revno_first;
      __pyx_v_ms_node->_revno_first = __pyx_t_5;

      /* "bzrlib/_known_graph_pyx.pyx":822
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first
 *                 ms_node._revno_second = ms_parent_node._revno_second             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = ms_parent_node._revno_last + 1
 *             else:
 */
      __pyx_t_5 = __pyx_v_ms_parent_node->_revno_second;
      __pyx_v_ms_node->_revno_second = __pyx_t_5;

      /* "bzrlib/_known_graph_pyx.pyx":823
 *                 ms_node._revno_first = ms_parent_node._revno_first
 *                 ms_node._revno_second = ms_parent_node._revno_second
 *                 ms_node._revno_last = ms_parent_node._revno_last + 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # Not the first child, make a new branch
 */
      __pyx_v_ms_node->_revno_last = (__pyx_v_ms_parent_node->_revno_last + 1);

      /* "bzrlib/_known_graph_pyx.pyx":819
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra
 *             if ms_node.is_first_child:             # <<<<<<<<<<<<<<
 *                 # First child just increments the final digit
 *                 ms_node._revno_first = ms_parent_node._revno_first
 */
      goto __pyx_L4;
    }

    /* "bzrlib/_known_graph_pyx.pyx":827
 *                 # Not the first child, make a new branch
 *                 #  (mainline_revno, branch_count, 1)
 *                 if ms_parent_node._revno_first == -1:             # <<<<<<<<<<<<<<
 *                     # Mainline ancestor, the increment is on the last digit
 *                     base_revno = ms_parent_node._revno_last
 */
    /*else*/ {
      __pyx_t_4 = ((__pyx_v_ms_parent_node->_revno_first == -1L) != 0);
      if (__pyx_t_4) {

        /* "bzrlib/_known_graph_pyx.pyx":829
 *                 if ms_parent_node._revno_first == -1:
 *                     # Mainline ancestor, the increment is on the last digit
 *                     base_revno = ms_parent_node._revno_last             # <<<<<<<<<<<<<<
 *                 else:
 *                     base_revno = ms_parent_node._revno_first
 */
        __pyx_t_5 = __pyx_v_ms_parent_node->_revno_last;
        __pyx_v_base_revno = __pyx_t_5;

        /* "bzrlib/_known_graph_pyx.pyx":827
 *                 # Not the first child, make a new branch
 *                 #  (mainline_revno, branch_count, 1)
 *                 if ms_parent_node._revno_first == -1:             # <<<<<<<<<<<<<<
 *                     # Mainline ancestor, the increment is on the last digit
 *                     base_revno = ms_parent_node._revno_last
 */
        goto __pyx_L5;
      }

      /* "bzrlib/_known_graph_pyx.pyx":831
 *                     base_revno = ms_parent_node._revno_last
 *                 else:
 *                     base_revno = ms_parent_node._revno_first             # <<<<<<<<<<<<<<
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)
 */
      /*else*/ {
        __pyx_t_5 = __pyx_v_ms_parent_node->_revno_first;
        __pyx_v_base_revno = __pyx_t_5;
      }
      __pyx_L5:;

      /* "bzrlib/_known_graph_pyx.pyx":832
 *                 else:
 *                     base_revno = ms_parent_node._revno_first
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,             # <<<<<<<<<<<<<<
 *                                       base_revno)
 *                 if temp == NULL:
 */
      __pyx_t_2 = __pyx_v_self->_revno_to_branch_count;
      __Pyx_INCREF(__pyx_t_2);

      /* "bzrlib/_known_graph_pyx.pyx":833
 *                     base_revno = ms_parent_node._revno_first
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)             # <<<<<<<<<<<<<<
 *                 if temp == NULL:
 *                     branch_count = 1
 */
      __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_base_revno); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);

      /* "bzrlib/_known_graph_pyx.pyx":832
 *                 else:
 *                     base_revno = ms_parent_node._revno_first
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,             # <<<<<<<<<<<<<<
 *                                       base_revno)
 *                 if temp == NULL:
 */
      __pyx_v_temp = PyDict_GetItem(__pyx_t_2, __pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":834
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)
 *                 if temp == NULL:             # <<<<<<<<<<<<<<
 *                     branch_count = 1
 *                 else:
 */
      __pyx_t_4 = ((__pyx_v_temp == NULL) != 0);
      if (__pyx_t_4) {

        /* "bzrlib/_known_graph_pyx.pyx":835
 *                                       base_revno)
 *                 if temp == NULL:
 *                     branch_count = 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     branch_count = (<object>temp) + 1
 */
        __Pyx_INCREF(__pyx_int_1);
        __pyx_v_branch_count = __pyx_int_1;

        /* "bzrlib/_known_graph_pyx.pyx":834
 *                 temp = PyDict_GetItem(self._revno_to_branch_count,
 *                                       base_revno)
 *                 if temp == NULL:             # <<<<<<<<<<<<<<
 *                     branch_count = 1
 *                 else:
 */
        goto __pyx_L6;
      }

      /* "bzrlib/_known_graph_pyx.pyx":837
 *                     branch_count = 1
 *                 else:
 *                     branch_count = (<object>temp) + 1             # <<<<<<<<<<<<<<
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,
 *                                branch_count)
 */
      /*else*/ {
        __pyx_t_1 = __Pyx_PyInt_AddObjC(((PyObject *)__pyx_v_temp), __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_v_branch_count = __pyx_t_1;
        __pyx_t_1 = 0;
      }
      __pyx_L6:;

      /* "bzrlib/_known_graph_pyx.pyx":838
 *                 else:
 *                     branch_count = (<object>temp) + 1
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,             # <<<<<<<<<<<<<<
 *                                branch_count)
 *                 ms_node._revno_first = base_revno
 */
      __pyx_t_1 = __pyx_v_self->_revno_to_branch_count;
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_base_revno); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);

      /* "bzrlib/_known_graph_pyx.pyx":839
 *                     branch_count = (<object>temp) + 1
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,
 *                                branch_count)             # <<<<<<<<<<<<<<
 *                 ms_node._revno_first = base_revno
 *                 ms_node._revno_second = branch_count
 */
      __pyx_t_6 = PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_v_branch_count); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":840
 *                 PyDict_SetItem(self._revno_to_branch_count, base_revno,
 *                                branch_count)
 *                 ms_node._revno_first = base_revno             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = branch_count
 *                 ms_node._revno_last = 1
 */
      __pyx_v_ms_node->_revno_first = __pyx_v_base_revno;

      /* "bzrlib/_known_graph_pyx.pyx":841
 *                                branch_count)
 *                 ms_node._revno_first = base_revno
 *                 ms_node._revno_second = branch_count             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = 1
 *         else:
 */
      __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_branch_count); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_ms_node->_revno_second = __pyx_t_5;

      /* "bzrlib/_known_graph_pyx.pyx":842
 *                 ms_node._revno_first = base_revno
 *                 ms_node._revno_second = branch_count
 *                 ms_node._revno_last = 1             # <<<<<<<<<<<<<<
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)
 */
      __pyx_v_ms_node->_revno_last = 1;
    }
    __pyx_L4:;

    /* "bzrlib/_known_graph_pyx.pyx":816
 *         ms_node = <_MergeSortNode>node.extra
 *         self._last_stack_item = self._last_stack_item - 1
 *         if ms_node.left_parent is not None:             # <<<<<<<<<<<<<<
 *             # Assign the revision number from the left-hand parent
 *             ms_parent_node = <_MergeSortNode>ms_node.left_parent.extra
 */
    goto __pyx_L3;
  }

  /* "bzrlib/_known_graph_pyx.pyx":844
 *                 ms_node._revno_last = 1
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)             # <<<<<<<<<<<<<<
 *             if temp == NULL:
 *                 # The first root node doesn't have a 3-digit revno
 */
  /*else*/ {
    __pyx_t_2 = __pyx_v_self->_revno_to_branch_count;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_v_temp = PyDict_GetItem(__pyx_t_2, __pyx_int_0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":845
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)
 *             if temp == NULL:             # <<<<<<<<<<<<<<
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0
 */
    __pyx_t_4 = ((__pyx_v_temp == NULL) != 0);
    if (__pyx_t_4) {

      /* "bzrlib/_known_graph_pyx.pyx":847
 *             if temp == NULL:
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0             # <<<<<<<<<<<<<<
 *                 ms_node._revno_first = -1
 *                 ms_node._revno_second = -1
 */
      __Pyx_INCREF(__pyx_int_0);
      __pyx_v_root_count = __pyx_int_0;

      /* "bzrlib/_known_graph_pyx.pyx":848
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0
 *                 ms_node._revno_first = -1             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = -1
 *                 ms_node._revno_last = 1
 */
      __pyx_v_ms_node->_revno_first = -1L;

      /* "bzrlib/_known_graph_pyx.pyx":849
 *                 root_count = 0
 *                 ms_node._revno_first = -1
 *                 ms_node._revno_second = -1             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = 1
 *             else:
 */
      __pyx_v_ms_node->_revno_second = -1L;

      /* "bzrlib/_known_graph_pyx.pyx":850
 *                 ms_node._revno_first = -1
 *                 ms_node._revno_second = -1
 *                 ms_node._revno_last = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 root_count = (<object>temp) + 1
 */
      __pyx_v_ms_node->_revno_last = 1;

      /* "bzrlib/_known_graph_pyx.pyx":845
 *         else:
 *             temp = PyDict_GetItem(self._revno_to_branch_count, 0)
 *             if temp == NULL:             # <<<<<<<<<<<<<<
 *                 # The first root node doesn't have a 3-digit revno
 *                 root_count = 0
 */
      goto __pyx_L7;
    }

    /* "bzrlib/_known_graph_pyx.pyx":852
 *                 ms_node._revno_last = 1
 *             else:
 *                 root_count = (<object>temp) + 1             # <<<<<<<<<<<<<<
 *                 ms_node._revno_first = 0
 *                 ms_node._revno_second = root_count
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyInt_AddObjC(((PyObject *)__pyx_v_temp), __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_v_root_count = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":853
 *             else:
 *                 root_count = (<object>temp) + 1
 *                 ms_node._revno_first = 0             # <<<<<<<<<<<<<<
 *                 ms_node._revno_second = root_count
 *                 ms_node._revno_last = 1
 */
      __pyx_v_ms_node->_revno_first = 0;

      /* "bzrlib/_known_graph_pyx.pyx":854
 *                 root_count = (<object>temp) + 1
 *                 ms_node._revno_first = 0
 *                 ms_node._revno_second = root_count             # <<<<<<<<<<<<<<
 *                 ms_node._revno_last = 1
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 */
      __pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_root_count); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_ms_node->_revno_second = __pyx_t_5;

      /* "bzrlib/_known_graph_pyx.pyx":855
 *                 ms_node._revno_first = 0
 *                 ms_node._revno_second = root_count
 *                 ms_node._revno_last = 1             # <<<<<<<<<<<<<<
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1
 */
      __pyx_v_ms_node->_revno_last = 1;
    }
    __pyx_L7:;

    /* "bzrlib/_known_graph_pyx.pyx":856
 *                 ms_node._revno_second = root_count
 *                 ms_node._revno_last = 1
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)             # <<<<<<<<<<<<<<
 *         ms_node.completed = 1
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:
 */
    __pyx_t_2 = __pyx_v_self->_revno_to_branch_count;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6 = PyDict_SetItem(__pyx_t_2, __pyx_int_0, __pyx_v_root_count); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L3:;

  /* "bzrlib/_known_graph_pyx.pyx":857
 *                 ms_node._revno_last = 1
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1             # <<<<<<<<<<<<<<
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:
 *             # The first scheduled node is always the end of merge
 */
  __pyx_v_ms_node->completed = 1;

  /* "bzrlib/_known_graph_pyx.pyx":858
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:             # <<<<<<<<<<<<<<
 *             # The first scheduled node is always the end of merge
 *             ms_node.end_of_merge = True
 */
  __pyx_t_2 = __pyx_v_self->_scheduled_nodes;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_4 = ((PyList_GET_SIZE(__pyx_t_2) == 0) != 0);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "bzrlib/_known_graph_pyx.pyx":860
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:
 *             # The first scheduled node is always the end of merge
 *             ms_node.end_of_merge = True             # <<<<<<<<<<<<<<
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,
 */
    __Pyx_INCREF(Py_True);
    __Pyx_GIVEREF(Py_True);
    __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
    __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
    __pyx_v_ms_node->end_of_merge = Py_True;

    /* "bzrlib/_known_graph_pyx.pyx":858
 *             PyDict_SetItem(self._revno_to_branch_count, 0, root_count)
 *         ms_node.completed = 1
 *         if PyList_GET_SIZE(self._scheduled_nodes) == 0:             # <<<<<<<<<<<<<<
 *             # The first scheduled node is always the end of merge
 *             ms_node.end_of_merge = True
 */
    goto __pyx_L8;
  }

  /* "bzrlib/_known_graph_pyx.pyx":862
 *             ms_node.end_of_merge = True
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,             # <<<<<<<<<<<<<<
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 */
  /*else*/ {
    __pyx_t_2 = __pyx_v_self->_scheduled_nodes;
    __Pyx_INCREF(__pyx_t_2);

    /* "bzrlib/_known_graph_pyx.pyx":863
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)             # <<<<<<<<<<<<<<
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:
 */
    __pyx_t_1 = __pyx_v_self->_scheduled_nodes;
    __Pyx_INCREF(__pyx_t_1);

    /* "bzrlib/_known_graph_pyx.pyx":862
 *             ms_node.end_of_merge = True
 *         else:
 *             prev_node = _get_list_node(self._scheduled_nodes,             # <<<<<<<<<<<<<<
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 */
    __pyx_t_7 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_2, (PyList_GET_SIZE(__pyx_t_1) - 1))); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":864
 *             prev_node = _get_list_node(self._scheduled_nodes,
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra             # <<<<<<<<<<<<<<
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:
 *                 # The previously pushed node is to our left, so this is the end
 */
    __pyx_t_7 = __pyx_v_prev_node->extra;
    __Pyx_INCREF(__pyx_t_7);
    __pyx_v_ms_prev_node = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":865
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:             # <<<<<<<<<<<<<<
 *                 # The previously pushed node is to our left, so this is the end
 *                 # of this right-hand chain
 */
    __pyx_t_4 = ((__pyx_v_ms_prev_node->merge_depth < __pyx_v_ms_node->merge_depth) != 0);
    if (__pyx_t_4) {

      /* "bzrlib/_known_graph_pyx.pyx":868
 *                 # The previously pushed node is to our left, so this is the end
 *                 # of this right-hand chain
 *                 ms_node.end_of_merge = True             # <<<<<<<<<<<<<<
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth
 *                   and prev_node not in node.parents):
 */
      __Pyx_INCREF(Py_True);
      __Pyx_GIVEREF(Py_True);
      __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
      __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = Py_True;

      /* "bzrlib/_known_graph_pyx.pyx":865
 *                                     PyList_GET_SIZE(self._scheduled_nodes) - 1)
 *             ms_prev_node = <_MergeSortNode>prev_node.extra
 *             if ms_prev_node.merge_depth < ms_node.merge_depth:             # <<<<<<<<<<<<<<
 *                 # The previously pushed node is to our left, so this is the end
 *                 # of this right-hand chain
 */
      goto __pyx_L9;
    }

    /* "bzrlib/_known_graph_pyx.pyx":869
 *                 # of this right-hand chain
 *                 ms_node.end_of_merge = True
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth             # <<<<<<<<<<<<<<
 *                   and prev_node not in node.parents):
 *                 # The next node is not a direct parent of this node
 */
    __pyx_t_3 = ((__pyx_v_ms_prev_node->merge_depth == __pyx_v_ms_node->merge_depth) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_4 = __pyx_t_3;
      goto __pyx_L10_bool_binop_done;
    }

    /* "bzrlib/_known_graph_pyx.pyx":870
 *                 ms_node.end_of_merge = True
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth
 *                   and prev_node not in node.parents):             # <<<<<<<<<<<<<<
 *                 # The next node is not a direct parent of this node
 *                 ms_node.end_of_merge = True
 */
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(((PyObject *)__pyx_v_prev_node), __pyx_v_node->parents, Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = (__pyx_t_3 != 0);
    __pyx_t_4 = __pyx_t_8;
    __pyx_L10_bool_binop_done:;

    /* "bzrlib/_known_graph_pyx.pyx":869
 *                 # of this right-hand chain
 *                 ms_node.end_of_merge = True
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth             # <<<<<<<<<<<<<<
 *                   and prev_node not in node.parents):
 *                 # The next node is not a direct parent of this node
 */
    if (__pyx_t_4) {

      /* "bzrlib/_known_graph_pyx.pyx":872
 *                   and prev_node not in node.parents):
 *                 # The next node is not a direct parent of this node
 *                 ms_node.end_of_merge = True             # <<<<<<<<<<<<<<
 *             else:
 *                 ms_node.end_of_merge = False
 */
      __Pyx_INCREF(Py_True);
      __Pyx_GIVEREF(Py_True);
      __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
      __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = Py_True;

      /* "bzrlib/_known_graph_pyx.pyx":869
 *                 # of this right-hand chain
 *                 ms_node.end_of_merge = True
 *             elif (ms_prev_node.merge_depth == ms_node.merge_depth             # <<<<<<<<<<<<<<
 *                   and prev_node not in node.parents):
 *                 # The next node is not a direct parent of this node
 */
      goto __pyx_L9;
    }

    /* "bzrlib/_known_graph_pyx.pyx":874
 *                 ms_node.end_of_merge = True
 *             else:
 *                 ms_node.end_of_merge = False             # <<<<<<<<<<<<<<
 *         PyList_Append(self._scheduled_nodes, node)
 * 
 */
    /*else*/ {
      __Pyx_INCREF(Py_False);
      __Pyx_GIVEREF(Py_False);
      __Pyx_GOTREF(__pyx_v_ms_node->end_of_merge);
      __Pyx_DECREF(__pyx_v_ms_node->end_of_merge);
      __pyx_v_ms_node->end_of_merge = Py_False;
    }
    __pyx_L9:;
  }
  __pyx_L8:;

  /* "bzrlib/_known_graph_pyx.pyx":875
 *             else:
 *                 ms_node.end_of_merge = False
 *         PyList_Append(self._scheduled_nodes, node)             # <<<<<<<<<<<<<<
 * 
 *     cdef _schedule_stack(self):
 */
  __pyx_t_7 = __pyx_v_self->_scheduled_nodes;
  __Pyx_INCREF(__pyx_t_7);
  __pyx_t_6 = PyList_Append(__pyx_t_7, ((PyObject *)__pyx_v_node)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":808
 *             PyList_Append(self._depth_first_stack, node)
 * 
 *     cdef _pop_node(self):             # <<<<<<<<<<<<<<
 *         cdef PyObject *temp
 *         cdef _MergeSortNode ms_node, ms_parent_node, ms_prev_node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._pop_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_parent_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_prev_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_prev_node);
  __Pyx_XDECREF(__pyx_v_branch_count);
  __Pyx_XDECREF(__pyx_v_root_count);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":877
 *         PyList_Append(self._scheduled_nodes, node)
 * 
 *     cdef _schedule_stack(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode last_node, next_node
 *         cdef _MergeSortNode ms_node, ms_last_node, ms_next_node
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__schedule_stack(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_last_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_next_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_last_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_next_node = 0;
  long __pyx_v_next_merge_depth;
  CYTHON_UNUSED PyObject *__pyx_v_ordered = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  long __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_schedule_stack", 0);

  /* "bzrlib/_known_graph_pyx.pyx":881
 *         cdef _MergeSortNode ms_node, ms_last_node, ms_next_node
 *         cdef long next_merge_depth
 *         ordered = []             # <<<<<<<<<<<<<<
 *         while self._last_stack_item >= 0:
 *             # Peek at the last item on the stack
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ordered = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":882
 *         cdef long next_merge_depth
 *         ordered = []
 *         while self._last_stack_item >= 0:             # <<<<<<<<<<<<<<
 *             # Peek at the last item on the stack
 *             last_node = _get_list_node(self._depth_first_stack,
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_self->_last_stack_item >= 0) != 0);
    if (!__pyx_t_2) break;

    /* "bzrlib/_known_graph_pyx.pyx":884
 *         while self._last_stack_item >= 0:
 *             # Peek at the last item on the stack
 *             last_node = _get_list_node(self._depth_first_stack,             # <<<<<<<<<<<<<<
 *                                        self._last_stack_item)
 *             if last_node.gdfo == -1:
 */
    __pyx_t_1 = __pyx_v_self->_depth_first_stack;
    __Pyx_INCREF(__pyx_t_1);

    /* "bzrlib/_known_graph_pyx.pyx":885
 *             # Peek at the last item on the stack
 *             last_node = _get_list_node(self._depth_first_stack,
 *                                        self._last_stack_item)             # <<<<<<<<<<<<<<
 *             if last_node.gdfo == -1:
 *                 # if _find_gdfo skipped a node, that means there is a graph
 */
    __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_1, __pyx_v_self->_last_stack_item)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_last_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":886
 *             last_node = _get_list_node(self._depth_first_stack,
 *                                        self._last_stack_item)
 *             if last_node.gdfo == -1:             # <<<<<<<<<<<<<<
 *                 # if _find_gdfo skipped a node, that means there is a graph
 *                 # cycle, error out now
 */
    __pyx_t_2 = ((__pyx_v_last_node->gdfo == -1L) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":889
 *                 # if _find_gdfo skipped a node, that means there is a graph
 *                 # cycle, error out now
 *                 raise errors.GraphCycleError(self.graph._nodes)             # <<<<<<<<<<<<<<
 *             ms_last_node = <_MergeSortNode>last_node.extra
 *             if not ms_last_node.has_pending_parents():
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_errors); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_GraphCycleError); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->graph->_nodes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
        __Pyx_INCREF(__pyx_v_self->graph->_nodes);
        __Pyx_GIVEREF(__pyx_v_self->graph->_nodes);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_self->graph->_nodes);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "bzrlib/_known_graph_pyx.pyx":886
 *             last_node = _get_list_node(self._depth_first_stack,
 *                                        self._last_stack_item)
 *             if last_node.gdfo == -1:             # <<<<<<<<<<<<<<
 *                 # if _find_gdfo skipped a node, that means there is a graph
 *                 # cycle, error out now
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":890
 *                 # cycle, error out now
 *                 raise errors.GraphCycleError(self.graph._nodes)
 *             ms_last_node = <_MergeSortNode>last_node.extra             # <<<<<<<<<<<<<<
 *             if not ms_last_node.has_pending_parents():
 *                 # Processed all parents, pop this node
 */
    __pyx_t_3 = __pyx_v_last_node->extra;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_ms_last_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":891
 *                 raise errors.GraphCycleError(self.graph._nodes)
 *             ms_last_node = <_MergeSortNode>last_node.extra
 *             if not ms_last_node.has_pending_parents():             # <<<<<<<<<<<<<<
 *                 # Processed all parents, pop this node
 *                 self._pop_node()
 */
    __pyx_t_2 = ((!(((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_ms_last_node->__pyx_vtab)->has_pending_parents(__pyx_v_ms_last_node) != 0)) != 0);
    if (__pyx_t_2) {

      /* "bzrlib/_known_graph_pyx.pyx":893
 *             if not ms_last_node.has_pending_parents():
 *                 # Processed all parents, pop this node
 *                 self._pop_node()             # <<<<<<<<<<<<<<
 *                 continue
 *             while ms_last_node.has_pending_parents():
 */
      __pyx_t_3 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_pop_node(__pyx_v_self); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":894
 *                 # Processed all parents, pop this node
 *                 self._pop_node()
 *                 continue             # <<<<<<<<<<<<<<
 *             while ms_last_node.has_pending_parents():
 *                 if ms_last_node.left_pending_parent is not None:
 */
      goto __pyx_L3_continue;

      /* "bzrlib/_known_graph_pyx.pyx":891
 *                 raise errors.GraphCycleError(self.graph._nodes)
 *             ms_last_node = <_MergeSortNode>last_node.extra
 *             if not ms_last_node.has_pending_parents():             # <<<<<<<<<<<<<<
 *                 # Processed all parents, pop this node
 *                 self._pop_node()
 */
    }

    /* "bzrlib/_known_graph_pyx.pyx":895
 *                 self._pop_node()
 *                 continue
 *             while ms_last_node.has_pending_parents():             # <<<<<<<<<<<<<<
 *                 if ms_last_node.left_pending_parent is not None:
 *                     # recurse depth first into the primary parent
 */
    while (1) {
      __pyx_t_2 = (((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_v_ms_last_node->__pyx_vtab)->has_pending_parents(__pyx_v_ms_last_node) != 0);
      if (!__pyx_t_2) break;

      /* "bzrlib/_known_graph_pyx.pyx":896
 *                 continue
 *             while ms_last_node.has_pending_parents():
 *                 if ms_last_node.left_pending_parent is not None:             # <<<<<<<<<<<<<<
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent
 */
      __pyx_t_2 = (((PyObject *)__pyx_v_ms_last_node->left_pending_parent) != Py_None);
      __pyx_t_6 = (__pyx_t_2 != 0);
      if (__pyx_t_6) {

        /* "bzrlib/_known_graph_pyx.pyx":898
 *                 if ms_last_node.left_pending_parent is not None:
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent             # <<<<<<<<<<<<<<
 *                     ms_last_node.left_pending_parent = None
 *                 else:
 */
        __pyx_t_3 = ((PyObject *)__pyx_v_ms_last_node->left_pending_parent);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_XDECREF_SET(__pyx_v_next_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
        __pyx_t_3 = 0;

        /* "bzrlib/_known_graph_pyx.pyx":899
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent
 *                     ms_last_node.left_pending_parent = None             # <<<<<<<<<<<<<<
 *                 else:
 *                     # place any merges in right-to-left order for scheduling
 */
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        __Pyx_GOTREF(__pyx_v_ms_last_node->left_pending_parent);
        __Pyx_DECREF(((PyObject *)__pyx_v_ms_last_node->left_pending_parent));
        __pyx_v_ms_last_node->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None);

        /* "bzrlib/_known_graph_pyx.pyx":896
 *                 continue
 *             while ms_last_node.has_pending_parents():
 *                 if ms_last_node.left_pending_parent is not None:             # <<<<<<<<<<<<<<
 *                     # recurse depth first into the primary parent
 *                     next_node = ms_last_node.left_pending_parent
 */
        goto __pyx_L9;
      }

      /* "bzrlib/_known_graph_pyx.pyx":908
 *                     #       left most, which will display nicely (you get
 *                     #       smaller trees at the top of the combined merge).
 *                     next_node = ms_last_node.pending_parents.pop()             # <<<<<<<<<<<<<<
 *                 ms_next_node = self._get_ms_node(next_node)
 *                 if ms_next_node.completed:
 */
      /*else*/ {
        __pyx_t_3 = __Pyx_PyObject_Pop(__pyx_v_ms_last_node->pending_parents); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_XDECREF_SET(__pyx_v_next_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
        __pyx_t_3 = 0;
      }
      __pyx_L9:;

      /* "bzrlib/_known_graph_pyx.pyx":909
 *                     #       smaller trees at the top of the combined merge).
 *                     next_node = ms_last_node.pending_parents.pop()
 *                 ms_next_node = self._get_ms_node(next_node)             # <<<<<<<<<<<<<<
 *                 if ms_next_node.completed:
 *                     # this parent was completed by a child on the
 */
      __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_get_ms_node(__pyx_v_self, __pyx_v_next_node)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_ms_next_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":910
 *                     next_node = ms_last_node.pending_parents.pop()
 *                 ms_next_node = self._get_ms_node(next_node)
 *                 if ms_next_node.completed:             # <<<<<<<<<<<<<<
 *                     # this parent was completed by a child on the
 *                     # call stack. skip it.
 */
      __pyx_t_6 = (__pyx_v_ms_next_node->completed != 0);
      if (__pyx_t_6) {

        /* "bzrlib/_known_graph_pyx.pyx":913
 *                     # this parent was completed by a child on the
 *                     # call stack. skip it.
 *                     continue             # <<<<<<<<<<<<<<
 *                 # otherwise transfer it from the source graph into the
 *                 # top of the current depth first search stack.
 */
        goto __pyx_L7_continue;

        /* "bzrlib/_known_graph_pyx.pyx":910
 *                     next_node = ms_last_node.pending_parents.pop()
 *                 ms_next_node = self._get_ms_node(next_node)
 *                 if ms_next_node.completed:             # <<<<<<<<<<<<<<
 *                     # this parent was completed by a child on the
 *                     # call stack. skip it.
 */
      }

      /* "bzrlib/_known_graph_pyx.pyx":917
 *                 # top of the current depth first search stack.
 * 
 *                 if next_node is ms_last_node.left_parent:             # <<<<<<<<<<<<<<
 *                     next_merge_depth = ms_last_node.merge_depth
 *                 else:
 */
      __pyx_t_6 = (__pyx_v_next_node == __pyx_v_ms_last_node->left_parent);
      __pyx_t_2 = (__pyx_t_6 != 0);
      if (__pyx_t_2) {

        /* "bzrlib/_known_graph_pyx.pyx":918
 * 
 *                 if next_node is ms_last_node.left_parent:
 *                     next_merge_depth = ms_last_node.merge_depth             # <<<<<<<<<<<<<<
 *                 else:
 *                     next_merge_depth = ms_last_node.merge_depth + 1
 */
        __pyx_t_7 = __pyx_v_ms_last_node->merge_depth;
        __pyx_v_next_merge_depth = __pyx_t_7;

        /* "bzrlib/_known_graph_pyx.pyx":917
 *                 # top of the current depth first search stack.
 * 
 *                 if next_node is ms_last_node.left_parent:             # <<<<<<<<<<<<<<
 *                     next_merge_depth = ms_last_node.merge_depth
 *                 else:
 */
        goto __pyx_L11;
      }

      /* "bzrlib/_known_graph_pyx.pyx":920
 *                     next_merge_depth = ms_last_node.merge_depth
 *                 else:
 *                     next_merge_depth = ms_last_node.merge_depth + 1             # <<<<<<<<<<<<<<
 *                 self._push_node(next_node, next_merge_depth)
 *                 # and do not continue processing parents until this 'call'
 */
      /*else*/ {
        __pyx_v_next_merge_depth = (__pyx_v_ms_last_node->merge_depth + 1);
      }
      __pyx_L11:;

      /* "bzrlib/_known_graph_pyx.pyx":921
 *                 else:
 *                     next_merge_depth = ms_last_node.merge_depth + 1
 *                 self._push_node(next_node, next_merge_depth)             # <<<<<<<<<<<<<<
 *                 # and do not continue processing parents until this 'call'
 *                 # has recursed.
 */
      __pyx_t_3 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_push_node(__pyx_v_self, __pyx_v_next_node, __pyx_v_next_merge_depth); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "bzrlib/_known_graph_pyx.pyx":924
 *                 # and do not continue processing parents until this 'call'
 *                 # has recursed.
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     cdef topo_order(self):
 */
      goto __pyx_L8_break;
      __pyx_L7_continue:;
    }
    __pyx_L8_break:;
    __pyx_L3_continue:;
  }

  /* "bzrlib/_known_graph_pyx.pyx":877
 *         PyList_Append(self._scheduled_nodes, node)
 * 
 *     cdef _schedule_stack(self):             # <<<<<<<<<<<<<<
 *         cdef _KnownGraphNode last_node, next_node
 *         cdef _MergeSortNode ms_node, ms_last_node, ms_next_node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter._schedule_stack", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_last_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_next_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_last_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_next_node);
  __Pyx_XDECREF(__pyx_v_ordered);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_known_graph_pyx.pyx":926
 *                 break
 * 
 *     cdef topo_order(self):             # <<<<<<<<<<<<<<
 *         cdef _MergeSortNode ms_node
 *         cdef _KnownGraphNode node
 */

static PyObject *__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter_topo_order(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *__pyx_v_self) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *__pyx_v_ms_node = 0;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *__pyx_v_node = 0;
  Py_ssize_t __pyx_v_pos;
  PyObject *__pyx_v_ordered = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("topo_order", 0);

  /* "bzrlib/_known_graph_pyx.pyx":936
 *         #       We might consider moving the attributes into the base
 *         #       KnownGraph object.
 *         self._schedule_stack()             # <<<<<<<<<<<<<<
 * 
 *         # We've set up the basic schedule, now we can continue processing the
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter *)__pyx_v_self->__pyx_vtab)->_schedule_stack(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":946
 *         #       7ms is computing the return tuple
 *         #       4ms is PyList_Append()
 *         ordered = []             # <<<<<<<<<<<<<<
 *         # output the result in reverse order, and separate the generated info
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ordered = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":948
 *         ordered = []
 *         # output the result in reverse order, and separate the generated info
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:             # <<<<<<<<<<<<<<
 *             node = _get_list_node(self._scheduled_nodes, pos)
 *             ms_node = <_MergeSortNode>node.extra
 */
  __pyx_t_1 = __pyx_v_self->_scheduled_nodes;
  __Pyx_INCREF(__pyx_t_1);
  for (__pyx_v_pos = PyList_GET_SIZE(__pyx_t_1)-1; __pyx_v_pos >= 0; __pyx_v_pos--) {

    /* "bzrlib/_known_graph_pyx.pyx":949
 *         # output the result in reverse order, and separate the generated info
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:
 *             node = _get_list_node(self._scheduled_nodes, pos)             # <<<<<<<<<<<<<<
 *             ms_node = <_MergeSortNode>node.extra
 *             PyList_Append(ordered, ms_node)
 */
    __pyx_t_2 = __pyx_v_self->_scheduled_nodes;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_6bzrlib_16_known_graph_pyx__get_list_node(__pyx_t_2, __pyx_v_pos)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":950
 *         for pos from PyList_GET_SIZE(self._scheduled_nodes) > pos >= 0:
 *             node = _get_list_node(self._scheduled_nodes, pos)
 *             ms_node = <_MergeSortNode>node.extra             # <<<<<<<<<<<<<<
 *             PyList_Append(ordered, ms_node)
 *             node.extra = None
 */
    __pyx_t_3 = __pyx_v_node->extra;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_ms_node, ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "bzrlib/_known_graph_pyx.pyx":951
 *             node = _get_list_node(self._scheduled_nodes, pos)
 *             ms_node = <_MergeSortNode>node.extra
 *             PyList_Append(ordered, ms_node)             # <<<<<<<<<<<<<<
 *             node.extra = None
 *         # Clear out the scheduled nodes now that we're done
 */
    __pyx_t_4 = PyList_Append(__pyx_v_ordered, ((PyObject *)__pyx_v_ms_node)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_known_graph_pyx.pyx":952
 *             ms_node = <_MergeSortNode>node.extra
 *             PyList_Append(ordered, ms_node)
 *             node.extra = None             # <<<<<<<<<<<<<<
 *         # Clear out the scheduled nodes now that we're done
 *         self._scheduled_nodes = []
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_node->extra);
    __Pyx_DECREF(__pyx_v_node->extra);
    __pyx_v_node->extra = Py_None;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":954
 *             node.extra = None
 *         # Clear out the scheduled nodes now that we're done
 *         self._scheduled_nodes = []             # <<<<<<<<<<<<<<
 *         return ordered
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_scheduled_nodes);
  __Pyx_DECREF(__pyx_v_self->_scheduled_nodes);
  __pyx_v_self->_scheduled_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":955
 *         # Clear out the scheduled nodes now that we're done
 *         self._scheduled_nodes = []
 *         return ordered             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ordered);
  __pyx_r = __pyx_v_ordered;
  goto __pyx_L0;

  /* "bzrlib/_known_graph_pyx.pyx":926
 *                 break
 * 
 *     cdef topo_order(self):             # <<<<<<<<<<<<<<
 *         cdef _MergeSortNode ms_node
 *         cdef _KnownGraphNode node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._known_graph_pyx._MergeSorter.topo_order", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ms_node);
  __Pyx_XDECREF((PyObject *)__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_ordered);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__KnownGraphNode __pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  p->key = Py_None; Py_INCREF(Py_None);
  p->parents = Py_None; Py_INCREF(Py_None);
  p->children = Py_None; Py_INCREF(Py_None);
  p->extra = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->key);
  Py_CLEAR(p->parents);
  Py_CLEAR(p->children);
  Py_CLEAR(p->extra);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o;
  if (p->key) {
    e = (*v)(p->key, a); if (e) return e;
  }
  if (p->parents) {
    e = (*v)(p->parents, a); if (e) return e;
  }
  if (p->children) {
    e = (*v)(p->children, a); if (e) return e;
  }
  if (p->extra) {
    e = (*v)(p->extra, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx__KnownGraphNode(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)o;
  tmp = ((PyObject*)p->key);
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->parents);
  p->parents = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->children);
  p->children = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->extra);
  p->extra = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_child_keys(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_10child_keys_1__get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_parent_keys(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_11parent_keys_1__get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_4gdfo_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx__KnownGraphNode[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx__KnownGraphNode[] = {
  {(char *)"child_keys", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_child_keys, 0, 0, 0},
  {(char *)"parent_keys", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_parent_keys, 0, 0, 0},
  {(char *)"gdfo", __pyx_getprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo, __pyx_setprop_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_gdfo, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode = {
  PyVarObject_HEAD_INIT(0, 0)
  "bzrlib._known_graph_pyx._KnownGraphNode", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_3__repr__, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "Represents a single object in the known graph.", /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx__KnownGraphNode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSorter __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSorter(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter;
  p->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)Py_None); Py_INCREF(Py_None);
  p->_depth_first_stack = Py_None; Py_INCREF(Py_None);
  p->_revno_to_branch_count = Py_None; Py_INCREF(Py_None);
  p->_scheduled_nodes = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSorter(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->graph);
  Py_CLEAR(p->_depth_first_stack);
  Py_CLEAR(p->_revno_to_branch_count);
  Py_CLEAR(p->_scheduled_nodes);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSorter(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o;
  if (p->graph) {
    e = (*v)(((PyObject*)p->graph), a); if (e) return e;
  }
  if (p->_depth_first_stack) {
    e = (*v)(p->_depth_first_stack, a); if (e) return e;
  }
  if (p->_revno_to_branch_count) {
    e = (*v)(p->_revno_to_branch_count, a); if (e) return e;
  }
  if (p->_scheduled_nodes) {
    e = (*v)(p->_scheduled_nodes, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSorter(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *)o;
  tmp = ((PyObject*)p->graph);
  p->graph = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_depth_first_stack);
  p->_depth_first_stack = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_revno_to_branch_count);
  p->_revno_to_branch_count = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_scheduled_nodes);
  p->_scheduled_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSorter[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter = {
  PyVarObject_HEAD_INIT(0, 0)
  "bzrlib._known_graph_pyx._MergeSorter", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "This class does the work of computing the merge_sort ordering.\n\n    We have some small advantages, in that we get all the extra information\n    that KnownGraph knows, like knowing the child lists, etc.\n    ", /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6bzrlib_16_known_graph_pyx_12_MergeSorter_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSorter, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx_KnownGraph __pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx_KnownGraph(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph;
  p->_nodes = Py_None; Py_INCREF(Py_None);
  p->_known_heads = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx_KnownGraph(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_nodes);
  Py_CLEAR(p->_known_heads);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx_KnownGraph(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o;
  if (p->_nodes) {
    e = (*v)(p->_nodes, a); if (e) return e;
  }
  if (p->_known_heads) {
    e = (*v)(p->_known_heads, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx_KnownGraph(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *)o;
  tmp = ((PyObject*)p->_nodes);
  p->_nodes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->_known_heads);
  p->_known_heads = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_3__set__(o, v);
  }
  else {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_6_nodes_5__del__(o);
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_3__set__(o, v);
  }
  else {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_12_known_heads_5__del__(o);
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_8do_cache_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx_KnownGraph[] = {
  {"_initialize_nodes", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_5_initialize_nodes, METH_O, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_4_initialize_nodes},
  {"_find_tails", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_7_find_tails, METH_NOARGS, 0},
  {"_find_tips", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_9_find_tips, METH_NOARGS, 0},
  {"_find_gdfo", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_11_find_gdfo, METH_NOARGS, 0},
  {"add_node", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_13add_node, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_12add_node},
  {"heads", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_15heads, METH_O, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_14heads},
  {"topo_sort", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_17topo_sort, METH_NOARGS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_16topo_sort},
  {"gc_sort", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_19gc_sort, METH_NOARGS, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_18gc_sort},
  {"merge_sort", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_21merge_sort, METH_O, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_20merge_sort},
  {"get_parent_keys", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_23get_parent_keys, METH_O, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_22get_parent_keys},
  {"get_child_keys", (PyCFunction)__pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_25get_child_keys, METH_O, __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph_24get_child_keys},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx_KnownGraph[] = {
  {(char *)"_nodes", __pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes, __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__nodes, 0, 0},
  {(char *)"_known_heads", __pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads, __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph__known_heads, 0, 0},
  {(char *)"do_cache", __pyx_getprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache, __pyx_setprop_6bzrlib_16_known_graph_pyx_10KnownGraph_do_cache, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph = {
  PyVarObject_HEAD_INIT(0, 0)
  "bzrlib._known_graph_pyx.KnownGraph", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "This is a class which assumes we already know the full graph.", /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6bzrlib_16_known_graph_pyx_10KnownGraph_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx_KnownGraph, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_6bzrlib_16_known_graph_pyx__MergeSortNode __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode;

static PyObject *__pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSortNode(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode;
  p->key = Py_None; Py_INCREF(Py_None);
  p->end_of_merge = Py_None; Py_INCREF(Py_None);
  p->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  p->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  p->pending_parents = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSortNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->key);
  Py_CLEAR(p->end_of_merge);
  Py_CLEAR(p->left_parent);
  Py_CLEAR(p->left_pending_parent);
  Py_CLEAR(p->pending_parents);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSortNode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o;
  if (p->key) {
    e = (*v)(p->key, a); if (e) return e;
  }
  if (p->end_of_merge) {
    e = (*v)(p->end_of_merge, a); if (e) return e;
  }
  if (p->left_parent) {
    e = (*v)(((PyObject*)p->left_parent), a); if (e) return e;
  }
  if (p->left_pending_parent) {
    e = (*v)(((PyObject*)p->left_pending_parent), a); if (e) return e;
  }
  if (p->pending_parents) {
    e = (*v)(p->pending_parents, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSortNode(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *p = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *)o;
  tmp = ((PyObject*)p->key);
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->end_of_merge);
  p->end_of_merge = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->left_parent);
  p->left_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->left_pending_parent);
  p->left_pending_parent = ((struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->pending_parents);
  p->pending_parents = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_revno(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_5revno_1__get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_3__set__(o, v);
  }
  else {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3key_5__del__(o);
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_11merge_depth_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_1__get__(o);
}

static int __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_3__set__(o, v);
  }
  else {
    return __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_12end_of_merge_5__del__(o);
  }
}

static PyMethodDef __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSortNode[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_16_known_graph_pyx__MergeSortNode[] = {
  {(char *)"revno", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_revno, 0, 0, 0},
  {(char *)"key", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key, __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_key, 0, 0},
  {(char *)"merge_depth", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth, __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_merge_depth, 0, 0},
  {(char *)"end_of_merge", __pyx_getprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge, __pyx_setprop_6bzrlib_16_known_graph_pyx_14_MergeSortNode_end_of_merge, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode = {
  PyVarObject_HEAD_INIT(0, 0)
  "bzrlib._known_graph_pyx._MergeSortNode", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_3__repr__, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "Tracks information about a node during the merge_sort operation.", /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_6bzrlib_16_known_graph_pyx_14_MergeSortNode_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_16_known_graph_pyx__MergeSortNode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "_known_graph_pyx",
    __pyx_k_Implementation_of_Graph_algorith, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_GraphCycleError, __pyx_k_GraphCycleError, sizeof(__pyx_k_GraphCycleError), 0, 0, 1, 1},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_n_s_NULL_REVISION, __pyx_k_NULL_REVISION, sizeof(__pyx_k_NULL_REVISION), 0, 0, 1, 1},
  {&__pyx_kp_s_Parent_key_mismatch_existing_nod, __pyx_k_Parent_key_mismatch_existing_nod, sizeof(__pyx_k_Parent_key_mismatch_existing_nod), 0, 0, 1, 0},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_kp_s_Something_wrong_with_s, __pyx_k_Something_wrong_with_s, sizeof(__pyx_k_Something_wrong_with_s), 0, 0, 1, 0},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_bzrlib, __pyx_k_bzrlib, sizeof(__pyx_k_bzrlib), 0, 0, 1, 1},
  {&__pyx_n_s_bzrlib__known_graph_pyx, __pyx_k_bzrlib__known_graph_pyx, sizeof(__pyx_k_bzrlib__known_graph_pyx), 0, 0, 1, 1},
  {&__pyx_n_s_child_keys, __pyx_k_child_keys, sizeof(__pyx_k_child_keys), 0, 0, 1, 1},
  {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
  {&__pyx_n_s_clear, __pyx_k_clear, sizeof(__pyx_k_clear), 0, 0, 1, 1},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_deque, __pyx_k_deque, sizeof(__pyx_k_deque), 0, 0, 1, 1},
  {&__pyx_n_s_do_cache, __pyx_k_do_cache, sizeof(__pyx_k_do_cache), 0, 0, 1, 1},
  {&__pyx_n_s_errors, __pyx_k_errors, sizeof(__pyx_k_errors), 0, 0, 1, 1},
  {&__pyx_n_s_find_gdfo, __pyx_k_find_gdfo, sizeof(__pyx_k_find_gdfo), 0, 0, 1, 1},
  {&__pyx_n_s_find_tails, __pyx_k_find_tails, sizeof(__pyx_k_find_tails), 0, 0, 1, 1},
  {&__pyx_n_s_find_tips, __pyx_k_find_tips, sizeof(__pyx_k_find_tips), 0, 0, 1, 1},
  {&__pyx_n_s_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 0, 1, 1},
  {&__pyx_n_s_get_key, __pyx_k_get_key, sizeof(__pyx_k_get_key), 0, 0, 1, 1},
  {&__pyx_kp_s_ghost_nodes_should_not_be_pushed, __pyx_k_ghost_nodes_should_not_be_pushed, sizeof(__pyx_k_ghost_nodes_should_not_be_pushed), 0, 0, 1, 0},
  {&__pyx_kp_s_home_vila_src_bzr_integration_2, __pyx_k_home_vila_src_bzr_integration_2, sizeof(__pyx_k_home_vila_src_bzr_integration_2), 0, 0, 1, 0},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_initialize_nodes, __pyx_k_initialize_nodes, sizeof(__pyx_k_initialize_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  {&__pyx_kp_s_key_s_not_in_nodes, __pyx_k_key_s_not_in_nodes, sizeof(__pyx_k_key_s_not_in_nodes), 0, 0, 1, 0},
  {&__pyx_n_s_known_graph, __pyx_k_known_graph, sizeof(__pyx_k_known_graph), 0, 0, 1, 1},
  {&__pyx_kp_s_lst_or_tpl_must_be_a_list_or_tup, __pyx_k_lst_or_tpl_must_be_a_list_or_tup, sizeof(__pyx_k_lst_or_tpl_must_be_a_list_or_tup), 0, 0, 1, 0},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_node, __pyx_k_node, sizeof(__pyx_k_node), 0, 0, 1, 1},
  {&__pyx_n_s_parent_keys, __pyx_k_parent_keys, sizeof(__pyx_k_parent_keys), 0, 0, 1, 1},
  {&__pyx_n_s_parent_map, __pyx_k_parent_map, sizeof(__pyx_k_parent_map), 0, 0, 1, 1},
  {&__pyx_kp_s_parent_map_should_be_a_dict_of_k, __pyx_k_parent_map_should_be_a_dict_of_k, sizeof(__pyx_k_parent_map_should_be_a_dict_of_k), 0, 0, 1, 0},
  {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
  {&__pyx_n_s_popleft, __pyx_k_popleft, sizeof(__pyx_k_popleft), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_real_node, __pyx_k_real_node, sizeof(__pyx_k_real_node), 0, 0, 1, 1},
  {&__pyx_n_s_reverse, __pyx_k_reverse, sizeof(__pyx_k_reverse), 0, 0, 1, 1},
  {&__pyx_n_s_revision, __pyx_k_revision, sizeof(__pyx_k_revision), 0, 0, 1, 1},
  {&__pyx_kp_s_s_s_depth_s_rev_s_s_s_first_s_s, __pyx_k_s_s_depth_s_rev_s_s_s_first_s_s, sizeof(__pyx_k_s_s_depth_s_rev_s_s_s_first_s_s), 0, 0, 1, 0},
  {&__pyx_kp_s_s_s_gdfo_s_par_s_child_s, __pyx_k_s_s_gdfo_s_par_s_child_s, sizeof(__pyx_k_s_s_gdfo_s_par_s_child_s), 0, 0, 1, 0},
  {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_tip_key, __pyx_k_tip_key, sizeof(__pyx_k_tip_key), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "bzrlib/_known_graph_pyx.pyx":156
 *     is_tuple = PyTuple_CheckExact(lst_or_tpl)
 *     if not (is_tuple or PyList_CheckExact(lst_or_tpl)):
 *         raise TypeError('lst_or_tpl must be a list or tuple.')             # <<<<<<<<<<<<<<
 *     length = len(lst_or_tpl)
 *     if length == 0 or length == 1:
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_lst_or_tpl_must_be_a_list_or_tup); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "bzrlib/_known_graph_pyx.pyx":273
 * 
 *         if not PyDict_CheckExact(parent_map):
 *             raise TypeError('parent_map should be a dict of {key:parent_keys}')             # <<<<<<<<<<<<<<
 *         # for key, parent_keys in parent_map.iteritems():
 *         pos = 0
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_parent_map_should_be_a_dict_of_k); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "bzrlib/_known_graph_pyx.pyx":138
 * 
 * 
 * def get_key(node):             # <<<<<<<<<<<<<<
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 */
  __pyx_tuple__4 = PyTuple_Pack(2, __pyx_n_s_node, __pyx_n_s_real_node); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);
  __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_vila_src_bzr_integration_2, __pyx_n_s_get_key, 138, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyList_Type_pop.type = (PyObject*)&PyList_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_known_graph_pyx(void); /*proto*/
PyMODINIT_FUNC init_known_graph_pyx(void)
#else
PyMODINIT_FUNC PyInit__known_graph_pyx(void); /*proto*/
PyMODINIT_FUNC PyInit__known_graph_pyx(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__known_graph_pyx(void)", 0);
  if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("_known_graph_pyx", __pyx_methods, __pyx_k_Implementation_of_Graph_algorith, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_bzrlib___known_graph_pyx) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "bzrlib._known_graph_pyx")) {
      if (unlikely(PyDict_SetItemString(modules, "bzrlib._known_graph_pyx", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION = Py_None; Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode = &__pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__KnownGraphNode.clear_references = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *))__pyx_f_6bzrlib_16_known_graph_pyx_15_KnownGraphNode_clear_references;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_KnownGraphNode", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__KnownGraphNode = &__pyx_type_6bzrlib_16_known_graph_pyx__KnownGraphNode;
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter = &__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._get_ms_node = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__get_ms_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._push_node = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, long))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__push_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._pop_node = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__pop_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter._schedule_stack = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter__schedule_stack;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSorter.topo_order = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSorter *))__pyx_f_6bzrlib_16_known_graph_pyx_12_MergeSorter_topo_order;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_MergeSorter", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSorter = &__pyx_type_6bzrlib_16_known_graph_pyx__MergeSorter;
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph = &__pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph;
  __pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph._get_or_create_node = (struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, PyObject *))__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__get_or_create_node;
  __pyx_vtable_6bzrlib_16_known_graph_pyx_KnownGraph._populate_parents = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx_KnownGraph *, struct __pyx_obj_6bzrlib_16_known_graph_pyx__KnownGraphNode *, PyObject *))__pyx_f_6bzrlib_16_known_graph_pyx_10KnownGraph__populate_parents;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph, "__init__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__.doc = __pyx_doc_6bzrlib_16_known_graph_pyx_10KnownGraph___init__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_6bzrlib_16_known_graph_pyx_10KnownGraph___init__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "KnownGraph", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx_KnownGraph = &__pyx_type_6bzrlib_16_known_graph_pyx_KnownGraph;
  __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode = &__pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode.has_pending_parents = (int (*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *))__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode_has_pending_parents;
  __pyx_vtable_6bzrlib_16_known_graph_pyx__MergeSortNode._revno = (PyObject *(*)(struct __pyx_obj_6bzrlib_16_known_graph_pyx__MergeSortNode *))__pyx_f_6bzrlib_16_known_graph_pyx_14_MergeSortNode__revno;
  if (PyType_Ready(&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode.tp_dict, __pyx_vtabptr_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "_MergeSortNode", (PyObject *)&__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_16_known_graph_pyx__MergeSortNode = &__pyx_type_6bzrlib_16_known_graph_pyx__MergeSortNode;
  /*--- Type import code ---*/
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif

  /* "bzrlib/_known_graph_pyx.pyx":54
 *     void Py_INCREF(object)
 * 
 * from collections import deque             # <<<<<<<<<<<<<<
 * import gc
 * 
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_deque);
  __Pyx_GIVEREF(__pyx_n_s_deque);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_deque);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_deque); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_deque, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":55
 * 
 * from collections import deque
 * import gc             # <<<<<<<<<<<<<<
 * 
 * from bzrlib import errors, revision
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_gc, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":57
 * import gc
 * 
 * from bzrlib import errors, revision             # <<<<<<<<<<<<<<
 * 
 * cdef object NULL_REVISION
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_errors);
  __Pyx_GIVEREF(__pyx_n_s_errors);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_errors);
  __Pyx_INCREF(__pyx_n_s_revision);
  __Pyx_GIVEREF(__pyx_n_s_revision);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_revision);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_bzrlib, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_errors); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_errors, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_revision); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_revision, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":60
 * 
 * cdef object NULL_REVISION
 * NULL_REVISION = revision.NULL_REVISION             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_revision); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_NULL_REVISION); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_XGOTREF(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION);
  __Pyx_DECREF_SET(__pyx_v_6bzrlib_16_known_graph_pyx_NULL_REVISION, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":138
 * 
 * 
 * def get_key(node):             # <<<<<<<<<<<<<<
 *     cdef _KnownGraphNode real_node
 *     real_node = node
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_16_known_graph_pyx_1get_key, NULL, __pyx_n_s_bzrlib__known_graph_pyx); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_key, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_known_graph_pyx.pyx":1
 * # Copyright (C) 2009, 2010 Canonical Ltd             # <<<<<<<<<<<<<<
 * #
 * # This program is free software; you can redistribute it and/or modify
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init bzrlib._known_graph_pyx", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init bzrlib._known_graph_pyx");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject* args = PyTuple_Pack(1, arg);
    return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#endif
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            args = PyTuple_New(2);
            if (unlikely(!args)) goto bad;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
bad:
    Py_XDECREF(method);
    return result;
}

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *function = PyMethod_GET_FUNCTION(method);
            result = __Pyx_PyObject_CallOneArg(function, self);
            Py_DECREF(method);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(PyObject_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_O | METH_NOARGS);
    }
#endif
    return 0;
}

static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (Py_TYPE(L) == &PySet_Type) {
        return PySet_Pop(L);
    }
#endif
    return __Pyx_PyObject_CallMethod0(L, __pyx_n_s_pop);
}
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
    if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
        Py_SIZE(L) -= 1;
        return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
    }
    return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyList_Type_pop, L);
}
#endif

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
