/* Generated by Cython 0.14.1 on Mon Jan 16 15:59:25 2012 */

#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.
#else

#include <stddef.h> /* For offsetof */
#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

#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif

#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#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_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#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
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#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

#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif

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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE_API__bzrlib___groupcompress_pyx
#include "python-compat.h"
#include "delta.h"

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif


/* inline attribute */
#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

/* unused attribute */
#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)
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), 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);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
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[] = {
  "_groupcompress_pyx.pyx",
};

/* Type declarations */

/* "bzrlib/_groupcompress_pyx.pyx":130
 * 
 * 
 * cdef class DeltaIndex:             # <<<<<<<<<<<<<<
 * 
 *     # We need Pyrex 0.9.8+ to understand a 'list' definition, and this object
 */

struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_vtab;
  PyObject *_sources;
  struct source_info *_source_infos;
  struct delta_index *_index;
  unsigned long _source_offset;
  unsigned int _max_num_sources;
  int _max_bytes_to_index;
};


struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex {
  PyObject *(*_populate_first_index)(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *);
  PyObject *(*_expand_sources)(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *);
};
static struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex;

#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) {
    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;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #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_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #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_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

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

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

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

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

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); /*proto*/

static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (PyList_Append(L, x) < 0) return NULL;
        Py_INCREF(Py_None);
        return Py_None; /* this is just to have an accurate signature */
    }
    else {
        PyObject *r, *m;
        m = __Pyx_GetAttrString(L, "append");
        if (!m) return NULL;
        r = PyObject_CallFunctionObjArgs(m, x, NULL);
        Py_DECREF(m);
        return r;
    }
}

#ifndef __PYX_FORCE_INIT_THREADS
  #if PY_VERSION_HEX < 0x02040200
    #define __PYX_FORCE_INIT_THREADS 1
  #else
    #define __PYX_FORCE_INIT_THREADS 0
  #endif
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

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

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from bzrlib._groupcompress_pyx */

static PyTypeObject *__pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex = 0;
static void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_malloc(size_t); /*proto*/
static void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_realloc(void *, size_t); /*proto*/
static int __pyx_f_6bzrlib_18_groupcompress_pyx_safe_free(void **); /*proto*/
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx__translate_delta_failure(delta_result); /*proto*/
static unsigned char *__pyx_f_6bzrlib_18_groupcompress_pyx__decode_copy_instruction(unsigned char *, unsigned char, unsigned int *, unsigned int *); /*proto*/
static PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(char *, Py_ssize_t, char *, Py_ssize_t); /*proto*/
#define __Pyx_MODULE_NAME "bzrlib._groupcompress_pyx"
static int __pyx_module_is_main_bzrlib___groupcompress_pyx = 0;

/* Implementation of bzrlib._groupcompress_pyx */
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_AssertionError;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_TypeError;
static char __pyx_k_1[] = "Failed to allocate %d bytes of memory";
static char __pyx_k_2[] = "Failed to reallocate to %d bytes of memory";
static char __pyx_k_3[] = "Delta function failed to allocate memory";
static char __pyx_k_5[] = "Delta function requires delta_index param";
static char __pyx_k_7[] = "Delta function given empty source_info param";
static char __pyx_k_9[] = "Delta function given invalid source_info param";
static char __pyx_k_11[] = "Delta function given empty buffer params";
static char __pyx_k_13[] = "Unrecognised delta result code: %d";
static char __pyx_k_14[] = "content must be a string";
static char __pyx_k_16[] = "content must be at least 16 bytes long";
static char __pyx_k_18[] = "%s(%d, %d)";
static char __pyx_k_19[] = "delta is not a str";
static char __pyx_k_21[] = "source is not a str";
static char __pyx_k_23[] = "_populate_first_index";
static char __pyx_k_24[] = "_populate_first_index should only be called when we have a single source and no index yet";
static char __pyx_k_26[] = "if we move self._source_infos, then we need to change all of the index pointers as well.";
static char __pyx_k_28[] = "target is not a str";
static char __pyx_k_32[] = "delta_size %d smaller than min delta size %d";
static char __pyx_k_33[] = "Something wrong with: cp_off = %s, cp_size = %s source_size = %s, size = %s";
static char __pyx_k_34[] = "Got delta opcode: 0, not supported";
static char __pyx_k_36[] = "Insert instruction longer than remaining bytes: %d > %d";
static char __pyx_k_37[] = "Did not extract the number of bytes we expected we were left with %d bytes in \"size\", and top - data = %d";
static char __pyx_k_38[] = "Number of bytes extracted did not match the size encoded in the delta header.";
static char __pyx_k_41[] = "delta starts after source";
static char __pyx_k_43[] = "delta ends after source";
static char __pyx_k_45[] = "delta starts after it ends";
static char __pyx_k_47[] = "encode_base128_int overflowed the buffer";
static char __pyx_k_49[] = "bytes is not a string";
static char __pyx_k_51[] = "Data not properly formatted, we ran out of bytes before 0x80 stopped being set.";
static char __pyx_k_53[] = "Compiled extensions for doing compression.";
static char __pyx_k_54[] = "bzrlib._groupcompress_pyx";
static char __pyx_k_55[] = "apply_delta_to_source";
static char __pyx_k__buf[] = "buf";
static char __pyx_k__map[] = "map";
static char __pyx_k__size[] = "size";
static char __pyx_k__delta[] = "delta";
static char __pyx_k___index[] = "_index";
static char __pyx_k__append[] = "append";
static char __pyx_k__source[] = "source";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____name__[] = "__name__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k___sources[] = "_sources";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k____class__[] = "__class__";
static char __pyx_k__delta_end[] = "delta_end";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k__add_source[] = "add_source";
static char __pyx_k__agg_offset[] = "agg_offset";
static char __pyx_k__make_delta[] = "make_delta";
static char __pyx_k__MemoryError[] = "MemoryError";
static char __pyx_k___rabin_hash[] = "_rabin_hash";
static char __pyx_k__apply_delta[] = "apply_delta";
static char __pyx_k__delta_bytes[] = "delta_bytes";
static char __pyx_k__delta_start[] = "delta_start";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__source_bytes[] = "source_bytes";
static char __pyx_k__target_bytes[] = "target_bytes";
static char __pyx_k___source_infos[] = "_source_infos";
static char __pyx_k__unadded_bytes[] = "unadded_bytes";
static char __pyx_k__AssertionError[] = "AssertionError";
static char __pyx_k___source_offset[] = "_source_offset";
static char __pyx_k__max_delta_size[] = "max_delta_size";
static char __pyx_k___expand_sources[] = "_expand_sources";
static char __pyx_k___max_num_sources[] = "_max_num_sources";
static char __pyx_k__make_delta_index[] = "make_delta_index";
static char __pyx_k__decode_base128_int[] = "decode_base128_int";
static char __pyx_k__encode_base128_int[] = "encode_base128_int";
static char __pyx_k__max_bytes_to_index[] = "max_bytes_to_index";
static char __pyx_k___max_bytes_to_index[] = "_max_bytes_to_index";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_14;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_21;
static PyObject *__pyx_n_s_23;
static PyObject *__pyx_kp_s_24;
static PyObject *__pyx_kp_s_26;
static PyObject *__pyx_kp_s_28;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_32;
static PyObject *__pyx_kp_s_33;
static PyObject *__pyx_kp_s_34;
static PyObject *__pyx_kp_s_36;
static PyObject *__pyx_kp_s_37;
static PyObject *__pyx_kp_s_38;
static PyObject *__pyx_kp_s_41;
static PyObject *__pyx_kp_s_43;
static PyObject *__pyx_kp_s_45;
static PyObject *__pyx_kp_s_47;
static PyObject *__pyx_kp_s_49;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_51;
static PyObject *__pyx_n_s_54;
static PyObject *__pyx_n_s_55;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__AssertionError;
static PyObject *__pyx_n_s__MemoryError;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____class__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____name__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___expand_sources;
static PyObject *__pyx_n_s___index;
static PyObject *__pyx_n_s___max_bytes_to_index;
static PyObject *__pyx_n_s___max_num_sources;
static PyObject *__pyx_n_s___rabin_hash;
static PyObject *__pyx_n_s___source_infos;
static PyObject *__pyx_n_s___source_offset;
static PyObject *__pyx_n_s___sources;
static PyObject *__pyx_n_s__add_source;
static PyObject *__pyx_n_s__agg_offset;
static PyObject *__pyx_n_s__append;
static PyObject *__pyx_n_s__apply_delta;
static PyObject *__pyx_n_s__buf;
static PyObject *__pyx_n_s__decode_base128_int;
static PyObject *__pyx_n_s__delta;
static PyObject *__pyx_n_s__delta_bytes;
static PyObject *__pyx_n_s__delta_end;
static PyObject *__pyx_n_s__delta_start;
static PyObject *__pyx_n_s__encode_base128_int;
static PyObject *__pyx_n_s__make_delta;
static PyObject *__pyx_n_s__make_delta_index;
static PyObject *__pyx_n_s__map;
static PyObject *__pyx_n_s__max_bytes_to_index;
static PyObject *__pyx_n_s__max_delta_size;
static PyObject *__pyx_n_s__size;
static PyObject *__pyx_n_s__source;
static PyObject *__pyx_n_s__source_bytes;
static PyObject *__pyx_n_s__target_bytes;
static PyObject *__pyx_n_s__unadded_bytes;
static PyObject *__pyx_int_0;
static PyObject *__pyx_k_tuple_4;
static PyObject *__pyx_k_tuple_6;
static PyObject *__pyx_k_tuple_8;
static PyObject *__pyx_k_tuple_10;
static PyObject *__pyx_k_tuple_12;
static PyObject *__pyx_k_tuple_15;
static PyObject *__pyx_k_tuple_17;
static PyObject *__pyx_k_tuple_20;
static PyObject *__pyx_k_tuple_22;
static PyObject *__pyx_k_tuple_25;
static PyObject *__pyx_k_tuple_27;
static PyObject *__pyx_k_tuple_29;
static PyObject *__pyx_k_tuple_30;
static PyObject *__pyx_k_tuple_31;
static PyObject *__pyx_k_tuple_35;
static PyObject *__pyx_k_tuple_39;
static PyObject *__pyx_k_tuple_40;
static PyObject *__pyx_k_tuple_42;
static PyObject *__pyx_k_tuple_44;
static PyObject *__pyx_k_tuple_46;
static PyObject *__pyx_k_tuple_48;
static PyObject *__pyx_k_tuple_50;
static PyObject *__pyx_k_tuple_52;

/* "bzrlib/_groupcompress_pyx.pyx":80
 * 
 * 
 * cdef void *safe_malloc(size_t count) except NULL:             # <<<<<<<<<<<<<<
 *     cdef void *result
 *     result = malloc(count)
 */

static  void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_malloc(size_t __pyx_v_count) {
  void *__pyx_v_result;
  void *__pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("safe_malloc");

  /* "bzrlib/_groupcompress_pyx.pyx":82
 * cdef void *safe_malloc(size_t count) except NULL:
 *     cdef void *result
 *     result = malloc(count)             # <<<<<<<<<<<<<<
 *     if result == NULL:
 *         raise MemoryError('Failed to allocate %d bytes of memory' % (count,))
 */
  __pyx_v_result = malloc(__pyx_v_count);

  /* "bzrlib/_groupcompress_pyx.pyx":83
 *     cdef void *result
 *     result = malloc(count)
 *     if result == NULL:             # <<<<<<<<<<<<<<
 *         raise MemoryError('Failed to allocate %d bytes of memory' % (count,))
 *     return result
 */
  __pyx_t_1 = (__pyx_v_result == NULL);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":84
 *     result = malloc(count)
 *     if result == NULL:
 *         raise MemoryError('Failed to allocate %d bytes of memory' % (count,))             # <<<<<<<<<<<<<<
 *     return result
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_groupcompress_pyx.pyx":85
 *     if result == NULL:
 *         raise MemoryError('Failed to allocate %d bytes of memory' % (count,))
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.safe_malloc");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":88
 * 
 * 
 * cdef void *safe_realloc(void * old, size_t count) except NULL:             # <<<<<<<<<<<<<<
 *     cdef void *result
 *     result = realloc(old, count)
 */

static  void *__pyx_f_6bzrlib_18_groupcompress_pyx_safe_realloc(void *__pyx_v_old, size_t __pyx_v_count) {
  void *__pyx_v_result;
  void *__pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("safe_realloc");

  /* "bzrlib/_groupcompress_pyx.pyx":90
 * cdef void *safe_realloc(void * old, size_t count) except NULL:
 *     cdef void *result
 *     result = realloc(old, count)             # <<<<<<<<<<<<<<
 *     if result == NULL:
 *         raise MemoryError('Failed to reallocate to %d bytes of memory'
 */
  __pyx_v_result = realloc(__pyx_v_old, __pyx_v_count);

  /* "bzrlib/_groupcompress_pyx.pyx":91
 *     cdef void *result
 *     result = realloc(old, count)
 *     if result == NULL:             # <<<<<<<<<<<<<<
 *         raise MemoryError('Failed to reallocate to %d bytes of memory'
 *                           % (count,))
 */
  __pyx_t_1 = (__pyx_v_result == NULL);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":93
 *     if result == NULL:
 *         raise MemoryError('Failed to reallocate to %d bytes of memory'
 *                           % (count,))             # <<<<<<<<<<<<<<
 *     return result
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_groupcompress_pyx.pyx":94
 *         raise MemoryError('Failed to reallocate to %d bytes of memory'
 *                           % (count,))
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.safe_realloc");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":97
 * 
 * 
 * cdef int safe_free(void **val) except -1:             # <<<<<<<<<<<<<<
 *     assert val != NULL
 *     if val[0] != NULL:
 */

static  int __pyx_f_6bzrlib_18_groupcompress_pyx_safe_free(void **__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("safe_free");

  /* "bzrlib/_groupcompress_pyx.pyx":98
 * 
 * cdef int safe_free(void **val) except -1:
 *     assert val != NULL             # <<<<<<<<<<<<<<
 *     if val[0] != NULL:
 *         free(val[0])
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_val != NULL))) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "bzrlib/_groupcompress_pyx.pyx":99
 * cdef int safe_free(void **val) except -1:
 *     assert val != NULL
 *     if val[0] != NULL:             # <<<<<<<<<<<<<<
 *         free(val[0])
 *         val[0] = NULL
 */
  __pyx_t_1 = ((__pyx_v_val[0]) != NULL);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":100
 *     assert val != NULL
 *     if val[0] != NULL:
 *         free(val[0])             # <<<<<<<<<<<<<<
 *         val[0] = NULL
 * 
 */
    free((__pyx_v_val[0]));

    /* "bzrlib/_groupcompress_pyx.pyx":101
 *     if val[0] != NULL:
 *         free(val[0])
 *         val[0] = NULL             # <<<<<<<<<<<<<<
 * 
 * def make_delta_index(source):
 */
    (__pyx_v_val[0]) = NULL;
    goto __pyx_L3;
  }
  __pyx_L3:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.safe_free");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":103
 *         val[0] = NULL
 * 
 * def make_delta_index(source):             # <<<<<<<<<<<<<<
 *     return DeltaIndex(source)
 * 
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_make_delta_index(PyObject *__pyx_self, PyObject *__pyx_v_source); /*proto*/
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_make_delta_index = {__Pyx_NAMESTR("make_delta_index"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_make_delta_index, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_make_delta_index(PyObject *__pyx_self, PyObject *__pyx_v_source) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("make_delta_index");
  __pyx_self = __pyx_self;

  /* "bzrlib/_groupcompress_pyx.pyx":104
 * 
 * def make_delta_index(source):
 *     return DeltaIndex(source)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_source);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_source);
  __Pyx_GIVEREF(__pyx_v_source);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __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_AddTraceback("bzrlib._groupcompress_pyx.make_delta_index");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":107
 * 
 * 
 * cdef object _translate_delta_failure(delta_result result):             # <<<<<<<<<<<<<<
 *     if result == DELTA_OUT_OF_MEMORY:
 *         return MemoryError("Delta function failed to allocate memory")
 */

static  PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx__translate_delta_failure(delta_result __pyx_v_result) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("_translate_delta_failure");

  /* "bzrlib/_groupcompress_pyx.pyx":108
 * 
 * cdef object _translate_delta_failure(delta_result result):
 *     if result == DELTA_OUT_OF_MEMORY:             # <<<<<<<<<<<<<<
 *         return MemoryError("Delta function failed to allocate memory")
 *     elif result == DELTA_INDEX_NEEDED:
 */
  __pyx_t_1 = (__pyx_v_result == DELTA_OUT_OF_MEMORY);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":109
 * cdef object _translate_delta_failure(delta_result result):
 *     if result == DELTA_OUT_OF_MEMORY:
 *         return MemoryError("Delta function failed to allocate memory")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_INDEX_NEEDED:
 *         return ValueError("Delta function requires delta_index param")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "bzrlib/_groupcompress_pyx.pyx":110
 *     if result == DELTA_OUT_OF_MEMORY:
 *         return MemoryError("Delta function failed to allocate memory")
 *     elif result == DELTA_INDEX_NEEDED:             # <<<<<<<<<<<<<<
 *         return ValueError("Delta function requires delta_index param")
 *     elif result == DELTA_SOURCE_EMPTY:
 */
  __pyx_t_1 = (__pyx_v_result == DELTA_INDEX_NEEDED);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":111
 *         return MemoryError("Delta function failed to allocate memory")
 *     elif result == DELTA_INDEX_NEEDED:
 *         return ValueError("Delta function requires delta_index param")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_SOURCE_EMPTY:
 *         return ValueError("Delta function given empty source_info param")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "bzrlib/_groupcompress_pyx.pyx":112
 *     elif result == DELTA_INDEX_NEEDED:
 *         return ValueError("Delta function requires delta_index param")
 *     elif result == DELTA_SOURCE_EMPTY:             # <<<<<<<<<<<<<<
 *         return ValueError("Delta function given empty source_info param")
 *     elif result == DELTA_SOURCE_BAD:
 */
  __pyx_t_1 = (__pyx_v_result == DELTA_SOURCE_EMPTY);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":113
 *         return ValueError("Delta function requires delta_index param")
 *     elif result == DELTA_SOURCE_EMPTY:
 *         return ValueError("Delta function given empty source_info param")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_SOURCE_BAD:
 *         return RuntimeError("Delta function given invalid source_info param")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "bzrlib/_groupcompress_pyx.pyx":114
 *     elif result == DELTA_SOURCE_EMPTY:
 *         return ValueError("Delta function given empty source_info param")
 *     elif result == DELTA_SOURCE_BAD:             # <<<<<<<<<<<<<<
 *         return RuntimeError("Delta function given invalid source_info param")
 *     elif result == DELTA_BUFFER_EMPTY:
 */
  __pyx_t_1 = (__pyx_v_result == DELTA_SOURCE_BAD);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":115
 *         return ValueError("Delta function given empty source_info param")
 *     elif result == DELTA_SOURCE_BAD:
 *         return RuntimeError("Delta function given invalid source_info param")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_BUFFER_EMPTY:
 *         return ValueError("Delta function given empty buffer params")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }

  /* "bzrlib/_groupcompress_pyx.pyx":116
 *     elif result == DELTA_SOURCE_BAD:
 *         return RuntimeError("Delta function given invalid source_info param")
 *     elif result == DELTA_BUFFER_EMPTY:             # <<<<<<<<<<<<<<
 *         return ValueError("Delta function given empty buffer params")
 *     return AssertionError("Unrecognised delta result code: %d" % result)
 */
  __pyx_t_1 = (__pyx_v_result == DELTA_BUFFER_EMPTY);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":117
 *         return RuntimeError("Delta function given invalid source_info param")
 *     elif result == DELTA_BUFFER_EMPTY:
 *         return ValueError("Delta function given empty buffer params")             # <<<<<<<<<<<<<<
 *     return AssertionError("Unrecognised delta result code: %d" % result)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_groupcompress_pyx.pyx":118
 *     elif result == DELTA_BUFFER_EMPTY:
 *         return ValueError("Delta function given empty buffer params")
 *     return AssertionError("Unrecognised delta result code: %d" % result)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_result); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__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 = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __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._groupcompress_pyx._translate_delta_failure");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":121
 * 
 * 
 * def _rabin_hash(content):             # <<<<<<<<<<<<<<
 *     if not PyString_CheckExact(content):
 *         raise ValueError('content must be a string')
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_1_rabin_hash(PyObject *__pyx_self, PyObject *__pyx_v_content); /*proto*/
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_1_rabin_hash = {__Pyx_NAMESTR("_rabin_hash"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_1_rabin_hash, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_1_rabin_hash(PyObject *__pyx_self, PyObject *__pyx_v_content) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("_rabin_hash");
  __pyx_self = __pyx_self;

  /* "bzrlib/_groupcompress_pyx.pyx":122
 * 
 * def _rabin_hash(content):
 *     if not PyString_CheckExact(content):             # <<<<<<<<<<<<<<
 *         raise ValueError('content must be a string')
 *     if len(content) < 16:
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_content));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":123
 * def _rabin_hash(content):
 *     if not PyString_CheckExact(content):
 *         raise ValueError('content must be a string')             # <<<<<<<<<<<<<<
 *     if len(content) < 16:
 *         raise ValueError('content must be at least 16 bytes long')
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_groupcompress_pyx.pyx":124
 *     if not PyString_CheckExact(content):
 *         raise ValueError('content must be a string')
 *     if len(content) < 16:             # <<<<<<<<<<<<<<
 *         raise ValueError('content must be at least 16 bytes long')
 *     # Try to cast it to an int, if it can fit
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_content); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = (__pyx_t_3 < 16);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":125
 *         raise ValueError('content must be a string')
 *     if len(content) < 16:
 *         raise ValueError('content must be at least 16 bytes long')             # <<<<<<<<<<<<<<
 *     # Try to cast it to an int, if it can fit
 *     return int(rabin_hash(<unsigned char*>(PyString_AS_STRING(content))))
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":127
 *         raise ValueError('content must be at least 16 bytes long')
 *     # Try to cast it to an int, if it can fit
 *     return int(rabin_hash(<unsigned char*>(PyString_AS_STRING(content))))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyLong_FromUnsignedLong(rabin_hash(((unsigned char *)PyString_AS_STRING(__pyx_v_content)))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx._rabin_hash");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":142
 *     cdef public int _max_bytes_to_index
 * 
 *     def __init__(self, source=None, max_bytes_to_index=None):             # <<<<<<<<<<<<<<
 *         self._sources = []
 *         self._index = NULL
 */

static int __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  PyObject *__pyx_v_max_bytes_to_index = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  void *__pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__source,&__pyx_n_s__max_bytes_to_index,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)Py_None);
    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);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__source);
        if (value) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_bytes_to_index);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_source = values[0];
    __pyx_v_max_bytes_to_index = values[1];
  } else {
    __pyx_v_source = ((PyObject *)Py_None);
    __pyx_v_max_bytes_to_index = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_max_bytes_to_index = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_source = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__init__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_groupcompress_pyx.pyx":143
 * 
 *     def __init__(self, source=None, max_bytes_to_index=None):
 *         self._sources = []             # <<<<<<<<<<<<<<
 *         self._index = NULL
 *         self._max_num_sources = 65000
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources);
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources);
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":144
 *     def __init__(self, source=None, max_bytes_to_index=None):
 *         self._sources = []
 *         self._index = NULL             # <<<<<<<<<<<<<<
 *         self._max_num_sources = 65000
 *         self._source_infos = <source_info *>safe_malloc(sizeof(source_info)
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = NULL;

  /* "bzrlib/_groupcompress_pyx.pyx":145
 *         self._sources = []
 *         self._index = NULL
 *         self._max_num_sources = 65000             # <<<<<<<<<<<<<<
 *         self._source_infos = <source_info *>safe_malloc(sizeof(source_info)
 *                                                         * self._max_num_sources)
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources = 65000;

  /* "bzrlib/_groupcompress_pyx.pyx":147
 *         self._max_num_sources = 65000
 *         self._source_infos = <source_info *>safe_malloc(sizeof(source_info)
 *                                                         * self._max_num_sources)             # <<<<<<<<<<<<<<
 *         self._source_offset = 0
 *         self._max_bytes_to_index = 0
 */
  __pyx_t_2 = __pyx_f_6bzrlib_18_groupcompress_pyx_safe_malloc(((sizeof(struct source_info)) * ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources)); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bzrlib/_groupcompress_pyx.pyx":146
 *         self._index = NULL
 *         self._max_num_sources = 65000
 *         self._source_infos = <source_info *>safe_malloc(sizeof(source_info)             # <<<<<<<<<<<<<<
 *                                                         * self._max_num_sources)
 *         self._source_offset = 0
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos = ((struct source_info *)__pyx_t_2);

  /* "bzrlib/_groupcompress_pyx.pyx":148
 *         self._source_infos = <source_info *>safe_malloc(sizeof(source_info)
 *                                                         * self._max_num_sources)
 *         self._source_offset = 0             # <<<<<<<<<<<<<<
 *         self._max_bytes_to_index = 0
 *         if max_bytes_to_index is not None:
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":149
 *                                                         * self._max_num_sources)
 *         self._source_offset = 0
 *         self._max_bytes_to_index = 0             # <<<<<<<<<<<<<<
 *         if max_bytes_to_index is not None:
 *             self._max_bytes_to_index = max_bytes_to_index
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_bytes_to_index = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":150
 *         self._source_offset = 0
 *         self._max_bytes_to_index = 0
 *         if max_bytes_to_index is not None:             # <<<<<<<<<<<<<<
 *             self._max_bytes_to_index = max_bytes_to_index
 * 
 */
  __pyx_t_3 = (__pyx_v_max_bytes_to_index != Py_None);
  if (__pyx_t_3) {

    /* "bzrlib/_groupcompress_pyx.pyx":151
 *         self._max_bytes_to_index = 0
 *         if max_bytes_to_index is not None:
 *             self._max_bytes_to_index = max_bytes_to_index             # <<<<<<<<<<<<<<
 * 
 *         if source is not None:
 */
    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_max_bytes_to_index); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_bytes_to_index = __pyx_t_4;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":153
 *             self._max_bytes_to_index = max_bytes_to_index
 * 
 *         if source is not None:             # <<<<<<<<<<<<<<
 *             self.add_source(source, 0)
 * 
 */
  __pyx_t_3 = (__pyx_v_source != Py_None);
  if (__pyx_t_3) {

    /* "bzrlib/_groupcompress_pyx.pyx":154
 * 
 *         if source is not None:
 *             self.add_source(source, 0)             # <<<<<<<<<<<<<<
 * 
 *     def __sizeof__(self):
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__add_source); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_INCREF(__pyx_v_source);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_source);
    __Pyx_GIVEREF(__pyx_v_source);
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":156
 *             self.add_source(source, 0)
 * 
 *     def __sizeof__(self):             # <<<<<<<<<<<<<<
 *         # We want to track the _source_infos allocations, but the referenced
 *         # void* are actually tracked in _sources itself.
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_1__sizeof__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_1__sizeof__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  Py_ssize_t __pyx_v_size;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__sizeof__");

  /* "bzrlib/_groupcompress_pyx.pyx":169
 *                  + sizeof(unsigned int))
 *                 + (sizeof(source_info) * self._max_num_sources)
 *                 + sizeof_delta_index(self._index))             # <<<<<<<<<<<<<<
 *         return size
 * 
 */
  __pyx_v_size = (((((((sizeof(PyObject)) + (sizeof(void *))) + (3 * (sizeof(PyObject *)))) + (sizeof(unsigned long))) + (sizeof(unsigned int))) + ((sizeof(struct source_info)) * ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources)) + sizeof_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index));

  /* "bzrlib/_groupcompress_pyx.pyx":170
 *                 + (sizeof(source_info) * self._max_num_sources)
 *                 + sizeof_delta_index(self._index))
 *         return size             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__sizeof__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":172
 *         return size
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return '%s(%d, %d)' % (self.__class__.__name__,
 *             len(self._sources), self._source_offset)
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_2__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_2__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("__repr__");

  /* "bzrlib/_groupcompress_pyx.pyx":173
 * 
 *     def __repr__(self):
 *         return '%s(%d, %d)' % (self.__class__.__name__,             # <<<<<<<<<<<<<<
 *             len(self._sources), self._source_offset)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____class__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____name__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":174
 *     def __repr__(self):
 *         return '%s(%d, %d)' % (self.__class__.__name__,
 *             len(self._sources), self._source_offset)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_1 = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_3 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __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 = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __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_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":176
 *             len(self._sources), self._source_offset)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self._index != NULL:
 *             free_delta_index(self._index)
 */

static void __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_3__dealloc__(PyObject *__pyx_v_self) {
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("__dealloc__");

  /* "bzrlib/_groupcompress_pyx.pyx":177
 * 
 *     def __dealloc__(self):
 *         if self._index != NULL:             # <<<<<<<<<<<<<<
 *             free_delta_index(self._index)
 *             self._index = NULL
 */
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index != NULL);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":178
 *     def __dealloc__(self):
 *         if self._index != NULL:
 *             free_delta_index(self._index)             # <<<<<<<<<<<<<<
 *             self._index = NULL
 *         safe_free(<void **>&self._source_infos)
 */
    free_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);

    /* "bzrlib/_groupcompress_pyx.pyx":179
 *         if self._index != NULL:
 *             free_delta_index(self._index)
 *             self._index = NULL             # <<<<<<<<<<<<<<
 *         safe_free(<void **>&self._source_infos)
 * 
 */
    ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = NULL;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_groupcompress_pyx.pyx":180
 *             free_delta_index(self._index)
 *             self._index = NULL
 *         safe_free(<void **>&self._source_infos)             # <<<<<<<<<<<<<<
 * 
 *     def _has_index(self):
 */
  __pyx_t_2 = __pyx_f_6bzrlib_18_groupcompress_pyx_safe_free(((void **)(&((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos))); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.__dealloc__");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "bzrlib/_groupcompress_pyx.pyx":182
 *         safe_free(<void **>&self._source_infos)
 * 
 *     def _has_index(self):             # <<<<<<<<<<<<<<
 *         return (self._index != NULL)
 * 
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_4_has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_4_has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("_has_index");

  /* "bzrlib/_groupcompress_pyx.pyx":183
 * 
 *     def _has_index(self):
 *         return (self._index != NULL)             # <<<<<<<<<<<<<<
 * 
 *     def _dump_index(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._has_index");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":185
 *         return (self._index != NULL)
 * 
 *     def _dump_index(self):             # <<<<<<<<<<<<<<
 *         """Dump the pointers in the index.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_5_dump_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_5_dump_index[] = "Dump the pointers in the index.\n\n        This is an arbitrary layout, used for testing. It is not meant to be\n        used in production code.\n\n        :return: (hash_list, entry_list)\n            hash_list   A list of offsets, so hash[i] points to the 'hash\n                        bucket' starting at the given offset and going until\n                        hash[i+1]\n            entry_list  A list of (text_offset, hash_val). text_offset is the\n                        offset in the \"source\" texts, and hash_val is the RABIN\n                        hash for that offset.\n                        Note that the entry should be in the hash bucket\n                        defined by\n                        hash[(hash_val & mask)] && hash[(hash_val & mask) + 1]\n        ";
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_5_dump_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  int __pyx_v_pos;
  unsigned int __pyx_v_text_offset;
  unsigned int __pyx_v_hash_val;
  unsigned int __pyx_v_hash_offset;
  PyObject *__pyx_v_hash_list;
  PyObject *__pyx_v_entry_list;
  PyObject *__pyx_v_val;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("_dump_index");
  __pyx_v_hash_list = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_entry_list = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_val = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_groupcompress_pyx.pyx":206
 *         cdef unsigned int hash_val
 *         cdef unsigned int hash_offset
 *         if self._index == NULL:             # <<<<<<<<<<<<<<
 *             return None
 *         hash_list = []
 */
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index == NULL);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":207
 *         cdef unsigned int hash_offset
 *         if self._index == NULL:
 *             return None             # <<<<<<<<<<<<<<
 *         hash_list = []
 *         pos = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_groupcompress_pyx.pyx":208
 *         if self._index == NULL:
 *             return None
 *         hash_list = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while get_hash_offset(self._index, pos, &hash_offset):
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_hash_list));
  __pyx_v_hash_list = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":209
 *             return None
 *         hash_list = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while get_hash_offset(self._index, pos, &hash_offset):
 *             hash_list.append(int(hash_offset))
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":210
 *         hash_list = []
 *         pos = 0
 *         while get_hash_offset(self._index, pos, &hash_offset):             # <<<<<<<<<<<<<<
 *             hash_list.append(int(hash_offset))
 *             pos += 1
 */
  while (1) {
    __pyx_t_3 = get_hash_offset(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index, __pyx_v_pos, (&__pyx_v_hash_offset));
    if (!__pyx_t_3) break;

    /* "bzrlib/_groupcompress_pyx.pyx":211
 *         pos = 0
 *         while get_hash_offset(self._index, pos, &hash_offset):
 *             hash_list.append(int(hash_offset))             # <<<<<<<<<<<<<<
 *             pos += 1
 *         entry_list = []
 */
    if (unlikely(__pyx_v_hash_list == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_hash_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_t_3 = PyList_Append(__pyx_v_hash_list, __pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "bzrlib/_groupcompress_pyx.pyx":212
 *         while get_hash_offset(self._index, pos, &hash_offset):
 *             hash_list.append(int(hash_offset))
 *             pos += 1             # <<<<<<<<<<<<<<
 *         entry_list = []
 *         pos = 0
 */
    __pyx_v_pos = (__pyx_v_pos + 1);
  }

  /* "bzrlib/_groupcompress_pyx.pyx":213
 *             hash_list.append(int(hash_offset))
 *             pos += 1
 *         entry_list = []             # <<<<<<<<<<<<<<
 *         pos = 0
 *         while get_entry_summary(self._index, pos, &text_offset, &hash_val):
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_entry_list));
  __pyx_v_entry_list = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":214
 *             pos += 1
 *         entry_list = []
 *         pos = 0             # <<<<<<<<<<<<<<
 *         while get_entry_summary(self._index, pos, &text_offset, &hash_val):
 *             # Map back using 'int' so that we don't get Long everywhere, when
 */
  __pyx_v_pos = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":215
 *         entry_list = []
 *         pos = 0
 *         while get_entry_summary(self._index, pos, &text_offset, &hash_val):             # <<<<<<<<<<<<<<
 *             # Map back using 'int' so that we don't get Long everywhere, when
 *             # almost everything is <2**31.
 */
  while (1) {
    __pyx_t_3 = get_entry_summary(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index, __pyx_v_pos, (&__pyx_v_text_offset), (&__pyx_v_hash_val));
    if (!__pyx_t_3) break;

    /* "bzrlib/_groupcompress_pyx.pyx":218
 *             # Map back using 'int' so that we don't get Long everywhere, when
 *             # almost everything is <2**31.
 *             val = tuple(map(int, [text_offset, hash_val]))             # <<<<<<<<<<<<<<
 *             entry_list.append(val)
 *             pos += 1
 */
    __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_text_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_hash_val); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyList_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_2 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type))));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyInt_Type))));
    __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type))));
    PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
    __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_val));
    __pyx_v_val = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "bzrlib/_groupcompress_pyx.pyx":219
 *             # almost everything is <2**31.
 *             val = tuple(map(int, [text_offset, hash_val]))
 *             entry_list.append(val)             # <<<<<<<<<<<<<<
 *             pos += 1
 *         return hash_list, entry_list
 */
    if (unlikely(__pyx_v_entry_list == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_3 = PyList_Append(__pyx_v_entry_list, ((PyObject *)__pyx_v_val)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_groupcompress_pyx.pyx":220
 *             val = tuple(map(int, [text_offset, hash_val]))
 *             entry_list.append(val)
 *             pos += 1             # <<<<<<<<<<<<<<
 *         return hash_list, entry_list
 * 
 */
    __pyx_v_pos = (__pyx_v_pos + 1);
  }

  /* "bzrlib/_groupcompress_pyx.pyx":221
 *             entry_list.append(val)
 *             pos += 1
 *         return hash_list, entry_list             # <<<<<<<<<<<<<<
 * 
 *     def add_delta_source(self, delta, unadded_bytes):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  __Pyx_INCREF(((PyObject *)__pyx_v_hash_list));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_hash_list));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hash_list));
  __Pyx_INCREF(((PyObject *)__pyx_v_entry_list));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_entry_list));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_entry_list));
  __pyx_r = ((PyObject *)__pyx_t_5);
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._dump_index");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_hash_list);
  __Pyx_DECREF(__pyx_v_entry_list);
  __Pyx_DECREF(__pyx_v_val);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":223
 *         return hash_list, entry_list
 * 
 *     def add_delta_source(self, delta, unadded_bytes):             # <<<<<<<<<<<<<<
 *         """Add a new delta to the source texts.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_6add_delta_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_6add_delta_source[] = "Add a new delta to the source texts.\n\n        :param delta: The text of the delta, this must be a byte string.\n        :param unadded_bytes: Number of bytes that were added to the source\n            that were not indexed.\n        ";
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_6add_delta_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_delta = 0;
  PyObject *__pyx_v_unadded_bytes = 0;
  char *__pyx_v_c_delta;
  Py_ssize_t __pyx_v_c_delta_size;
  struct delta_index *__pyx_v_index;
  delta_result __pyx_v_res;
  unsigned int __pyx_v_source_location;
  struct source_info *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  unsigned long __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__delta,&__pyx_n_s__unadded_bytes,0};
  __Pyx_RefNannySetupContext("add_delta_source");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    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);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__delta);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unadded_bytes);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("add_delta_source", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_delta_source") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_delta = values[0];
    __pyx_v_unadded_bytes = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_delta = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_unadded_bytes = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add_delta_source", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.add_delta_source");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_groupcompress_pyx.pyx":238
 *         cdef unsigned int num_indexes
 * 
 *         if not PyString_CheckExact(delta):             # <<<<<<<<<<<<<<
 *             raise TypeError('delta is not a str')
 * 
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_delta));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":239
 * 
 *         if not PyString_CheckExact(delta):
 *             raise TypeError('delta is not a str')             # <<<<<<<<<<<<<<
 * 
 *         source_location = len(self._sources)
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":241
 *             raise TypeError('delta is not a str')
 * 
 *         source_location = len(self._sources)             # <<<<<<<<<<<<<<
 *         if source_location >= self._max_num_sources:
 *             self._expand_sources()
 */
  __pyx_t_2 = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_source_location = __pyx_t_3;

  /* "bzrlib/_groupcompress_pyx.pyx":242
 * 
 *         source_location = len(self._sources)
 *         if source_location >= self._max_num_sources:             # <<<<<<<<<<<<<<
 *             self._expand_sources()
 *         self._sources.append(delta)
 */
  __pyx_t_1 = (__pyx_v_source_location >= ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":243
 *         source_location = len(self._sources)
 *         if source_location >= self._max_num_sources:
 *             self._expand_sources()             # <<<<<<<<<<<<<<
 *         self._sources.append(delta)
 *         c_delta = PyString_AS_STRING(delta)
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_expand_sources(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":244
 *         if source_location >= self._max_num_sources:
 *             self._expand_sources()
 *         self._sources.append(delta)             # <<<<<<<<<<<<<<
 *         c_delta = PyString_AS_STRING(delta)
 *         c_delta_size = PyString_GET_SIZE(delta)
 */
  __pyx_t_2 = __Pyx_PyObject_Append(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources, __pyx_v_delta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":245
 *             self._expand_sources()
 *         self._sources.append(delta)
 *         c_delta = PyString_AS_STRING(delta)             # <<<<<<<<<<<<<<
 *         c_delta_size = PyString_GET_SIZE(delta)
 *         src = self._source_infos + source_location
 */
  __pyx_v_c_delta = PyString_AS_STRING(__pyx_v_delta);

  /* "bzrlib/_groupcompress_pyx.pyx":246
 *         self._sources.append(delta)
 *         c_delta = PyString_AS_STRING(delta)
 *         c_delta_size = PyString_GET_SIZE(delta)             # <<<<<<<<<<<<<<
 *         src = self._source_infos + source_location
 *         src.buf = c_delta
 */
  __pyx_v_c_delta_size = PyString_GET_SIZE(__pyx_v_delta);

  /* "bzrlib/_groupcompress_pyx.pyx":247
 *         c_delta = PyString_AS_STRING(delta)
 *         c_delta_size = PyString_GET_SIZE(delta)
 *         src = self._source_infos + source_location             # <<<<<<<<<<<<<<
 *         src.buf = c_delta
 *         src.size = c_delta_size
 */
  __pyx_v_src = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos + __pyx_v_source_location);

  /* "bzrlib/_groupcompress_pyx.pyx":248
 *         c_delta_size = PyString_GET_SIZE(delta)
 *         src = self._source_infos + source_location
 *         src.buf = c_delta             # <<<<<<<<<<<<<<
 *         src.size = c_delta_size
 *         src.agg_offset = self._source_offset + unadded_bytes
 */
  __pyx_v_src->buf = __pyx_v_c_delta;

  /* "bzrlib/_groupcompress_pyx.pyx":249
 *         src = self._source_infos + source_location
 *         src.buf = c_delta
 *         src.size = c_delta_size             # <<<<<<<<<<<<<<
 *         src.agg_offset = self._source_offset + unadded_bytes
 *         with nogil:
 */
  __pyx_v_src->size = __pyx_v_c_delta_size;

  /* "bzrlib/_groupcompress_pyx.pyx":250
 *         src.buf = c_delta
 *         src.size = c_delta_size
 *         src.agg_offset = self._source_offset + unadded_bytes             # <<<<<<<<<<<<<<
 *         with nogil:
 *             res = create_delta_index_from_delta(src, self._index, &index)
 */
  __pyx_t_2 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_v_unadded_bytes); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyInt_AsUnsignedLong(__pyx_t_4); if (unlikely((__pyx_t_5 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_src->agg_offset = __pyx_t_5;

  /* "bzrlib/_groupcompress_pyx.pyx":251
 *         src.size = c_delta_size
 *         src.agg_offset = self._source_offset + unadded_bytes
 *         with nogil:             # <<<<<<<<<<<<<<
 *             res = create_delta_index_from_delta(src, self._index, &index)
 *         if res != DELTA_OK:
 */
  {
    #ifdef WITH_THREAD
    PyThreadState *_save;
    #endif
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "bzrlib/_groupcompress_pyx.pyx":252
 *         src.agg_offset = self._source_offset + unadded_bytes
 *         with nogil:
 *             res = create_delta_index_from_delta(src, self._index, &index)             # <<<<<<<<<<<<<<
 *         if res != DELTA_OK:
 *             raise _translate_delta_failure(res)
 */
      __pyx_v_res = create_delta_index_from_delta(__pyx_v_src, ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index, (&__pyx_v_index));
    }

    /* "bzrlib/_groupcompress_pyx.pyx":251
 *         src.size = c_delta_size
 *         src.agg_offset = self._source_offset + unadded_bytes
 *         with nogil:             # <<<<<<<<<<<<<<
 *             res = create_delta_index_from_delta(src, self._index, &index)
 *         if res != DELTA_OK:
 */
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "bzrlib/_groupcompress_pyx.pyx":253
 *         with nogil:
 *             res = create_delta_index_from_delta(src, self._index, &index)
 *         if res != DELTA_OK:             # <<<<<<<<<<<<<<
 *             raise _translate_delta_failure(res)
 *         self._source_offset = src.agg_offset + src.size
 */
  __pyx_t_1 = (__pyx_v_res != DELTA_OK);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":254
 *             res = create_delta_index_from_delta(src, self._index, &index)
 *         if res != DELTA_OK:
 *             raise _translate_delta_failure(res)             # <<<<<<<<<<<<<<
 *         self._source_offset = src.agg_offset + src.size
 *         if index != self._index:
 */
    __pyx_t_4 = __pyx_f_6bzrlib_18_groupcompress_pyx__translate_delta_failure(__pyx_v_res); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "bzrlib/_groupcompress_pyx.pyx":255
 *         if res != DELTA_OK:
 *             raise _translate_delta_failure(res)
 *         self._source_offset = src.agg_offset + src.size             # <<<<<<<<<<<<<<
 *         if index != self._index:
 *             free_delta_index(self._index)
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = (__pyx_v_src->agg_offset + __pyx_v_src->size);

  /* "bzrlib/_groupcompress_pyx.pyx":256
 *             raise _translate_delta_failure(res)
 *         self._source_offset = src.agg_offset + src.size
 *         if index != self._index:             # <<<<<<<<<<<<<<
 *             free_delta_index(self._index)
 *             self._index = index
 */
  __pyx_t_1 = (__pyx_v_index != ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":257
 *         self._source_offset = src.agg_offset + src.size
 *         if index != self._index:
 *             free_delta_index(self._index)             # <<<<<<<<<<<<<<
 *             self._index = index
 * 
 */
    free_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);

    /* "bzrlib/_groupcompress_pyx.pyx":258
 *         if index != self._index:
 *             free_delta_index(self._index)
 *             self._index = index             # <<<<<<<<<<<<<<
 * 
 *     def add_source(self, source, unadded_bytes):
 */
    ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = __pyx_v_index;
    goto __pyx_L12;
  }
  __pyx_L12:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.add_delta_source");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":260
 *             self._index = index
 * 
 *     def add_source(self, source, unadded_bytes):             # <<<<<<<<<<<<<<
 *         """Add a new bit of source text to the delta indexes.
 * 
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_7add_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_7add_source[] = "Add a new bit of source text to the delta indexes.\n\n        :param source: The text in question, this must be a byte string\n        :param unadded_bytes: Assume there are this many bytes that didn't get\n            added between this source and the end of the previous source.\n        :param max_pointers: Add no more than this many entries to the index.\n            By default, we sample every 16 bytes, if that would require more\n            than max_entries, we will reduce the sampling rate.\n            A value of 0 means unlimited, None means use the default limit.\n        ";
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_7add_source(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  PyObject *__pyx_v_unadded_bytes = 0;
  char *__pyx_v_c_source;
  Py_ssize_t __pyx_v_c_source_size;
  struct delta_index *__pyx_v_index;
  delta_result __pyx_v_res;
  unsigned int __pyx_v_source_location;
  struct source_info *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  unsigned long __pyx_t_7;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__source,&__pyx_n_s__unadded_bytes,0};
  __Pyx_RefNannySetupContext("add_source");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    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);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__source);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unadded_bytes);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("add_source", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_source") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_source = values[0];
    __pyx_v_unadded_bytes = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_source = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_unadded_bytes = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add_source", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.add_source");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_groupcompress_pyx.pyx":280
 *         cdef int max_num_entries
 * 
 *         if not PyString_CheckExact(source):             # <<<<<<<<<<<<<<
 *             raise TypeError('source is not a str')
 * 
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_source));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":281
 * 
 *         if not PyString_CheckExact(source):
 *             raise TypeError('source is not a str')             # <<<<<<<<<<<<<<
 * 
 *         source_location = len(self._sources)
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":283
 *             raise TypeError('source is not a str')
 * 
 *         source_location = len(self._sources)             # <<<<<<<<<<<<<<
 *         if source_location >= self._max_num_sources:
 *             self._expand_sources()
 */
  __pyx_t_2 = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_source_location = __pyx_t_3;

  /* "bzrlib/_groupcompress_pyx.pyx":284
 * 
 *         source_location = len(self._sources)
 *         if source_location >= self._max_num_sources:             # <<<<<<<<<<<<<<
 *             self._expand_sources()
 *         if source_location != 0 and self._index == NULL:
 */
  __pyx_t_1 = (__pyx_v_source_location >= ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":285
 *         source_location = len(self._sources)
 *         if source_location >= self._max_num_sources:
 *             self._expand_sources()             # <<<<<<<<<<<<<<
 *         if source_location != 0 and self._index == NULL:
 *             # We were lazy about populating the index, create it now
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_expand_sources(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":286
 *         if source_location >= self._max_num_sources:
 *             self._expand_sources()
 *         if source_location != 0 and self._index == NULL:             # <<<<<<<<<<<<<<
 *             # We were lazy about populating the index, create it now
 *             self._populate_first_index()
 */
  __pyx_t_1 = (__pyx_v_source_location != 0);
  if (__pyx_t_1) {
    __pyx_t_4 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index == NULL);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_1;
  }
  if (__pyx_t_5) {

    /* "bzrlib/_groupcompress_pyx.pyx":288
 *         if source_location != 0 and self._index == NULL:
 *             # We were lazy about populating the index, create it now
 *             self._populate_first_index()             # <<<<<<<<<<<<<<
 *         self._sources.append(source)
 *         c_source = PyString_AS_STRING(source)
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_populate_first_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_groupcompress_pyx.pyx":289
 *             # We were lazy about populating the index, create it now
 *             self._populate_first_index()
 *         self._sources.append(source)             # <<<<<<<<<<<<<<
 *         c_source = PyString_AS_STRING(source)
 *         c_source_size = PyString_GET_SIZE(source)
 */
  __pyx_t_2 = __Pyx_PyObject_Append(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources, __pyx_v_source); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":290
 *             self._populate_first_index()
 *         self._sources.append(source)
 *         c_source = PyString_AS_STRING(source)             # <<<<<<<<<<<<<<
 *         c_source_size = PyString_GET_SIZE(source)
 *         src = self._source_infos + source_location
 */
  __pyx_v_c_source = PyString_AS_STRING(__pyx_v_source);

  /* "bzrlib/_groupcompress_pyx.pyx":291
 *         self._sources.append(source)
 *         c_source = PyString_AS_STRING(source)
 *         c_source_size = PyString_GET_SIZE(source)             # <<<<<<<<<<<<<<
 *         src = self._source_infos + source_location
 *         src.buf = c_source
 */
  __pyx_v_c_source_size = PyString_GET_SIZE(__pyx_v_source);

  /* "bzrlib/_groupcompress_pyx.pyx":292
 *         c_source = PyString_AS_STRING(source)
 *         c_source_size = PyString_GET_SIZE(source)
 *         src = self._source_infos + source_location             # <<<<<<<<<<<<<<
 *         src.buf = c_source
 *         src.size = c_source_size
 */
  __pyx_v_src = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_infos + __pyx_v_source_location);

  /* "bzrlib/_groupcompress_pyx.pyx":293
 *         c_source_size = PyString_GET_SIZE(source)
 *         src = self._source_infos + source_location
 *         src.buf = c_source             # <<<<<<<<<<<<<<
 *         src.size = c_source_size
 * 
 */
  __pyx_v_src->buf = __pyx_v_c_source;

  /* "bzrlib/_groupcompress_pyx.pyx":294
 *         src = self._source_infos + source_location
 *         src.buf = c_source
 *         src.size = c_source_size             # <<<<<<<<<<<<<<
 * 
 *         src.agg_offset = self._source_offset + unadded_bytes
 */
  __pyx_v_src->size = __pyx_v_c_source_size;

  /* "bzrlib/_groupcompress_pyx.pyx":296
 *         src.size = c_source_size
 * 
 *         src.agg_offset = self._source_offset + unadded_bytes             # <<<<<<<<<<<<<<
 *         self._source_offset = src.agg_offset + src.size
 *         # We delay creating the index on the first insert
 */
  __pyx_t_2 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_v_unadded_bytes); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyInt_AsUnsignedLong(__pyx_t_6); if (unlikely((__pyx_t_7 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_src->agg_offset = __pyx_t_7;

  /* "bzrlib/_groupcompress_pyx.pyx":297
 * 
 *         src.agg_offset = self._source_offset + unadded_bytes
 *         self._source_offset = src.agg_offset + src.size             # <<<<<<<<<<<<<<
 *         # We delay creating the index on the first insert
 *         if source_location != 0:
 */
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = (__pyx_v_src->agg_offset + __pyx_v_src->size);

  /* "bzrlib/_groupcompress_pyx.pyx":299
 *         self._source_offset = src.agg_offset + src.size
 *         # We delay creating the index on the first insert
 *         if source_location != 0:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 res = create_delta_index(src, self._index, &index,
 */
  __pyx_t_5 = (__pyx_v_source_location != 0);
  if (__pyx_t_5) {

    /* "bzrlib/_groupcompress_pyx.pyx":300
 *         # We delay creating the index on the first insert
 *         if source_location != 0:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 res = create_delta_index(src, self._index, &index,
 *                                          self._max_bytes_to_index)
 */
    {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      #endif
      Py_UNBLOCK_THREADS
      /*try:*/ {

        /* "bzrlib/_groupcompress_pyx.pyx":302
 *             with nogil:
 *                 res = create_delta_index(src, self._index, &index,
 *                                          self._max_bytes_to_index)             # <<<<<<<<<<<<<<
 *             if res != DELTA_OK:
 *                 raise _translate_delta_failure(res)
 */
        __pyx_v_res = create_delta_index(__pyx_v_src, ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index, (&__pyx_v_index), ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_bytes_to_index);
      }

      /* "bzrlib/_groupcompress_pyx.pyx":300
 *         # We delay creating the index on the first insert
 *         if source_location != 0:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 res = create_delta_index(src, self._index, &index,
 *                                          self._max_bytes_to_index)
 */
      /*finally:*/ {
        Py_BLOCK_THREADS
      }
    }

    /* "bzrlib/_groupcompress_pyx.pyx":303
 *                 res = create_delta_index(src, self._index, &index,
 *                                          self._max_bytes_to_index)
 *             if res != DELTA_OK:             # <<<<<<<<<<<<<<
 *                 raise _translate_delta_failure(res)
 *             if index != self._index:
 */
    __pyx_t_5 = (__pyx_v_res != DELTA_OK);
    if (__pyx_t_5) {

      /* "bzrlib/_groupcompress_pyx.pyx":304
 *                                          self._max_bytes_to_index)
 *             if res != DELTA_OK:
 *                 raise _translate_delta_failure(res)             # <<<<<<<<<<<<<<
 *             if index != self._index:
 *                 free_delta_index(self._index)
 */
      __pyx_t_6 = __pyx_f_6bzrlib_18_groupcompress_pyx__translate_delta_failure(__pyx_v_res); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "bzrlib/_groupcompress_pyx.pyx":305
 *             if res != DELTA_OK:
 *                 raise _translate_delta_failure(res)
 *             if index != self._index:             # <<<<<<<<<<<<<<
 *                 free_delta_index(self._index)
 *                 self._index = index
 */
    __pyx_t_5 = (__pyx_v_index != ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);
    if (__pyx_t_5) {

      /* "bzrlib/_groupcompress_pyx.pyx":306
 *                 raise _translate_delta_failure(res)
 *             if index != self._index:
 *                 free_delta_index(self._index)             # <<<<<<<<<<<<<<
 *                 self._index = index
 * 
 */
      free_delta_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index);

      /* "bzrlib/_groupcompress_pyx.pyx":307
 *             if index != self._index:
 *                 free_delta_index(self._index)
 *                 self._index = index             # <<<<<<<<<<<<<<
 * 
 *     cdef _populate_first_index(self):
 */
      ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index = __pyx_v_index;
      goto __pyx_L14;
    }
    __pyx_L14:;
    goto __pyx_L9;
  }
  __pyx_L9:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.add_source");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":309
 *                 self._index = index
 * 
 *     cdef _populate_first_index(self):             # <<<<<<<<<<<<<<
 *         cdef delta_index *index
 *         cdef delta_result res
 */

static  PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__populate_first_index(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_v_self) {
  struct delta_index *__pyx_v_index;
  delta_result __pyx_v_res;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("_populate_first_index");

  /* "bzrlib/_groupcompress_pyx.pyx":312
 *         cdef delta_index *index
 *         cdef delta_result res
 *         if len(self._sources) != 1 or self._index != NULL:             # <<<<<<<<<<<<<<
 *             raise AssertionError('_populate_first_index should only be'
 *                 ' called when we have a single source and no index yet')
 */
  __pyx_t_1 = __pyx_v_self->_sources;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 1);
  if (!__pyx_t_3) {
    __pyx_t_4 = (__pyx_v_self->_index != NULL);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_3;
  }
  if (__pyx_t_5) {

    /* "bzrlib/_groupcompress_pyx.pyx":313
 *         cdef delta_result res
 *         if len(self._sources) != 1 or self._index != NULL:
 *             raise AssertionError('_populate_first_index should only be'             # <<<<<<<<<<<<<<
 *                 ' called when we have a single source and no index yet')
 * 
 */
    __pyx_t_1 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_groupcompress_pyx.pyx":318
 *         # We know that self._index is already NULL, so create_delta_index
 *         # will always create a new index unless there's a malloc failure
 *         with nogil:             # <<<<<<<<<<<<<<
 *             res = create_delta_index(&self._source_infos[0], NULL, &index,
 *                                      self._max_bytes_to_index)
 */
  {
    #ifdef WITH_THREAD
    PyThreadState *_save;
    #endif
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "bzrlib/_groupcompress_pyx.pyx":320
 *         with nogil:
 *             res = create_delta_index(&self._source_infos[0], NULL, &index,
 *                                      self._max_bytes_to_index)             # <<<<<<<<<<<<<<
 *         if res != DELTA_OK:
 *             raise _translate_delta_failure(res)
 */
      __pyx_v_res = create_delta_index((&(__pyx_v_self->_source_infos[0])), NULL, (&__pyx_v_index), __pyx_v_self->_max_bytes_to_index);
    }

    /* "bzrlib/_groupcompress_pyx.pyx":318
 *         # We know that self._index is already NULL, so create_delta_index
 *         # will always create a new index unless there's a malloc failure
 *         with nogil:             # <<<<<<<<<<<<<<
 *             res = create_delta_index(&self._source_infos[0], NULL, &index,
 *                                      self._max_bytes_to_index)
 */
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "bzrlib/_groupcompress_pyx.pyx":321
 *             res = create_delta_index(&self._source_infos[0], NULL, &index,
 *                                      self._max_bytes_to_index)
 *         if res != DELTA_OK:             # <<<<<<<<<<<<<<
 *             raise _translate_delta_failure(res)
 *         self._index = index
 */
  __pyx_t_5 = (__pyx_v_res != DELTA_OK);
  if (__pyx_t_5) {

    /* "bzrlib/_groupcompress_pyx.pyx":322
 *                                      self._max_bytes_to_index)
 *         if res != DELTA_OK:
 *             raise _translate_delta_failure(res)             # <<<<<<<<<<<<<<
 *         self._index = index
 * 
 */
    __pyx_t_1 = __pyx_f_6bzrlib_18_groupcompress_pyx__translate_delta_failure(__pyx_v_res); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":323
 *         if res != DELTA_OK:
 *             raise _translate_delta_failure(res)
 *         self._index = index             # <<<<<<<<<<<<<<
 * 
 *     cdef _expand_sources(self):
 */
  __pyx_v_self->_index = __pyx_v_index;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._populate_first_index");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":325
 *         self._index = index
 * 
 *     cdef _expand_sources(self):             # <<<<<<<<<<<<<<
 *         raise RuntimeError('if we move self._source_infos, then we need to'
 *                            ' change all of the index pointers as well.')
 */

static  PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__expand_sources(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  void *__pyx_t_2;
  __Pyx_RefNannySetupContext("_expand_sources");

  /* "bzrlib/_groupcompress_pyx.pyx":326
 * 
 *     cdef _expand_sources(self):
 *         raise RuntimeError('if we move self._source_infos, then we need to'             # <<<<<<<<<<<<<<
 *                            ' change all of the index pointers as well.')
 *         self._max_num_sources = self._max_num_sources * 2
 */
  __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bzrlib/_groupcompress_pyx.pyx":328
 *         raise RuntimeError('if we move self._source_infos, then we need to'
 *                            ' change all of the index pointers as well.')
 *         self._max_num_sources = self._max_num_sources * 2             # <<<<<<<<<<<<<<
 *         self._source_infos = <source_info *>safe_realloc(self._source_infos,
 *                                                 sizeof(source_info)
 */
  __pyx_v_self->_max_num_sources = (__pyx_v_self->_max_num_sources * 2);

  /* "bzrlib/_groupcompress_pyx.pyx":331
 *         self._source_infos = <source_info *>safe_realloc(self._source_infos,
 *                                                 sizeof(source_info)
 *                                                 * self._max_num_sources)             # <<<<<<<<<<<<<<
 * 
 *     def make_delta(self, target_bytes, max_delta_size=0):
 */
  __pyx_t_2 = __pyx_f_6bzrlib_18_groupcompress_pyx_safe_realloc(__pyx_v_self->_source_infos, ((sizeof(struct source_info)) * __pyx_v_self->_max_num_sources)); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bzrlib/_groupcompress_pyx.pyx":329
 *                            ' change all of the index pointers as well.')
 *         self._max_num_sources = self._max_num_sources * 2
 *         self._source_infos = <source_info *>safe_realloc(self._source_infos,             # <<<<<<<<<<<<<<
 *                                                 sizeof(source_info)
 *                                                 * self._max_num_sources)
 */
  __pyx_v_self->_source_infos = ((struct source_info *)__pyx_t_2);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._expand_sources");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":333
 *                                                 * self._max_num_sources)
 * 
 *     def make_delta(self, target_bytes, max_delta_size=0):             # <<<<<<<<<<<<<<
 *         """Create a delta from the current source to the target bytes."""
 *         cdef char *target
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8make_delta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8make_delta[] = "Create a delta from the current source to the target bytes.";
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8make_delta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_target_bytes = 0;
  PyObject *__pyx_v_max_delta_size = 0;
  char *__pyx_v_target;
  Py_ssize_t __pyx_v_target_size;
  void *__pyx_v_delta;
  unsigned long __pyx_v_delta_size;
  unsigned long __pyx_v_c_max_delta_size;
  delta_result __pyx_v_res;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  unsigned long __pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__target_bytes,&__pyx_n_s__max_delta_size,0};
  __Pyx_RefNannySetupContext("make_delta");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_0);
    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);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__target_bytes);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_delta_size);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "make_delta") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_target_bytes = values[0];
    __pyx_v_max_delta_size = values[1];
  } else {
    __pyx_v_max_delta_size = ((PyObject *)__pyx_int_0);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_max_delta_size = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_target_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("make_delta", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.make_delta");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_result = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_groupcompress_pyx.pyx":342
 *         cdef delta_result res
 * 
 *         if self._index == NULL:             # <<<<<<<<<<<<<<
 *             if len(self._sources) == 0:
 *                 return None
 */
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index == NULL);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":343
 * 
 *         if self._index == NULL:
 *             if len(self._sources) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             # We were just lazy about generating the index
 */
    __pyx_t_2 = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_1 = (__pyx_t_3 == 0);
    if (__pyx_t_1) {

      /* "bzrlib/_groupcompress_pyx.pyx":344
 *         if self._index == NULL:
 *             if len(self._sources) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             # We were just lazy about generating the index
 *             self._populate_first_index()
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_None);
      __pyx_r = Py_None;
      goto __pyx_L0;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "bzrlib/_groupcompress_pyx.pyx":346
 *                 return None
 *             # We were just lazy about generating the index
 *             self._populate_first_index()             # <<<<<<<<<<<<<<
 * 
 *         if not PyString_CheckExact(target_bytes):
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex *)((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->__pyx_vtab)->_populate_first_index(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":348
 *             self._populate_first_index()
 * 
 *         if not PyString_CheckExact(target_bytes):             # <<<<<<<<<<<<<<
 *             raise TypeError('target is not a str')
 * 
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_target_bytes));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":349
 * 
 *         if not PyString_CheckExact(target_bytes):
 *             raise TypeError('target is not a str')             # <<<<<<<<<<<<<<
 * 
 *         target = PyString_AS_STRING(target_bytes)
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_groupcompress_pyx.pyx":351
 *             raise TypeError('target is not a str')
 * 
 *         target = PyString_AS_STRING(target_bytes)             # <<<<<<<<<<<<<<
 *         target_size = PyString_GET_SIZE(target_bytes)
 * 
 */
  __pyx_v_target = PyString_AS_STRING(__pyx_v_target_bytes);

  /* "bzrlib/_groupcompress_pyx.pyx":352
 * 
 *         target = PyString_AS_STRING(target_bytes)
 *         target_size = PyString_GET_SIZE(target_bytes)             # <<<<<<<<<<<<<<
 * 
 *         # TODO: inline some of create_delta so we at least don't have to double
 */
  __pyx_v_target_size = PyString_GET_SIZE(__pyx_v_target_bytes);

  /* "bzrlib/_groupcompress_pyx.pyx":357
 *         #       malloc, and can instead use PyString_FromStringAndSize, to
 *         #       allocate the bytes into the final string
 *         c_max_delta_size = max_delta_size             # <<<<<<<<<<<<<<
 *         with nogil:
 *             res = create_delta(self._index, target, target_size,
 */
  __pyx_t_4 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_max_delta_size); if (unlikely((__pyx_t_4 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_c_max_delta_size = __pyx_t_4;

  /* "bzrlib/_groupcompress_pyx.pyx":358
 *         #       allocate the bytes into the final string
 *         c_max_delta_size = max_delta_size
 *         with nogil:             # <<<<<<<<<<<<<<
 *             res = create_delta(self._index, target, target_size,
 *                                &delta_size, c_max_delta_size, &delta)
 */
  {
    #ifdef WITH_THREAD
    PyThreadState *_save;
    #endif
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "bzrlib/_groupcompress_pyx.pyx":360
 *         with nogil:
 *             res = create_delta(self._index, target, target_size,
 *                                &delta_size, c_max_delta_size, &delta)             # <<<<<<<<<<<<<<
 *         result = None
 *         if res == DELTA_OK:
 */
      __pyx_v_res = create_delta(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_index, __pyx_v_target, __pyx_v_target_size, (&__pyx_v_delta_size), __pyx_v_c_max_delta_size, (&__pyx_v_delta));
    }

    /* "bzrlib/_groupcompress_pyx.pyx":358
 *         #       allocate the bytes into the final string
 *         c_max_delta_size = max_delta_size
 *         with nogil:             # <<<<<<<<<<<<<<
 *             res = create_delta(self._index, target, target_size,
 *                                &delta_size, c_max_delta_size, &delta)
 */
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "bzrlib/_groupcompress_pyx.pyx":361
 *             res = create_delta(self._index, target, target_size,
 *                                &delta_size, c_max_delta_size, &delta)
 *         result = None             # <<<<<<<<<<<<<<
 *         if res == DELTA_OK:
 *             result = PyString_FromStringAndSize(<char *>delta, delta_size)
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF(__pyx_v_result);
  __pyx_v_result = Py_None;

  /* "bzrlib/_groupcompress_pyx.pyx":362
 *                                &delta_size, c_max_delta_size, &delta)
 *         result = None
 *         if res == DELTA_OK:             # <<<<<<<<<<<<<<
 *             result = PyString_FromStringAndSize(<char *>delta, delta_size)
 *             free(delta)
 */
  __pyx_t_1 = (__pyx_v_res == DELTA_OK);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":363
 *         result = None
 *         if res == DELTA_OK:
 *             result = PyString_FromStringAndSize(<char *>delta, delta_size)             # <<<<<<<<<<<<<<
 *             free(delta)
 *         elif res != DELTA_SIZE_TOO_BIG:
 */
    __pyx_t_2 = PyString_FromStringAndSize(((char *)__pyx_v_delta), __pyx_v_delta_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_result);
    __pyx_v_result = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "bzrlib/_groupcompress_pyx.pyx":364
 *         if res == DELTA_OK:
 *             result = PyString_FromStringAndSize(<char *>delta, delta_size)
 *             free(delta)             # <<<<<<<<<<<<<<
 *         elif res != DELTA_SIZE_TOO_BIG:
 *             raise _translate_delta_failure(res)
 */
    free(__pyx_v_delta);
    goto __pyx_L12;
  }

  /* "bzrlib/_groupcompress_pyx.pyx":365
 *             result = PyString_FromStringAndSize(<char *>delta, delta_size)
 *             free(delta)
 *         elif res != DELTA_SIZE_TOO_BIG:             # <<<<<<<<<<<<<<
 *             raise _translate_delta_failure(res)
 *         return result
 */
  __pyx_t_1 = (__pyx_v_res != DELTA_SIZE_TOO_BIG);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":366
 *             free(delta)
 *         elif res != DELTA_SIZE_TOO_BIG:
 *             raise _translate_delta_failure(res)             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
    __pyx_t_2 = __pyx_f_6bzrlib_18_groupcompress_pyx__translate_delta_failure(__pyx_v_res); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "bzrlib/_groupcompress_pyx.pyx":367
 *         elif res != DELTA_SIZE_TOO_BIG:
 *             raise _translate_delta_failure(res)
 *         return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex.make_delta");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":135
 *     # isn't performance critical
 *     # cdef readonly list _sources
 *     cdef readonly object _sources             # <<<<<<<<<<<<<<
 *     cdef source_info *_source_infos
 *     cdef delta_index *_index
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8_sources___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8_sources___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources);
  __pyx_r = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_sources;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":138
 *     cdef source_info *_source_infos
 *     cdef delta_index *_index
 *     cdef public unsigned long _source_offset             # <<<<<<<<<<<<<<
 *     cdef readonly unsigned int _max_num_sources
 *     cdef public int _max_bytes_to_index
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_14_source_offset___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_14_source_offset___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._source_offset.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_14_source_offset_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_14_source_offset_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  unsigned long __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsUnsignedLong(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_source_offset = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._source_offset.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":139
 *     cdef delta_index *_index
 *     cdef public unsigned long _source_offset
 *     cdef readonly unsigned int _max_num_sources             # <<<<<<<<<<<<<<
 *     cdef public int _max_bytes_to_index
 * 
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_16_max_num_sources___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_16_max_num_sources___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_num_sources); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._max_num_sources.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":140
 *     cdef public unsigned long _source_offset
 *     cdef readonly unsigned int _max_num_sources
 *     cdef public int _max_bytes_to_index             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, source=None, max_bytes_to_index=None):
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_19_max_bytes_to_index___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_19_max_bytes_to_index___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_bytes_to_index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._max_bytes_to_index.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_19_max_bytes_to_index_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_19_max_bytes_to_index_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__set__");
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_v_self)->_max_bytes_to_index = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.DeltaIndex._max_bytes_to_index.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":370
 * 
 * 
 * def make_delta(source_bytes, target_bytes):             # <<<<<<<<<<<<<<
 *     """Create a delta, this is a wrapper around DeltaIndex.make_delta."""
 *     di = DeltaIndex(source_bytes)
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_2make_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_2make_delta[] = "Create a delta, this is a wrapper around DeltaIndex.make_delta.";
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_2make_delta = {__Pyx_NAMESTR("make_delta"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_2make_delta, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_2make_delta)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_2make_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source_bytes = 0;
  PyObject *__pyx_v_target_bytes = 0;
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *__pyx_v_di;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__source_bytes,&__pyx_n_s__target_bytes,0};
  __Pyx_RefNannySetupContext("make_delta");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    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);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__source_bytes);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__target_bytes);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("make_delta", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "make_delta") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_source_bytes = values[0];
    __pyx_v_target_bytes = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_source_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_target_bytes = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("make_delta", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.make_delta");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_di = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)Py_None); __Pyx_INCREF(Py_None);

  /* "bzrlib/_groupcompress_pyx.pyx":372
 * def make_delta(source_bytes, target_bytes):
 *     """Create a delta, this is a wrapper around DeltaIndex.make_delta."""
 *     di = DeltaIndex(source_bytes)             # <<<<<<<<<<<<<<
 *     return di.make_delta(target_bytes)
 * 
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_source_bytes);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_source_bytes);
  __Pyx_GIVEREF(__pyx_v_source_bytes);
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_di));
  __pyx_v_di = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":373
 *     """Create a delta, this is a wrapper around DeltaIndex.make_delta."""
 *     di = DeltaIndex(source_bytes)
 *     return di.make_delta(target_bytes)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_di), __pyx_n_s__make_delta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_target_bytes);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_target_bytes);
  __Pyx_GIVEREF(__pyx_v_target_bytes);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __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._groupcompress_pyx.make_delta");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_di);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":376
 * 
 * 
 * def apply_delta(source_bytes, delta_bytes):             # <<<<<<<<<<<<<<
 *     """Apply a delta generated by make_delta to source_bytes."""
 *     cdef char *source
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_3apply_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_3apply_delta[] = "Apply a delta generated by make_delta to source_bytes.";
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_3apply_delta = {__Pyx_NAMESTR("apply_delta"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_3apply_delta, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_3apply_delta)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_3apply_delta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source_bytes = 0;
  PyObject *__pyx_v_delta_bytes = 0;
  char *__pyx_v_source;
  Py_ssize_t __pyx_v_source_size;
  char *__pyx_v_delta;
  Py_ssize_t __pyx_v_delta_size;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__source_bytes,&__pyx_n_s__delta_bytes,0};
  __Pyx_RefNannySetupContext("apply_delta");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    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);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__source_bytes);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__delta_bytes);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("apply_delta", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "apply_delta") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_source_bytes = values[0];
    __pyx_v_delta_bytes = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_source_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_delta_bytes = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("apply_delta", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.apply_delta");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_groupcompress_pyx.pyx":383
 *     cdef Py_ssize_t delta_size
 * 
 *     if not PyString_CheckExact(source_bytes):             # <<<<<<<<<<<<<<
 *         raise TypeError('source is not a str')
 *     if not PyString_CheckExact(delta_bytes):
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_source_bytes));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":384
 * 
 *     if not PyString_CheckExact(source_bytes):
 *         raise TypeError('source is not a str')             # <<<<<<<<<<<<<<
 *     if not PyString_CheckExact(delta_bytes):
 *         raise TypeError('delta is not a str')
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":385
 *     if not PyString_CheckExact(source_bytes):
 *         raise TypeError('source is not a str')
 *     if not PyString_CheckExact(delta_bytes):             # <<<<<<<<<<<<<<
 *         raise TypeError('delta is not a str')
 *     source = PyString_AS_STRING(source_bytes)
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_delta_bytes));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":386
 *         raise TypeError('source is not a str')
 *     if not PyString_CheckExact(delta_bytes):
 *         raise TypeError('delta is not a str')             # <<<<<<<<<<<<<<
 *     source = PyString_AS_STRING(source_bytes)
 *     source_size = PyString_GET_SIZE(source_bytes)
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":387
 *     if not PyString_CheckExact(delta_bytes):
 *         raise TypeError('delta is not a str')
 *     source = PyString_AS_STRING(source_bytes)             # <<<<<<<<<<<<<<
 *     source_size = PyString_GET_SIZE(source_bytes)
 *     delta = PyString_AS_STRING(delta_bytes)
 */
  __pyx_v_source = PyString_AS_STRING(__pyx_v_source_bytes);

  /* "bzrlib/_groupcompress_pyx.pyx":388
 *         raise TypeError('delta is not a str')
 *     source = PyString_AS_STRING(source_bytes)
 *     source_size = PyString_GET_SIZE(source_bytes)             # <<<<<<<<<<<<<<
 *     delta = PyString_AS_STRING(delta_bytes)
 *     delta_size = PyString_GET_SIZE(delta_bytes)
 */
  __pyx_v_source_size = PyString_GET_SIZE(__pyx_v_source_bytes);

  /* "bzrlib/_groupcompress_pyx.pyx":389
 *     source = PyString_AS_STRING(source_bytes)
 *     source_size = PyString_GET_SIZE(source_bytes)
 *     delta = PyString_AS_STRING(delta_bytes)             # <<<<<<<<<<<<<<
 *     delta_size = PyString_GET_SIZE(delta_bytes)
 *     # Code taken from patch-delta.c, only brought here to give better error
 */
  __pyx_v_delta = PyString_AS_STRING(__pyx_v_delta_bytes);

  /* "bzrlib/_groupcompress_pyx.pyx":390
 *     source_size = PyString_GET_SIZE(source_bytes)
 *     delta = PyString_AS_STRING(delta_bytes)
 *     delta_size = PyString_GET_SIZE(delta_bytes)             # <<<<<<<<<<<<<<
 *     # Code taken from patch-delta.c, only brought here to give better error
 *     # handling, and to avoid double allocating memory
 */
  __pyx_v_delta_size = PyString_GET_SIZE(__pyx_v_delta_bytes);

  /* "bzrlib/_groupcompress_pyx.pyx":393
 *     # Code taken from patch-delta.c, only brought here to give better error
 *     # handling, and to avoid double allocating memory
 *     if (delta_size < DELTA_SIZE_MIN):             # <<<<<<<<<<<<<<
 *         # XXX: Invalid delta block
 *         raise RuntimeError('delta_size %d smaller than min delta size %d'
 */
  __pyx_t_1 = (__pyx_v_delta_size < DELTA_SIZE_MIN);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":396
 *         # XXX: Invalid delta block
 *         raise RuntimeError('delta_size %d smaller than min delta size %d'
 *                            % (delta_size, DELTA_SIZE_MIN))             # <<<<<<<<<<<<<<
 * 
 *     return _apply_delta(source, source_size, delta, delta_size)
 */
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_delta_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyInt_FromSsize_t(DELTA_SIZE_MIN); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_groupcompress_pyx.pyx":398
 *                            % (delta_size, DELTA_SIZE_MIN))
 * 
 *     return _apply_delta(source, source_size, delta, delta_size)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(__pyx_v_source, __pyx_v_source_size, __pyx_v_delta, __pyx_v_delta_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.apply_delta");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":401
 * 
 * 
 * cdef unsigned char *_decode_copy_instruction(unsigned char *bytes,             # <<<<<<<<<<<<<<
 *     unsigned char cmd, unsigned int *offset,
 *     unsigned int *length) nogil: # cannot_raise
 */

static  unsigned char *__pyx_f_6bzrlib_18_groupcompress_pyx__decode_copy_instruction(unsigned char *__pyx_v_bytes, unsigned char __pyx_v_cmd, unsigned int *__pyx_v_offset, unsigned int *__pyx_v_length) {
  unsigned int __pyx_v_off;
  unsigned int __pyx_v_size;
  unsigned int __pyx_v_count;
  unsigned char *__pyx_r;
  long __pyx_t_1;
  int __pyx_t_2;

  /* "bzrlib/_groupcompress_pyx.pyx":415
 *     """
 *     cdef unsigned int off, size, count
 *     off = 0             # <<<<<<<<<<<<<<
 *     size = 0
 *     count = 0
 */
  __pyx_v_off = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":416
 *     cdef unsigned int off, size, count
 *     off = 0
 *     size = 0             # <<<<<<<<<<<<<<
 *     count = 0
 *     if (cmd & 0x01):
 */
  __pyx_v_size = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":417
 *     off = 0
 *     size = 0
 *     count = 0             # <<<<<<<<<<<<<<
 *     if (cmd & 0x01):
 *         off = bytes[count]
 */
  __pyx_v_count = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":418
 *     size = 0
 *     count = 0
 *     if (cmd & 0x01):             # <<<<<<<<<<<<<<
 *         off = bytes[count]
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x01);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":419
 *     count = 0
 *     if (cmd & 0x01):
 *         off = bytes[count]             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (cmd & 0x02):
 */
    __pyx_v_off = (__pyx_v_bytes[__pyx_v_count]);

    /* "bzrlib/_groupcompress_pyx.pyx":420
 *     if (cmd & 0x01):
 *         off = bytes[count]
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (cmd & 0x02):
 *         off = off | (bytes[count] << 8)
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "bzrlib/_groupcompress_pyx.pyx":421
 *         off = bytes[count]
 *         count = count + 1
 *     if (cmd & 0x02):             # <<<<<<<<<<<<<<
 *         off = off | (bytes[count] << 8)
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x02);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":422
 *         count = count + 1
 *     if (cmd & 0x02):
 *         off = off | (bytes[count] << 8)             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (cmd & 0x04):
 */
    __pyx_v_off = (__pyx_v_off | ((__pyx_v_bytes[__pyx_v_count]) << 8));

    /* "bzrlib/_groupcompress_pyx.pyx":423
 *     if (cmd & 0x02):
 *         off = off | (bytes[count] << 8)
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (cmd & 0x04):
 *         off = off | (bytes[count] << 16)
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "bzrlib/_groupcompress_pyx.pyx":424
 *         off = off | (bytes[count] << 8)
 *         count = count + 1
 *     if (cmd & 0x04):             # <<<<<<<<<<<<<<
 *         off = off | (bytes[count] << 16)
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x04);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":425
 *         count = count + 1
 *     if (cmd & 0x04):
 *         off = off | (bytes[count] << 16)             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (cmd & 0x08):
 */
    __pyx_v_off = (__pyx_v_off | ((__pyx_v_bytes[__pyx_v_count]) << 16));

    /* "bzrlib/_groupcompress_pyx.pyx":426
 *     if (cmd & 0x04):
 *         off = off | (bytes[count] << 16)
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (cmd & 0x08):
 *         off = off | (bytes[count] << 24)
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_groupcompress_pyx.pyx":427
 *         off = off | (bytes[count] << 16)
 *         count = count + 1
 *     if (cmd & 0x08):             # <<<<<<<<<<<<<<
 *         off = off | (bytes[count] << 24)
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x08);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":428
 *         count = count + 1
 *     if (cmd & 0x08):
 *         off = off | (bytes[count] << 24)             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (cmd & 0x10):
 */
    __pyx_v_off = (__pyx_v_off | ((__pyx_v_bytes[__pyx_v_count]) << 24));

    /* "bzrlib/_groupcompress_pyx.pyx":429
 *     if (cmd & 0x08):
 *         off = off | (bytes[count] << 24)
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (cmd & 0x10):
 *         size = bytes[count]
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":430
 *         off = off | (bytes[count] << 24)
 *         count = count + 1
 *     if (cmd & 0x10):             # <<<<<<<<<<<<<<
 *         size = bytes[count]
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x10);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":431
 *         count = count + 1
 *     if (cmd & 0x10):
 *         size = bytes[count]             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (cmd & 0x20):
 */
    __pyx_v_size = (__pyx_v_bytes[__pyx_v_count]);

    /* "bzrlib/_groupcompress_pyx.pyx":432
 *     if (cmd & 0x10):
 *         size = bytes[count]
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (cmd & 0x20):
 *         size = size | (bytes[count] << 8)
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":433
 *         size = bytes[count]
 *         count = count + 1
 *     if (cmd & 0x20):             # <<<<<<<<<<<<<<
 *         size = size | (bytes[count] << 8)
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x20);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":434
 *         count = count + 1
 *     if (cmd & 0x20):
 *         size = size | (bytes[count] << 8)             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (cmd & 0x40):
 */
    __pyx_v_size = (__pyx_v_size | ((__pyx_v_bytes[__pyx_v_count]) << 8));

    /* "bzrlib/_groupcompress_pyx.pyx":435
 *     if (cmd & 0x20):
 *         size = size | (bytes[count] << 8)
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (cmd & 0x40):
 *         size = size | (bytes[count] << 16)
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_groupcompress_pyx.pyx":436
 *         size = size | (bytes[count] << 8)
 *         count = count + 1
 *     if (cmd & 0x40):             # <<<<<<<<<<<<<<
 *         size = size | (bytes[count] << 16)
 *         count = count + 1
 */
  __pyx_t_1 = (__pyx_v_cmd & 0x40);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":437
 *         count = count + 1
 *     if (cmd & 0x40):
 *         size = size | (bytes[count] << 16)             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if (size == 0):
 */
    __pyx_v_size = (__pyx_v_size | ((__pyx_v_bytes[__pyx_v_count]) << 16));

    /* "bzrlib/_groupcompress_pyx.pyx":438
 *     if (cmd & 0x40):
 *         size = size | (bytes[count] << 16)
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if (size == 0):
 *         size = 0x10000
 */
    __pyx_v_count = (__pyx_v_count + 1);
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "bzrlib/_groupcompress_pyx.pyx":439
 *         size = size | (bytes[count] << 16)
 *         count = count + 1
 *     if (size == 0):             # <<<<<<<<<<<<<<
 *         size = 0x10000
 *     offset[0] = off
 */
  __pyx_t_2 = (__pyx_v_size == 0);
  if (__pyx_t_2) {

    /* "bzrlib/_groupcompress_pyx.pyx":440
 *         count = count + 1
 *     if (size == 0):
 *         size = 0x10000             # <<<<<<<<<<<<<<
 *     offset[0] = off
 *     length[0] = size
 */
    __pyx_v_size = 0x10000;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "bzrlib/_groupcompress_pyx.pyx":441
 *     if (size == 0):
 *         size = 0x10000
 *     offset[0] = off             # <<<<<<<<<<<<<<
 *     length[0] = size
 *     return bytes + count
 */
  (__pyx_v_offset[0]) = __pyx_v_off;

  /* "bzrlib/_groupcompress_pyx.pyx":442
 *         size = 0x10000
 *     offset[0] = off
 *     length[0] = size             # <<<<<<<<<<<<<<
 *     return bytes + count
 * 
 */
  (__pyx_v_length[0]) = __pyx_v_size;

  /* "bzrlib/_groupcompress_pyx.pyx":443
 *     offset[0] = off
 *     length[0] = size
 *     return bytes + count             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = (__pyx_v_bytes + __pyx_v_count);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":446
 * 
 * 
 * cdef object _apply_delta(char *source, Py_ssize_t source_size,             # <<<<<<<<<<<<<<
 *                          char *delta, Py_ssize_t delta_size):
 *     """common functionality between apply_delta and apply_delta_to_source."""
 */

static  PyObject *__pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(char *__pyx_v_source, Py_ssize_t __pyx_v_source_size, char *__pyx_v_delta, Py_ssize_t __pyx_v_delta_size) {
  unsigned char *__pyx_v_data;
  unsigned char *__pyx_v_top;
  unsigned char *__pyx_v_dst_buf;
  unsigned char *__pyx_v_out;
  unsigned char __pyx_v_cmd;
  Py_ssize_t __pyx_v_size;
  unsigned int __pyx_v_cp_off;
  unsigned int __pyx_v_cp_size;
  int __pyx_v_failed;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  long __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_RefNannySetupContext("_apply_delta");
  __pyx_v_result = Py_None; __Pyx_INCREF(Py_None);

  /* "bzrlib/_groupcompress_pyx.pyx":455
 *     cdef int failed
 * 
 *     data = <unsigned char *>delta             # <<<<<<<<<<<<<<
 *     top = data + delta_size
 * 
 */
  __pyx_v_data = ((unsigned char *)__pyx_v_delta);

  /* "bzrlib/_groupcompress_pyx.pyx":456
 * 
 *     data = <unsigned char *>delta
 *     top = data + delta_size             # <<<<<<<<<<<<<<
 * 
 *     # now the result size
 */
  __pyx_v_top = (__pyx_v_data + __pyx_v_delta_size);

  /* "bzrlib/_groupcompress_pyx.pyx":459
 * 
 *     # now the result size
 *     size = get_delta_hdr_size(&data, top)             # <<<<<<<<<<<<<<
 *     result = PyString_FromStringAndSize(NULL, size)
 *     dst_buf = <unsigned char*>PyString_AS_STRING(result)
 */
  __pyx_v_size = get_delta_hdr_size((&__pyx_v_data), __pyx_v_top);

  /* "bzrlib/_groupcompress_pyx.pyx":460
 *     # now the result size
 *     size = get_delta_hdr_size(&data, top)
 *     result = PyString_FromStringAndSize(NULL, size)             # <<<<<<<<<<<<<<
 *     dst_buf = <unsigned char*>PyString_AS_STRING(result)
 * 
 */
  __pyx_t_1 = PyString_FromStringAndSize(NULL, __pyx_v_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":461
 *     size = get_delta_hdr_size(&data, top)
 *     result = PyString_FromStringAndSize(NULL, size)
 *     dst_buf = <unsigned char*>PyString_AS_STRING(result)             # <<<<<<<<<<<<<<
 * 
 *     failed = 0
 */
  __pyx_v_dst_buf = ((unsigned char *)PyString_AS_STRING(__pyx_v_result));

  /* "bzrlib/_groupcompress_pyx.pyx":463
 *     dst_buf = <unsigned char*>PyString_AS_STRING(result)
 * 
 *     failed = 0             # <<<<<<<<<<<<<<
 *     with nogil:
 *         out = dst_buf
 */
  __pyx_v_failed = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":464
 * 
 *     failed = 0
 *     with nogil:             # <<<<<<<<<<<<<<
 *         out = dst_buf
 *         while (data < top):
 */
  {
    #ifdef WITH_THREAD
    PyThreadState *_save;
    #endif
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "bzrlib/_groupcompress_pyx.pyx":465
 *     failed = 0
 *     with nogil:
 *         out = dst_buf             # <<<<<<<<<<<<<<
 *         while (data < top):
 *             cmd = data[0]
 */
      __pyx_v_out = __pyx_v_dst_buf;

      /* "bzrlib/_groupcompress_pyx.pyx":466
 *     with nogil:
 *         out = dst_buf
 *         while (data < top):             # <<<<<<<<<<<<<<
 *             cmd = data[0]
 *             data = data + 1
 */
      while (1) {
        __pyx_t_2 = (__pyx_v_data < __pyx_v_top);
        if (!__pyx_t_2) break;

        /* "bzrlib/_groupcompress_pyx.pyx":467
 *         out = dst_buf
 *         while (data < top):
 *             cmd = data[0]             # <<<<<<<<<<<<<<
 *             data = data + 1
 *             if (cmd & 0x80):
 */
        __pyx_v_cmd = (__pyx_v_data[0]);

        /* "bzrlib/_groupcompress_pyx.pyx":468
 *         while (data < top):
 *             cmd = data[0]
 *             data = data + 1             # <<<<<<<<<<<<<<
 *             if (cmd & 0x80):
 *                 # Copy instruction
 */
        __pyx_v_data = (__pyx_v_data + 1);

        /* "bzrlib/_groupcompress_pyx.pyx":469
 *             cmd = data[0]
 *             data = data + 1
 *             if (cmd & 0x80):             # <<<<<<<<<<<<<<
 *                 # Copy instruction
 *                 data = _decode_copy_instruction(data, cmd, &cp_off, &cp_size)
 */
        __pyx_t_3 = (__pyx_v_cmd & 0x80);
        if (__pyx_t_3) {

          /* "bzrlib/_groupcompress_pyx.pyx":471
 *             if (cmd & 0x80):
 *                 # Copy instruction
 *                 data = _decode_copy_instruction(data, cmd, &cp_off, &cp_size)             # <<<<<<<<<<<<<<
 *                 if (cp_off + cp_size < cp_size or
 *                     cp_off + cp_size > <unsigned int>source_size or
 */
          __pyx_v_data = __pyx_f_6bzrlib_18_groupcompress_pyx__decode_copy_instruction(__pyx_v_data, __pyx_v_cmd, (&__pyx_v_cp_off), (&__pyx_v_cp_size));

          /* "bzrlib/_groupcompress_pyx.pyx":472
 *                 # Copy instruction
 *                 data = _decode_copy_instruction(data, cmd, &cp_off, &cp_size)
 *                 if (cp_off + cp_size < cp_size or             # <<<<<<<<<<<<<<
 *                     cp_off + cp_size > <unsigned int>source_size or
 *                     cp_size > <unsigned int>size):
 */
          __pyx_t_2 = ((__pyx_v_cp_off + __pyx_v_cp_size) < __pyx_v_cp_size);
          if (!__pyx_t_2) {

            /* "bzrlib/_groupcompress_pyx.pyx":473
 *                 data = _decode_copy_instruction(data, cmd, &cp_off, &cp_size)
 *                 if (cp_off + cp_size < cp_size or
 *                     cp_off + cp_size > <unsigned int>source_size or             # <<<<<<<<<<<<<<
 *                     cp_size > <unsigned int>size):
 *                     failed = 1
 */
            __pyx_t_4 = ((__pyx_v_cp_off + __pyx_v_cp_size) > ((unsigned int)__pyx_v_source_size));
            if (!__pyx_t_4) {

              /* "bzrlib/_groupcompress_pyx.pyx":474
 *                 if (cp_off + cp_size < cp_size or
 *                     cp_off + cp_size > <unsigned int>source_size or
 *                     cp_size > <unsigned int>size):             # <<<<<<<<<<<<<<
 *                     failed = 1
 *                     break
 */
              __pyx_t_5 = (__pyx_v_cp_size > ((unsigned int)__pyx_v_size));
              __pyx_t_6 = __pyx_t_5;
            } else {
              __pyx_t_6 = __pyx_t_4;
            }
            __pyx_t_4 = __pyx_t_6;
          } else {
            __pyx_t_4 = __pyx_t_2;
          }
          if (__pyx_t_4) {

            /* "bzrlib/_groupcompress_pyx.pyx":475
 *                     cp_off + cp_size > <unsigned int>source_size or
 *                     cp_size > <unsigned int>size):
 *                     failed = 1             # <<<<<<<<<<<<<<
 *                     break
 *                 memcpy(out, source + cp_off, cp_size)
 */
            __pyx_v_failed = 1;

            /* "bzrlib/_groupcompress_pyx.pyx":476
 *                     cp_size > <unsigned int>size):
 *                     failed = 1
 *                     break             # <<<<<<<<<<<<<<
 *                 memcpy(out, source + cp_off, cp_size)
 *                 out = out + cp_size
 */
            goto __pyx_L7_break;
            goto __pyx_L9;
          }
          __pyx_L9:;

          /* "bzrlib/_groupcompress_pyx.pyx":477
 *                     failed = 1
 *                     break
 *                 memcpy(out, source + cp_off, cp_size)             # <<<<<<<<<<<<<<
 *                 out = out + cp_size
 *                 size = size - cp_size
 */
          memcpy(__pyx_v_out, (__pyx_v_source + __pyx_v_cp_off), __pyx_v_cp_size);

          /* "bzrlib/_groupcompress_pyx.pyx":478
 *                     break
 *                 memcpy(out, source + cp_off, cp_size)
 *                 out = out + cp_size             # <<<<<<<<<<<<<<
 *                 size = size - cp_size
 *             else:
 */
          __pyx_v_out = (__pyx_v_out + __pyx_v_cp_size);

          /* "bzrlib/_groupcompress_pyx.pyx":479
 *                 memcpy(out, source + cp_off, cp_size)
 *                 out = out + cp_size
 *                 size = size - cp_size             # <<<<<<<<<<<<<<
 *             else:
 *                 # Insert instruction
 */
          __pyx_v_size = (__pyx_v_size - __pyx_v_cp_size);
          goto __pyx_L8;
        }
        /*else*/ {

          /* "bzrlib/_groupcompress_pyx.pyx":482
 *             else:
 *                 # Insert instruction
 *                 if cmd == 0:             # <<<<<<<<<<<<<<
 *                     # cmd == 0 is reserved for future encoding
 *                     # extensions. In the mean time we must fail when
 */
          __pyx_t_4 = (__pyx_v_cmd == 0);
          if (__pyx_t_4) {

            /* "bzrlib/_groupcompress_pyx.pyx":486
 *                     # extensions. In the mean time we must fail when
 *                     # encountering them (might be data corruption).
 *                     failed = 2             # <<<<<<<<<<<<<<
 *                     break
 *                 if cmd > size:
 */
            __pyx_v_failed = 2;

            /* "bzrlib/_groupcompress_pyx.pyx":487
 *                     # encountering them (might be data corruption).
 *                     failed = 2
 *                     break             # <<<<<<<<<<<<<<
 *                 if cmd > size:
 *                     failed = 3
 */
            goto __pyx_L7_break;
            goto __pyx_L10;
          }
          __pyx_L10:;

          /* "bzrlib/_groupcompress_pyx.pyx":488
 *                     failed = 2
 *                     break
 *                 if cmd > size:             # <<<<<<<<<<<<<<
 *                     failed = 3
 *                     break
 */
          __pyx_t_4 = (__pyx_v_cmd > __pyx_v_size);
          if (__pyx_t_4) {

            /* "bzrlib/_groupcompress_pyx.pyx":489
 *                     break
 *                 if cmd > size:
 *                     failed = 3             # <<<<<<<<<<<<<<
 *                     break
 *                 memcpy(out, data, cmd)
 */
            __pyx_v_failed = 3;

            /* "bzrlib/_groupcompress_pyx.pyx":490
 *                 if cmd > size:
 *                     failed = 3
 *                     break             # <<<<<<<<<<<<<<
 *                 memcpy(out, data, cmd)
 *                 out = out + cmd
 */
            goto __pyx_L7_break;
            goto __pyx_L11;
          }
          __pyx_L11:;

          /* "bzrlib/_groupcompress_pyx.pyx":491
 *                     failed = 3
 *                     break
 *                 memcpy(out, data, cmd)             # <<<<<<<<<<<<<<
 *                 out = out + cmd
 *                 data = data + cmd
 */
          memcpy(__pyx_v_out, __pyx_v_data, __pyx_v_cmd);

          /* "bzrlib/_groupcompress_pyx.pyx":492
 *                     break
 *                 memcpy(out, data, cmd)
 *                 out = out + cmd             # <<<<<<<<<<<<<<
 *                 data = data + cmd
 *                 size = size - cmd
 */
          __pyx_v_out = (__pyx_v_out + __pyx_v_cmd);

          /* "bzrlib/_groupcompress_pyx.pyx":493
 *                 memcpy(out, data, cmd)
 *                 out = out + cmd
 *                 data = data + cmd             # <<<<<<<<<<<<<<
 *                 size = size - cmd
 *     if failed:
 */
          __pyx_v_data = (__pyx_v_data + __pyx_v_cmd);

          /* "bzrlib/_groupcompress_pyx.pyx":494
 *                 out = out + cmd
 *                 data = data + cmd
 *                 size = size - cmd             # <<<<<<<<<<<<<<
 *     if failed:
 *         if failed == 1:
 */
          __pyx_v_size = (__pyx_v_size - __pyx_v_cmd);
        }
        __pyx_L8:;
      }
      __pyx_L7_break:;
    }

    /* "bzrlib/_groupcompress_pyx.pyx":464
 * 
 *     failed = 0
 *     with nogil:             # <<<<<<<<<<<<<<
 *         out = dst_buf
 *         while (data < top):
 */
    /*finally:*/ {
      Py_BLOCK_THREADS
    }
  }

  /* "bzrlib/_groupcompress_pyx.pyx":495
 *                 data = data + cmd
 *                 size = size - cmd
 *     if failed:             # <<<<<<<<<<<<<<
 *         if failed == 1:
 *             raise ValueError('Something wrong with:'
 */
  if (__pyx_v_failed) {

    /* "bzrlib/_groupcompress_pyx.pyx":503
 *         elif failed == 2:
 *             raise ValueError('Got delta opcode: 0, not supported')
 *         elif failed == 3:             # <<<<<<<<<<<<<<
 *             raise ValueError('Insert instruction longer than remaining'
 *                 ' bytes: %d > %d' % (cmd, size))
 */
    switch (__pyx_v_failed) {

      /* "bzrlib/_groupcompress_pyx.pyx":496
 *                 size = size - cmd
 *     if failed:
 *         if failed == 1:             # <<<<<<<<<<<<<<
 *             raise ValueError('Something wrong with:'
 *                 ' cp_off = %s, cp_size = %s'
 */
      case 1:

      /* "bzrlib/_groupcompress_pyx.pyx":500
 *                 ' cp_off = %s, cp_size = %s'
 *                 ' source_size = %s, size = %s'
 *                 % (cp_off, cp_size, source_size, size))             # <<<<<<<<<<<<<<
 *         elif failed == 2:
 *             raise ValueError('Got delta opcode: 0, not supported')
 */
      __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_cp_off); 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_t_7 = PyLong_FromUnsignedLong(__pyx_v_cp_size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PyInt_FromSsize_t(__pyx_v_source_size); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_10));
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      __pyx_t_1 = 0;
      __pyx_t_7 = 0;
      __pyx_t_8 = 0;
      __pyx_t_9 = 0;
      __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_33), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_9));
      __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
      __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_10));
      PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
      __pyx_t_9 = 0;
      __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
      __Pyx_Raise(__pyx_t_9, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;

      /* "bzrlib/_groupcompress_pyx.pyx":501
 *                 ' source_size = %s, size = %s'
 *                 % (cp_off, cp_size, source_size, size))
 *         elif failed == 2:             # <<<<<<<<<<<<<<
 *             raise ValueError('Got delta opcode: 0, not supported')
 *         elif failed == 3:
 */
      case 2:

      /* "bzrlib/_groupcompress_pyx.pyx":502
 *                 % (cp_off, cp_size, source_size, size))
 *         elif failed == 2:
 *             raise ValueError('Got delta opcode: 0, not supported')             # <<<<<<<<<<<<<<
 *         elif failed == 3:
 *             raise ValueError('Insert instruction longer than remaining'
 */
      __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_Raise(__pyx_t_9, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;

      /* "bzrlib/_groupcompress_pyx.pyx":503
 *         elif failed == 2:
 *             raise ValueError('Got delta opcode: 0, not supported')
 *         elif failed == 3:             # <<<<<<<<<<<<<<
 *             raise ValueError('Insert instruction longer than remaining'
 *                 ' bytes: %d > %d' % (cmd, size))
 */
      case 3:

      /* "bzrlib/_groupcompress_pyx.pyx":505
 *         elif failed == 3:
 *             raise ValueError('Insert instruction longer than remaining'
 *                 ' bytes: %d > %d' % (cmd, size))             # <<<<<<<<<<<<<<
 * 
 *     # sanity check
 */
      __pyx_t_9 = PyInt_FromLong(__pyx_v_cmd); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      __pyx_t_9 = 0;
      __pyx_t_10 = 0;
      __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_36), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_10));
      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_10));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
      __pyx_t_10 = 0;
      __pyx_t_10 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
      __Pyx_Raise(__pyx_t_10, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;
    }
    goto __pyx_L12;
  }
  __pyx_L12:;

  /* "bzrlib/_groupcompress_pyx.pyx":508
 * 
 *     # sanity check
 *     if (data != top or size != 0):             # <<<<<<<<<<<<<<
 *         raise RuntimeError('Did not extract the number of bytes we expected'
 *             ' we were left with %d bytes in "size", and top - data = %d'
 */
  __pyx_t_4 = (__pyx_v_data != __pyx_v_top);
  if (!__pyx_t_4) {
    __pyx_t_2 = (__pyx_v_size != 0);
    __pyx_t_6 = __pyx_t_2;
  } else {
    __pyx_t_6 = __pyx_t_4;
  }
  if (__pyx_t_6) {

    /* "bzrlib/_groupcompress_pyx.pyx":511
 *         raise RuntimeError('Did not extract the number of bytes we expected'
 *             ' we were left with %d bytes in "size", and top - data = %d'
 *             % (size, <int>(top - data)))             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
    __pyx_t_10 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_8 = PyInt_FromLong((__pyx_v_top - __pyx_v_data)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_10 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_37), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
    __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __Pyx_Raise(__pyx_t_8, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "bzrlib/_groupcompress_pyx.pyx":512
 *             ' we were left with %d bytes in "size", and top - data = %d'
 *             % (size, <int>(top - data)))
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     # *dst_size = out - dst_buf;
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "bzrlib/_groupcompress_pyx.pyx":515
 * 
 *     # *dst_size = out - dst_buf;
 *     if (out - dst_buf) != PyString_GET_SIZE(result):             # <<<<<<<<<<<<<<
 *         raise RuntimeError('Number of bytes extracted did not match the'
 *             ' size encoded in the delta header.')
 */
  __pyx_t_6 = ((__pyx_v_out - __pyx_v_dst_buf) != PyString_GET_SIZE(__pyx_v_result));
  if (__pyx_t_6) {

    /* "bzrlib/_groupcompress_pyx.pyx":516
 *     # *dst_size = out - dst_buf;
 *     if (out - dst_buf) != PyString_GET_SIZE(result):
 *         raise RuntimeError('Number of bytes extracted did not match the'             # <<<<<<<<<<<<<<
 *             ' size encoded in the delta header.')
 *     return result
 */
    __pyx_t_8 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_Raise(__pyx_t_8, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "bzrlib/_groupcompress_pyx.pyx":518
 *         raise RuntimeError('Number of bytes extracted did not match the'
 *             ' size encoded in the delta header.')
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx._apply_delta");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":521
 * 
 * 
 * def apply_delta_to_source(source, delta_start, delta_end):             # <<<<<<<<<<<<<<
 *     """Extract a delta from source bytes, and apply it."""
 *     cdef char *c_source
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source[] = "Extract a delta from source bytes, and apply it.";
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source = {__Pyx_NAMESTR("apply_delta_to_source"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_source = 0;
  PyObject *__pyx_v_delta_start = 0;
  PyObject *__pyx_v_delta_end = 0;
  char *__pyx_v_c_source;
  Py_ssize_t __pyx_v_c_source_size;
  char *__pyx_v_c_delta;
  Py_ssize_t __pyx_v_c_delta_size;
  Py_ssize_t __pyx_v_c_delta_start;
  Py_ssize_t __pyx_v_c_delta_end;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__source,&__pyx_n_s__delta_start,&__pyx_n_s__delta_end,0};
  __Pyx_RefNannySetupContext("apply_delta_to_source");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      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;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__source);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__delta_start);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("apply_delta_to_source", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__delta_end);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("apply_delta_to_source", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "apply_delta_to_source") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_source = values[0];
    __pyx_v_delta_start = values[1];
    __pyx_v_delta_end = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_source = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_delta_start = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_delta_end = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("apply_delta_to_source", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.apply_delta_to_source");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bzrlib/_groupcompress_pyx.pyx":529
 *     cdef Py_ssize_t c_delta_start, c_delta_end
 * 
 *     if not PyString_CheckExact(source):             # <<<<<<<<<<<<<<
 *         raise TypeError('source is not a str')
 *     c_source_size = PyString_GET_SIZE(source)
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_source));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":530
 * 
 *     if not PyString_CheckExact(source):
 *         raise TypeError('source is not a str')             # <<<<<<<<<<<<<<
 *     c_source_size = PyString_GET_SIZE(source)
 *     c_delta_start = delta_start
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bzrlib/_groupcompress_pyx.pyx":531
 *     if not PyString_CheckExact(source):
 *         raise TypeError('source is not a str')
 *     c_source_size = PyString_GET_SIZE(source)             # <<<<<<<<<<<<<<
 *     c_delta_start = delta_start
 *     c_delta_end = delta_end
 */
  __pyx_v_c_source_size = PyString_GET_SIZE(__pyx_v_source);

  /* "bzrlib/_groupcompress_pyx.pyx":532
 *         raise TypeError('source is not a str')
 *     c_source_size = PyString_GET_SIZE(source)
 *     c_delta_start = delta_start             # <<<<<<<<<<<<<<
 *     c_delta_end = delta_end
 *     if c_delta_start >= c_source_size:
 */
  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_delta_start); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_c_delta_start = __pyx_t_3;

  /* "bzrlib/_groupcompress_pyx.pyx":533
 *     c_source_size = PyString_GET_SIZE(source)
 *     c_delta_start = delta_start
 *     c_delta_end = delta_end             # <<<<<<<<<<<<<<
 *     if c_delta_start >= c_source_size:
 *         raise ValueError('delta starts after source')
 */
  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_delta_end); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_c_delta_end = __pyx_t_3;

  /* "bzrlib/_groupcompress_pyx.pyx":534
 *     c_delta_start = delta_start
 *     c_delta_end = delta_end
 *     if c_delta_start >= c_source_size:             # <<<<<<<<<<<<<<
 *         raise ValueError('delta starts after source')
 *     if c_delta_end > c_source_size:
 */
  __pyx_t_1 = (__pyx_v_c_delta_start >= __pyx_v_c_source_size);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":535
 *     c_delta_end = delta_end
 *     if c_delta_start >= c_source_size:
 *         raise ValueError('delta starts after source')             # <<<<<<<<<<<<<<
 *     if c_delta_end > c_source_size:
 *         raise ValueError('delta ends after source')
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":536
 *     if c_delta_start >= c_source_size:
 *         raise ValueError('delta starts after source')
 *     if c_delta_end > c_source_size:             # <<<<<<<<<<<<<<
 *         raise ValueError('delta ends after source')
 *     if c_delta_start >= c_delta_end:
 */
  __pyx_t_1 = (__pyx_v_c_delta_end > __pyx_v_c_source_size);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":537
 *         raise ValueError('delta starts after source')
 *     if c_delta_end > c_source_size:
 *         raise ValueError('delta ends after source')             # <<<<<<<<<<<<<<
 *     if c_delta_start >= c_delta_end:
 *         raise ValueError('delta starts after it ends')
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_groupcompress_pyx.pyx":538
 *     if c_delta_end > c_source_size:
 *         raise ValueError('delta ends after source')
 *     if c_delta_start >= c_delta_end:             # <<<<<<<<<<<<<<
 *         raise ValueError('delta starts after it ends')
 * 
 */
  __pyx_t_1 = (__pyx_v_c_delta_start >= __pyx_v_c_delta_end);
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":539
 *         raise ValueError('delta ends after source')
 *     if c_delta_start >= c_delta_end:
 *         raise ValueError('delta starts after it ends')             # <<<<<<<<<<<<<<
 * 
 *     c_delta_size = c_delta_end - c_delta_start
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "bzrlib/_groupcompress_pyx.pyx":541
 *         raise ValueError('delta starts after it ends')
 * 
 *     c_delta_size = c_delta_end - c_delta_start             # <<<<<<<<<<<<<<
 *     c_source = PyString_AS_STRING(source)
 *     c_delta = c_source + c_delta_start
 */
  __pyx_v_c_delta_size = (__pyx_v_c_delta_end - __pyx_v_c_delta_start);

  /* "bzrlib/_groupcompress_pyx.pyx":542
 * 
 *     c_delta_size = c_delta_end - c_delta_start
 *     c_source = PyString_AS_STRING(source)             # <<<<<<<<<<<<<<
 *     c_delta = c_source + c_delta_start
 *     # We don't use source_size, because we know the delta should not refer to
 */
  __pyx_v_c_source = PyString_AS_STRING(__pyx_v_source);

  /* "bzrlib/_groupcompress_pyx.pyx":543
 *     c_delta_size = c_delta_end - c_delta_start
 *     c_source = PyString_AS_STRING(source)
 *     c_delta = c_source + c_delta_start             # <<<<<<<<<<<<<<
 *     # We don't use source_size, because we know the delta should not refer to
 *     # any bytes after it starts
 */
  __pyx_v_c_delta = (__pyx_v_c_source + __pyx_v_c_delta_start);

  /* "bzrlib/_groupcompress_pyx.pyx":546
 *     # We don't use source_size, because we know the delta should not refer to
 *     # any bytes after it starts
 *     return _apply_delta(c_source, c_delta_start, c_delta, c_delta_size)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_6bzrlib_18_groupcompress_pyx__apply_delta(__pyx_v_c_source, __pyx_v_c_delta_start, __pyx_v_c_delta, __pyx_v_c_delta_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.apply_delta_to_source");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":549
 * 
 * 
 * def encode_base128_int(val):             # <<<<<<<<<<<<<<
 *     """Convert an integer into a 7-bit lsb encoding."""
 *     cdef unsigned int c_val
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_5encode_base128_int(PyObject *__pyx_self, PyObject *__pyx_v_val); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_5encode_base128_int[] = "Convert an integer into a 7-bit lsb encoding.";
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_5encode_base128_int = {__Pyx_NAMESTR("encode_base128_int"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_5encode_base128_int, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_5encode_base128_int)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_5encode_base128_int(PyObject *__pyx_self, PyObject *__pyx_v_val) {
  unsigned int __pyx_v_c_val;
  Py_ssize_t __pyx_v_count;
  unsigned char __pyx_v_c_bytes[8];
  PyObject *__pyx_r = NULL;
  unsigned int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("encode_base128_int");
  __pyx_self = __pyx_self;

  /* "bzrlib/_groupcompress_pyx.pyx":556
 *     cdef unsigned char c_bytes[8] # max size for 32-bit int is 5 bytes
 * 
 *     c_val = val             # <<<<<<<<<<<<<<
 *     count = 0
 *     while c_val >= 0x80 and count < 8:
 */
  __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_val); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_c_val = __pyx_t_1;

  /* "bzrlib/_groupcompress_pyx.pyx":557
 * 
 *     c_val = val
 *     count = 0             # <<<<<<<<<<<<<<
 *     while c_val >= 0x80 and count < 8:
 *         c_bytes[count] = <unsigned char>((c_val | 0x80) & 0xFF)
 */
  __pyx_v_count = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":558
 *     c_val = val
 *     count = 0
 *     while c_val >= 0x80 and count < 8:             # <<<<<<<<<<<<<<
 *         c_bytes[count] = <unsigned char>((c_val | 0x80) & 0xFF)
 *         c_val = c_val >> 7
 */
  while (1) {
    __pyx_t_2 = (__pyx_v_c_val >= 0x80);
    if (__pyx_t_2) {
      __pyx_t_3 = (__pyx_v_count < 8);
      __pyx_t_4 = __pyx_t_3;
    } else {
      __pyx_t_4 = __pyx_t_2;
    }
    if (!__pyx_t_4) break;

    /* "bzrlib/_groupcompress_pyx.pyx":559
 *     count = 0
 *     while c_val >= 0x80 and count < 8:
 *         c_bytes[count] = <unsigned char>((c_val | 0x80) & 0xFF)             # <<<<<<<<<<<<<<
 *         c_val = c_val >> 7
 *         count = count + 1
 */
    (__pyx_v_c_bytes[__pyx_v_count]) = ((unsigned char)((__pyx_v_c_val | 0x80) & 0xFF));

    /* "bzrlib/_groupcompress_pyx.pyx":560
 *     while c_val >= 0x80 and count < 8:
 *         c_bytes[count] = <unsigned char>((c_val | 0x80) & 0xFF)
 *         c_val = c_val >> 7             # <<<<<<<<<<<<<<
 *         count = count + 1
 *     if count >= 8 or c_val >= 0x80:
 */
    __pyx_v_c_val = (__pyx_v_c_val >> 7);

    /* "bzrlib/_groupcompress_pyx.pyx":561
 *         c_bytes[count] = <unsigned char>((c_val | 0x80) & 0xFF)
 *         c_val = c_val >> 7
 *         count = count + 1             # <<<<<<<<<<<<<<
 *     if count >= 8 or c_val >= 0x80:
 *         raise ValueError('encode_base128_int overflowed the buffer')
 */
    __pyx_v_count = (__pyx_v_count + 1);
  }

  /* "bzrlib/_groupcompress_pyx.pyx":562
 *         c_val = c_val >> 7
 *         count = count + 1
 *     if count >= 8 or c_val >= 0x80:             # <<<<<<<<<<<<<<
 *         raise ValueError('encode_base128_int overflowed the buffer')
 *     c_bytes[count] = <unsigned char>(c_val & 0xFF)
 */
  __pyx_t_4 = (__pyx_v_count >= 8);
  if (!__pyx_t_4) {
    __pyx_t_2 = (__pyx_v_c_val >= 0x80);
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_4;
  }
  if (__pyx_t_3) {

    /* "bzrlib/_groupcompress_pyx.pyx":563
 *         count = count + 1
 *     if count >= 8 or c_val >= 0x80:
 *         raise ValueError('encode_base128_int overflowed the buffer')             # <<<<<<<<<<<<<<
 *     c_bytes[count] = <unsigned char>(c_val & 0xFF)
 *     count = count + 1
 */
    __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bzrlib/_groupcompress_pyx.pyx":564
 *     if count >= 8 or c_val >= 0x80:
 *         raise ValueError('encode_base128_int overflowed the buffer')
 *     c_bytes[count] = <unsigned char>(c_val & 0xFF)             # <<<<<<<<<<<<<<
 *     count = count + 1
 *     return PyString_FromStringAndSize(<char *>c_bytes, count)
 */
  (__pyx_v_c_bytes[__pyx_v_count]) = ((unsigned char)(__pyx_v_c_val & 0xFF));

  /* "bzrlib/_groupcompress_pyx.pyx":565
 *         raise ValueError('encode_base128_int overflowed the buffer')
 *     c_bytes[count] = <unsigned char>(c_val & 0xFF)
 *     count = count + 1             # <<<<<<<<<<<<<<
 *     return PyString_FromStringAndSize(<char *>c_bytes, count)
 * 
 */
  __pyx_v_count = (__pyx_v_count + 1);

  /* "bzrlib/_groupcompress_pyx.pyx":566
 *     c_bytes[count] = <unsigned char>(c_val & 0xFF)
 *     count = count + 1
 *     return PyString_FromStringAndSize(<char *>c_bytes, count)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyString_FromStringAndSize(((char *)__pyx_v_c_bytes), __pyx_v_count); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.encode_base128_int");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bzrlib/_groupcompress_pyx.pyx":569
 * 
 * 
 * def decode_base128_int(bytes):             # <<<<<<<<<<<<<<
 *     """Decode an integer from a 7-bit lsb encoding."""
 *     cdef int offset
 */

static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_6decode_base128_int(PyObject *__pyx_self, PyObject *__pyx_v_bytes); /*proto*/
static char __pyx_doc_6bzrlib_18_groupcompress_pyx_6decode_base128_int[] = "Decode an integer from a 7-bit lsb encoding.";
static PyMethodDef __pyx_mdef_6bzrlib_18_groupcompress_pyx_6decode_base128_int = {__Pyx_NAMESTR("decode_base128_int"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_6decode_base128_int, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_6decode_base128_int)};
static PyObject *__pyx_pf_6bzrlib_18_groupcompress_pyx_6decode_base128_int(PyObject *__pyx_self, PyObject *__pyx_v_bytes) {
  int __pyx_v_offset;
  int __pyx_v_val;
  unsigned int __pyx_v_uval;
  int __pyx_v_shift;
  Py_ssize_t __pyx_v_num_low_bytes;
  unsigned char *__pyx_v_c_bytes;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  long __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __Pyx_RefNannySetupContext("decode_base128_int");
  __pyx_self = __pyx_self;

  /* "bzrlib/_groupcompress_pyx.pyx":578
 *     cdef unsigned char *c_bytes
 * 
 *     offset = 0             # <<<<<<<<<<<<<<
 *     val = 0
 *     shift = 0
 */
  __pyx_v_offset = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":579
 * 
 *     offset = 0
 *     val = 0             # <<<<<<<<<<<<<<
 *     shift = 0
 *     if not PyString_CheckExact(bytes):
 */
  __pyx_v_val = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":580
 *     offset = 0
 *     val = 0
 *     shift = 0             # <<<<<<<<<<<<<<
 *     if not PyString_CheckExact(bytes):
 *         raise TypeError('bytes is not a string')
 */
  __pyx_v_shift = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":581
 *     val = 0
 *     shift = 0
 *     if not PyString_CheckExact(bytes):             # <<<<<<<<<<<<<<
 *         raise TypeError('bytes is not a string')
 *     c_bytes = <unsigned char*>PyString_AS_STRING(bytes)
 */
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_bytes));
  if (__pyx_t_1) {

    /* "bzrlib/_groupcompress_pyx.pyx":582
 *     shift = 0
 *     if not PyString_CheckExact(bytes):
 *         raise TypeError('bytes is not a string')             # <<<<<<<<<<<<<<
 *     c_bytes = <unsigned char*>PyString_AS_STRING(bytes)
 *     # We take off 1, because we have to be able to decode the non-expanded byte
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bzrlib/_groupcompress_pyx.pyx":583
 *     if not PyString_CheckExact(bytes):
 *         raise TypeError('bytes is not a string')
 *     c_bytes = <unsigned char*>PyString_AS_STRING(bytes)             # <<<<<<<<<<<<<<
 *     # We take off 1, because we have to be able to decode the non-expanded byte
 *     num_low_bytes = PyString_GET_SIZE(bytes) - 1
 */
  __pyx_v_c_bytes = ((unsigned char *)PyString_AS_STRING(__pyx_v_bytes));

  /* "bzrlib/_groupcompress_pyx.pyx":585
 *     c_bytes = <unsigned char*>PyString_AS_STRING(bytes)
 *     # We take off 1, because we have to be able to decode the non-expanded byte
 *     num_low_bytes = PyString_GET_SIZE(bytes) - 1             # <<<<<<<<<<<<<<
 *     while (c_bytes[offset] & 0x80) and offset < num_low_bytes:
 *         val = val | ((c_bytes[offset] & 0x7F) << shift)
 */
  __pyx_v_num_low_bytes = (PyString_GET_SIZE(__pyx_v_bytes) - 1);

  /* "bzrlib/_groupcompress_pyx.pyx":586
 *     # We take off 1, because we have to be able to decode the non-expanded byte
 *     num_low_bytes = PyString_GET_SIZE(bytes) - 1
 *     while (c_bytes[offset] & 0x80) and offset < num_low_bytes:             # <<<<<<<<<<<<<<
 *         val = val | ((c_bytes[offset] & 0x7F) << shift)
 *         shift = shift + 7
 */
  while (1) {
    if (((__pyx_v_c_bytes[__pyx_v_offset]) & 0x80)) {
      __pyx_t_1 = (__pyx_v_offset < __pyx_v_num_low_bytes);
      __pyx_t_3 = __pyx_t_1;
    } else {
      __pyx_t_3 = ((__pyx_v_c_bytes[__pyx_v_offset]) & 0x80);
    }
    if (!__pyx_t_3) break;

    /* "bzrlib/_groupcompress_pyx.pyx":587
 *     num_low_bytes = PyString_GET_SIZE(bytes) - 1
 *     while (c_bytes[offset] & 0x80) and offset < num_low_bytes:
 *         val = val | ((c_bytes[offset] & 0x7F) << shift)             # <<<<<<<<<<<<<<
 *         shift = shift + 7
 *         offset = offset + 1
 */
    __pyx_v_val = (__pyx_v_val | (((__pyx_v_c_bytes[__pyx_v_offset]) & 0x7F) << __pyx_v_shift));

    /* "bzrlib/_groupcompress_pyx.pyx":588
 *     while (c_bytes[offset] & 0x80) and offset < num_low_bytes:
 *         val = val | ((c_bytes[offset] & 0x7F) << shift)
 *         shift = shift + 7             # <<<<<<<<<<<<<<
 *         offset = offset + 1
 *     if c_bytes[offset] & 0x80:
 */
    __pyx_v_shift = (__pyx_v_shift + 7);

    /* "bzrlib/_groupcompress_pyx.pyx":589
 *         val = val | ((c_bytes[offset] & 0x7F) << shift)
 *         shift = shift + 7
 *         offset = offset + 1             # <<<<<<<<<<<<<<
 *     if c_bytes[offset] & 0x80:
 *         raise ValueError('Data not properly formatted, we ran out of'
 */
    __pyx_v_offset = (__pyx_v_offset + 1);
  }

  /* "bzrlib/_groupcompress_pyx.pyx":590
 *         shift = shift + 7
 *         offset = offset + 1
 *     if c_bytes[offset] & 0x80:             # <<<<<<<<<<<<<<
 *         raise ValueError('Data not properly formatted, we ran out of'
 *                          ' bytes before 0x80 stopped being set.')
 */
  __pyx_t_4 = ((__pyx_v_c_bytes[__pyx_v_offset]) & 0x80);
  if (__pyx_t_4) {

    /* "bzrlib/_groupcompress_pyx.pyx":591
 *         offset = offset + 1
 *     if c_bytes[offset] & 0x80:
 *         raise ValueError('Data not properly formatted, we ran out of'             # <<<<<<<<<<<<<<
 *                          ' bytes before 0x80 stopped being set.')
 *     val = val | (c_bytes[offset] << shift)
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bzrlib/_groupcompress_pyx.pyx":593
 *         raise ValueError('Data not properly formatted, we ran out of'
 *                          ' bytes before 0x80 stopped being set.')
 *     val = val | (c_bytes[offset] << shift)             # <<<<<<<<<<<<<<
 *     offset = offset + 1
 *     if val < 0:
 */
  __pyx_v_val = (__pyx_v_val | ((__pyx_v_c_bytes[__pyx_v_offset]) << __pyx_v_shift));

  /* "bzrlib/_groupcompress_pyx.pyx":594
 *                          ' bytes before 0x80 stopped being set.')
 *     val = val | (c_bytes[offset] << shift)
 *     offset = offset + 1             # <<<<<<<<<<<<<<
 *     if val < 0:
 *         uval = <unsigned int> val
 */
  __pyx_v_offset = (__pyx_v_offset + 1);

  /* "bzrlib/_groupcompress_pyx.pyx":595
 *     val = val | (c_bytes[offset] << shift)
 *     offset = offset + 1
 *     if val < 0:             # <<<<<<<<<<<<<<
 *         uval = <unsigned int> val
 *         return uval, offset
 */
  __pyx_t_3 = (__pyx_v_val < 0);
  if (__pyx_t_3) {

    /* "bzrlib/_groupcompress_pyx.pyx":596
 *     offset = offset + 1
 *     if val < 0:
 *         uval = <unsigned int> val             # <<<<<<<<<<<<<<
 *         return uval, offset
 *     return val, offset
 */
    __pyx_v_uval = ((unsigned int)__pyx_v_val);

    /* "bzrlib/_groupcompress_pyx.pyx":597
 *     if val < 0:
 *         uval = <unsigned int> val
 *         return uval, offset             # <<<<<<<<<<<<<<
 *     return val, offset
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_uval); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyInt_FromLong(__pyx_v_offset); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_r = ((PyObject *)__pyx_t_6);
    __pyx_t_6 = 0;
    goto __pyx_L0;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "bzrlib/_groupcompress_pyx.pyx":598
 *         uval = <unsigned int> val
 *         return uval, offset
 *     return val, offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = PyInt_FromLong(__pyx_v_val); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyInt_FromLong(__pyx_v_offset); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_6 = 0;
  __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("bzrlib._groupcompress_pyx.decode_base128_int");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_6bzrlib_18_groupcompress_pyx_DeltaIndex __pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex;

static PyObject *__pyx_tp_new_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o);
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex;
  p->_sources = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyObject *o) {
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p = (struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_3__dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->_sources);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p = (struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o;
  if (p->_sources) {
    e = (*v)(p->_sources, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_18_groupcompress_pyx_DeltaIndex(PyObject *o) {
  struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *p = (struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->_sources);
  p->_sources = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__sources(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8_sources___get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__source_offset(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_14_source_offset___get__(o);
}

static int __pyx_setprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__source_offset(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_14_source_offset_1__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__max_num_sources(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_16_max_num_sources___get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__max_bytes_to_index(PyObject *o, void *x) {
  return __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_19_max_bytes_to_index___get__(o);
}

static int __pyx_setprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__max_bytes_to_index(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_19_max_bytes_to_index_1__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_6bzrlib_18_groupcompress_pyx_DeltaIndex[] = {
  {__Pyx_NAMESTR("__sizeof__"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_1__sizeof__, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("_has_index"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_4_has_index, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("_dump_index"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_5_dump_index, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_5_dump_index)},
  {__Pyx_NAMESTR("add_delta_source"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_6add_delta_source, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_6add_delta_source)},
  {__Pyx_NAMESTR("add_source"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_7add_source, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_7add_source)},
  {__Pyx_NAMESTR("make_delta"), (PyCFunction)__pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8make_delta, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_18_groupcompress_pyx_10DeltaIndex_8make_delta)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_18_groupcompress_pyx_DeltaIndex[] = {
  {(char *)"_sources", __pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__sources, 0, 0, 0},
  {(char *)"_source_offset", __pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__source_offset, __pyx_setprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__source_offset, 0, 0},
  {(char *)"_max_num_sources", __pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__max_num_sources, 0, 0, 0},
  {(char *)"_max_bytes_to_index", __pyx_getprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__max_bytes_to_index, __pyx_setprop_6bzrlib_18_groupcompress_pyx_10DeltaIndex__max_bytes_to_index, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_DeltaIndex = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_DeltaIndex = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_DeltaIndex = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_DeltaIndex = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("bzrlib._groupcompress_pyx.DeltaIndex"), /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex_2__repr__, /*tp_repr*/
  &__pyx_tp_as_number_DeltaIndex, /*tp_as_number*/
  &__pyx_tp_as_sequence_DeltaIndex, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_DeltaIndex, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_DeltaIndex, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_6bzrlib_18_groupcompress_pyx_10DeltaIndex___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_18_groupcompress_pyx_DeltaIndex, /*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*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_groupcompress_pyx"),
    __Pyx_DOCSTR(__pyx_k_53), /* 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_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
  {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
  {&__pyx_n_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 1},
  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
  {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
  {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0},
  {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
  {&__pyx_kp_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 0},
  {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0},
  {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
  {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
  {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0},
  {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0},
  {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0},
  {&__pyx_n_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 1},
  {&__pyx_n_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 1},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__AssertionError, __pyx_k__AssertionError, sizeof(__pyx_k__AssertionError), 0, 0, 1, 1},
  {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1},
  {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
  {&__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_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1},
  {&__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____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s___expand_sources, __pyx_k___expand_sources, sizeof(__pyx_k___expand_sources), 0, 0, 1, 1},
  {&__pyx_n_s___index, __pyx_k___index, sizeof(__pyx_k___index), 0, 0, 1, 1},
  {&__pyx_n_s___max_bytes_to_index, __pyx_k___max_bytes_to_index, sizeof(__pyx_k___max_bytes_to_index), 0, 0, 1, 1},
  {&__pyx_n_s___max_num_sources, __pyx_k___max_num_sources, sizeof(__pyx_k___max_num_sources), 0, 0, 1, 1},
  {&__pyx_n_s___rabin_hash, __pyx_k___rabin_hash, sizeof(__pyx_k___rabin_hash), 0, 0, 1, 1},
  {&__pyx_n_s___source_infos, __pyx_k___source_infos, sizeof(__pyx_k___source_infos), 0, 0, 1, 1},
  {&__pyx_n_s___source_offset, __pyx_k___source_offset, sizeof(__pyx_k___source_offset), 0, 0, 1, 1},
  {&__pyx_n_s___sources, __pyx_k___sources, sizeof(__pyx_k___sources), 0, 0, 1, 1},
  {&__pyx_n_s__add_source, __pyx_k__add_source, sizeof(__pyx_k__add_source), 0, 0, 1, 1},
  {&__pyx_n_s__agg_offset, __pyx_k__agg_offset, sizeof(__pyx_k__agg_offset), 0, 0, 1, 1},
  {&__pyx_n_s__append, __pyx_k__append, sizeof(__pyx_k__append), 0, 0, 1, 1},
  {&__pyx_n_s__apply_delta, __pyx_k__apply_delta, sizeof(__pyx_k__apply_delta), 0, 0, 1, 1},
  {&__pyx_n_s__buf, __pyx_k__buf, sizeof(__pyx_k__buf), 0, 0, 1, 1},
  {&__pyx_n_s__decode_base128_int, __pyx_k__decode_base128_int, sizeof(__pyx_k__decode_base128_int), 0, 0, 1, 1},
  {&__pyx_n_s__delta, __pyx_k__delta, sizeof(__pyx_k__delta), 0, 0, 1, 1},
  {&__pyx_n_s__delta_bytes, __pyx_k__delta_bytes, sizeof(__pyx_k__delta_bytes), 0, 0, 1, 1},
  {&__pyx_n_s__delta_end, __pyx_k__delta_end, sizeof(__pyx_k__delta_end), 0, 0, 1, 1},
  {&__pyx_n_s__delta_start, __pyx_k__delta_start, sizeof(__pyx_k__delta_start), 0, 0, 1, 1},
  {&__pyx_n_s__encode_base128_int, __pyx_k__encode_base128_int, sizeof(__pyx_k__encode_base128_int), 0, 0, 1, 1},
  {&__pyx_n_s__make_delta, __pyx_k__make_delta, sizeof(__pyx_k__make_delta), 0, 0, 1, 1},
  {&__pyx_n_s__make_delta_index, __pyx_k__make_delta_index, sizeof(__pyx_k__make_delta_index), 0, 0, 1, 1},
  {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1},
  {&__pyx_n_s__max_bytes_to_index, __pyx_k__max_bytes_to_index, sizeof(__pyx_k__max_bytes_to_index), 0, 0, 1, 1},
  {&__pyx_n_s__max_delta_size, __pyx_k__max_delta_size, sizeof(__pyx_k__max_delta_size), 0, 0, 1, 1},
  {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1},
  {&__pyx_n_s__source, __pyx_k__source, sizeof(__pyx_k__source), 0, 0, 1, 1},
  {&__pyx_n_s__source_bytes, __pyx_k__source_bytes, sizeof(__pyx_k__source_bytes), 0, 0, 1, 1},
  {&__pyx_n_s__target_bytes, __pyx_k__target_bytes, sizeof(__pyx_k__target_bytes), 0, 0, 1, 1},
  {&__pyx_n_s__unadded_bytes, __pyx_k__unadded_bytes, sizeof(__pyx_k__unadded_bytes), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_AssertionError = __Pyx_GetName(__pyx_b, __pyx_n_s__AssertionError); if (!__pyx_builtin_AssertionError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");

  /* "bzrlib/_groupcompress_pyx.pyx":109
 * cdef object _translate_delta_failure(delta_result result):
 *     if result == DELTA_OUT_OF_MEMORY:
 *         return MemoryError("Delta function failed to allocate memory")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_INDEX_NEEDED:
 *         return ValueError("Delta function requires delta_index param")
 */
  __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));

  /* "bzrlib/_groupcompress_pyx.pyx":111
 *         return MemoryError("Delta function failed to allocate memory")
 *     elif result == DELTA_INDEX_NEEDED:
 *         return ValueError("Delta function requires delta_index param")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_SOURCE_EMPTY:
 *         return ValueError("Delta function given empty source_info param")
 */
  __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
  PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_s_5));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_5));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));

  /* "bzrlib/_groupcompress_pyx.pyx":113
 *         return ValueError("Delta function requires delta_index param")
 *     elif result == DELTA_SOURCE_EMPTY:
 *         return ValueError("Delta function given empty source_info param")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_SOURCE_BAD:
 *         return RuntimeError("Delta function given invalid source_info param")
 */
  __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_8));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_7));
  PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));

  /* "bzrlib/_groupcompress_pyx.pyx":115
 *         return ValueError("Delta function given empty source_info param")
 *     elif result == DELTA_SOURCE_BAD:
 *         return RuntimeError("Delta function given invalid source_info param")             # <<<<<<<<<<<<<<
 *     elif result == DELTA_BUFFER_EMPTY:
 *         return ValueError("Delta function given empty buffer params")
 */
  __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
  PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_s_9));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));

  /* "bzrlib/_groupcompress_pyx.pyx":117
 *         return RuntimeError("Delta function given invalid source_info param")
 *     elif result == DELTA_BUFFER_EMPTY:
 *         return ValueError("Delta function given empty buffer params")             # <<<<<<<<<<<<<<
 *     return AssertionError("Unrecognised delta result code: %d" % result)
 * 
 */
  __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_11));
  PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_kp_s_11));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));

  /* "bzrlib/_groupcompress_pyx.pyx":123
 * def _rabin_hash(content):
 *     if not PyString_CheckExact(content):
 *         raise ValueError('content must be a string')             # <<<<<<<<<<<<<<
 *     if len(content) < 16:
 *         raise ValueError('content must be at least 16 bytes long')
 */
  __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_15));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_14));
  PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15));

  /* "bzrlib/_groupcompress_pyx.pyx":125
 *         raise ValueError('content must be a string')
 *     if len(content) < 16:
 *         raise ValueError('content must be at least 16 bytes long')             # <<<<<<<<<<<<<<
 *     # Try to cast it to an int, if it can fit
 *     return int(rabin_hash(<unsigned char*>(PyString_AS_STRING(content))))
 */
  __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_17));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
  PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_16));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17));

  /* "bzrlib/_groupcompress_pyx.pyx":239
 * 
 *         if not PyString_CheckExact(delta):
 *             raise TypeError('delta is not a str')             # <<<<<<<<<<<<<<
 * 
 *         source_location = len(self._sources)
 */
  __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_20));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
  PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_19));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20));

  /* "bzrlib/_groupcompress_pyx.pyx":281
 * 
 *         if not PyString_CheckExact(source):
 *             raise TypeError('source is not a str')             # <<<<<<<<<<<<<<
 * 
 *         source_location = len(self._sources)
 */
  __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_22));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_21));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));

  /* "bzrlib/_groupcompress_pyx.pyx":313
 *         cdef delta_result res
 *         if len(self._sources) != 1 or self._index != NULL:
 *             raise AssertionError('_populate_first_index should only be'             # <<<<<<<<<<<<<<
 *                 ' called when we have a single source and no index yet')
 * 
 */
  __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_25));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
  PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_24));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25));

  /* "bzrlib/_groupcompress_pyx.pyx":326
 * 
 *     cdef _expand_sources(self):
 *         raise RuntimeError('if we move self._source_infos, then we need to'             # <<<<<<<<<<<<<<
 *                            ' change all of the index pointers as well.')
 *         self._max_num_sources = self._max_num_sources * 2
 */
  __pyx_k_tuple_27 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_27));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_26));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, ((PyObject *)__pyx_kp_s_26));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_26));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27));

  /* "bzrlib/_groupcompress_pyx.pyx":349
 * 
 *         if not PyString_CheckExact(target_bytes):
 *             raise TypeError('target is not a str')             # <<<<<<<<<<<<<<
 * 
 *         target = PyString_AS_STRING(target_bytes)
 */
  __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_29));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_28));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_28));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));

  /* "bzrlib/_groupcompress_pyx.pyx":384
 * 
 *     if not PyString_CheckExact(source_bytes):
 *         raise TypeError('source is not a str')             # <<<<<<<<<<<<<<
 *     if not PyString_CheckExact(delta_bytes):
 *         raise TypeError('delta is not a str')
 */
  __pyx_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_30));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_21));
  PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30));

  /* "bzrlib/_groupcompress_pyx.pyx":386
 *         raise TypeError('source is not a str')
 *     if not PyString_CheckExact(delta_bytes):
 *         raise TypeError('delta is not a str')             # <<<<<<<<<<<<<<
 *     source = PyString_AS_STRING(source_bytes)
 *     source_size = PyString_GET_SIZE(source_bytes)
 */
  __pyx_k_tuple_31 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_31));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_19));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_kp_s_19));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31));

  /* "bzrlib/_groupcompress_pyx.pyx":502
 *                 % (cp_off, cp_size, source_size, size))
 *         elif failed == 2:
 *             raise ValueError('Got delta opcode: 0, not supported')             # <<<<<<<<<<<<<<
 *         elif failed == 3:
 *             raise ValueError('Insert instruction longer than remaining'
 */
  __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_35));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_34));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_kp_s_34));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_34));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));

  /* "bzrlib/_groupcompress_pyx.pyx":516
 *     # *dst_size = out - dst_buf;
 *     if (out - dst_buf) != PyString_GET_SIZE(result):
 *         raise RuntimeError('Number of bytes extracted did not match the'             # <<<<<<<<<<<<<<
 *             ' size encoded in the delta header.')
 *     return result
 */
  __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_39));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_38));
  PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_kp_s_38));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_38));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39));

  /* "bzrlib/_groupcompress_pyx.pyx":530
 * 
 *     if not PyString_CheckExact(source):
 *         raise TypeError('source is not a str')             # <<<<<<<<<<<<<<
 *     c_source_size = PyString_GET_SIZE(source)
 *     c_delta_start = delta_start
 */
  __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_40));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_21));
  PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40));

  /* "bzrlib/_groupcompress_pyx.pyx":535
 *     c_delta_end = delta_end
 *     if c_delta_start >= c_source_size:
 *         raise ValueError('delta starts after source')             # <<<<<<<<<<<<<<
 *     if c_delta_end > c_source_size:
 *         raise ValueError('delta ends after source')
 */
  __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_42));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_41));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));

  /* "bzrlib/_groupcompress_pyx.pyx":537
 *         raise ValueError('delta starts after source')
 *     if c_delta_end > c_source_size:
 *         raise ValueError('delta ends after source')             # <<<<<<<<<<<<<<
 *     if c_delta_start >= c_delta_end:
 *         raise ValueError('delta starts after it ends')
 */
  __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_44));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
  PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44));

  /* "bzrlib/_groupcompress_pyx.pyx":539
 *         raise ValueError('delta ends after source')
 *     if c_delta_start >= c_delta_end:
 *         raise ValueError('delta starts after it ends')             # <<<<<<<<<<<<<<
 * 
 *     c_delta_size = c_delta_end - c_delta_start
 */
  __pyx_k_tuple_46 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_46));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_45));
  PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, ((PyObject *)__pyx_kp_s_45));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_45));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46));

  /* "bzrlib/_groupcompress_pyx.pyx":563
 *         count = count + 1
 *     if count >= 8 or c_val >= 0x80:
 *         raise ValueError('encode_base128_int overflowed the buffer')             # <<<<<<<<<<<<<<
 *     c_bytes[count] = <unsigned char>(c_val & 0xFF)
 *     count = count + 1
 */
  __pyx_k_tuple_48 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_48));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_47));
  PyTuple_SET_ITEM(__pyx_k_tuple_48, 0, ((PyObject *)__pyx_kp_s_47));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_47));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48));

  /* "bzrlib/_groupcompress_pyx.pyx":582
 *     shift = 0
 *     if not PyString_CheckExact(bytes):
 *         raise TypeError('bytes is not a string')             # <<<<<<<<<<<<<<
 *     c_bytes = <unsigned char*>PyString_AS_STRING(bytes)
 *     # We take off 1, because we have to be able to decode the non-expanded byte
 */
  __pyx_k_tuple_50 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_50));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_49));
  PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_kp_s_49));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_49));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50));

  /* "bzrlib/_groupcompress_pyx.pyx":591
 *         offset = offset + 1
 *     if c_bytes[offset] & 0x80:
 *         raise ValueError('Data not properly formatted, we ran out of'             # <<<<<<<<<<<<<<
 *                          ' bytes before 0x80 stopped being set.')
 *     val = val | (c_bytes[offset] << shift)
 */
  __pyx_k_tuple_52 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_52));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_51));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_kp_s_51));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_51));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  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;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_groupcompress_pyx(void); /*proto*/
PyMODINIT_FUNC init_groupcompress_pyx(void)
#else
PyMODINIT_FUNC PyInit__groupcompress_pyx(void); /*proto*/
PyMODINIT_FUNC PyInit__groupcompress_pyx(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __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");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__groupcompress_pyx(void)", __LINE__, __FILE__);
  #endif
  __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_binding_PyCFunctionType_USED
  if (__pyx_binding_PyCFunctionType_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(__Pyx_NAMESTR("_groupcompress_pyx"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_53), 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_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 (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_bzrlib___groupcompress_pyx) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex = &__pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex;
  __pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex._populate_first_index = (PyObject *(*)(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *))__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__populate_first_index;
  __pyx_vtable_6bzrlib_18_groupcompress_pyx_DeltaIndex._expand_sources = (PyObject *(*)(struct __pyx_obj_6bzrlib_18_groupcompress_pyx_DeltaIndex *))__pyx_f_6bzrlib_18_groupcompress_pyx_10DeltaIndex__expand_sources;
  if (PyType_Ready(&__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex.tp_dict, __pyx_vtabptr_6bzrlib_18_groupcompress_pyx_DeltaIndex) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "DeltaIndex", (PyObject *)&__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_6bzrlib_18_groupcompress_pyx_DeltaIndex = &__pyx_type_6bzrlib_18_groupcompress_pyx_DeltaIndex;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "bzrlib/_groupcompress_pyx.pyx":103
 *         val[0] = NULL
 * 
 * def make_delta_index(source):             # <<<<<<<<<<<<<<
 *     return DeltaIndex(source)
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_make_delta_index, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__make_delta_index, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":121
 * 
 * 
 * def _rabin_hash(content):             # <<<<<<<<<<<<<<
 *     if not PyString_CheckExact(content):
 *         raise ValueError('content must be a string')
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_1_rabin_hash, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___rabin_hash, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":370
 * 
 * 
 * def make_delta(source_bytes, target_bytes):             # <<<<<<<<<<<<<<
 *     """Create a delta, this is a wrapper around DeltaIndex.make_delta."""
 *     di = DeltaIndex(source_bytes)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_2make_delta, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__make_delta, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":376
 * 
 * 
 * def apply_delta(source_bytes, delta_bytes):             # <<<<<<<<<<<<<<
 *     """Apply a delta generated by make_delta to source_bytes."""
 *     cdef char *source
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_3apply_delta, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__apply_delta, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":521
 * 
 * 
 * def apply_delta_to_source(source, delta_start, delta_end):             # <<<<<<<<<<<<<<
 *     """Extract a delta from source bytes, and apply it."""
 *     cdef char *c_source
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_4apply_delta_to_source, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_55, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":549
 * 
 * 
 * def encode_base128_int(val):             # <<<<<<<<<<<<<<
 *     """Convert an integer into a 7-bit lsb encoding."""
 *     cdef unsigned int c_val
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_5encode_base128_int, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__encode_base128_int, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":569
 * 
 * 
 * def decode_base128_int(bytes):             # <<<<<<<<<<<<<<
 *     """Decode an integer from a 7-bit lsb encoding."""
 *     cdef int offset
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_18_groupcompress_pyx_6decode_base128_int, NULL, __pyx_n_s_54); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__decode_base128_int, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "bzrlib/_groupcompress_pyx.pyx":1
 * # Copyright (C) 2008, 2009, 2010 Canonical Ltd             # <<<<<<<<<<<<<<
 * #
 * # This program is free software; you can redistribute it and/or modify
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  if (__pyx_m) {
    __Pyx_AddTraceback("init bzrlib._groupcompress_pyx");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init bzrlib._groupcompress_pyx");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    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);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    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;
}


#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            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;
            }
        #endif
    }

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    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)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        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);
        }
    }

bad:
    return;
}
#endif

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_AS_STRING(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;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        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 *number, *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";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #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_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __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,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

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  /* Python 3+ has unicode identifiers */
        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;
}

/* Type Conversion Functions */

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_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  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_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (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 = 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) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
