/* Generated by Cython 0.16 on Fri Apr 19 15:23:20 2013 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02040000
    #error Cython requires Python 2.4+.
#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

#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif

#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif

#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyCFunction_Call PyObject_Call
#else
  #define __Pyx_PyCFunction_Call PyCFunction_Call
#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)   __Pyx_PyInt_AsInt(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)
  #define __PYX_BUILD_PY_SSIZE_T "i"
#else
  #define __PYX_BUILD_PY_SSIZE_T "n"
#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)
  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)

  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif

#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#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_VERSION_HEX > 0x03030000 && defined(PyUnicode_GET_LENGTH)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
#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_VERSION_HEX < 0x03020000
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif

#if (PY_MAJOR_VERSION < 3) || (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

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

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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE__GatSegmentList
#define __PYX_HAVE_API__GatSegmentList
#include "string.h"
#include "stdlib.h"
#include "stdint.h"
#include "stdio.h"
#include "errno.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "sys/mman.h"
#include "unistd.h"
#include "math.h"
#include "fileobject.h"
#include "gat_utils.h"
#include "pythread.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#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) && !defined(_MSC_VER))
#   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_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#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))
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_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;

#if !defined(CYTHON_CCOMPLEX)
  #if defined(__cplusplus)
    #define CYTHON_CCOMPLEX 1
  #elif defined(_Complex_I)
    #define CYTHON_CCOMPLEX 1
  #else
    #define CYTHON_CCOMPLEX 0
  #endif
#endif
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #include <complex>
  #else
    #include <complex.h>
  #endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
  #undef _Complex_I
  #define _Complex_I 1.0fj
#endif


static const char *__pyx_f[] = {
  "GatSegmentList.pyx",
  "numpy.pxd",
  "GatSegmentList.pxd",
  "bool.pxd",
  "complex.pxd",
};
#define IS_UNSIGNED(type) (((type) -1) > 0)
struct __Pyx_StructField_;
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
typedef struct {
  const char* name; /* for error messages only */
  struct __Pyx_StructField_* fields;
  size_t size;     /* sizeof(type) */
  size_t arraysize[8]; /* length of array in each dimension */
  int ndim;
  char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */
  char is_unsigned;
  int flags;
} __Pyx_TypeInfo;
typedef struct __Pyx_StructField_ {
  __Pyx_TypeInfo* type;
  const char* name;
  size_t offset;
} __Pyx_StructField;
typedef struct {
  __Pyx_StructField* field;
  size_t parent_offset;
} __Pyx_BufFmt_StackElem;
typedef struct {
  __Pyx_StructField root;
  __Pyx_BufFmt_StackElem* head;
  size_t fmt_offset;
  size_t new_count, enc_count;
  size_t struct_alignment;
  int is_complex;
  char enc_type;
  char new_packmode;
  char enc_packmode;
  char is_valid_array;
} __Pyx_BufFmt_Context;


/* "numpy.pxd":722
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "numpy.pxd":723
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "numpy.pxd":724
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "numpy.pxd":725
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "numpy.pxd":729
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "numpy.pxd":730
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "numpy.pxd":731
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "numpy.pxd":732
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "numpy.pxd":736
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "numpy.pxd":737
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "numpy.pxd":746
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "numpy.pxd":747
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "numpy.pxd":748
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "numpy.pxd":750
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "numpy.pxd":751
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "numpy.pxd":752
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "numpy.pxd":754
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "numpy.pxd":755
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "numpy.pxd":757
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "numpy.pxd":758
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "numpy.pxd":759
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;

/* "GatSegmentList.pxd":137
 * #####################################################
 * # type for positions
 * ctypedef unsigned int Position             # <<<<<<<<<<<<<<
 * # type for position difference - can be negative
 * ctypedef int PositionDifference
 */
typedef unsigned int __pyx_t_14GatSegmentList_Position;

/* "GatSegmentList.pxd":139
 * ctypedef unsigned int Position
 * # type for position difference - can be negative
 * ctypedef int PositionDifference             # <<<<<<<<<<<<<<
 * 
 * # A segment (without strand)
 */
typedef int __pyx_t_14GatSegmentList_PositionDifference;

/* "GatSegmentList.pyx":22
 * cimport numpy
 * DTYPE_INT = numpy.int
 * ctypedef numpy.int_t DTYPE_INT_t             # <<<<<<<<<<<<<<
 * DTYPE_FLOAT = numpy.float
 * ctypedef numpy.float_t DTYPE_FLOAT_t
 */
typedef __pyx_t_5numpy_int_t __pyx_t_14GatSegmentList_DTYPE_INT_t;

/* "GatSegmentList.pyx":24
 * ctypedef numpy.int_t DTYPE_INT_t
 * DTYPE_FLOAT = numpy.float
 * ctypedef numpy.float_t DTYPE_FLOAT_t             # <<<<<<<<<<<<<<
 * 
 * def getSegmentSize():
 */
typedef __pyx_t_5numpy_float_t __pyx_t_14GatSegmentList_DTYPE_FLOAT_t;
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< double > __pyx_t_double_complex;
  #else
    typedef double _Complex __pyx_t_double_complex;
  #endif
#else
    typedef struct { double real, imag; } __pyx_t_double_complex;
#endif


/*--- Type declarations ---*/
struct __pyx_obj_14GatSegmentList_SegmentListIterator;
struct __pyx_obj_14GatSegmentList_SegmentList;

/* "numpy.pxd":761
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "numpy.pxd":762
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "numpy.pxd":763
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "numpy.pxd":765
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;
struct __pyx_t_14GatSegmentList_Segment;
struct __pyx_opt_args_14GatSegmentList_11SegmentList_intersectionWithSegments;

/* "GatSegmentList.pxd":142
 * 
 * # A segment (without strand)
 * cdef struct Segment:             # <<<<<<<<<<<<<<
 *     Position start
 *     Position end
 */
struct __pyx_t_14GatSegmentList_Segment {
  __pyx_t_14GatSegmentList_Position start;
  __pyx_t_14GatSegmentList_Position end;
};

/* "GatSegmentList.pxd":174
 *     cpdef SegmentList getOverlappingSegmentsWithRange( self, Position start, Position end )
 *     cpdef Position overlapWithSegments( self, SegmentList other )
 *     cpdef Position intersectionWithSegments( self, SegmentList other, mode = * )             # <<<<<<<<<<<<<<
 *     cpdef SegmentList getFilledSegmentsFromStart( self, Position start, PositionDifference remainder )
 *     cpdef SegmentList getFilledSegmentsFromEnd( self, Position end, PositionDifference remainder )
 */
struct __pyx_opt_args_14GatSegmentList_11SegmentList_intersectionWithSegments {
  int __pyx_n;
  PyObject *mode;
};

/* "GatSegmentList.pyx":1564
 * # SegmentTuple = collections.namedtuple( "SegmentTuple", "start, end" )
 * 
 * cdef class SegmentListIterator:             # <<<<<<<<<<<<<<
 * 
 *     cdef SegmentList segment_list
 */
struct __pyx_obj_14GatSegmentList_SegmentListIterator {
  PyObject_HEAD
  struct __pyx_obj_14GatSegmentList_SegmentList *segment_list;
  __pyx_t_14GatSegmentList_Position idx;
};


/* "GatSegmentList.pxd":150
 * ## definition of segmentlist
 * #####################################################
 * cdef class SegmentList:             # <<<<<<<<<<<<<<
 * 
 *     cdef Segment * segments
 */
struct __pyx_obj_14GatSegmentList_SegmentList {
  PyObject_HEAD
  struct __pyx_vtabstruct_14GatSegmentList_SegmentList *__pyx_vtab;
  struct __pyx_t_14GatSegmentList_Segment *segments;
  size_t nsegments;
  size_t allocated;
  int flag;
  int chunk_size;
  int shared_fd;
  PyObject *key;
};



/* "GatSegmentList.pyx":97
 * DEF SEG_SLAVE = 4
 * 
 * cdef class SegmentList:             # <<<<<<<<<<<<<<
 *     '''list of segments.
 * 
 */

struct __pyx_vtabstruct_14GatSegmentList_SegmentList {
  PyObject *(*share)(struct __pyx_obj_14GatSegmentList_SegmentList *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*sort)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*extend)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  PyObject *(*add)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch);
  PyObject *(*trim_ends)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int, int __pyx_skip_dispatch);
  PyObject *(*trim)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch);
  PyObject *(*normalize)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  PyObject *(*merge)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_PositionDifference, int __pyx_skip_dispatch);
  PyObject *(*check)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*getRandomPosition)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*overlapWithRange)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*getOverlappingSegmentsWithRange)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*overlapWithSegments)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*intersectionWithSegments)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch, struct __pyx_opt_args_14GatSegmentList_11SegmentList_intersectionWithSegments *__pyx_optional_args);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*getFilledSegmentsFromStart)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_PositionDifference, int __pyx_skip_dispatch);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*getFilledSegmentsFromEnd)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_PositionDifference, int __pyx_skip_dispatch);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*filter)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*intersect)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*subtract)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  PyObject *(*extend_segments)(struct __pyx_obj_14GatSegmentList_SegmentList *, int, int __pyx_skip_dispatch);
  PyObject *(*expand_segments)(struct __pyx_obj_14GatSegmentList_SegmentList *, double, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*sum)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*max)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  __pyx_t_14GatSegmentList_Position (*min)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  PyObject *(*clear)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  PyObject *(*summarize)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch);
  PyObject *(*_add)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment);
  PyObject *(*_resize)(struct __pyx_obj_14GatSegmentList_SegmentList *, int);
  PyObject *(*insert)(struct __pyx_obj_14GatSegmentList_SegmentList *, int, struct __pyx_t_14GatSegmentList_Segment);
  int (*_getInsertionPoint)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment);
  __pyx_t_14GatSegmentList_Position (*overlap)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*getOverlappingSegments)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment);
  struct __pyx_obj_14GatSegmentList_SegmentList *(*truncate)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment);
  off_t (*toMMAP)(struct __pyx_obj_14GatSegmentList_SegmentList *, void *, int, off_t);
  void (*fromMMAP)(struct __pyx_obj_14GatSegmentList_SegmentList *);
};
static struct __pyx_vtabstruct_14GatSegmentList_SegmentList *__pyx_vtabptr_14GatSegmentList_SegmentList;
#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); /*proto*/
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          if (acquire_gil) { \
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
              PyGILState_Release(__pyx_gilstate_save); \
          } else { \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext() \
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*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 int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact); /*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, PyObject *cause); /*proto*/

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
    if (PyList_CheckExact(o)) {
        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (likely(i >= 0)) {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            return m->sq_item(o, i);
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

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

static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */

static CYTHON_INLINE int  __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);

static void __Pyx_RaiseBufferFallbackError(void); /*proto*/

static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
#define __Pyx_PyObject_AsDouble(obj) \
((likely(PyFloat_CheckExact(obj))) ? \
 PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))

static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/

#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0)
static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/

typedef struct {
  Py_ssize_t shape, strides, suboffsets;
} __Pyx_Buf_DimInfo;
typedef struct {
  size_t refcount;
  Py_buffer pybuffer;
} __Pyx_Buffer;
typedef struct {
  __Pyx_Buffer *rcbuffer;
  char *data;
  __Pyx_Buf_DimInfo diminfo[8];
} __Pyx_LocalBuf_ND;

#if PY_MAJOR_VERSION < 3
    static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
    static void __Pyx_ReleaseBuffer(Py_buffer *view);
#else
    #define __Pyx_GetBuffer PyObject_GetBuffer
    #define __Pyx_ReleaseBuffer PyBuffer_Release
#endif

static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0};
static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1};

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/

struct __pyx_t_14GatSegmentList_Segment;
static PyObject* __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment(struct __pyx_t_14GatSegmentList_Segment s);
#include <string.h>

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/

#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

struct __pyx_t_14GatSegmentList_Segment;
static struct __pyx_t_14GatSegmentList_Segment __pyx_convert__from_py___pyx_t_14GatSegmentList_Segment(PyObject *);

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #define __Pyx_CREAL(z) ((z).real())
    #define __Pyx_CIMAG(z) ((z).imag())
  #else
    #define __Pyx_CREAL(z) (__real__(z))
    #define __Pyx_CIMAG(z) (__imag__(z))
  #endif
#else
    #define __Pyx_CREAL(z) ((z).real)
    #define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eqf(a, b)   ((a)==(b))
    #define __Pyx_c_sumf(a, b)  ((a)+(b))
    #define __Pyx_c_difff(a, b) ((a)-(b))
    #define __Pyx_c_prodf(a, b) ((a)*(b))
    #define __Pyx_c_quotf(a, b) ((a)/(b))
    #define __Pyx_c_negf(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zerof(z) ((z)==(float)0)
    #define __Pyx_c_conjf(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_absf(z)     (::std::abs(z))
        #define __Pyx_c_powf(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zerof(z) ((z)==0)
    #define __Pyx_c_conjf(z)    (conjf(z))
    #if 1
        #define __Pyx_c_absf(z)     (cabsf(z))
        #define __Pyx_c_powf(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq(a, b)   ((a)==(b))
    #define __Pyx_c_sum(a, b)  ((a)+(b))
    #define __Pyx_c_diff(a, b) ((a)-(b))
    #define __Pyx_c_prod(a, b) ((a)*(b))
    #define __Pyx_c_quot(a, b) ((a)/(b))
    #define __Pyx_c_neg(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero(z) ((z)==(double)0)
    #define __Pyx_c_conj(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (::std::abs(z))
        #define __Pyx_c_pow(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero(z) ((z)==0)
    #define __Pyx_c_conj(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (cabs(z))
        #define __Pyx_c_pow(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex, __pyx_t_double_complex);
    #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 void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename); /*proto*/

static int __Pyx_check_binary_version(void);

#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);  /*proto*/

static PyObject *__Pyx_ImportModule(const char *name); /*proto*/

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

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

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

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/


/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.version' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'cpython.exc' */

/* Module declarations from 'cpython.module' */

/* Module declarations from 'cpython.mem' */

/* Module declarations from 'cpython.tuple' */

/* Module declarations from 'cpython.list' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.sequence' */

/* Module declarations from 'cpython.mapping' */

/* Module declarations from 'cpython.iterator' */

/* Module declarations from 'cpython.type' */

/* Module declarations from 'cpython.number' */

/* Module declarations from 'cpython.int' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.bool' */
static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;

/* Module declarations from 'cpython.long' */

/* Module declarations from 'cpython.float' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.complex' */
static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;

/* Module declarations from 'cpython.string' */

/* Module declarations from 'cpython.unicode' */

/* Module declarations from 'cpython.dict' */

/* Module declarations from 'cpython.instance' */

/* Module declarations from 'cpython.function' */

/* Module declarations from 'cpython.method' */

/* Module declarations from 'cpython.weakref' */

/* Module declarations from 'cpython.getargs' */

/* Module declarations from 'cpython.pythread' */

/* Module declarations from 'cpython.pystate' */

/* Module declarations from 'cpython.cobject' */

/* Module declarations from 'cpython.oldbuffer' */

/* Module declarations from 'cpython.set' */

/* Module declarations from 'cpython.buffer' */

/* Module declarations from 'cpython.bytes' */

/* Module declarations from 'cpython.pycapsule' */

/* Module declarations from 'cpython' */

/* Module declarations from 'cython' */

/* Module declarations from 'libc.stdint' */

/* Module declarations from 'libc.stdlib' */

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;
static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/

/* Module declarations from 'GatSegmentList' */
static PyTypeObject *__pyx_ptype_14GatSegmentList_file = 0;
static PyTypeObject *__pyx_ptype_14GatSegmentList_SegmentList = 0;
static PyTypeObject *__pyx_ptype_14GatSegmentList_SegmentListIterator = 0;
static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_lmin(__pyx_t_14GatSegmentList_PositionDifference, __pyx_t_14GatSegmentList_PositionDifference); /*proto*/
static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_lmax(__pyx_t_14GatSegmentList_PositionDifference, __pyx_t_14GatSegmentList_PositionDifference); /*proto*/
static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_segment_overlap(struct __pyx_t_14GatSegmentList_Segment, struct __pyx_t_14GatSegmentList_Segment); /*proto*/
static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_segment_overlap_raw(struct __pyx_t_14GatSegmentList_Segment, struct __pyx_t_14GatSegmentList_Segment); /*proto*/
static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_segment_length(struct __pyx_t_14GatSegmentList_Segment); /*proto*/
static int __pyx_f_14GatSegmentList_cmpSegments(const void*, const void*); /*proto*/
static int __pyx_f_14GatSegmentList_cmpSegmentsStartAndEnd(const void*, const void*); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_14GatSegmentList_DTYPE_INT_t = { "DTYPE_INT_t", NULL, sizeof(__pyx_t_14GatSegmentList_DTYPE_INT_t), { 0 }, 0, 'I', IS_UNSIGNED(__pyx_t_14GatSegmentList_DTYPE_INT_t), 0 };
#define __Pyx_MODULE_NAME "GatSegmentList"
int __pyx_module_is_main_GatSegmentList = 0;

/* Implementation of 'GatSegmentList' */
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_OSError;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_pf_14GatSegmentList_getSegmentSize(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static int __pyx_pf_14GatSegmentList_11SegmentList___init__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_allocate, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_clone, PyObject *__pyx_v_iter, PyObject *__pyx_v_normalize, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_share, PyObject *__pyx_v_unreduce); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_2__reduce__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_4share(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_6unshare(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_8sort(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_10extend(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_12add(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_14trim_ends(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_pos, __pyx_t_14GatSegmentList_Position __pyx_v_size, int __pyx_v_forward); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_16trim(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_pos, __pyx_t_14GatSegmentList_Position __pyx_v_size); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_18normalize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_20merge(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_distance); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_22check(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_24getInsertionPoint(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_12isNormalized___get__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_10statusflag___get__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_7isEmpty___get__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_26getRandomPosition(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_28overlapWithRange(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_30getOverlappingSegmentsWithRange(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_32overlapWithSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_34intersectionWithSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, PyObject *__pyx_v_mode); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_36getLengthDistribution(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_bucket_size, PyObject *__pyx_v_nbuckets); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_38subtract(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_40summarize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_42getFilledSegmentsFromStart(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_44getFilledSegmentsFromEnd(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_end, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_46filter(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_48intersect(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_50extend_segments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_extension); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_52expand_segments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, double __pyx_v_expansion); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_54shift(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_offset); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_56sum(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_58largest(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_60max(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_62min(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_64clear(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static Py_ssize_t __pyx_pf_14GatSegmentList_11SegmentList_66__len__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static void __pyx_pf_14GatSegmentList_11SegmentList_68__dealloc__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_70__str__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_72asList(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_74asLengths(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_76__iter__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_78__getitem__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
#if PY_MAJOR_VERSION < 3
static int __pyx_pf_14GatSegmentList_11SegmentList_80__cmp__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other); /* proto */
#endif
static PyObject *__pyx_pf_14GatSegmentList_2buildSegmentList(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args); /* proto */
static int __pyx_pf_14GatSegmentList_19SegmentListIterator___init__(struct __pyx_obj_14GatSegmentList_SegmentListIterator *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_container); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_19SegmentListIterator_2__iter__(struct __pyx_obj_14GatSegmentList_SegmentListIterator *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_14GatSegmentList_19SegmentListIterator_4__next__(struct __pyx_obj_14GatSegmentList_SegmentListIterator *__pyx_v_self); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static char __pyx_k_2[] = "sharing from a non-shared SegmentList";
static char __pyx_k_3[] = "could not read list from shared segment - error=%i";
static char __pyx_k_4[] = "could not unpickle as slave - error=%i";
static char __pyx_k_5[] = "sharing in non-normalized list";
static char __pyx_k_6[] = "/";
static char __pyx_k_8[] = "SegmentList already shared";
static char __pyx_k_9[] = "could not create shared memory at %s; ERRNO=%i";
static char __pyx_k_10[] = "could not resize memory at %s; ERRNO=%i";
static char __pyx_k_11[] = "could not create memory mapped file";
static char __pyx_k_13[] = "unsharing unshared SegmentList";
static char __pyx_k_15[] = "could not unlink shared memory";
static char __pyx_k_17[] = "could not allocate memory when unsharing";
static char __pyx_k_19[] = "error while unmapping memory";
static char __pyx_k_22[] = "can not move shared segmentlist to mmap";
static char __pyx_k_24[] = "out of memory when allocation %i bytes";
static char __pyx_k_25[] = "attempting to add invalid segment %i-%i";
static char __pyx_k_26[] = "trimming in non-normalized list";
static char __pyx_k_27[] = "trimming more than the total length (%i < %i)";
static char __pyx_k_28[] = "resizing will loose segments";
static char __pyx_k_29[] = "only positive indices accepted (%i)";
static char __pyx_k_30[] = "insertion_idx out of range: %i >= %i";
static char __pyx_k_31[] = "empty/invalid segment in segmentlist: %s";
static char __pyx_k_32[] = "segment list is not sorted: %s > %s";
static char __pyx_k_33[] = "segment overlap: %s overlaps %s";
static char __pyx_k_34[] = "searching in non-normalized list";
static char __pyx_k_35[] = "non-normalized segment list";
static char __pyx_k_36[] = "getOverlappingSegmentsWithRange";
static char __pyx_k_37[] = "intersection from non-normalized list";
static char __pyx_k_38[] = "intersection with non-normalized list";
static char __pyx_k_39[] = "intersectionWithSegments";
static char __pyx_k_40[] = "bucket_size is 0";
static char __pyx_k_41[] = "nbuckets is 0";
static char __pyx_k_42[] = "segment %i-%i too large: %i >= %i, increase nbuckets (%i) or bucket_size (%i) such that nbuckets * bucket_size > %i";
static char __pyx_k_43[] = "subtraction of a non-normalized list";
static char __pyx_k_44[] = "subtraction with non-normalized list";
static char __pyx_k_46[] = "getFilledSegmentsFromStart";
static char __pyx_k_47[] = "getFilledSegmentsFromEnd";
static char __pyx_k_48[] = "intersection of a non-normalized list";
static char __pyx_k_49[] = "invalid expansion: %f <= 0";
static char __pyx_k_50[] = "shift creates negative coordinates";
static char __pyx_k_52[] = "largest segment from empty list";
static char __pyx_k_54[] = "maximum from non-normalized list";
static char __pyx_k_55[] = "minimum from non-normalized list";
static char __pyx_k_57[] = "index out of range";
static char __pyx_k_59[] = "ndarray is not C contiguous";
static char __pyx_k_61[] = "ndarray is not Fortran contiguous";
static char __pyx_k_63[] = "Non-native byte order not supported";
static char __pyx_k_65[] = "unknown dtype code in numpy.pxd (%d)";
static char __pyx_k_66[] = "Format string allocated too short, see comment in numpy.pxd";
static char __pyx_k_69[] = "Format string allocated too short.";
static char __pyx_k_72[] = "/ifs/devel/gat/GatSegmentList/GatSegmentList.pyx";
static char __pyx_k__B[] = "B";
static char __pyx_k__H[] = "H";
static char __pyx_k__I[] = "I";
static char __pyx_k__L[] = "L";
static char __pyx_k__O[] = "O";
static char __pyx_k__Q[] = "Q";
static char __pyx_k__b[] = "b";
static char __pyx_k__d[] = "d";
static char __pyx_k__f[] = "f";
static char __pyx_k__g[] = "g";
static char __pyx_k__h[] = "h";
static char __pyx_k__i[] = "i";
static char __pyx_k__l[] = "l";
static char __pyx_k__q[] = "q";
static char __pyx_k__Zd[] = "Zd";
static char __pyx_k__Zf[] = "Zf";
static char __pyx_k__Zg[] = "Zg";
static char __pyx_k__os[] = "os";
static char __pyx_k__re[] = "re";
static char __pyx_k__add[] = "add";
static char __pyx_k__end[] = "end";
static char __pyx_k__int[] = "int";
static char __pyx_k__max[] = "max";
static char __pyx_k__min[] = "min";
static char __pyx_k__pos[] = "pos";
static char __pyx_k__sum[] = "sum";
static char __pyx_k__args[] = "args";
static char __pyx_k__base[] = "base";
static char __pyx_k__ceil[] = "ceil";
static char __pyx_k__iter[] = "iter";
static char __pyx_k__math[] = "math";
static char __pyx_k__mode[] = "mode";
static char __pyx_k__size[] = "size";
static char __pyx_k__sort[] = "sort";
static char __pyx_k__trim[] = "trim";
static char __pyx_k__check[] = "check";
static char __pyx_k__clear[] = "clear";
static char __pyx_k__clone[] = "clone";
static char __pyx_k__dtype[] = "dtype";
static char __pyx_k__float[] = "float";
static char __pyx_k__merge[] = "merge";
static char __pyx_k__numpy[] = "numpy";
static char __pyx_k__other[] = "other";
static char __pyx_k__range[] = "range";
static char __pyx_k__share[] = "share";
static char __pyx_k__start[] = "start";
static char __pyx_k__types[] = "types";
static char __pyx_k__zeros[] = "zeros";
static char __pyx_k__asList[] = "asList";
static char __pyx_k__extend[] = "extend";
static char __pyx_k__filter[] = "filter";
static char __pyx_k__random[] = "random";
static char __pyx_k__OSError[] = "OSError";
static char __pyx_k____cmp__[] = "__cmp__";
static char __pyx_k____len__[] = "__len__";
static char __pyx_k__forward[] = "forward";
static char __pyx_k__largest[] = "largest";
static char __pyx_k__randint[] = "randint";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__allocate[] = "allocate";
static char __pyx_k__midpoint[] = "midpoint";
static char __pyx_k__nbuckets[] = "nbuckets";
static char __pyx_k__subtract[] = "subtract";
static char __pyx_k__unreduce[] = "unreduce";
static char __pyx_k__DTYPE_INT[] = "DTYPE_INT";
static char __pyx_k__container[] = "container";
static char __pyx_k__intersect[] = "intersect";
static char __pyx_k__normalize[] = "normalize";
static char __pyx_k__remainder[] = "remainder";
static char __pyx_k__summarize[] = "summarize";
static char __pyx_k__trim_ends[] = "trim_ends";
static char __pyx_k__IndexError[] = "IndexError";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k__startswith[] = "startswith";
static char __pyx_k__DTYPE_FLOAT[] = "DTYPE_FLOAT";
static char __pyx_k__MemoryError[] = "MemoryError";
static char __pyx_k__bucket_size[] = "bucket_size";
static char __pyx_k__collections[] = "collections";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__StopIteration[] = "StopIteration";
static char __pyx_k__GatSegmentList[] = "GatSegmentList";
static char __pyx_k__getSegmentSize[] = "getSegmentSize";
static char __pyx_k__expand_segments[] = "expand_segments";
static char __pyx_k__extend_segments[] = "extend_segments";
static char __pyx_k__buildSegmentList[] = "buildSegmentList";
static char __pyx_k__overlapWithRange[] = "overlapWithRange";
static char __pyx_k__getInsertionPoint[] = "getInsertionPoint";
static char __pyx_k__getRandomPosition[] = "getRandomPosition";
static char __pyx_k__overlapWithSegments[] = "overlapWithSegments";
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_15;
static PyObject *__pyx_kp_s_17;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_22;
static PyObject *__pyx_kp_s_24;
static PyObject *__pyx_kp_s_25;
static PyObject *__pyx_kp_s_26;
static PyObject *__pyx_kp_s_27;
static PyObject *__pyx_kp_s_28;
static PyObject *__pyx_kp_s_29;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_30;
static PyObject *__pyx_kp_s_31;
static PyObject *__pyx_kp_s_32;
static PyObject *__pyx_kp_s_33;
static PyObject *__pyx_kp_s_34;
static PyObject *__pyx_kp_s_35;
static PyObject *__pyx_n_s_36;
static PyObject *__pyx_kp_s_37;
static PyObject *__pyx_kp_s_38;
static PyObject *__pyx_n_s_39;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_s_40;
static PyObject *__pyx_kp_s_41;
static PyObject *__pyx_kp_s_42;
static PyObject *__pyx_kp_s_43;
static PyObject *__pyx_kp_s_44;
static PyObject *__pyx_n_s_46;
static PyObject *__pyx_n_s_47;
static PyObject *__pyx_kp_s_48;
static PyObject *__pyx_kp_s_49;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_s_50;
static PyObject *__pyx_kp_s_52;
static PyObject *__pyx_kp_s_54;
static PyObject *__pyx_kp_s_55;
static PyObject *__pyx_kp_s_57;
static PyObject *__pyx_kp_u_59;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_u_61;
static PyObject *__pyx_kp_u_63;
static PyObject *__pyx_kp_u_65;
static PyObject *__pyx_kp_u_66;
static PyObject *__pyx_kp_u_69;
static PyObject *__pyx_kp_s_72;
static PyObject *__pyx_kp_s_8;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__DTYPE_FLOAT;
static PyObject *__pyx_n_s__DTYPE_INT;
static PyObject *__pyx_n_s__GatSegmentList;
static PyObject *__pyx_n_s__IndexError;
static PyObject *__pyx_n_s__MemoryError;
static PyObject *__pyx_n_s__OSError;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__StopIteration;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____cmp__;
static PyObject *__pyx_n_s____len__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s__add;
static PyObject *__pyx_n_s__allocate;
static PyObject *__pyx_n_s__args;
static PyObject *__pyx_n_s__asList;
static PyObject *__pyx_n_s__base;
static PyObject *__pyx_n_s__bucket_size;
static PyObject *__pyx_n_s__buildSegmentList;
static PyObject *__pyx_n_s__ceil;
static PyObject *__pyx_n_s__check;
static PyObject *__pyx_n_s__clear;
static PyObject *__pyx_n_s__clone;
static PyObject *__pyx_n_s__collections;
static PyObject *__pyx_n_s__container;
static PyObject *__pyx_n_s__dtype;
static PyObject *__pyx_n_s__end;
static PyObject *__pyx_n_s__expand_segments;
static PyObject *__pyx_n_s__extend;
static PyObject *__pyx_n_s__extend_segments;
static PyObject *__pyx_n_s__filter;
static PyObject *__pyx_n_s__float;
static PyObject *__pyx_n_s__forward;
static PyObject *__pyx_n_s__getInsertionPoint;
static PyObject *__pyx_n_s__getRandomPosition;
static PyObject *__pyx_n_s__getSegmentSize;
static PyObject *__pyx_n_s__int;
static PyObject *__pyx_n_s__intersect;
static PyObject *__pyx_n_s__iter;
static PyObject *__pyx_n_s__largest;
static PyObject *__pyx_n_s__math;
static PyObject *__pyx_n_s__max;
static PyObject *__pyx_n_s__merge;
static PyObject *__pyx_n_s__midpoint;
static PyObject *__pyx_n_s__min;
static PyObject *__pyx_n_s__mode;
static PyObject *__pyx_n_s__nbuckets;
static PyObject *__pyx_n_s__normalize;
static PyObject *__pyx_n_s__numpy;
static PyObject *__pyx_n_s__os;
static PyObject *__pyx_n_s__other;
static PyObject *__pyx_n_s__overlapWithRange;
static PyObject *__pyx_n_s__overlapWithSegments;
static PyObject *__pyx_n_s__pos;
static PyObject *__pyx_n_s__randint;
static PyObject *__pyx_n_s__random;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__re;
static PyObject *__pyx_n_s__remainder;
static PyObject *__pyx_n_s__share;
static PyObject *__pyx_n_s__size;
static PyObject *__pyx_n_s__sort;
static PyObject *__pyx_n_s__start;
static PyObject *__pyx_n_s__startswith;
static PyObject *__pyx_n_s__subtract;
static PyObject *__pyx_n_s__sum;
static PyObject *__pyx_n_s__summarize;
static PyObject *__pyx_n_s__trim;
static PyObject *__pyx_n_s__trim_ends;
static PyObject *__pyx_n_s__types;
static PyObject *__pyx_n_s__unreduce;
static PyObject *__pyx_n_s__zeros;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_15;
static PyObject *__pyx_int_100000;
static PyObject *__pyx_k_1;
static PyObject *__pyx_k_tuple_7;
static PyObject *__pyx_k_tuple_12;
static PyObject *__pyx_k_tuple_14;
static PyObject *__pyx_k_tuple_16;
static PyObject *__pyx_k_tuple_18;
static PyObject *__pyx_k_tuple_20;
static PyObject *__pyx_k_tuple_21;
static PyObject *__pyx_k_tuple_23;
static PyObject *__pyx_k_tuple_45;
static PyObject *__pyx_k_tuple_51;
static PyObject *__pyx_k_tuple_53;
static PyObject *__pyx_k_tuple_56;
static PyObject *__pyx_k_tuple_58;
static PyObject *__pyx_k_tuple_60;
static PyObject *__pyx_k_tuple_62;
static PyObject *__pyx_k_tuple_64;
static PyObject *__pyx_k_tuple_67;
static PyObject *__pyx_k_tuple_68;
static PyObject *__pyx_k_tuple_70;
static PyObject *__pyx_k_tuple_73;
static PyObject *__pyx_k_codeobj_71;
static PyObject *__pyx_k_codeobj_74;

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_1getSegmentSize(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_getSegmentSize[] = "getSegmentSize()\nreturn size of coordinate and size of a segment.";
static PyMethodDef __pyx_mdef_14GatSegmentList_1getSegmentSize = {__Pyx_NAMESTR("getSegmentSize"), (PyCFunction)__pyx_pw_14GatSegmentList_1getSegmentSize, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_getSegmentSize)};
static PyObject *__pyx_pw_14GatSegmentList_1getSegmentSize(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getSegmentSize (wrapper)", 0);
  __pyx_self = __pyx_self;
  __pyx_r = __pyx_pf_14GatSegmentList_getSegmentSize(__pyx_self);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":26
 * ctypedef numpy.float_t DTYPE_FLOAT_t
 * 
 * def getSegmentSize():             # <<<<<<<<<<<<<<
 *     '''return size of coordinate and size of a segment.'''
 *     return sizeof(Segment) // 2, sizeof(Segment)
 */

static PyObject *__pyx_pf_14GatSegmentList_getSegmentSize(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getSegmentSize", 0);

  /* "GatSegmentList.pyx":28
 * def getSegmentSize():
 *     '''return size of coordinate and size of a segment.'''
 *     return sizeof(Segment) // 2, sizeof(Segment)             # <<<<<<<<<<<<<<
 * 
 * # min/max are not optimized, so declare them as C functions
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(((sizeof(struct __pyx_t_14GatSegmentList_Segment)) / 2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_FromSize_t((sizeof(struct __pyx_t_14GatSegmentList_Segment))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_r = ((PyObject *)__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("GatSegmentList.getSegmentSize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":33
 * # declare as signed comparisons as a Position might be negative
 * @cython.profile(False)
 * cdef inline PositionDifference lmin( PositionDifference a, PositionDifference b):             # <<<<<<<<<<<<<<
 *     if a < b: return a
 *     return b
 */

static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_lmin(__pyx_t_14GatSegmentList_PositionDifference __pyx_v_a, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_b) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("lmin", 0);

  /* "GatSegmentList.pyx":34
 * @cython.profile(False)
 * cdef inline PositionDifference lmin( PositionDifference a, PositionDifference b):
 *     if a < b: return a             # <<<<<<<<<<<<<<
 *     return b
 * @cython.profile(False)
 */
  __pyx_t_1 = (__pyx_v_a < __pyx_v_b);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_a;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":35
 * cdef inline PositionDifference lmin( PositionDifference a, PositionDifference b):
 *     if a < b: return a
 *     return b             # <<<<<<<<<<<<<<
 * @cython.profile(False)
 * cdef inline PositionDifference lmax( PositionDifference a, PositionDifference b):
 */
  __pyx_r = __pyx_v_b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":37
 *     return b
 * @cython.profile(False)
 * cdef inline PositionDifference lmax( PositionDifference a, PositionDifference b):             # <<<<<<<<<<<<<<
 *     if a > b: return a
 *     return b
 */

static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_lmax(__pyx_t_14GatSegmentList_PositionDifference __pyx_v_a, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_b) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("lmax", 0);

  /* "GatSegmentList.pyx":38
 * @cython.profile(False)
 * cdef inline PositionDifference lmax( PositionDifference a, PositionDifference b):
 *     if a > b: return a             # <<<<<<<<<<<<<<
 *     return b
 * 
 */
  __pyx_t_1 = (__pyx_v_a > __pyx_v_b);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_a;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":39
 * cdef inline PositionDifference lmax( PositionDifference a, PositionDifference b):
 *     if a > b: return a
 *     return b             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = __pyx_v_b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":42
 * 
 * @cython.profile(False)
 * cdef inline double dmin( double a, double b):             # <<<<<<<<<<<<<<
 *     if a < b: return a
 *     return b
 */

static CYTHON_INLINE double __pyx_f_14GatSegmentList_dmin(double __pyx_v_a, double __pyx_v_b) {
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("dmin", 0);

  /* "GatSegmentList.pyx":43
 * @cython.profile(False)
 * cdef inline double dmin( double a, double b):
 *     if a < b: return a             # <<<<<<<<<<<<<<
 *     return b
 * 
 */
  __pyx_t_1 = (__pyx_v_a < __pyx_v_b);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_a;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":44
 * cdef inline double dmin( double a, double b):
 *     if a < b: return a
 *     return b             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = __pyx_v_b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":47
 * 
 * @cython.profile(False)
 * cdef inline double dmax( double a, double b):             # <<<<<<<<<<<<<<
 *     if a > b: return a
 *     return b
 */

static CYTHON_INLINE double __pyx_f_14GatSegmentList_dmax(double __pyx_v_a, double __pyx_v_b) {
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("dmax", 0);

  /* "GatSegmentList.pyx":48
 * @cython.profile(False)
 * cdef inline double dmax( double a, double b):
 *     if a > b: return a             # <<<<<<<<<<<<<<
 *     return b
 * 
 */
  __pyx_t_1 = (__pyx_v_a > __pyx_v_b);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_a;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":49
 * cdef inline double dmax( double a, double b):
 *     if a > b: return a
 *     return b             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = __pyx_v_b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":52
 * 
 * @cython.profile(False)
 * cdef inline PositionDifference segment_overlap( Segment a, Segment b ):             # <<<<<<<<<<<<<<
 *     return lmax(0, <PositionDifference>lmin( a.end, b.end) - <PositionDifference>lmax(a.start, b.start))
 * 
 */

static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_segment_overlap(struct __pyx_t_14GatSegmentList_Segment __pyx_v_a, struct __pyx_t_14GatSegmentList_Segment __pyx_v_b) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("segment_overlap", 0);

  /* "GatSegmentList.pyx":53
 * @cython.profile(False)
 * cdef inline PositionDifference segment_overlap( Segment a, Segment b ):
 *     return lmax(0, <PositionDifference>lmin( a.end, b.end) - <PositionDifference>lmax(a.start, b.start))             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = __pyx_f_14GatSegmentList_lmax(0, (((__pyx_t_14GatSegmentList_PositionDifference)__pyx_f_14GatSegmentList_lmin(__pyx_v_a.end, __pyx_v_b.end)) - ((__pyx_t_14GatSegmentList_PositionDifference)__pyx_f_14GatSegmentList_lmax(__pyx_v_a.start, __pyx_v_b.start))));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":56
 * 
 * @cython.profile(False)
 * cdef inline PositionDifference range_overlap( Position astart, Position aend, Position bstart, Position bend ):             # <<<<<<<<<<<<<<
 *     return lmax(0,
 *                 <PositionDifference>lmin( aend, bend) -
 */

static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_range_overlap(__pyx_t_14GatSegmentList_Position __pyx_v_astart, __pyx_t_14GatSegmentList_Position __pyx_v_aend, __pyx_t_14GatSegmentList_Position __pyx_v_bstart, __pyx_t_14GatSegmentList_Position __pyx_v_bend) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("range_overlap", 0);

  /* "GatSegmentList.pyx":59
 *     return lmax(0,
 *                 <PositionDifference>lmin( aend, bend) -
 *                 <PositionDifference>lmax(astart, bstart))             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = __pyx_f_14GatSegmentList_lmax(0, (((__pyx_t_14GatSegmentList_PositionDifference)__pyx_f_14GatSegmentList_lmin(__pyx_v_aend, __pyx_v_bend)) - ((__pyx_t_14GatSegmentList_PositionDifference)__pyx_f_14GatSegmentList_lmax(__pyx_v_astart, __pyx_v_bstart))));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":62
 * 
 * @cython.profile(False)
 * cdef inline PositionDifference segment_overlap_raw(  Segment a, Segment b ):             # <<<<<<<<<<<<<<
 *     return <PositionDifference>lmin(a.end, b.end) - <PositionDifference>lmax(a.start, b.start)
 * 
 */

static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_segment_overlap_raw(struct __pyx_t_14GatSegmentList_Segment __pyx_v_a, struct __pyx_t_14GatSegmentList_Segment __pyx_v_b) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("segment_overlap_raw", 0);

  /* "GatSegmentList.pyx":63
 * @cython.profile(False)
 * cdef inline PositionDifference segment_overlap_raw(  Segment a, Segment b ):
 *     return <PositionDifference>lmin(a.end, b.end) - <PositionDifference>lmax(a.start, b.start)             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = (((__pyx_t_14GatSegmentList_PositionDifference)__pyx_f_14GatSegmentList_lmin(__pyx_v_a.end, __pyx_v_b.end)) - ((__pyx_t_14GatSegmentList_PositionDifference)__pyx_f_14GatSegmentList_lmax(__pyx_v_a.start, __pyx_v_b.start)));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":66
 * 
 * @cython.profile(False)
 * cdef inline PositionDifference segment_length(  Segment a ):             # <<<<<<<<<<<<<<
 *     return <PositionDifference>a.end - <PositionDifference>a.start
 * 
 */

static CYTHON_INLINE __pyx_t_14GatSegmentList_PositionDifference __pyx_f_14GatSegmentList_segment_length(struct __pyx_t_14GatSegmentList_Segment __pyx_v_a) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("segment_length", 0);

  /* "GatSegmentList.pyx":67
 * @cython.profile(False)
 * cdef inline PositionDifference segment_length(  Segment a ):
 *     return <PositionDifference>a.end - <PositionDifference>a.start             # <<<<<<<<<<<<<<
 * 
 * # trick to permit const void * in function definitions
 */
  __pyx_r = (((__pyx_t_14GatSegmentList_PositionDifference)__pyx_v_a.end) - ((__pyx_t_14GatSegmentList_PositionDifference)__pyx_v_a.start));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":74
 * 
 * @cython.profile(False)
 * cdef int cmpSegments( const_void_ptr s1, const_void_ptr s2 ):             # <<<<<<<<<<<<<<
 *     return <PositionDifference>(<Segment *>s1).start - <PositionDifference>(<Segment *>s2).start
 * 
 */

static int __pyx_f_14GatSegmentList_cmpSegments(const void* __pyx_v_s1, const void* __pyx_v_s2) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cmpSegments", 0);

  /* "GatSegmentList.pyx":75
 * @cython.profile(False)
 * cdef int cmpSegments( const_void_ptr s1, const_void_ptr s2 ):
 *     return <PositionDifference>(<Segment *>s1).start - <PositionDifference>(<Segment *>s2).start             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = (((__pyx_t_14GatSegmentList_PositionDifference)((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_s1)->start) - ((__pyx_t_14GatSegmentList_PositionDifference)((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_s2)->start));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":78
 * 
 * @cython.profile(False)
 * cdef int cmpSegmentsStartAndEnd( const_void_ptr s1, const_void_ptr s2 ):             # <<<<<<<<<<<<<<
 *     cdef int x
 *     x = <PositionDifference>(<Segment *>s1).start - <PositionDifference>(<Segment *>s2).start
 */

static int __pyx_f_14GatSegmentList_cmpSegmentsStartAndEnd(const void* __pyx_v_s1, const void* __pyx_v_s2) {
  int __pyx_v_x;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("cmpSegmentsStartAndEnd", 0);

  /* "GatSegmentList.pyx":80
 * cdef int cmpSegmentsStartAndEnd( const_void_ptr s1, const_void_ptr s2 ):
 *     cdef int x
 *     x = <PositionDifference>(<Segment *>s1).start - <PositionDifference>(<Segment *>s2).start             # <<<<<<<<<<<<<<
 *     if x != 0: return x
 *     return <PositionDifference>(<Segment *>s1).end - <PositionDifference>(<Segment *>s2).end
 */
  __pyx_v_x = (((__pyx_t_14GatSegmentList_PositionDifference)((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_s1)->start) - ((__pyx_t_14GatSegmentList_PositionDifference)((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_s2)->start));

  /* "GatSegmentList.pyx":81
 *     cdef int x
 *     x = <PositionDifference>(<Segment *>s1).start - <PositionDifference>(<Segment *>s2).start
 *     if x != 0: return x             # <<<<<<<<<<<<<<
 *     return <PositionDifference>(<Segment *>s1).end - <PositionDifference>(<Segment *>s2).end
 * 
 */
  __pyx_t_1 = (__pyx_v_x != 0);
  if (__pyx_t_1) {
    __pyx_r = __pyx_v_x;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":82
 *     x = <PositionDifference>(<Segment *>s1).start - <PositionDifference>(<Segment *>s2).start
 *     if x != 0: return x
 *     return <PositionDifference>(<Segment *>s1).end - <PositionDifference>(<Segment *>s2).end             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = (((__pyx_t_14GatSegmentList_PositionDifference)((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_s1)->end) - ((__pyx_t_14GatSegmentList_PositionDifference)((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_s2)->end));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":85
 * 
 * @cython.profile(False)
 * cdef int cmpPosition( const_void_ptr s1, const_void_ptr s2 ):             # <<<<<<<<<<<<<<
 *     return (<Position*>s1)[0] - (<Position*>s2)[0]
 * 
 */

static int __pyx_f_14GatSegmentList_cmpPosition(const void* __pyx_v_s1, const void* __pyx_v_s2) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cmpPosition", 0);

  /* "GatSegmentList.pyx":86
 * @cython.profile(False)
 * cdef int cmpPosition( const_void_ptr s1, const_void_ptr s2 ):
 *     return (<Position*>s1)[0] - (<Position*>s2)[0]             # <<<<<<<<<<<<<<
 * 
 * @cython.profile(False)
 */
  __pyx_r = ((((__pyx_t_14GatSegmentList_Position *)__pyx_v_s1)[0]) - (((__pyx_t_14GatSegmentList_Position *)__pyx_v_s2)[0]));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":89
 * 
 * @cython.profile(False)
 * cdef int cmpDouble( const_void_ptr s1, const_void_ptr s2 ):             # <<<<<<<<<<<<<<
 *     return <int>((<double*>s1)[0] - (<double*>s2)[0])
 * 
 */

static int __pyx_f_14GatSegmentList_cmpDouble(const void* __pyx_v_s1, const void* __pyx_v_s2) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cmpDouble", 0);

  /* "GatSegmentList.pyx":90
 * @cython.profile(False)
 * cdef int cmpDouble( const_void_ptr s1, const_void_ptr s2 ):
 *     return <int>((<double*>s1)[0] - (<double*>s2)[0])             # <<<<<<<<<<<<<<
 * 
 * # Flag for Segment list status
 */
  __pyx_r = ((int)((((double *)__pyx_v_s1)[0]) - (((double *)__pyx_v_s2)[0])));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_14GatSegmentList_11SegmentList_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList___init__[] = "create empty list of segments.\n        \n        Creating is a lazy operation, no memory is allocated unless\n        explitely given. A SegmentList might be initialized using\n        the following options:\n\n        If *allocate* is set, create an empty list, but allocate slots\n\n        If *clone* is given, create a copy an existing list.\n\n        If *iter* is given, initialize list from iterable.\n\n        If *share* is set, the list will be a slave. It will share\n        memory with a _master_, which has been set up by calling the \n        :meth:`share` method. Memory access for the slave is read-only.\n\n        If *unreduce* is given, the list will be re-constituted\n        from a pickled data representation (see __reduce__). Note that\n        if a _master_ has been pickled, the reconstituted object will be\n        a _slave_.\n\n        If *normalize* is set, the list will be normalized.\n        ";
struct wrapperbase __pyx_wrapperbase_14GatSegmentList_11SegmentList___init__;
static int __pyx_pw_14GatSegmentList_11SegmentList_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_allocate;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_clone = 0;
  PyObject *__pyx_v_iter = 0;
  PyObject *__pyx_v_normalize = 0;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_share = 0;
  PyObject *__pyx_v_unreduce = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__allocate,&__pyx_n_s__clone,&__pyx_n_s__iter,&__pyx_n_s__normalize,&__pyx_n_s__share,&__pyx_n_s__unreduce,0};
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "GatSegmentList.pyx":109
 *     def __init__(self,
 *                  int allocate = 0,
 *                  SegmentList clone = None,             # <<<<<<<<<<<<<<
 *                  iter = None,
 *                  normalize = False,
 */
    values[1] = (PyObject *)((struct __pyx_obj_14GatSegmentList_SegmentList *)Py_None);

    /* "GatSegmentList.pyx":110
 *                  int allocate = 0,
 *                  SegmentList clone = None,
 *                  iter = None,             # <<<<<<<<<<<<<<
 *                  normalize = False,
 *                  SegmentList share = None,
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k_1;

    /* "GatSegmentList.pyx":112
 *                  iter = None,
 *                  normalize = False,
 *                  SegmentList share = None,             # <<<<<<<<<<<<<<
 *                  unreduce = None ):
 *         '''create empty list of segments.
 */
    values[4] = (PyObject *)((struct __pyx_obj_14GatSegmentList_SegmentList *)Py_None);

    /* "GatSegmentList.pyx":113
 *                  normalize = False,
 *                  SegmentList share = None,
 *                  unreduce = None ):             # <<<<<<<<<<<<<<
 *         '''create empty list of segments.
 * 
 */
    values[5] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__allocate);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__clone);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__iter);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__normalize);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__share);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unreduce);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      if (values[0]) {
      } else {
        __pyx_v_allocate = ((int)0);
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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;
      }
    }
    if (values[0]) {
      __pyx_v_allocate = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_allocate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_allocate = ((int)0);
    }
    __pyx_v_clone = ((struct __pyx_obj_14GatSegmentList_SegmentList *)values[1]);
    __pyx_v_iter = values[2];
    __pyx_v_normalize = values[3];
    __pyx_v_share = ((struct __pyx_obj_14GatSegmentList_SegmentList *)values[4]);
    __pyx_v_unreduce = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_clone), __pyx_ptype_14GatSegmentList_SegmentList, 1, "clone", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_share), __pyx_ptype_14GatSegmentList_SegmentList, 1, "share", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList___init__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_allocate, __pyx_v_clone, __pyx_v_iter, __pyx_v_normalize, __pyx_v_share, __pyx_v_unreduce);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":107
 *     Call normalize to merge overlapping segments.
 *     '''
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  int allocate = 0,
 *                  SegmentList clone = None,
 */

static int __pyx_pf_14GatSegmentList_11SegmentList___init__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_allocate, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_clone, PyObject *__pyx_v_iter, PyObject *__pyx_v_normalize, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_share, PyObject *__pyx_v_unreduce) {
  char *__pyx_v_p;
  long __pyx_v_idx;
  long __pyx_v_nsegments;
  void *__pyx_v_retval;
  int __pyx_v_error_number;
  PyObject *__pyx_v_shared_fd = NULL;
  PyObject *__pyx_v_a = NULL;
  PyObject *__pyx_v_start = NULL;
  PyObject *__pyx_v_end = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  size_t __pyx_t_10;
  size_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  char *__pyx_t_14;
  Py_ssize_t __pyx_t_15;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_16;
  __pyx_t_14GatSegmentList_Position __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "GatSegmentList.pyx":144
 * 
 *         # initialize empty list
 *         self.segments = NULL             # <<<<<<<<<<<<<<
 *         self.nsegments = 0
 *         self.allocated = 0
 */
  __pyx_v_self->segments = NULL;

  /* "GatSegmentList.pyx":145
 *         # initialize empty list
 *         self.segments = NULL
 *         self.nsegments = 0             # <<<<<<<<<<<<<<
 *         self.allocated = 0
 * 
 */
  __pyx_v_self->nsegments = 0;

  /* "GatSegmentList.pyx":146
 *         self.segments = NULL
 *         self.nsegments = 0
 *         self.allocated = 0             # <<<<<<<<<<<<<<
 * 
 *         # The state of a segment list can be:
 */
  __pyx_v_self->allocated = 0;

  /* "GatSegmentList.pyx":164
 * 
 *         # an empty list is normalized
 *         self.flag = 1             # <<<<<<<<<<<<<<
 *         self.chunk_size = 10000
 * 
 */
  __pyx_v_self->flag = 1;

  /* "GatSegmentList.pyx":165
 *         # an empty list is normalized
 *         self.flag = 1
 *         self.chunk_size = 10000             # <<<<<<<<<<<<<<
 * 
 *         # no sharing
 */
  __pyx_v_self->chunk_size = 10000;

  /* "GatSegmentList.pyx":168
 * 
 *         # no sharing
 *         self.shared_fd = -1             # <<<<<<<<<<<<<<
 *         self.key = None
 * 
 */
  __pyx_v_self->shared_fd = -1;

  /* "GatSegmentList.pyx":169
 *         # no sharing
 *         self.shared_fd = -1
 *         self.key = None             # <<<<<<<<<<<<<<
 * 
 *         # initialize list from shared memory
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->key);
  __Pyx_DECREF(__pyx_v_self->key);
  __pyx_v_self->key = Py_None;

  /* "GatSegmentList.pyx":173
 *         # initialize list from shared memory
 *         # allocated is 0
 *         if share != None:             # <<<<<<<<<<<<<<
 *             self.nsegments = share.nsegments
 *             if self.nsegments > 0:
 */
  __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_share), Py_None, Py_NE); 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 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "GatSegmentList.pyx":174
 *         # allocated is 0
 *         if share != None:
 *             self.nsegments = share.nsegments             # <<<<<<<<<<<<<<
 *             if self.nsegments > 0:
 *                 assert share.shared_fd >= 0, "sharing from a non-shared SegmentList"
 */
    __pyx_v_self->nsegments = __pyx_v_share->nsegments;

    /* "GatSegmentList.pyx":175
 *         if share != None:
 *             self.nsegments = share.nsegments
 *             if self.nsegments > 0:             # <<<<<<<<<<<<<<
 *                 assert share.shared_fd >= 0, "sharing from a non-shared SegmentList"
 * 
 */
    __pyx_t_2 = (__pyx_v_self->nsegments > 0);
    if (__pyx_t_2) {

      /* "GatSegmentList.pyx":176
 *             self.nsegments = share.nsegments
 *             if self.nsegments > 0:
 *                 assert share.shared_fd >= 0, "sharing from a non-shared SegmentList"             # <<<<<<<<<<<<<<
 * 
 *                 self.allocated = 0
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!(__pyx_v_share->shared_fd >= 0))) {
        PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_2));
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif

      /* "GatSegmentList.pyx":178
 *                 assert share.shared_fd >= 0, "sharing from a non-shared SegmentList"
 * 
 *                 self.allocated = 0             # <<<<<<<<<<<<<<
 *                 self.flag = share.flag | SEG_SHARED | SEG_SLAVE
 *                 self.chunk_size = share.chunk_size
 */
      __pyx_v_self->allocated = 0;

      /* "GatSegmentList.pyx":179
 * 
 *                 self.allocated = 0
 *                 self.flag = share.flag | SEG_SHARED | SEG_SLAVE             # <<<<<<<<<<<<<<
 *                 self.chunk_size = share.chunk_size
 *                 retval = <Segment*>mmap(NULL,
 */
      __pyx_v_self->flag = ((__pyx_v_share->flag | 2) | 4);

      /* "GatSegmentList.pyx":180
 *                 self.allocated = 0
 *                 self.flag = share.flag | SEG_SHARED | SEG_SLAVE
 *                 self.chunk_size = share.chunk_size             # <<<<<<<<<<<<<<
 *                 retval = <Segment*>mmap(NULL,
 *                                         self.nsegments * sizeof(Segment),
 */
      __pyx_v_self->chunk_size = __pyx_v_share->chunk_size;

      /* "GatSegmentList.pyx":185
 *                                         PROT_READ,
 *                                         MAP_SHARED,
 *                                         share.shared_fd,             # <<<<<<<<<<<<<<
 *                                         0)
 * 
 */
      __pyx_v_retval = ((struct __pyx_t_14GatSegmentList_Segment *)mmap(NULL, (__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment))), PROT_READ, MAP_SHARED, __pyx_v_share->shared_fd, 0));

      /* "GatSegmentList.pyx":188
 *                                         0)
 * 
 *                 error_number = errno             # <<<<<<<<<<<<<<
 * 
 *                 if retval == MAP_FAILED:
 */
      __pyx_v_error_number = errno;

      /* "GatSegmentList.pyx":190
 *                 error_number = errno
 * 
 *                 if retval == MAP_FAILED:             # <<<<<<<<<<<<<<
 *                     raise ValueError("could not read list from shared segment - error=%i" % error_number )
 *                 self.segments = <Segment *>retval
 */
      __pyx_t_2 = (__pyx_v_retval == MAP_FAILED);
      if (__pyx_t_2) {

        /* "GatSegmentList.pyx":191
 * 
 *                 if retval == MAP_FAILED:
 *                     raise ValueError("could not read list from shared segment - error=%i" % error_number )             # <<<<<<<<<<<<<<
 *                 self.segments = <Segment *>retval
 * 
 */
        __pyx_t_1 = PyInt_FromLong(__pyx_v_error_number); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_3));
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
        __pyx_t_3 = 0;
        __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L5;
      }
      __pyx_L5:;

      /* "GatSegmentList.pyx":192
 *                 if retval == MAP_FAILED:
 *                     raise ValueError("could not read list from shared segment - error=%i" % error_number )
 *                 self.segments = <Segment *>retval             # <<<<<<<<<<<<<<
 * 
 *         # create from pickled representation
 */
      __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_retval);
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":197
 *         # if a shared object is pickled, it will be re-constituted
 *         # as a slave list.
 *         elif unreduce:             # <<<<<<<<<<<<<<
 *             self.nsegments, self.allocated, self.flag, self.chunk_size, self.key = unreduce[:5]
 *             if type(unreduce[5]) == int:
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_unreduce); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "GatSegmentList.pyx":198
 *         # as a slave list.
 *         elif unreduce:
 *             self.nsegments, self.allocated, self.flag, self.chunk_size, self.key = unreduce[:5]             # <<<<<<<<<<<<<<
 *             if type(unreduce[5]) == int:
 *                 # shared memory
 */
    __pyx_t_3 = __Pyx_PySequence_GetSlice(__pyx_v_unreduce, 0, 5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
      PyObject* sequence = __pyx_t_3;
      if (likely(PyTuple_CheckExact(sequence))) {
        if (unlikely(PyTuple_GET_SIZE(sequence) != 5)) {
          if (PyTuple_GET_SIZE(sequence) > 5) __Pyx_RaiseTooManyValuesError(5);
          else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 4); 
      } else {
        if (unlikely(PyList_GET_SIZE(sequence) != 5)) {
          if (PyList_GET_SIZE(sequence) > 5) __Pyx_RaiseTooManyValuesError(5);
          else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 3); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 4); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      index = 2; __pyx_t_5 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_5)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      index = 3; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      index = 4; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
      if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L7_unpacking_done:;
    }
    __pyx_t_10 = __Pyx_PyInt_AsSize_t(__pyx_t_1); if (unlikely((__pyx_t_10 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_11 = __Pyx_PyInt_AsSize_t(__pyx_t_4); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_self->nsegments = __pyx_t_10;
    __pyx_v_self->allocated = __pyx_t_11;
    __pyx_v_self->flag = __pyx_t_12;
    __pyx_v_self->chunk_size = __pyx_t_13;
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_self->key);
    __Pyx_DECREF(__pyx_v_self->key);
    __pyx_v_self->key = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "GatSegmentList.pyx":199
 *         elif unreduce:
 *             self.nsegments, self.allocated, self.flag, self.chunk_size, self.key = unreduce[:5]
 *             if type(unreduce[5]) == int:             # <<<<<<<<<<<<<<
 *                 # shared memory
 *                 shared_fd = unreduce[5]
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_unreduce, 5, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_t_3)), ((PyObject *)((PyObject*)(&PyInt_Type))), Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_2) {

      /* "GatSegmentList.pyx":201
 *             if type(unreduce[5]) == int:
 *                 # shared memory
 *                 shared_fd = unreduce[5]             # <<<<<<<<<<<<<<
 * 
 *                 retval = mmap(NULL,
 */
      __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_unreduce, 5, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_v_shared_fd = __pyx_t_7;
      __pyx_t_7 = 0;

      /* "GatSegmentList.pyx":207
 *                               PROT_READ,
 *                               MAP_SHARED,
 *                               shared_fd,             # <<<<<<<<<<<<<<
 *                               0)
 * 
 */
      __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_shared_fd); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_retval = mmap(NULL, (__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment))), PROT_READ, MAP_SHARED, __pyx_t_13, 0);

      /* "GatSegmentList.pyx":210
 *                               0)
 * 
 *                 error_number = errno             # <<<<<<<<<<<<<<
 * 
 *                 if retval == MAP_FAILED:
 */
      __pyx_v_error_number = errno;

      /* "GatSegmentList.pyx":212
 *                 error_number = errno
 * 
 *                 if retval == MAP_FAILED:             # <<<<<<<<<<<<<<
 *                     raise ValueError( "could not unpickle as slave - error=%i" % error_number)
 * 
 */
      __pyx_t_2 = (__pyx_v_retval == MAP_FAILED);
      if (__pyx_t_2) {

        /* "GatSegmentList.pyx":213
 * 
 *                 if retval == MAP_FAILED:
 *                     raise ValueError( "could not unpickle as slave - error=%i" % error_number)             # <<<<<<<<<<<<<<
 * 
 *                 self.segments = <Segment *>retval
 */
        __pyx_t_7 = PyInt_FromLong(__pyx_v_error_number); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_4), __pyx_t_7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_3));
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_3));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
        __pyx_t_3 = 0;
        __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L9;
      }
      __pyx_L9:;

      /* "GatSegmentList.pyx":215
 *                     raise ValueError( "could not unpickle as slave - error=%i" % error_number)
 * 
 *                 self.segments = <Segment *>retval             # <<<<<<<<<<<<<<
 * 
 *                 # mark memory as slave - nothing allocated and no shared_fd
 */
      __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_retval);

      /* "GatSegmentList.pyx":218
 * 
 *                 # mark memory as slave - nothing allocated and no shared_fd
 *                 self.allocated = 0             # <<<<<<<<<<<<<<
 *                 self.shared_fd = -1
 *                 self.flag |= SEG_SHARED | SEG_SLAVE
 */
      __pyx_v_self->allocated = 0;

      /* "GatSegmentList.pyx":219
 *                 # mark memory as slave - nothing allocated and no shared_fd
 *                 self.allocated = 0
 *                 self.shared_fd = -1             # <<<<<<<<<<<<<<
 *                 self.flag |= SEG_SHARED | SEG_SLAVE
 *             else:
 */
      __pyx_v_self->shared_fd = -1;

      /* "GatSegmentList.pyx":220
 *                 self.allocated = 0
 *                 self.shared_fd = -1
 *                 self.flag |= SEG_SHARED | SEG_SLAVE             # <<<<<<<<<<<<<<
 *             else:
 *                 p = PyString_AsString(unreduce[5])
 */
      __pyx_v_self->flag = (__pyx_v_self->flag | 6);
      goto __pyx_L8;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":222
 *                 self.flag |= SEG_SHARED | SEG_SLAVE
 *             else:
 *                 p = PyString_AsString(unreduce[5])             # <<<<<<<<<<<<<<
 *                 self.segments = <Segment*>malloc( self.nsegments * sizeof( Segment ) )
 *                 memcpy( self.segments, p, cython.sizeof( Position ) * 2 * self.nsegments )
 */
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_unreduce, 5, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_14 = PyString_AsString(__pyx_t_3); if (unlikely(__pyx_t_14 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_p = __pyx_t_14;

      /* "GatSegmentList.pyx":223
 *             else:
 *                 p = PyString_AsString(unreduce[5])
 *                 self.segments = <Segment*>malloc( self.nsegments * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *                 memcpy( self.segments, p, cython.sizeof( Position ) * 2 * self.nsegments )
 * 
 */
      __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

      /* "GatSegmentList.pyx":224
 *                 p = PyString_AsString(unreduce[5])
 *                 self.segments = <Segment*>malloc( self.nsegments * sizeof( Segment ) )
 *                 memcpy( self.segments, p, cython.sizeof( Position ) * 2 * self.nsegments )             # <<<<<<<<<<<<<<
 * 
 *         # clone from another list
 */
      memcpy(__pyx_v_self->segments, __pyx_v_p, (((sizeof(__pyx_t_14GatSegmentList_Position)) * 2) * __pyx_v_self->nsegments));
    }
    __pyx_L8:;
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":227
 * 
 *         # clone from another list
 *         elif clone != None:             # <<<<<<<<<<<<<<
 *             self.nsegments = self.allocated = clone.nsegments
 *             self.segments = <Segment*>calloc( clone.nsegments, sizeof( Segment ) )
 */
  __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_clone), Py_None, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_2) {

    /* "GatSegmentList.pyx":228
 *         # clone from another list
 *         elif clone != None:
 *             self.nsegments = self.allocated = clone.nsegments             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>calloc( clone.nsegments, sizeof( Segment ) )
 *             memcpy( self.segments,
 */
    __pyx_v_self->nsegments = __pyx_v_clone->nsegments;
    __pyx_v_self->allocated = __pyx_v_clone->nsegments;

    /* "GatSegmentList.pyx":229
 *         elif clone != None:
 *             self.nsegments = self.allocated = clone.nsegments
 *             self.segments = <Segment*>calloc( clone.nsegments, sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *             memcpy( self.segments,
 *                     clone.segments,
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)calloc(__pyx_v_clone->nsegments, (sizeof(struct __pyx_t_14GatSegmentList_Segment))));

    /* "GatSegmentList.pyx":232
 *             memcpy( self.segments,
 *                     clone.segments,
 *                     clone.nsegments * sizeof(Segment ) )             # <<<<<<<<<<<<<<
 *             self.flag = clone.flag & SEG_NORMALIZED
 * 
 */
    memcpy(__pyx_v_self->segments, __pyx_v_clone->segments, (__pyx_v_clone->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment))));

    /* "GatSegmentList.pyx":233
 *                     clone.segments,
 *                     clone.nsegments * sizeof(Segment ) )
 *             self.flag = clone.flag & SEG_NORMALIZED             # <<<<<<<<<<<<<<
 * 
 *         # create from an iterable
 */
    __pyx_v_self->flag = (__pyx_v_clone->flag & 1);
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":236
 * 
 *         # create from an iterable
 *         elif iter:             # <<<<<<<<<<<<<<
 *             a = tuple(iter)
 *             nsegments = len(a)
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_iter); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "GatSegmentList.pyx":237
 *         # create from an iterable
 *         elif iter:
 *             a = tuple(iter)             # <<<<<<<<<<<<<<
 *             nsegments = len(a)
 *             self.nsegments = self.allocated = nsegments
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_iter);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_iter);
    __Pyx_GIVEREF(__pyx_v_iter);
    __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_v_a = ((PyObject*)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "GatSegmentList.pyx":238
 *         elif iter:
 *             a = tuple(iter)
 *             nsegments = len(a)             # <<<<<<<<<<<<<<
 *             self.nsegments = self.allocated = nsegments
 *             self.segments = <Segment*>calloc( self.nsegments, sizeof( Segment ) )
 */
    __pyx_t_15 = PyTuple_GET_SIZE(((PyObject *)__pyx_v_a)); 
    __pyx_v_nsegments = __pyx_t_15;

    /* "GatSegmentList.pyx":239
 *             a = tuple(iter)
 *             nsegments = len(a)
 *             self.nsegments = self.allocated = nsegments             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>calloc( self.nsegments, sizeof( Segment ) )
 *             idx = 0
 */
    __pyx_v_self->nsegments = __pyx_v_nsegments;
    __pyx_v_self->allocated = __pyx_v_nsegments;

    /* "GatSegmentList.pyx":240
 *             nsegments = len(a)
 *             self.nsegments = self.allocated = nsegments
 *             self.segments = <Segment*>calloc( self.nsegments, sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *             idx = 0
 *             for start, end in a:
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)calloc(__pyx_v_self->nsegments, (sizeof(struct __pyx_t_14GatSegmentList_Segment))));

    /* "GatSegmentList.pyx":241
 *             self.nsegments = self.allocated = nsegments
 *             self.segments = <Segment*>calloc( self.nsegments, sizeof( Segment ) )
 *             idx = 0             # <<<<<<<<<<<<<<
 *             for start, end in a:
 *                 self.segments[idx] = Segment( start, end )
 */
    __pyx_v_idx = 0;

    /* "GatSegmentList.pyx":242
 *             self.segments = <Segment*>calloc( self.nsegments, sizeof( Segment ) )
 *             idx = 0
 *             for start, end in a:             # <<<<<<<<<<<<<<
 *                 self.segments[idx] = Segment( start, end )
 *                 idx += 1
 */
    __pyx_t_7 = ((PyObject *)__pyx_v_a); __Pyx_INCREF(__pyx_t_7); __pyx_t_15 = 0;
    for (;;) {
      if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_15); __Pyx_INCREF(__pyx_t_3); __pyx_t_15++;
      if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
        PyObject* sequence = __pyx_t_3;
        if (likely(PyTuple_CheckExact(sequence))) {
          if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
            if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
            else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
            if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
            else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L12_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_5 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_5)) goto __pyx_L12_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_5);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L13_unpacking_done;
        __pyx_L12_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
        if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L13_unpacking_done:;
      }
      __Pyx_XDECREF(__pyx_v_start);
      __pyx_v_start = __pyx_t_6;
      __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_v_end);
      __pyx_v_end = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "GatSegmentList.pyx":243
 *             idx = 0
 *             for start, end in a:
 *                 self.segments[idx] = Segment( start, end )             # <<<<<<<<<<<<<<
 *                 idx += 1
 *             self.flag = 0
 */
      __pyx_t_17 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_start); if (unlikely((__pyx_t_17 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_16.start = __pyx_t_17;
      __pyx_t_17 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_end); if (unlikely((__pyx_t_17 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_16.end = __pyx_t_17;
      (__pyx_v_self->segments[__pyx_v_idx]) = __pyx_t_16;

      /* "GatSegmentList.pyx":244
 *             for start, end in a:
 *                 self.segments[idx] = Segment( start, end )
 *                 idx += 1             # <<<<<<<<<<<<<<
 *             self.flag = 0
 * 
 */
      __pyx_v_idx = (__pyx_v_idx + 1);
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "GatSegmentList.pyx":245
 *                 self.segments[idx] = Segment( start, end )
 *                 idx += 1
 *             self.flag = 0             # <<<<<<<<<<<<<<
 * 
 *         # allocated memory, list remains empty
 */
    __pyx_v_self->flag = 0;
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":248
 * 
 *         # allocated memory, list remains empty
 *         elif allocate:             # <<<<<<<<<<<<<<
 *             self.allocated = allocate
 *             self.segments = <Segment*>calloc( allocate, sizeof( Segment ) )
 */
  if (__pyx_v_allocate) {

    /* "GatSegmentList.pyx":249
 *         # allocated memory, list remains empty
 *         elif allocate:
 *             self.allocated = allocate             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>calloc( allocate, sizeof( Segment ) )
 * 
 */
    __pyx_v_self->allocated = __pyx_v_allocate;

    /* "GatSegmentList.pyx":250
 *         elif allocate:
 *             self.allocated = allocate
 *             self.segments = <Segment*>calloc( allocate, sizeof( Segment ) )             # <<<<<<<<<<<<<<
 * 
 *         if normalize: self.normalize()
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)calloc(__pyx_v_allocate, (sizeof(struct __pyx_t_14GatSegmentList_Segment))));
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":252
 *             self.segments = <Segment*>calloc( allocate, sizeof( Segment ) )
 * 
 *         if normalize: self.normalize()             # <<<<<<<<<<<<<<
 * 
 *     def __reduce__( self ):
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_normalize); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {
    __pyx_t_7 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->normalize(__pyx_v_self, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L14;
  }
  __pyx_L14:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_shared_fd);
  __Pyx_XDECREF(__pyx_v_a);
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_3__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_2__reduce__[] = "SegmentList.__reduce__(self)\npickling function - returns class contents as a tuple.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_3__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_2__reduce__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":254
 *         if normalize: self.normalize()
 * 
 *     def __reduce__( self ):             # <<<<<<<<<<<<<<
 *         '''pickling function - returns class contents as a tuple.'''
 * 
 */

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

  /* "GatSegmentList.pyx":259
 *         cdef str data
 * 
 *         if self.shared_fd >= 0:             # <<<<<<<<<<<<<<
 *             return (buildSegmentList, ( self.nsegments,
 *                                         self.allocated,
 */
  __pyx_t_1 = (__pyx_v_self->shared_fd >= 0);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":260
 * 
 *         if self.shared_fd >= 0:
 *             return (buildSegmentList, ( self.nsegments,             # <<<<<<<<<<<<<<
 *                                         self.allocated,
 *                                         self.flag,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__buildSegmentList); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_self->nsegments); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "GatSegmentList.pyx":261
 *         if self.shared_fd >= 0:
 *             return (buildSegmentList, ( self.nsegments,
 *                                         self.allocated,             # <<<<<<<<<<<<<<
 *                                         self.flag,
 *                                         self.chunk_size,
 */
    __pyx_t_4 = __Pyx_PyInt_FromSize_t(__pyx_v_self->allocated); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "GatSegmentList.pyx":262
 *             return (buildSegmentList, ( self.nsegments,
 *                                         self.allocated,
 *                                         self.flag,             # <<<<<<<<<<<<<<
 *                                         self.chunk_size,
 *                                         self.key,
 */
    __pyx_t_5 = PyInt_FromLong(__pyx_v_self->flag); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);

    /* "GatSegmentList.pyx":263
 *                                         self.allocated,
 *                                         self.flag,
 *                                         self.chunk_size,             # <<<<<<<<<<<<<<
 *                                         self.key,
 *                                         self.shared_fd) )
 */
    __pyx_t_6 = PyInt_FromLong(__pyx_v_self->chunk_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);

    /* "GatSegmentList.pyx":265
 *                                         self.chunk_size,
 *                                         self.key,
 *                                         self.shared_fd) )             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
    __pyx_t_7 = PyInt_FromLong(__pyx_v_self->shared_fd); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_self->key);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_self->key);
    __Pyx_GIVEREF(__pyx_v_self->key);
    PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_3 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_t_8));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
    __pyx_t_2 = 0;
    __pyx_t_8 = 0;
    __pyx_r = ((PyObject *)__pyx_t_7);
    __pyx_t_7 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "GatSegmentList.pyx":269
 *         else:
 *             data = PyString_FromStringAndSize(<char*>self.segments, \
 *                                                    self.nsegments * cython.sizeof( Position ) * 2 )             # <<<<<<<<<<<<<<
 * 
 *             return (buildSegmentList, ( self.nsegments,
 */
    __pyx_t_7 = PyString_FromStringAndSize(((char *)__pyx_v_self->segments), ((__pyx_v_self->nsegments * (sizeof(__pyx_t_14GatSegmentList_Position))) * 2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    if (!(likely(PyString_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(__pyx_t_7)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_data = ((PyObject*)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "GatSegmentList.pyx":271
 *                                                    self.nsegments * cython.sizeof( Position ) * 2 )
 * 
 *             return (buildSegmentList, ( self.nsegments,             # <<<<<<<<<<<<<<
 *                                         self.allocated,
 *                                         self.flag,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__buildSegmentList); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyInt_FromSize_t(__pyx_v_self->nsegments); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);

    /* "GatSegmentList.pyx":272
 * 
 *             return (buildSegmentList, ( self.nsegments,
 *                                         self.allocated,             # <<<<<<<<<<<<<<
 *                                         self.flag,
 *                                         self.chunk_size,
 */
    __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->allocated); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);

    /* "GatSegmentList.pyx":273
 *             return (buildSegmentList, ( self.nsegments,
 *                                         self.allocated,
 *                                         self.flag,             # <<<<<<<<<<<<<<
 *                                         self.chunk_size,
 *                                         self.key,
 */
    __pyx_t_6 = PyInt_FromLong(__pyx_v_self->flag); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);

    /* "GatSegmentList.pyx":274
 *                                         self.allocated,
 *                                         self.flag,
 *                                         self.chunk_size,             # <<<<<<<<<<<<<<
 *                                         self.key,
 *                                         data) )
 */
    __pyx_t_5 = PyInt_FromLong(__pyx_v_self->chunk_size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);

    /* "GatSegmentList.pyx":276
 *                                         self.chunk_size,
 *                                         self.key,
 *                                         data) )             # <<<<<<<<<<<<<<
 * 
 *     cpdef share( self, key ):
 */
    __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_self->key);
    PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_self->key);
    __Pyx_GIVEREF(__pyx_v_self->key);
    __Pyx_INCREF(((PyObject *)__pyx_v_data));
    PyTuple_SET_ITEM(__pyx_t_4, 5, ((PyObject *)__pyx_v_data));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_data));
    __pyx_t_8 = 0;
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __pyx_t_7 = 0;
    __pyx_t_4 = 0;
    __pyx_r = ((PyObject *)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }
  __pyx_L3:;

  __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_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":278
 *                                         data) )
 * 
 *     cpdef share( self, key ):             # <<<<<<<<<<<<<<
 *         '''share data as a memory map.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_5share(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_share(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_key, int __pyx_skip_dispatch) {
  int __pyx_v_error;
  int __pyx_v_fd;
  off_t __pyx_v_nbytes;
  void *__pyx_v_p;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  char *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("share", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__share); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_5share)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
      __Pyx_GIVEREF(__pyx_v_key);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __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;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":285
 *         Returns file descriptor of shared memory.
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "sharing in non-normalized list"             # <<<<<<<<<<<<<<
 *         assert key.startswith( "/" )
 *         assert self.shared_fd == -1, "SegmentList already shared"
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_5));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":286
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "sharing in non-normalized list"
 *         assert key.startswith( "/" )             # <<<<<<<<<<<<<<
 *         assert self.shared_fd == -1, "SegmentList already shared"
 *         cdef int error
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__startswith); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_4)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":287
 *         assert self.flag & SEG_NORMALIZED, "sharing in non-normalized list"
 *         assert key.startswith( "/" )
 *         assert self.shared_fd == -1, "SegmentList already shared"             # <<<<<<<<<<<<<<
 *         cdef int error
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->shared_fd == -1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_8));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":290
 *         cdef int error
 * 
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             # do not share empty objects
 *             return
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":292
 *         if self.nsegments == 0:
 *             # do not share empty objects
 *             return             # <<<<<<<<<<<<<<
 * 
 *         cdef int fd
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":295
 * 
 *         cdef int fd
 *         fd = shm_open( key, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)             # <<<<<<<<<<<<<<
 *         if fd == -1:
 *             error = errno
 */
  __pyx_t_5 = PyBytes_AsString(__pyx_v_key); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_fd = shm_open(__pyx_t_5, (O_CREAT | O_RDWR), (S_IRUSR | S_IWUSR));

  /* "GatSegmentList.pyx":296
 *         cdef int fd
 *         fd = shm_open( key, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)
 *         if fd == -1:             # <<<<<<<<<<<<<<
 *             error = errno
 *             raise OSError( "could not create shared memory at %s; ERRNO=%i" % (key, error ))
 */
  __pyx_t_4 = (__pyx_v_fd == -1);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":297
 *         fd = shm_open( key, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)
 *         if fd == -1:
 *             error = errno             # <<<<<<<<<<<<<<
 *             raise OSError( "could not create shared memory at %s; ERRNO=%i" % (key, error ))
 * 
 */
    __pyx_v_error = errno;

    /* "GatSegmentList.pyx":298
 *         if fd == -1:
 *             error = errno
 *             raise OSError( "could not create shared memory at %s; ERRNO=%i" % (key, error ))             # <<<<<<<<<<<<<<
 * 
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 */
    __pyx_t_3 = PyInt_FromLong(__pyx_v_error); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":300
 *             raise OSError( "could not create shared memory at %s; ERRNO=%i" % (key, error ))
 * 
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments             # <<<<<<<<<<<<<<
 *         # save file descriptor
 *         self.shared_fd = fd
 */
  __pyx_v_nbytes = ((sizeof(struct __pyx_t_14GatSegmentList_Segment)) * __pyx_v_self->nsegments);

  /* "GatSegmentList.pyx":302
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 *         # save file descriptor
 *         self.shared_fd = fd             # <<<<<<<<<<<<<<
 *         if ftruncate(fd, nbytes) == -1:
 *             error = errno
 */
  __pyx_v_self->shared_fd = __pyx_v_fd;

  /* "GatSegmentList.pyx":303
 *         # save file descriptor
 *         self.shared_fd = fd
 *         if ftruncate(fd, nbytes) == -1:             # <<<<<<<<<<<<<<
 *             error = errno
 *             raise OSError( "could not resize memory at %s; ERRNO=%i" % (key, error) )
 */
  __pyx_t_4 = (ftruncate(__pyx_v_fd, __pyx_v_nbytes) == -1);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":304
 *         self.shared_fd = fd
 *         if ftruncate(fd, nbytes) == -1:
 *             error = errno             # <<<<<<<<<<<<<<
 *             raise OSError( "could not resize memory at %s; ERRNO=%i" % (key, error) )
 * 
 */
    __pyx_v_error = errno;

    /* "GatSegmentList.pyx":305
 *         if ftruncate(fd, nbytes) == -1:
 *             error = errno
 *             raise OSError( "could not resize memory at %s; ERRNO=%i" % (key, error) )             # <<<<<<<<<<<<<<
 * 
 *         # open as memory map
 */
    __pyx_t_3 = PyInt_FromLong(__pyx_v_error); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
    __Pyx_GIVEREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_10), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":312
 *                  PROT_READ | PROT_WRITE,
 *                  MAP_SHARED,
 *                  fd,             # <<<<<<<<<<<<<<
 *                  0);
 * 
 */
  __pyx_v_p = mmap(NULL, __pyx_v_nbytes, (PROT_READ | PROT_WRITE), MAP_SHARED, __pyx_v_fd, 0);

  /* "GatSegmentList.pyx":315
 *                  0);
 * 
 *         if p == MAP_FAILED:             # <<<<<<<<<<<<<<
 *             raise ValueError("could not create memory mapped file" )
 * 
 */
  __pyx_t_4 = (__pyx_v_p == MAP_FAILED);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":316
 * 
 *         if p == MAP_FAILED:
 *             raise ValueError("could not create memory mapped file" )             # <<<<<<<<<<<<<<
 * 
 *         # copy data to shared memory location
 */
    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "GatSegmentList.pyx":319
 * 
 *         # copy data to shared memory location
 *         memcpy( p, self.segments, nbytes)             # <<<<<<<<<<<<<<
 *         self.key = key
 * 
 */
  memcpy(__pyx_v_p, __pyx_v_self->segments, __pyx_v_nbytes);

  /* "GatSegmentList.pyx":320
 *         # copy data to shared memory location
 *         memcpy( p, self.segments, nbytes)
 *         self.key = key             # <<<<<<<<<<<<<<
 * 
 *         # free allocated private memory
 */
  __Pyx_INCREF(__pyx_v_key);
  __Pyx_GIVEREF(__pyx_v_key);
  __Pyx_GOTREF(__pyx_v_self->key);
  __Pyx_DECREF(__pyx_v_self->key);
  __pyx_v_self->key = __pyx_v_key;

  /* "GatSegmentList.pyx":323
 * 
 *         # free allocated private memory
 *         self.allocated = 0             # <<<<<<<<<<<<<<
 *         free( self.segments )
 * 
 */
  __pyx_v_self->allocated = 0;

  /* "GatSegmentList.pyx":324
 *         # free allocated private memory
 *         self.allocated = 0
 *         free( self.segments )             # <<<<<<<<<<<<<<
 * 
 *         self.segments = <Segment *>p
 */
  free(__pyx_v_self->segments);

  /* "GatSegmentList.pyx":326
 *         free( self.segments )
 * 
 *         self.segments = <Segment *>p             # <<<<<<<<<<<<<<
 *         self.flag |= SEG_SHARED
 * 
 */
  __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_p);

  /* "GatSegmentList.pyx":327
 * 
 *         self.segments = <Segment *>p
 *         self.flag |= SEG_SHARED             # <<<<<<<<<<<<<<
 * 
 *     def unshare( self ):
 */
  __pyx_v_self->flag = (__pyx_v_self->flag | 2);

  __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("GatSegmentList.SegmentList.share", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_5share(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_4share[] = "SegmentList.share(self, key)\nshare data as a memory map.\n        \n        The data is shared under 'key'.\n\n        Returns file descriptor of shared memory.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_5share(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("share (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_4share(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((PyObject *)__pyx_v_key));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":278
 *                                         data) )
 * 
 *     cpdef share( self, key ):             # <<<<<<<<<<<<<<
 *         '''share data as a memory map.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_4share(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("share", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->share(__pyx_v_self, __pyx_v_key, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __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("GatSegmentList.SegmentList.share", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_7unshare(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_6unshare[] = "SegmentList.unshare(self)\ntake ownership of shared data.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_7unshare(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unshare (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_6unshare(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":329
 *         self.flag |= SEG_SHARED
 * 
 *     def unshare( self ):             # <<<<<<<<<<<<<<
 *         '''take ownership of shared data.
 *         '''
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_6unshare(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  int __pyx_v_fd;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  off_t __pyx_v_nbytes;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("unshare", 0);

  /* "GatSegmentList.pyx":333
 *         '''
 *         # empty lists are not shared
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":334
 *         # empty lists are not shared
 *         if self.nsegments == 0:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         cdef int fd
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":337
 * 
 *         cdef int fd
 *         assert self.flag & SEG_SHARED             # <<<<<<<<<<<<<<
 *         assert self.flag & ~SEG_SLAVE
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 2))) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":338
 *         cdef int fd
 *         assert self.flag & SEG_SHARED
 *         assert self.flag & ~SEG_SLAVE             # <<<<<<<<<<<<<<
 * 
 *         if self.shared_fd == -1:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & (~4)))) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":340
 *         assert self.flag & ~SEG_SLAVE
 * 
 *         if self.shared_fd == -1:             # <<<<<<<<<<<<<<
 *             raise ValueError("unsharing unshared SegmentList")
 * 
 */
  __pyx_t_1 = (__pyx_v_self->shared_fd == -1);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":341
 * 
 *         if self.shared_fd == -1:
 *             raise ValueError("unsharing unshared SegmentList")             # <<<<<<<<<<<<<<
 * 
 *         fd = shm_unlink( self.key )
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":343
 *             raise ValueError("unsharing unshared SegmentList")
 * 
 *         fd = shm_unlink( self.key )             # <<<<<<<<<<<<<<
 *         if fd == -1:
 *             raise OSError( "could not unlink shared memory" )
 */
  __pyx_t_3 = PyBytes_AsString(__pyx_v_self->key); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_fd = shm_unlink(__pyx_t_3);

  /* "GatSegmentList.pyx":344
 * 
 *         fd = shm_unlink( self.key )
 *         if fd == -1:             # <<<<<<<<<<<<<<
 *             raise OSError( "could not unlink shared memory" )
 * 
 */
  __pyx_t_1 = (__pyx_v_fd == -1);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":345
 *         fd = shm_unlink( self.key )
 *         if fd == -1:
 *             raise OSError( "could not unlink shared memory" )             # <<<<<<<<<<<<<<
 * 
 *         # copy data back to unshared memory
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":349
 *         # copy data back to unshared memory
 *         cdef Segment * s
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments             # <<<<<<<<<<<<<<
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:
 */
  __pyx_v_nbytes = ((sizeof(struct __pyx_t_14GatSegmentList_Segment)) * __pyx_v_self->nsegments);

  /* "GatSegmentList.pyx":350
 *         cdef Segment * s
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 *         s = <Segment *>malloc( nbytes )             # <<<<<<<<<<<<<<
 *         if s == NULL:
 *             raise ValueError( "could not allocate memory when unsharing" )
 */
  __pyx_v_s = ((struct __pyx_t_14GatSegmentList_Segment *)malloc(__pyx_v_nbytes));

  /* "GatSegmentList.pyx":351
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError( "could not allocate memory when unsharing" )
 * 
 */
  __pyx_t_1 = (__pyx_v_s == NULL);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":352
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:
 *             raise ValueError( "could not allocate memory when unsharing" )             # <<<<<<<<<<<<<<
 * 
 *         memcpy( s, self.segments, nbytes )
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "GatSegmentList.pyx":354
 *             raise ValueError( "could not allocate memory when unsharing" )
 * 
 *         memcpy( s, self.segments, nbytes )             # <<<<<<<<<<<<<<
 * 
 *         # unmap
 */
  memcpy(__pyx_v_s, __pyx_v_self->segments, __pyx_v_nbytes);

  /* "GatSegmentList.pyx":357
 * 
 *         # unmap
 *         if munmap( self.segments, nbytes ) == -1:             # <<<<<<<<<<<<<<
 *             raise ValueError( "error while unmapping memory")
 * 
 */
  __pyx_t_1 = (munmap(__pyx_v_self->segments, __pyx_v_nbytes) == -1);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":358
 *         # unmap
 *         if munmap( self.segments, nbytes ) == -1:
 *             raise ValueError( "error while unmapping memory")             # <<<<<<<<<<<<<<
 * 
 *         self.segments = s
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "GatSegmentList.pyx":360
 *             raise ValueError( "error while unmapping memory")
 * 
 *         self.segments = s             # <<<<<<<<<<<<<<
 *         self.allocated = self.nsegments
 *         self.shared_fd = -1
 */
  __pyx_v_self->segments = __pyx_v_s;

  /* "GatSegmentList.pyx":361
 * 
 *         self.segments = s
 *         self.allocated = self.nsegments             # <<<<<<<<<<<<<<
 *         self.shared_fd = -1
 *         self.flag &= ~SEG_SHARED
 */
  __pyx_v_self->allocated = __pyx_v_self->nsegments;

  /* "GatSegmentList.pyx":362
 *         self.segments = s
 *         self.allocated = self.nsegments
 *         self.shared_fd = -1             # <<<<<<<<<<<<<<
 *         self.flag &= ~SEG_SHARED
 * 
 */
  __pyx_v_self->shared_fd = -1;

  /* "GatSegmentList.pyx":363
 *         self.allocated = self.nsegments
 *         self.shared_fd = -1
 *         self.flag &= ~SEG_SHARED             # <<<<<<<<<<<<<<
 * 
 *     cdef void fromMMAP( self ):
 */
  __pyx_v_self->flag = (__pyx_v_self->flag & (~2));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.unshare", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":365
 *         self.flag &= ~SEG_SHARED
 * 
 *     cdef void fromMMAP( self ):             # <<<<<<<<<<<<<<
 *         '''retrieve data from mmapped location to private copy.
 *         '''
 */

static void __pyx_f_14GatSegmentList_11SegmentList_fromMMAP(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  off_t __pyx_v_nbytes;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("fromMMAP", 0);

  /* "GatSegmentList.pyx":370
 *         # copy data back to unshared memory
 *         cdef Segment * s
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments             # <<<<<<<<<<<<<<
 * 
 *         if self.nsegments == 0:
 */
  __pyx_v_nbytes = ((sizeof(struct __pyx_t_14GatSegmentList_Segment)) * __pyx_v_self->nsegments);

  /* "GatSegmentList.pyx":372
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 * 
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":373
 * 
 *         if self.nsegments == 0:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         s = <Segment *>malloc( nbytes )
 */
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":375
 *             return
 * 
 *         s = <Segment *>malloc( nbytes )             # <<<<<<<<<<<<<<
 *         if s == NULL:
 *             raise ValueError( "could not allocate memory when unsharing" )
 */
  __pyx_v_s = ((struct __pyx_t_14GatSegmentList_Segment *)malloc(__pyx_v_nbytes));

  /* "GatSegmentList.pyx":376
 * 
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError( "could not allocate memory when unsharing" )
 * 
 */
  __pyx_t_1 = (__pyx_v_s == NULL);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":377
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:
 *             raise ValueError( "could not allocate memory when unsharing" )             # <<<<<<<<<<<<<<
 * 
 *         memcpy( s, self.segments, nbytes )
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":379
 *             raise ValueError( "could not allocate memory when unsharing" )
 * 
 *         memcpy( s, self.segments, nbytes )             # <<<<<<<<<<<<<<
 * 
 *         self.segments = s
 */
  memcpy(__pyx_v_s, __pyx_v_self->segments, __pyx_v_nbytes);

  /* "GatSegmentList.pyx":381
 *         memcpy( s, self.segments, nbytes )
 * 
 *         self.segments = s             # <<<<<<<<<<<<<<
 *         self.allocated = self.nsegments
 *         self.flag &= ~(SEG_SHARED+SEG_SLAVE)
 */
  __pyx_v_self->segments = __pyx_v_s;

  /* "GatSegmentList.pyx":382
 * 
 *         self.segments = s
 *         self.allocated = self.nsegments             # <<<<<<<<<<<<<<
 *         self.flag &= ~(SEG_SHARED+SEG_SLAVE)
 * 
 */
  __pyx_v_self->allocated = __pyx_v_self->nsegments;

  /* "GatSegmentList.pyx":383
 *         self.segments = s
 *         self.allocated = self.nsegments
 *         self.flag &= ~(SEG_SHARED+SEG_SLAVE)             # <<<<<<<<<<<<<<
 * 
 *     cdef off_t toMMAP( self,
 */
  __pyx_v_self->flag = (__pyx_v_self->flag & (~6));

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.fromMMAP", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "GatSegmentList.pyx":385
 *         self.flag &= ~(SEG_SHARED+SEG_SLAVE)
 * 
 *     cdef off_t toMMAP( self,             # <<<<<<<<<<<<<<
 *                        void * mmap,
 *                        int shared_fd,
 */

static off_t __pyx_f_14GatSegmentList_11SegmentList_toMMAP(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, void *__pyx_v_mmap, CYTHON_UNUSED int __pyx_v_shared_fd, off_t __pyx_v_offset) {
  off_t __pyx_v_nbytes;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_p;
  off_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("toMMAP", 0);

  /* "GatSegmentList.pyx":392
 *         at *mmap* with *offset*.
 *         '''
 *         if self.shared_fd != -1:             # <<<<<<<<<<<<<<
 *             raise ValueError("can not move shared segmentlist to mmap")
 * 
 */
  __pyx_t_1 = (__pyx_v_self->shared_fd != -1);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":393
 *         '''
 *         if self.shared_fd != -1:
 *             raise ValueError("can not move shared segmentlist to mmap")             # <<<<<<<<<<<<<<
 * 
 *         if self.nsegments == 0:
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":395
 *             raise ValueError("can not move shared segmentlist to mmap")
 * 
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             # do not move empty segment lists
 *             return offset
 */
  __pyx_t_1 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":397
 *         if self.nsegments == 0:
 *             # do not move empty segment lists
 *             return offset             # <<<<<<<<<<<<<<
 * 
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 */
    __pyx_r = __pyx_v_offset;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":399
 *             return offset
 * 
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments             # <<<<<<<<<<<<<<
 *         cdef Segment * p = <Segment *>mmap + offset
 * 
 */
  __pyx_v_nbytes = ((sizeof(struct __pyx_t_14GatSegmentList_Segment)) * __pyx_v_self->nsegments);

  /* "GatSegmentList.pyx":400
 * 
 *         cdef off_t nbytes = sizeof(Segment) * self.nsegments
 *         cdef Segment * p = <Segment *>mmap + offset             # <<<<<<<<<<<<<<
 * 
 *         # copy data
 */
  __pyx_v_p = (((struct __pyx_t_14GatSegmentList_Segment *)__pyx_v_mmap) + __pyx_v_offset);

  /* "GatSegmentList.pyx":403
 * 
 *         # copy data
 *         memcpy( p, self.segments, nbytes )             # <<<<<<<<<<<<<<
 * 
 *         # free allocated private memory
 */
  memcpy(__pyx_v_p, __pyx_v_self->segments, __pyx_v_nbytes);

  /* "GatSegmentList.pyx":406
 * 
 *         # free allocated private memory
 *         self.allocated = 0             # <<<<<<<<<<<<<<
 *         free( self.segments )
 *         self.segments = p
 */
  __pyx_v_self->allocated = 0;

  /* "GatSegmentList.pyx":407
 *         # free allocated private memory
 *         self.allocated = 0
 *         free( self.segments )             # <<<<<<<<<<<<<<
 *         self.segments = p
 * 
 */
  free(__pyx_v_self->segments);

  /* "GatSegmentList.pyx":408
 *         self.allocated = 0
 *         free( self.segments )
 *         self.segments = p             # <<<<<<<<<<<<<<
 * 
 *         self.flag |= SEG_SHARED | SEG_SLAVE
 */
  __pyx_v_self->segments = __pyx_v_p;

  /* "GatSegmentList.pyx":410
 *         self.segments = p
 * 
 *         self.flag |= SEG_SHARED | SEG_SLAVE             # <<<<<<<<<<<<<<
 * 
 *         return offset + self.nsegments
 */
  __pyx_v_self->flag = (__pyx_v_self->flag | 6);

  /* "GatSegmentList.pyx":412
 *         self.flag |= SEG_SHARED | SEG_SLAVE
 * 
 *         return offset + self.nsegments             # <<<<<<<<<<<<<<
 * 
 *     cpdef sort( self ):
 */
  __pyx_r = (__pyx_v_offset + __pyx_v_self->nsegments);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.toMMAP", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":414
 *         return offset + self.nsegments
 * 
 *     cpdef sort( self ):             # <<<<<<<<<<<<<<
 *         '''sort segments.'''
 *         if self.nsegments == 0: return
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_9sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_sort(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sort", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__sort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_9sort)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":416
 *     cpdef sort( self ):
 *         '''sort segments.'''
 *         if self.nsegments == 0: return             # <<<<<<<<<<<<<<
 * 
 *         qsort( <void*>self.segments,
 */
  __pyx_t_3 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_3) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":421
 *                self.nsegments,
 *                sizeof( Segment ),
 *                &cmpSegments )             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList extend( self, SegmentList other ):
 */
  qsort(((void *)__pyx_v_self->segments), __pyx_v_self->nsegments, (sizeof(struct __pyx_t_14GatSegmentList_Segment)), (&__pyx_f_14GatSegmentList_cmpSegments));

  __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("GatSegmentList.SegmentList.sort", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_9sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_8sort[] = "SegmentList.sort(self)\nsort segments.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_9sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sort (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_8sort(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":414
 *         return offset + self.nsegments
 * 
 *     cpdef sort( self ):             # <<<<<<<<<<<<<<
 *         '''sort segments.'''
 *         if self.nsegments == 0: return
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_8sort(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sort", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sort(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __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("GatSegmentList.SegmentList.sort", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":423
 *                &cmpSegments )
 * 
 *     cpdef SegmentList extend( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''extend a list of segments with segments in other list.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_11extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_extend(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, int __pyx_skip_dispatch) {
  size_t __pyx_v_new_size;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_11extend)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":430
 *         '''
 *         cdef size_t new_size
 *         new_size = other.nsegments + self.nsegments             # <<<<<<<<<<<<<<
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( new_size * sizeof( Segment ) )
 */
  __pyx_v_new_size = (__pyx_v_other->nsegments + __pyx_v_self->nsegments);

  /* "GatSegmentList.pyx":431
 *         cdef size_t new_size
 *         new_size = other.nsegments + self.nsegments
 *         if self.allocated == 0:             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>malloc( new_size * sizeof( Segment ) )
 *             if not self.segments:
 */
  __pyx_t_4 = (__pyx_v_self->allocated == 0);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":432
 *         new_size = other.nsegments + self.nsegments
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( new_size * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *             if not self.segments:
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_new_size * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

    /* "GatSegmentList.pyx":433
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( new_size * sizeof( Segment ) )
 *             if not self.segments:             # <<<<<<<<<<<<<<
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 *             self.allocated = new_size
 */
    __pyx_t_4 = (!(__pyx_v_self->segments != 0));
    if (__pyx_t_4) {

      /* "GatSegmentList.pyx":434
 *             self.segments = <Segment*>malloc( new_size * sizeof( Segment ) )
 *             if not self.segments:
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 *             self.allocated = new_size
 *         elif new_size >= self.allocated:
 */
      __pyx_t_1 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_new_size * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "GatSegmentList.pyx":435
 *             if not self.segments:
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 *             self.allocated = new_size             # <<<<<<<<<<<<<<
 *         elif new_size >= self.allocated:
 *             self.segments = <Segment*>realloc( <void *>self.segments, new_size * sizeof( Segment ) )
 */
    __pyx_v_self->allocated = __pyx_v_new_size;
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":436
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 *             self.allocated = new_size
 *         elif new_size >= self.allocated:             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>realloc( <void *>self.segments, new_size * sizeof( Segment ) )
 *             if not self.segments:
 */
  __pyx_t_4 = (__pyx_v_new_size >= __pyx_v_self->allocated);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":437
 *             self.allocated = new_size
 *         elif new_size >= self.allocated:
 *             self.segments = <Segment*>realloc( <void *>self.segments, new_size * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *             if not self.segments:
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)realloc(((void *)__pyx_v_self->segments), (__pyx_v_new_size * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

    /* "GatSegmentList.pyx":438
 *         elif new_size >= self.allocated:
 *             self.segments = <Segment*>realloc( <void *>self.segments, new_size * sizeof( Segment ) )
 *             if not self.segments:             # <<<<<<<<<<<<<<
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 *             self.allocated = new_size
 */
    __pyx_t_4 = (!(__pyx_v_self->segments != 0));
    if (__pyx_t_4) {

      /* "GatSegmentList.pyx":439
 *             self.segments = <Segment*>realloc( <void *>self.segments, new_size * sizeof( Segment ) )
 *             if not self.segments:
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 *             self.allocated = new_size
 *         memcpy( &self.segments[self.nsegments],
 */
      __pyx_t_3 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_new_size * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_DECREF(__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 = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "GatSegmentList.pyx":440
 *             if not self.segments:
 *                 raise MemoryError( "out of memory when allocation %i bytes" % sizeof( new_size * sizeof( Segment ) ))
 *             self.allocated = new_size             # <<<<<<<<<<<<<<
 *         memcpy( &self.segments[self.nsegments],
 *                  other.segments,
 */
    __pyx_v_self->allocated = __pyx_v_new_size;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":443
 *         memcpy( &self.segments[self.nsegments],
 *                  other.segments,
 *                  other.nsegments * sizeof(Segment ) )             # <<<<<<<<<<<<<<
 *         self.nsegments = new_size
 *         self.flag = 0
 */
  memcpy((&(__pyx_v_self->segments[__pyx_v_self->nsegments])), __pyx_v_other->segments, (__pyx_v_other->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment))));

  /* "GatSegmentList.pyx":444
 *                  other.segments,
 *                  other.nsegments * sizeof(Segment ) )
 *         self.nsegments = new_size             # <<<<<<<<<<<<<<
 *         self.flag = 0
 *         return self
 */
  __pyx_v_self->nsegments = __pyx_v_new_size;

  /* "GatSegmentList.pyx":445
 *                  other.nsegments * sizeof(Segment ) )
 *         self.nsegments = new_size
 *         self.flag = 0             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_v_self->flag = 0;

  /* "GatSegmentList.pyx":446
 *         self.nsegments = new_size
 *         self.flag = 0
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef _add( self, Segment segment ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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("GatSegmentList.SegmentList.extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_11extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_10extend[] = "SegmentList.extend(self, SegmentList other) -> SegmentList\nextend a list of segments with segments in other list.\n\n        The list will not be normalized automatically - call\n        :meth:`SegmentList.normalize`.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_11extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("extend (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_10extend(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_other));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":423
 *                &cmpSegments )
 * 
 *     cpdef SegmentList extend( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''extend a list of segments with segments in other list.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_10extend(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->extend(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __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("GatSegmentList.SegmentList.extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":448
 *         return self
 * 
 *     cdef _add( self, Segment segment ):             # <<<<<<<<<<<<<<
 *         '''add a new segment.
 * 
 */

static PyObject *__pyx_f_14GatSegmentList_11SegmentList__add(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_t_14GatSegmentList_Segment __pyx_v_segment) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_add", 0);

  /* "GatSegmentList.pyx":455
 *         '''
 * 
 *         if self.allocated == 0:             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>malloc( self.chunk_size * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.chunk_size * sizeof( Segment ) ))
 */
  __pyx_t_1 = (__pyx_v_self->allocated == 0);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":456
 * 
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( self.chunk_size * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.chunk_size * sizeof( Segment ) ))
 *             self.allocated = self.chunk_size
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_self->chunk_size * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

    /* "GatSegmentList.pyx":457
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( self.chunk_size * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.chunk_size * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 *             self.allocated = self.chunk_size
 *         elif self.nsegments == self.allocated:
 */
    __pyx_t_1 = (!(__pyx_v_self->segments != 0));
    if (__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_self->chunk_size * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __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 = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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_MemoryError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "GatSegmentList.pyx":458
 *             self.segments = <Segment*>malloc( self.chunk_size * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.chunk_size * sizeof( Segment ) ))
 *             self.allocated = self.chunk_size             # <<<<<<<<<<<<<<
 *         elif self.nsegments == self.allocated:
 *             self.allocated *= 2
 */
    __pyx_v_self->allocated = __pyx_v_self->chunk_size;
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":459
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.chunk_size * sizeof( Segment ) ))
 *             self.allocated = self.chunk_size
 *         elif self.nsegments == self.allocated:             # <<<<<<<<<<<<<<
 *             self.allocated *= 2
 *             self.segments = <Segment*>realloc( self.segments,
 */
  __pyx_t_1 = (__pyx_v_self->nsegments == __pyx_v_self->allocated);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":460
 *             self.allocated = self.chunk_size
 *         elif self.nsegments == self.allocated:
 *             self.allocated *= 2             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>realloc( self.segments,
 *                                                self.allocated * sizeof( Segment ) )
 */
    __pyx_v_self->allocated = (__pyx_v_self->allocated * 2);

    /* "GatSegmentList.pyx":461
 *         elif self.nsegments == self.allocated:
 *             self.allocated *= 2
 *             self.segments = <Segment*>realloc( self.segments,             # <<<<<<<<<<<<<<
 *                                                self.allocated * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.allocated * sizeof( Segment ) ))
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)realloc(__pyx_v_self->segments, (__pyx_v_self->allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

    /* "GatSegmentList.pyx":463
 *             self.segments = <Segment*>realloc( self.segments,
 *                                                self.allocated * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.allocated * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 * 
 *         self.segments[self.nsegments] = segment
 */
    __pyx_t_1 = (!(__pyx_v_self->segments != 0));
    if (__pyx_t_1) {
      __pyx_t_3 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_self->allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_DECREF(__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 = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = 463; __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, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":465
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.allocated * sizeof( Segment ) ))
 * 
 *         self.segments[self.nsegments] = segment             # <<<<<<<<<<<<<<
 *         self.nsegments += 1
 *         self.flag = 0
 */
  (__pyx_v_self->segments[__pyx_v_self->nsegments]) = __pyx_v_segment;

  /* "GatSegmentList.pyx":466
 * 
 *         self.segments[self.nsegments] = segment
 *         self.nsegments += 1             # <<<<<<<<<<<<<<
 *         self.flag = 0
 * 
 */
  __pyx_v_self->nsegments = (__pyx_v_self->nsegments + 1);

  /* "GatSegmentList.pyx":467
 *         self.segments[self.nsegments] = segment
 *         self.nsegments += 1
 *         self.flag = 0             # <<<<<<<<<<<<<<
 * 
 *     cpdef add( self, Position start, Position end ):
 */
  __pyx_v_self->flag = 0;

  __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("GatSegmentList.SegmentList._add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":469
 *         self.flag = 0
 * 
 *     cpdef add( self, Position start, Position end ):             # <<<<<<<<<<<<<<
 *         cdef Segment segment
 *         assert start <= end, "attempting to add invalid segment %i-%i" % (start, end)
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_13add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_add(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end, int __pyx_skip_dispatch) {
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_segment;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__add); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_13add)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __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 = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":471
 *     cpdef add( self, Position start, Position end ):
 *         cdef Segment segment
 *         assert start <= end, "attempting to add invalid segment %i-%i" % (start, end)             # <<<<<<<<<<<<<<
 *         segment = Segment( start, end)
 *         self._add( segment )
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_start <= __pyx_v_end))) {
    __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __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 = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_25), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":472
 *         cdef Segment segment
 *         assert start <= end, "attempting to add invalid segment %i-%i" % (start, end)
 *         segment = Segment( start, end)             # <<<<<<<<<<<<<<
 *         self._add( segment )
 * 
 */
  __pyx_t_5.start = __pyx_v_start;
  __pyx_t_5.end = __pyx_v_end;
  __pyx_v_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":473
 *         assert start <= end, "attempting to add invalid segment %i-%i" % (start, end)
 *         segment = Segment( start, end)
 *         self._add( segment )             # <<<<<<<<<<<<<<
 * 
 *     cpdef trim_ends( self, Position pos, Position size, int forward ):
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_add(__pyx_v_self, __pyx_v_segment); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_13add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_12add[] = "SegmentList.add(self, Position start, Position end)";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_13add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_start;
  __pyx_t_14GatSegmentList_Position __pyx_v_end;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_start == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_end == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_12add(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_start, __pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":469
 *         self.flag = 0
 * 
 *     cpdef add( self, Position start, Position end ):             # <<<<<<<<<<<<<<
 *         cdef Segment segment
 *         assert start <= end, "attempting to add invalid segment %i-%i" % (start, end)
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_12add(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->add(__pyx_v_self, __pyx_v_start, __pyx_v_end, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __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("GatSegmentList.SegmentList.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":475
 *         self._add( segment )
 * 
 *     cpdef trim_ends( self, Position pos, Position size, int forward ):             # <<<<<<<<<<<<<<
 *         '''trim segment list by removing *size* nucleotides from
 *         the segment that includes *pos*.
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_15trim_ends(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_trim_ends(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_pos, __pyx_t_14GatSegmentList_Position __pyx_v_size, int __pyx_v_forward, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_l;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_s;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_seg;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("trim_ends", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__trim_ends); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_15trim_ends)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyInt_FromLong(__pyx_v_forward); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __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 = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_2 = 0;
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":481
 *         The flag *forward* gives the direction.
 *         '''
 *         if self.nsegments == 0: return             # <<<<<<<<<<<<<<
 * 
 *         assert self.flag & SEG_NORMALIZED, "trimming in non-normalized list"
 */
  __pyx_t_6 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_6) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":483
 *         if self.nsegments == 0: return
 * 
 *         assert self.flag & SEG_NORMALIZED, "trimming in non-normalized list"             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_26));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":487
 *         cdef int idx
 *         cdef Position l
 *         cdef PositionDifference s = size             # <<<<<<<<<<<<<<
 *         cdef Segment other, seg
 * 
 */
  __pyx_v_s = __pyx_v_size;

  /* "GatSegmentList.pyx":490
 *         cdef Segment other, seg
 * 
 *         assert self.sum() > s, "trimming more than the total length (%i < %i)" % (self.sum(), s)             # <<<<<<<<<<<<<<
 *         #print "at start=%i, removing %i" % (self.sum(), s)
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0) > __pyx_v_s))) {
    __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_1 = 0;
    __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_27), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_4));
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":493
 *         #print "at start=%i, removing %i" % (self.sum(), s)
 * 
 *         other = Segment( pos, pos + 1)             # <<<<<<<<<<<<<<
 *         idx = self._getInsertionPoint( other )
 * 
 */
  __pyx_t_7.start = __pyx_v_pos;
  __pyx_t_7.end = (__pyx_v_pos + 1);
  __pyx_v_other = __pyx_t_7;

  /* "GatSegmentList.pyx":494
 * 
 *         other = Segment( pos, pos + 1)
 *         idx = self._getInsertionPoint( other )             # <<<<<<<<<<<<<<
 * 
 *         # wrap around
 */
  __pyx_v_idx = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_getInsertionPoint(__pyx_v_self, __pyx_v_other);

  /* "GatSegmentList.pyx":497
 * 
 *         # wrap around
 *         if idx == self.nsegments: idx = 0             # <<<<<<<<<<<<<<
 *         if idx < 0: idx = self.nsegments - 1
 * 
 */
  __pyx_t_6 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_6) {
    __pyx_v_idx = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":498
 *         # wrap around
 *         if idx == self.nsegments: idx = 0
 *         if idx < 0: idx = self.nsegments - 1             # <<<<<<<<<<<<<<
 * 
 *         if forward:
 */
  __pyx_t_6 = (__pyx_v_idx < 0);
  if (__pyx_t_6) {
    __pyx_v_idx = (__pyx_v_self->nsegments - 1);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":500
 *         if idx < 0: idx = self.nsegments - 1
 * 
 *         if forward:             # <<<<<<<<<<<<<<
 *             while s > 0:
 *                 seg = self.segments[idx]
 */
  if (__pyx_v_forward) {

    /* "GatSegmentList.pyx":501
 * 
 *         if forward:
 *             while s > 0:             # <<<<<<<<<<<<<<
 *                 seg = self.segments[idx]
 *                 l = segment_length( seg )
 */
    while (1) {
      __pyx_t_6 = (__pyx_v_s > 0);
      if (!__pyx_t_6) break;

      /* "GatSegmentList.pyx":502
 *         if forward:
 *             while s > 0:
 *                 seg = self.segments[idx]             # <<<<<<<<<<<<<<
 *                 l = segment_length( seg )
 *                 if segment_length( seg ) < s:
 */
      __pyx_v_seg = (__pyx_v_self->segments[__pyx_v_idx]);

      /* "GatSegmentList.pyx":503
 *             while s > 0:
 *                 seg = self.segments[idx]
 *                 l = segment_length( seg )             # <<<<<<<<<<<<<<
 *                 if segment_length( seg ) < s:
 *                     self.segments[idx] = Segment(0,0)
 */
      __pyx_v_l = __pyx_f_14GatSegmentList_segment_length(__pyx_v_seg);

      /* "GatSegmentList.pyx":504
 *                 seg = self.segments[idx]
 *                 l = segment_length( seg )
 *                 if segment_length( seg ) < s:             # <<<<<<<<<<<<<<
 *                     self.segments[idx] = Segment(0,0)
 *                     s -= l
 */
      __pyx_t_6 = (__pyx_f_14GatSegmentList_segment_length(__pyx_v_seg) < __pyx_v_s);
      if (__pyx_t_6) {

        /* "GatSegmentList.pyx":505
 *                 l = segment_length( seg )
 *                 if segment_length( seg ) < s:
 *                     self.segments[idx] = Segment(0,0)             # <<<<<<<<<<<<<<
 *                     s -= l
 *                 else:
 */
        __pyx_t_7.start = 0;
        __pyx_t_7.end = 0;
        (__pyx_v_self->segments[__pyx_v_idx]) = __pyx_t_7;

        /* "GatSegmentList.pyx":506
 *                 if segment_length( seg ) < s:
 *                     self.segments[idx] = Segment(0,0)
 *                     s -= l             # <<<<<<<<<<<<<<
 *                 else:
 *                     self.segments[idx] = Segment( seg.start + s, seg.end )
 */
        __pyx_v_s = (__pyx_v_s - __pyx_v_l);
        goto __pyx_L9;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":508
 *                     s -= l
 *                 else:
 *                     self.segments[idx] = Segment( seg.start + s, seg.end )             # <<<<<<<<<<<<<<
 *                     s = 0
 * 
 */
        __pyx_t_7.start = (__pyx_v_seg.start + __pyx_v_s);
        __pyx_t_7.end = __pyx_v_seg.end;
        (__pyx_v_self->segments[__pyx_v_idx]) = __pyx_t_7;

        /* "GatSegmentList.pyx":509
 *                 else:
 *                     self.segments[idx] = Segment( seg.start + s, seg.end )
 *                     s = 0             # <<<<<<<<<<<<<<
 * 
 *                 idx += 1
 */
        __pyx_v_s = 0;
      }
      __pyx_L9:;

      /* "GatSegmentList.pyx":511
 *                     s = 0
 * 
 *                 idx += 1             # <<<<<<<<<<<<<<
 *                 if idx == self.nsegments: idx = 0
 *         else:
 */
      __pyx_v_idx = (__pyx_v_idx + 1);

      /* "GatSegmentList.pyx":512
 * 
 *                 idx += 1
 *                 if idx == self.nsegments: idx = 0             # <<<<<<<<<<<<<<
 *         else:
 *             while s > 0:
 */
      __pyx_t_6 = (__pyx_v_idx == __pyx_v_self->nsegments);
      if (__pyx_t_6) {
        __pyx_v_idx = 0;
        goto __pyx_L10;
      }
      __pyx_L10:;
    }
    goto __pyx_L6;
  }
  /*else*/ {

    /* "GatSegmentList.pyx":514
 *                 if idx == self.nsegments: idx = 0
 *         else:
 *             while s > 0:             # <<<<<<<<<<<<<<
 *                 seg = self.segments[idx]
 *                 l = segment_length( seg )
 */
    while (1) {
      __pyx_t_6 = (__pyx_v_s > 0);
      if (!__pyx_t_6) break;

      /* "GatSegmentList.pyx":515
 *         else:
 *             while s > 0:
 *                 seg = self.segments[idx]             # <<<<<<<<<<<<<<
 *                 l = segment_length( seg )
 *                 if segment_length( seg ) < s:
 */
      __pyx_v_seg = (__pyx_v_self->segments[__pyx_v_idx]);

      /* "GatSegmentList.pyx":516
 *             while s > 0:
 *                 seg = self.segments[idx]
 *                 l = segment_length( seg )             # <<<<<<<<<<<<<<
 *                 if segment_length( seg ) < s:
 *                     self.segments[idx] = Segment(0,0)
 */
      __pyx_v_l = __pyx_f_14GatSegmentList_segment_length(__pyx_v_seg);

      /* "GatSegmentList.pyx":517
 *                 seg = self.segments[idx]
 *                 l = segment_length( seg )
 *                 if segment_length( seg ) < s:             # <<<<<<<<<<<<<<
 *                     self.segments[idx] = Segment(0,0)
 *                     s -= l
 */
      __pyx_t_6 = (__pyx_f_14GatSegmentList_segment_length(__pyx_v_seg) < __pyx_v_s);
      if (__pyx_t_6) {

        /* "GatSegmentList.pyx":518
 *                 l = segment_length( seg )
 *                 if segment_length( seg ) < s:
 *                     self.segments[idx] = Segment(0,0)             # <<<<<<<<<<<<<<
 *                     s -= l
 *                 else:
 */
        __pyx_t_7.start = 0;
        __pyx_t_7.end = 0;
        (__pyx_v_self->segments[__pyx_v_idx]) = __pyx_t_7;

        /* "GatSegmentList.pyx":519
 *                 if segment_length( seg ) < s:
 *                     self.segments[idx] = Segment(0,0)
 *                     s -= l             # <<<<<<<<<<<<<<
 *                 else:
 *                     self.segments[idx] = Segment( seg.start, <PositionDifference>seg.end - s )
 */
        __pyx_v_s = (__pyx_v_s - __pyx_v_l);
        goto __pyx_L13;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":521
 *                     s -= l
 *                 else:
 *                     self.segments[idx] = Segment( seg.start, <PositionDifference>seg.end - s )             # <<<<<<<<<<<<<<
 *                     s = 0
 * 
 */
        __pyx_t_7.start = __pyx_v_seg.start;
        __pyx_t_7.end = (((__pyx_t_14GatSegmentList_PositionDifference)__pyx_v_seg.end) - __pyx_v_s);
        (__pyx_v_self->segments[__pyx_v_idx]) = __pyx_t_7;

        /* "GatSegmentList.pyx":522
 *                 else:
 *                     self.segments[idx] = Segment( seg.start, <PositionDifference>seg.end - s )
 *                     s = 0             # <<<<<<<<<<<<<<
 * 
 *                 idx -= 1
 */
        __pyx_v_s = 0;
      }
      __pyx_L13:;

      /* "GatSegmentList.pyx":524
 *                     s = 0
 * 
 *                 idx -= 1             # <<<<<<<<<<<<<<
 *                 if idx < 0: idx = self.nsegments - 1
 * 
 */
      __pyx_v_idx = (__pyx_v_idx - 1);

      /* "GatSegmentList.pyx":525
 * 
 *                 idx -= 1
 *                 if idx < 0: idx = self.nsegments - 1             # <<<<<<<<<<<<<<
 * 
 *         #print "at end=%i, removing %i" % (self.sum(), s)
 */
      __pyx_t_6 = (__pyx_v_idx < 0);
      if (__pyx_t_6) {
        __pyx_v_idx = (__pyx_v_self->nsegments - 1);
        goto __pyx_L14;
      }
      __pyx_L14:;
    }
  }
  __pyx_L6:;

  __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_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.trim_ends", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_15trim_ends(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_14trim_ends[] = "SegmentList.trim_ends(self, Position pos, Position size, int forward)\ntrim segment list by removing *size* nucleotides from\n        the segment that includes *pos*.\n        \n        The flag *forward* gives the direction.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_15trim_ends(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_pos;
  __pyx_t_14GatSegmentList_Position __pyx_v_size;
  int __pyx_v_forward;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__pos,&__pyx_n_s__size,&__pyx_n_s__forward,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("trim_ends (wrapper)", 0);
  {
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pos);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("trim_ends", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__forward);
        if (likely(values[2])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("trim_ends", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trim_ends") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_pos = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_pos == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_size = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_forward = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_forward == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("trim_ends", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.trim_ends", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_14trim_ends(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_pos, __pyx_v_size, __pyx_v_forward);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":475
 *         self._add( segment )
 * 
 *     cpdef trim_ends( self, Position pos, Position size, int forward ):             # <<<<<<<<<<<<<<
 *         '''trim segment list by removing *size* nucleotides from
 *         the segment that includes *pos*.
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_14trim_ends(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_pos, __pyx_t_14GatSegmentList_Position __pyx_v_size, int __pyx_v_forward) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("trim_ends", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->trim_ends(__pyx_v_self, __pyx_v_pos, __pyx_v_size, __pyx_v_forward, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __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("GatSegmentList.SegmentList.trim_ends", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":529
 *         #print "at end=%i, removing %i" % (self.sum(), s)
 * 
 *     cdef _resize( self, int nsegments ):             # <<<<<<<<<<<<<<
 *         '''resize segment list to nsegments.'''
 *         # do not free all if there are no segments
 */

static PyObject *__pyx_f_14GatSegmentList_11SegmentList__resize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_nsegments) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_resize", 0);

  /* "GatSegmentList.pyx":532
 *         '''resize segment list to nsegments.'''
 *         # do not free all if there are no segments
 *         if nsegments == 0: nsegments = 1             # <<<<<<<<<<<<<<
 * 
 *         assert nsegments >= self.nsegments, "resizing will loose segments"
 */
  __pyx_t_1 = (__pyx_v_nsegments == 0);
  if (__pyx_t_1) {
    __pyx_v_nsegments = 1;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":534
 *         if nsegments == 0: nsegments = 1
 * 
 *         assert nsegments >= self.nsegments, "resizing will loose segments"             # <<<<<<<<<<<<<<
 * 
 *         if self.allocated == 0:
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_nsegments >= __pyx_v_self->nsegments))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_28));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":536
 *         assert nsegments >= self.nsegments, "resizing will loose segments"
 * 
 *         if self.allocated == 0:             # <<<<<<<<<<<<<<
 *             self.segments = <Segment*>malloc( nsegments * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( nsegments * sizeof( Segment ) ))
 */
  __pyx_t_1 = (__pyx_v_self->allocated == 0);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":537
 * 
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( nsegments * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( nsegments * sizeof( Segment ) ))
 *         else:
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

    /* "GatSegmentList.pyx":538
 *         if self.allocated == 0:
 *             self.segments = <Segment*>malloc( nsegments * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( nsegments * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 *         else:
 *             self.segments = <Segment*>realloc( self.segments,
 */
    __pyx_t_1 = (!(__pyx_v_self->segments != 0));
    if (__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __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 = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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_MemoryError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "GatSegmentList.pyx":540
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( nsegments * sizeof( Segment ) ))
 *         else:
 *             self.segments = <Segment*>realloc( self.segments,             # <<<<<<<<<<<<<<
 *                                                nsegments * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.nsegments * sizeof( Segment ) ))
 */
    __pyx_v_self->segments = ((struct __pyx_t_14GatSegmentList_Segment *)realloc(__pyx_v_self->segments, (__pyx_v_nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

    /* "GatSegmentList.pyx":542
 *             self.segments = <Segment*>realloc( self.segments,
 *                                                nsegments * sizeof( Segment ) )
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.nsegments * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 * 
 *         self.allocated = nsegments
 */
    __pyx_t_1 = (!(__pyx_v_self->segments != 0));
    if (__pyx_t_1) {
      __pyx_t_3 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_DECREF(__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 = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = 542; __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, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":544
 *             if not self.segments: raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.nsegments * sizeof( Segment ) ))
 * 
 *         self.allocated = nsegments             # <<<<<<<<<<<<<<
 * 
 *     cdef insert( self, int idx, Segment seg ):
 */
  __pyx_v_self->allocated = __pyx_v_nsegments;

  __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("GatSegmentList.SegmentList._resize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":546
 *         self.allocated = nsegments
 * 
 *     cdef insert( self, int idx, Segment seg ):             # <<<<<<<<<<<<<<
 *         '''insert Segment *seg* at position *idx*'''
 *         if idx < 0: raise ValueError( "only positive indices accepted (%i)" % idx )
 */

static PyObject *__pyx_f_14GatSegmentList_11SegmentList_insert(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_idx, struct __pyx_t_14GatSegmentList_Segment __pyx_v_seg) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  size_t __pyx_t_4;
  int __pyx_t_5;
  size_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("insert", 0);

  /* "GatSegmentList.pyx":548
 *     cdef insert( self, int idx, Segment seg ):
 *         '''insert Segment *seg* at position *idx*'''
 *         if idx < 0: raise ValueError( "only positive indices accepted (%i)" % idx )             # <<<<<<<<<<<<<<
 * 
 *         idx = max( idx, self.nsegments )
 */
  __pyx_t_1 = (__pyx_v_idx < 0);
  if (__pyx_t_1) {
    __pyx_t_2 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_29), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __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 = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__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_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":550
 *         if idx < 0: raise ValueError( "only positive indices accepted (%i)" % idx )
 * 
 *         idx = max( idx, self.nsegments )             # <<<<<<<<<<<<<<
 *         if self.allocated == self.nsegments:
 *             self._resize( self.allocated * 2)
 */
  __pyx_t_4 = __pyx_v_self->nsegments;
  __pyx_t_5 = __pyx_v_idx;
  if ((__pyx_t_4 > __pyx_t_5)) {
    __pyx_t_6 = __pyx_t_4;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  __pyx_v_idx = __pyx_t_6;

  /* "GatSegmentList.pyx":551
 * 
 *         idx = max( idx, self.nsegments )
 *         if self.allocated == self.nsegments:             # <<<<<<<<<<<<<<
 *             self._resize( self.allocated * 2)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->allocated == __pyx_v_self->nsegments);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":552
 *         idx = max( idx, self.nsegments )
 *         if self.allocated == self.nsegments:
 *             self._resize( self.allocated * 2)             # <<<<<<<<<<<<<<
 * 
 *         memmove( &self.segments[idx+1],
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_resize(__pyx_v_self, (__pyx_v_self->allocated * 2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":556
 *         memmove( &self.segments[idx+1],
 *                  &self.segments[idx],
 *                  sizeof( Segment ) * (self.nsegments - idx) )             # <<<<<<<<<<<<<<
 * 
 *         self.nsegments += 1
 */
  memmove((&(__pyx_v_self->segments[(__pyx_v_idx + 1)])), (&(__pyx_v_self->segments[__pyx_v_idx])), ((sizeof(struct __pyx_t_14GatSegmentList_Segment)) * (__pyx_v_self->nsegments - __pyx_v_idx)));

  /* "GatSegmentList.pyx":558
 *                  sizeof( Segment ) * (self.nsegments - idx) )
 * 
 *         self.nsegments += 1             # <<<<<<<<<<<<<<
 *         self.segments[idx] = seg
 * 
 */
  __pyx_v_self->nsegments = (__pyx_v_self->nsegments + 1);

  /* "GatSegmentList.pyx":559
 * 
 *         self.nsegments += 1
 *         self.segments[idx] = seg             # <<<<<<<<<<<<<<
 * 
 *     cpdef trim( self, Position pos, Position size ):
 */
  (__pyx_v_self->segments[__pyx_v_idx]) = __pyx_v_seg;

  __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("GatSegmentList.SegmentList.insert", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":561
 *         self.segments[idx] = seg
 * 
 *     cpdef trim( self, Position pos, Position size ):             # <<<<<<<<<<<<<<
 *         '''trim segment list by removing *size* nucleotides
 *         starting at pos.
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_17trim(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_trim(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_pos, __pyx_t_14GatSegmentList_Position __pyx_v_size, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_l;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_s;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_p;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_seg;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("trim", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__trim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_17trim)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __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 = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":569
 * 
 *         '''
 *         if self.nsegments == 0: return             # <<<<<<<<<<<<<<
 * 
 *         assert self.flag & SEG_NORMALIZED, "trimming in non-normalized list"
 */
  __pyx_t_5 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_5) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":571
 *         if self.nsegments == 0: return
 * 
 *         assert self.flag & SEG_NORMALIZED, "trimming in non-normalized list"             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_26));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":575
 *         cdef int idx
 *         cdef PositionDifference l
 *         cdef PositionDifference s = size             # <<<<<<<<<<<<<<
 *         cdef PositionDifference p = pos
 *         cdef Segment other, seg
 */
  __pyx_v_s = __pyx_v_size;

  /* "GatSegmentList.pyx":576
 *         cdef PositionDifference l
 *         cdef PositionDifference s = size
 *         cdef PositionDifference p = pos             # <<<<<<<<<<<<<<
 *         cdef Segment other, seg
 * 
 */
  __pyx_v_p = __pyx_v_pos;

  /* "GatSegmentList.pyx":579
 *         cdef Segment other, seg
 * 
 *         assert self.sum() > s, "trimming more than the total length (%i < %i)" % (self.sum(), s)             # <<<<<<<<<<<<<<
 * 
 *         p = lmax( p, self.segments[0].start )
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0) > __pyx_v_s))) {
    __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __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 = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_27), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_3));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":581
 *         assert self.sum() > s, "trimming more than the total length (%i < %i)" % (self.sum(), s)
 * 
 *         p = lmax( p, self.segments[0].start )             # <<<<<<<<<<<<<<
 *         p = lmin( p, self.segments[self.nsegments-1].end )
 * 
 */
  __pyx_v_p = __pyx_f_14GatSegmentList_lmax(__pyx_v_p, (__pyx_v_self->segments[0]).start);

  /* "GatSegmentList.pyx":582
 * 
 *         p = lmax( p, self.segments[0].start )
 *         p = lmin( p, self.segments[self.nsegments-1].end )             # <<<<<<<<<<<<<<
 * 
 *         other = Segment( p, p + 1)
 */
  __pyx_v_p = __pyx_f_14GatSegmentList_lmin(__pyx_v_p, (__pyx_v_self->segments[(__pyx_v_self->nsegments - 1)]).end);

  /* "GatSegmentList.pyx":584
 *         p = lmin( p, self.segments[self.nsegments-1].end )
 * 
 *         other = Segment( p, p + 1)             # <<<<<<<<<<<<<<
 *         idx = self._getInsertionPoint( other )
 *         # wrap around
 */
  __pyx_t_6.start = __pyx_v_p;
  __pyx_t_6.end = (__pyx_v_p + 1);
  __pyx_v_other = __pyx_t_6;

  /* "GatSegmentList.pyx":585
 * 
 *         other = Segment( p, p + 1)
 *         idx = self._getInsertionPoint( other )             # <<<<<<<<<<<<<<
 *         # wrap around
 *         if idx == self.nsegments:
 */
  __pyx_v_idx = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_getInsertionPoint(__pyx_v_self, __pyx_v_other);

  /* "GatSegmentList.pyx":587
 *         idx = self._getInsertionPoint( other )
 *         # wrap around
 *         if idx == self.nsegments:             # <<<<<<<<<<<<<<
 *             idx = 0
 *             p = self.segments[0].start
 */
  __pyx_t_5 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_5) {

    /* "GatSegmentList.pyx":588
 *         # wrap around
 *         if idx == self.nsegments:
 *             idx = 0             # <<<<<<<<<<<<<<
 *             p = self.segments[0].start
 * 
 */
    __pyx_v_idx = 0;

    /* "GatSegmentList.pyx":589
 *         if idx == self.nsegments:
 *             idx = 0
 *             p = self.segments[0].start             # <<<<<<<<<<<<<<
 * 
 *         #assert p >= self.segments[idx].start, "pos=%i, %i, %s, %s" % (p, idx, str(self.segments[idx]), str(self.asList()))
 */
    __pyx_v_p = (__pyx_v_self->segments[0]).start;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":594
 *         #assert p < self.segments[idx].end, "pos=%i, %i, %s, %s" % (p, idx, str(self.segments[idx]), str(self.asList()))
 * 
 *         while s > 0:             # <<<<<<<<<<<<<<
 *             seg = self.segments[idx]
 * 
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_s > 0);
    if (!__pyx_t_5) break;

    /* "GatSegmentList.pyx":595
 * 
 *         while s > 0:
 *             seg = self.segments[idx]             # <<<<<<<<<<<<<<
 * 
 *             l = <PositionDifference>self.segments[idx].end - p
 */
    __pyx_v_seg = (__pyx_v_self->segments[__pyx_v_idx]);

    /* "GatSegmentList.pyx":597
 *             seg = self.segments[idx]
 * 
 *             l = <PositionDifference>self.segments[idx].end - p             # <<<<<<<<<<<<<<
 * 
 *             if s < l:
 */
    __pyx_v_l = (((__pyx_t_14GatSegmentList_PositionDifference)(__pyx_v_self->segments[__pyx_v_idx]).end) - __pyx_v_p);

    /* "GatSegmentList.pyx":599
 *             l = <PositionDifference>self.segments[idx].end - p
 * 
 *             if s < l:             # <<<<<<<<<<<<<<
 *                 if p == self.segments[idx].start:
 *                     # truncate from left and stop
 */
    __pyx_t_5 = (__pyx_v_s < __pyx_v_l);
    if (__pyx_t_5) {

      /* "GatSegmentList.pyx":600
 * 
 *             if s < l:
 *                 if p == self.segments[idx].start:             # <<<<<<<<<<<<<<
 *                     # truncate from left and stop
 *                     self.segments[idx].start = p + s
 */
      __pyx_t_5 = (__pyx_v_p == (__pyx_v_self->segments[__pyx_v_idx]).start);
      if (__pyx_t_5) {

        /* "GatSegmentList.pyx":602
 *                 if p == self.segments[idx].start:
 *                     # truncate from left and stop
 *                     self.segments[idx].start = p + s             # <<<<<<<<<<<<<<
 *                     break
 *                 else:
 */
        (__pyx_v_self->segments[__pyx_v_idx]).start = (__pyx_v_p + __pyx_v_s);

        /* "GatSegmentList.pyx":603
 *                     # truncate from left and stop
 *                     self.segments[idx].start = p + s
 *                     break             # <<<<<<<<<<<<<<
 *                 else:
 *                     # remove from middle and stop
 */
        goto __pyx_L6_break;
        goto __pyx_L8;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":606
 *                 else:
 *                     # remove from middle and stop
 *                     self.insert( idx + 1, Segment( p + s, self.segments[idx].end) )             # <<<<<<<<<<<<<<
 *                     self.segments[idx].end = p
 *                     break
 */
        __pyx_t_6.start = (__pyx_v_p + __pyx_v_s);
        __pyx_t_6.end = (__pyx_v_self->segments[__pyx_v_idx]).end;
        __pyx_t_3 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->insert(__pyx_v_self, (__pyx_v_idx + 1), __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "GatSegmentList.pyx":607
 *                     # remove from middle and stop
 *                     self.insert( idx + 1, Segment( p + s, self.segments[idx].end) )
 *                     self.segments[idx].end = p             # <<<<<<<<<<<<<<
 *                     break
 *             else:
 */
        (__pyx_v_self->segments[__pyx_v_idx]).end = __pyx_v_p;

        /* "GatSegmentList.pyx":608
 *                     self.insert( idx + 1, Segment( p + s, self.segments[idx].end) )
 *                     self.segments[idx].end = p
 *                     break             # <<<<<<<<<<<<<<
 *             else:
 *                 self.segments[idx].end = p
 */
        goto __pyx_L6_break;
      }
      __pyx_L8:;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":610
 *                     break
 *             else:
 *                 self.segments[idx].end = p             # <<<<<<<<<<<<<<
 *                 s -= l
 * 
 */
      (__pyx_v_self->segments[__pyx_v_idx]).end = __pyx_v_p;

      /* "GatSegmentList.pyx":611
 *             else:
 *                 self.segments[idx].end = p
 *                 s -= l             # <<<<<<<<<<<<<<
 * 
 *             idx += 1
 */
      __pyx_v_s = (__pyx_v_s - __pyx_v_l);
    }
    __pyx_L7:;

    /* "GatSegmentList.pyx":613
 *                 s -= l
 * 
 *             idx += 1             # <<<<<<<<<<<<<<
 * 
 *             # wrap around
 */
    __pyx_v_idx = (__pyx_v_idx + 1);

    /* "GatSegmentList.pyx":616
 * 
 *             # wrap around
 *             if idx == self.nsegments: idx = 0             # <<<<<<<<<<<<<<
 *             p = self.segments[idx].start
 * 
 */
    __pyx_t_5 = (__pyx_v_idx == __pyx_v_self->nsegments);
    if (__pyx_t_5) {
      __pyx_v_idx = 0;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "GatSegmentList.pyx":617
 *             # wrap around
 *             if idx == self.nsegments: idx = 0
 *             p = self.segments[idx].start             # <<<<<<<<<<<<<<
 * 
 *         #print "at end=%i, removing %i" % (self.sum(), s)
 */
    __pyx_v_p = (__pyx_v_self->segments[__pyx_v_idx]).start;
  }
  __pyx_L6_break:;

  __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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.trim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_17trim(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_16trim[] = "SegmentList.trim(self, Position pos, Position size)\ntrim segment list by removing *size* nucleotides\n        starting at pos.\n\n        If (pos, pos+size) is fully within a segment, this segment\n        will be split.\n\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_17trim(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_pos;
  __pyx_t_14GatSegmentList_Position __pyx_v_size;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__pos,&__pyx_n_s__size,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("trim (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pos);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("trim", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trim") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_pos = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_pos == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_size = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("trim", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.trim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_16trim(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_pos, __pyx_v_size);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":561
 *         self.segments[idx] = seg
 * 
 *     cpdef trim( self, Position pos, Position size ):             # <<<<<<<<<<<<<<
 *         '''trim segment list by removing *size* nucleotides
 *         starting at pos.
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_16trim(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_pos, __pyx_t_14GatSegmentList_Position __pyx_v_size) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("trim", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->trim(__pyx_v_self, __pyx_v_pos, __pyx_v_size, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __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("GatSegmentList.SegmentList.trim", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":621
 *         #print "at end=%i, removing %i" % (self.sum(), s)
 * 
 *     cpdef normalize( self ):             # <<<<<<<<<<<<<<
 *         '''merge all overlapping segments and remove empty segments.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_19normalize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_normalize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  int __pyx_v_insertion_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_max_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("normalize", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__normalize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_19normalize)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":631
 *         cdef int idx, insertion_idx
 *         cdef Position max_end
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             self.flag = 1
 *             return
 */
  __pyx_t_3 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_3) {

    /* "GatSegmentList.pyx":632
 *         cdef Position max_end
 *         if self.nsegments == 0:
 *             self.flag = 1             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    __pyx_v_self->flag = 1;

    /* "GatSegmentList.pyx":633
 *         if self.nsegments == 0:
 *             self.flag = 1
 *             return             # <<<<<<<<<<<<<<
 * 
 *         self.sort()
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":635
 *             return
 * 
 *         self.sort()             # <<<<<<<<<<<<<<
 * 
 *         insertion_idx = 0
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sort(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":637
 *         self.sort()
 * 
 *         insertion_idx = 0             # <<<<<<<<<<<<<<
 * 
 *         # skip to first non-empty segment
 */
  __pyx_v_insertion_idx = 0;

  /* "GatSegmentList.pyx":640
 * 
 *         # skip to first non-empty segment
 *         idx = 0             # <<<<<<<<<<<<<<
 *         while idx < self.nsegments and self.segments[idx].start == self.segments[idx].end:
 *             idx += 1
 */
  __pyx_v_idx = 0;

  /* "GatSegmentList.pyx":641
 *         # skip to first non-empty segment
 *         idx = 0
 *         while idx < self.nsegments and self.segments[idx].start == self.segments[idx].end:             # <<<<<<<<<<<<<<
 *             idx += 1
 * 
 */
  while (1) {
    __pyx_t_3 = (__pyx_v_idx < __pyx_v_self->nsegments);
    if (__pyx_t_3) {
      __pyx_t_4 = ((__pyx_v_self->segments[__pyx_v_idx]).start == (__pyx_v_self->segments[__pyx_v_idx]).end);
      __pyx_t_5 = __pyx_t_4;
    } else {
      __pyx_t_5 = __pyx_t_3;
    }
    if (!__pyx_t_5) break;

    /* "GatSegmentList.pyx":642
 *         idx = 0
 *         while idx < self.nsegments and self.segments[idx].start == self.segments[idx].end:
 *             idx += 1             # <<<<<<<<<<<<<<
 * 
 *         # only empty segments - empty list, but declare normalized
 */
    __pyx_v_idx = (__pyx_v_idx + 1);
  }

  /* "GatSegmentList.pyx":645
 * 
 *         # only empty segments - empty list, but declare normalized
 *         if idx == self.nsegments:             # <<<<<<<<<<<<<<
 *             self.nsegments = 0
 *             self.flag = 1
 */
  __pyx_t_5 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_5) {

    /* "GatSegmentList.pyx":646
 *         # only empty segments - empty list, but declare normalized
 *         if idx == self.nsegments:
 *             self.nsegments = 0             # <<<<<<<<<<<<<<
 *             self.flag = 1
 *             return
 */
    __pyx_v_self->nsegments = 0;

    /* "GatSegmentList.pyx":647
 *         if idx == self.nsegments:
 *             self.nsegments = 0
 *             self.flag = 1             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    __pyx_v_self->flag = 1;

    /* "GatSegmentList.pyx":648
 *             self.nsegments = 0
 *             self.flag = 1
 *             return             # <<<<<<<<<<<<<<
 * 
 *         self.segments[insertion_idx].start = self.segments[idx].start
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "GatSegmentList.pyx":650
 *             return
 * 
 *         self.segments[insertion_idx].start = self.segments[idx].start             # <<<<<<<<<<<<<<
 *         max_end = self.segments[idx].end
 * 
 */
  (__pyx_v_self->segments[__pyx_v_insertion_idx]).start = (__pyx_v_self->segments[__pyx_v_idx]).start;

  /* "GatSegmentList.pyx":651
 * 
 *         self.segments[insertion_idx].start = self.segments[idx].start
 *         max_end = self.segments[idx].end             # <<<<<<<<<<<<<<
 * 
 *         while idx < self.nsegments:
 */
  __pyx_v_max_end = (__pyx_v_self->segments[__pyx_v_idx]).end;

  /* "GatSegmentList.pyx":653
 *         max_end = self.segments[idx].end
 * 
 *         while idx < self.nsegments:             # <<<<<<<<<<<<<<
 * 
 *             # skip empty
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_idx < __pyx_v_self->nsegments);
    if (!__pyx_t_5) break;

    /* "GatSegmentList.pyx":656
 * 
 *             # skip empty
 *             if self.segments[idx].start == self.segments[idx].end:             # <<<<<<<<<<<<<<
 *                 idx += 1
 *                 continue
 */
    __pyx_t_5 = ((__pyx_v_self->segments[__pyx_v_idx]).start == (__pyx_v_self->segments[__pyx_v_idx]).end);
    if (__pyx_t_5) {

      /* "GatSegmentList.pyx":657
 *             # skip empty
 *             if self.segments[idx].start == self.segments[idx].end:
 *                 idx += 1             # <<<<<<<<<<<<<<
 *                 continue
 *             # no overlap - save segment
 */
      __pyx_v_idx = (__pyx_v_idx + 1);

      /* "GatSegmentList.pyx":658
 *             if self.segments[idx].start == self.segments[idx].end:
 *                 idx += 1
 *                 continue             # <<<<<<<<<<<<<<
 *             # no overlap - save segment
 *             if self.segments[idx].start >= max_end:
 */
      goto __pyx_L7_continue;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "GatSegmentList.pyx":660
 *                 continue
 *             # no overlap - save segment
 *             if self.segments[idx].start >= max_end:             # <<<<<<<<<<<<<<
 *                 self.segments[insertion_idx].end = max_end
 *                 insertion_idx += 1
 */
    __pyx_t_5 = ((__pyx_v_self->segments[__pyx_v_idx]).start >= __pyx_v_max_end);
    if (__pyx_t_5) {

      /* "GatSegmentList.pyx":661
 *             # no overlap - save segment
 *             if self.segments[idx].start >= max_end:
 *                 self.segments[insertion_idx].end = max_end             # <<<<<<<<<<<<<<
 *                 insertion_idx += 1
 *                 assert insertion_idx < self.nsegments, "insertion_idx out of range: %i >= %i" % (insertion_idx, self.nsegments)
 */
      (__pyx_v_self->segments[__pyx_v_insertion_idx]).end = __pyx_v_max_end;

      /* "GatSegmentList.pyx":662
 *             if self.segments[idx].start >= max_end:
 *                 self.segments[insertion_idx].end = max_end
 *                 insertion_idx += 1             # <<<<<<<<<<<<<<
 *                 assert insertion_idx < self.nsegments, "insertion_idx out of range: %i >= %i" % (insertion_idx, self.nsegments)
 *                 self.segments[insertion_idx].start = self.segments[idx].start
 */
      __pyx_v_insertion_idx = (__pyx_v_insertion_idx + 1);

      /* "GatSegmentList.pyx":663
 *                 self.segments[insertion_idx].end = max_end
 *                 insertion_idx += 1
 *                 assert insertion_idx < self.nsegments, "insertion_idx out of range: %i >= %i" % (insertion_idx, self.nsegments)             # <<<<<<<<<<<<<<
 *                 self.segments[insertion_idx].start = self.segments[idx].start
 * 
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!(__pyx_v_insertion_idx < __pyx_v_self->nsegments))) {
        __pyx_t_1 = PyInt_FromLong(__pyx_v_insertion_idx); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->nsegments); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_1 = 0;
        __pyx_t_2 = 0;
        __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_30), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_2));
        __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
        PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_2));
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif

      /* "GatSegmentList.pyx":664
 *                 insertion_idx += 1
 *                 assert insertion_idx < self.nsegments, "insertion_idx out of range: %i >= %i" % (insertion_idx, self.nsegments)
 *                 self.segments[insertion_idx].start = self.segments[idx].start             # <<<<<<<<<<<<<<
 * 
 *             max_end = lmax( self.segments[idx].end, max_end )
 */
      (__pyx_v_self->segments[__pyx_v_insertion_idx]).start = (__pyx_v_self->segments[__pyx_v_idx]).start;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "GatSegmentList.pyx":666
 *                 self.segments[insertion_idx].start = self.segments[idx].start
 * 
 *             max_end = lmax( self.segments[idx].end, max_end )             # <<<<<<<<<<<<<<
 *             idx += 1
 * 
 */
    __pyx_v_max_end = __pyx_f_14GatSegmentList_lmax((__pyx_v_self->segments[__pyx_v_idx]).end, __pyx_v_max_end);

    /* "GatSegmentList.pyx":667
 * 
 *             max_end = lmax( self.segments[idx].end, max_end )
 *             idx += 1             # <<<<<<<<<<<<<<
 * 
 *         # store final segment
 */
    __pyx_v_idx = (__pyx_v_idx + 1);
    __pyx_L7_continue:;
  }

  /* "GatSegmentList.pyx":670
 * 
 *         # store final segment
 *         self.segments[insertion_idx].end = max_end             # <<<<<<<<<<<<<<
 * 
 *         # truncate array
 */
  (__pyx_v_self->segments[__pyx_v_insertion_idx]).end = __pyx_v_max_end;

  /* "GatSegmentList.pyx":673
 * 
 *         # truncate array
 *         insertion_idx += 1             # <<<<<<<<<<<<<<
 *         self.nsegments = insertion_idx
 *         self._resize( self.nsegments )
 */
  __pyx_v_insertion_idx = (__pyx_v_insertion_idx + 1);

  /* "GatSegmentList.pyx":674
 *         # truncate array
 *         insertion_idx += 1
 *         self.nsegments = insertion_idx             # <<<<<<<<<<<<<<
 *         self._resize( self.nsegments )
 *         self.flag = 1
 */
  __pyx_v_self->nsegments = __pyx_v_insertion_idx;

  /* "GatSegmentList.pyx":675
 *         insertion_idx += 1
 *         self.nsegments = insertion_idx
 *         self._resize( self.nsegments )             # <<<<<<<<<<<<<<
 *         self.flag = 1
 * 
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_resize(__pyx_v_self, __pyx_v_self->nsegments); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "GatSegmentList.pyx":676
 *         self.nsegments = insertion_idx
 *         self._resize( self.nsegments )
 *         self.flag = 1             # <<<<<<<<<<<<<<
 * 
 *     cpdef merge( self, PositionDifference distance ):
 */
  __pyx_v_self->flag = 1;

  __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_6);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.normalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_19normalize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_18normalize[] = "SegmentList.normalize(self)\nmerge all overlapping segments and remove empty segments.\n\n        Adjacent segments are not merged.\n\n        This function works in-place.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_19normalize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("normalize (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_18normalize(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":621
 *         #print "at end=%i, removing %i" % (self.sum(), s)
 * 
 *     cpdef normalize( self ):             # <<<<<<<<<<<<<<
 *         '''merge all overlapping segments and remove empty segments.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_18normalize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("normalize", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->normalize(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __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("GatSegmentList.SegmentList.normalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":678
 *         self.flag = 1
 * 
 *     cpdef merge( self, PositionDifference distance ):             # <<<<<<<<<<<<<<
 *         '''merge all overlapping segments and remove empty segments.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_21merge(PyObject *__pyx_v_self, PyObject *__pyx_arg_distance); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_merge(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_distance, int __pyx_skip_dispatch) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_max_end;
  int __pyx_v_idx;
  int __pyx_v_insertion_idx;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__merge); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_21merge)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_distance); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __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 = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":694
 *         cdef PositionDifference max_end
 *         cdef int idx, insertion_idx
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             self.flag = 1
 *             return
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":695
 *         cdef int idx, insertion_idx
 *         if self.nsegments == 0:
 *             self.flag = 1             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    __pyx_v_self->flag = 1;

    /* "GatSegmentList.pyx":696
 *         if self.nsegments == 0:
 *             self.flag = 1
 *             return             # <<<<<<<<<<<<<<
 * 
 *         self.sort()
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":698
 *             return
 * 
 *         self.sort()             # <<<<<<<<<<<<<<
 * 
 *         insertion_idx = 0
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sort(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":700
 *         self.sort()
 * 
 *         insertion_idx = 0             # <<<<<<<<<<<<<<
 * 
 *         # skip to first non-empty segment
 */
  __pyx_v_insertion_idx = 0;

  /* "GatSegmentList.pyx":703
 * 
 *         # skip to first non-empty segment
 *         idx = 0             # <<<<<<<<<<<<<<
 *         while idx < self.nsegments and self.segments[idx].start == self.segments[idx].end:
 *             idx += 1
 */
  __pyx_v_idx = 0;

  /* "GatSegmentList.pyx":704
 *         # skip to first non-empty segment
 *         idx = 0
 *         while idx < self.nsegments and self.segments[idx].start == self.segments[idx].end:             # <<<<<<<<<<<<<<
 *             idx += 1
 * 
 */
  while (1) {
    __pyx_t_4 = (__pyx_v_idx < __pyx_v_self->nsegments);
    if (__pyx_t_4) {
      __pyx_t_5 = ((__pyx_v_self->segments[__pyx_v_idx]).start == (__pyx_v_self->segments[__pyx_v_idx]).end);
      __pyx_t_6 = __pyx_t_5;
    } else {
      __pyx_t_6 = __pyx_t_4;
    }
    if (!__pyx_t_6) break;

    /* "GatSegmentList.pyx":705
 *         idx = 0
 *         while idx < self.nsegments and self.segments[idx].start == self.segments[idx].end:
 *             idx += 1             # <<<<<<<<<<<<<<
 * 
 *         # only empty segments - empty list, but declare normalized
 */
    __pyx_v_idx = (__pyx_v_idx + 1);
  }

  /* "GatSegmentList.pyx":708
 * 
 *         # only empty segments - empty list, but declare normalized
 *         if idx == self.nsegments:             # <<<<<<<<<<<<<<
 *             self.nsegments = 0
 *             self.flag = 1
 */
  __pyx_t_6 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_6) {

    /* "GatSegmentList.pyx":709
 *         # only empty segments - empty list, but declare normalized
 *         if idx == self.nsegments:
 *             self.nsegments = 0             # <<<<<<<<<<<<<<
 *             self.flag = 1
 *             return
 */
    __pyx_v_self->nsegments = 0;

    /* "GatSegmentList.pyx":710
 *         if idx == self.nsegments:
 *             self.nsegments = 0
 *             self.flag = 1             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    __pyx_v_self->flag = 1;

    /* "GatSegmentList.pyx":711
 *             self.nsegments = 0
 *             self.flag = 1
 *             return             # <<<<<<<<<<<<<<
 * 
 *         self.segments[insertion_idx].start = self.segments[idx].start
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "GatSegmentList.pyx":713
 *             return
 * 
 *         self.segments[insertion_idx].start = self.segments[idx].start             # <<<<<<<<<<<<<<
 *         max_end = self.segments[idx].end
 * 
 */
  (__pyx_v_self->segments[__pyx_v_insertion_idx]).start = (__pyx_v_self->segments[__pyx_v_idx]).start;

  /* "GatSegmentList.pyx":714
 * 
 *         self.segments[insertion_idx].start = self.segments[idx].start
 *         max_end = self.segments[idx].end             # <<<<<<<<<<<<<<
 * 
 *         while idx < self.nsegments:
 */
  __pyx_v_max_end = (__pyx_v_self->segments[__pyx_v_idx]).end;

  /* "GatSegmentList.pyx":716
 *         max_end = self.segments[idx].end
 * 
 *         while idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             # skip empty
 *             if self.segments[idx].start == self.segments[idx].end:
 */
  while (1) {
    __pyx_t_6 = (__pyx_v_idx < __pyx_v_self->nsegments);
    if (!__pyx_t_6) break;

    /* "GatSegmentList.pyx":718
 *         while idx < self.nsegments:
 *             # skip empty
 *             if self.segments[idx].start == self.segments[idx].end:             # <<<<<<<<<<<<<<
 *                 idx += 1
 *                 continue
 */
    __pyx_t_6 = ((__pyx_v_self->segments[__pyx_v_idx]).start == (__pyx_v_self->segments[__pyx_v_idx]).end);
    if (__pyx_t_6) {

      /* "GatSegmentList.pyx":719
 *             # skip empty
 *             if self.segments[idx].start == self.segments[idx].end:
 *                 idx += 1             # <<<<<<<<<<<<<<
 *                 continue
 *             # no overlap - save segment
 */
      __pyx_v_idx = (__pyx_v_idx + 1);

      /* "GatSegmentList.pyx":720
 *             if self.segments[idx].start == self.segments[idx].end:
 *                 idx += 1
 *                 continue             # <<<<<<<<<<<<<<
 *             # no overlap - save segment
 *             # note the cange from > to >=
 */
      goto __pyx_L7_continue;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "GatSegmentList.pyx":723
 *             # no overlap - save segment
 *             # note the cange from > to >=
 *             if <PositionDifference>self.segments[idx].start - distance > max_end:             # <<<<<<<<<<<<<<
 *                 self.segments[insertion_idx].end = max_end
 *                 insertion_idx += 1
 */
    __pyx_t_6 = ((((__pyx_t_14GatSegmentList_PositionDifference)(__pyx_v_self->segments[__pyx_v_idx]).start) - __pyx_v_distance) > __pyx_v_max_end);
    if (__pyx_t_6) {

      /* "GatSegmentList.pyx":724
 *             # note the cange from > to >=
 *             if <PositionDifference>self.segments[idx].start - distance > max_end:
 *                 self.segments[insertion_idx].end = max_end             # <<<<<<<<<<<<<<
 *                 insertion_idx += 1
 *                 self.segments[insertion_idx].start = self.segments[idx].start
 */
      (__pyx_v_self->segments[__pyx_v_insertion_idx]).end = __pyx_v_max_end;

      /* "GatSegmentList.pyx":725
 *             if <PositionDifference>self.segments[idx].start - distance > max_end:
 *                 self.segments[insertion_idx].end = max_end
 *                 insertion_idx += 1             # <<<<<<<<<<<<<<
 *                 self.segments[insertion_idx].start = self.segments[idx].start
 * 
 */
      __pyx_v_insertion_idx = (__pyx_v_insertion_idx + 1);

      /* "GatSegmentList.pyx":726
 *                 self.segments[insertion_idx].end = max_end
 *                 insertion_idx += 1
 *                 self.segments[insertion_idx].start = self.segments[idx].start             # <<<<<<<<<<<<<<
 * 
 *             max_end = lmax( self.segments[idx].end, max_end )
 */
      (__pyx_v_self->segments[__pyx_v_insertion_idx]).start = (__pyx_v_self->segments[__pyx_v_idx]).start;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "GatSegmentList.pyx":728
 *                 self.segments[insertion_idx].start = self.segments[idx].start
 * 
 *             max_end = lmax( self.segments[idx].end, max_end )             # <<<<<<<<<<<<<<
 *             idx += 1
 * 
 */
    __pyx_v_max_end = __pyx_f_14GatSegmentList_lmax((__pyx_v_self->segments[__pyx_v_idx]).end, __pyx_v_max_end);

    /* "GatSegmentList.pyx":729
 * 
 *             max_end = lmax( self.segments[idx].end, max_end )
 *             idx += 1             # <<<<<<<<<<<<<<
 * 
 *         # store final segment
 */
    __pyx_v_idx = (__pyx_v_idx + 1);
    __pyx_L7_continue:;
  }

  /* "GatSegmentList.pyx":732
 * 
 *         # store final segment
 *         self.segments[insertion_idx].end = max_end             # <<<<<<<<<<<<<<
 * 
 *         # truncate array
 */
  (__pyx_v_self->segments[__pyx_v_insertion_idx]).end = __pyx_v_max_end;

  /* "GatSegmentList.pyx":735
 * 
 *         # truncate array
 *         insertion_idx += 1             # <<<<<<<<<<<<<<
 *         self.nsegments = insertion_idx
 *         self._resize( self.nsegments )
 */
  __pyx_v_insertion_idx = (__pyx_v_insertion_idx + 1);

  /* "GatSegmentList.pyx":736
 *         # truncate array
 *         insertion_idx += 1
 *         self.nsegments = insertion_idx             # <<<<<<<<<<<<<<
 *         self._resize( self.nsegments )
 *         self.flag = 1
 */
  __pyx_v_self->nsegments = __pyx_v_insertion_idx;

  /* "GatSegmentList.pyx":737
 *         insertion_idx += 1
 *         self.nsegments = insertion_idx
 *         self._resize( self.nsegments )             # <<<<<<<<<<<<<<
 *         self.flag = 1
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_resize(__pyx_v_self, __pyx_v_self->nsegments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":738
 *         self.nsegments = insertion_idx
 *         self._resize( self.nsegments )
 *         self.flag = 1             # <<<<<<<<<<<<<<
 * 
 *     cpdef check( self ):
 */
  __pyx_v_self->flag = 1;

  __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("GatSegmentList.SegmentList.merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_21merge(PyObject *__pyx_v_self, PyObject *__pyx_arg_distance); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_20merge[] = "SegmentList.merge(self, PositionDifference distance)\nmerge all overlapping segments and remove empty segments.\n\n        This function is a generalization of the merge method and\n        will merge adjacent and/or neighbouring segments.\n\n        If *distance* = 0, adjacent segments will be merged. \n\n        If*distance* = n, neighbouring segments with a separation of at most\n        *n* bases will be merged.\n\n        This function works in-place.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_21merge(PyObject *__pyx_v_self, PyObject *__pyx_arg_distance) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_distance;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("merge (wrapper)", 0);
  assert(__pyx_arg_distance); {
    __pyx_v_distance = __Pyx_PyInt_AsInt(__pyx_arg_distance); if (unlikely((__pyx_v_distance == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_20merge(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((__pyx_t_14GatSegmentList_PositionDifference)__pyx_v_distance));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":678
 *         self.flag = 1
 * 
 *     cpdef merge( self, PositionDifference distance ):             # <<<<<<<<<<<<<<
 *         '''merge all overlapping segments and remove empty segments.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_20merge(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_distance) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->merge(__pyx_v_self, __pyx_v_distance, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __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("GatSegmentList.SegmentList.merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":740
 *         self.flag = 1
 * 
 *     cpdef check( self ):             # <<<<<<<<<<<<<<
 *         '''check if segment list is normalized.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_23check(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_check(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_segment;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__check); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_23check)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":747
 * 
 *         # empty lists are normalized
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             self.flag = 1
 *             return self.flag
 */
  __pyx_t_3 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_3) {

    /* "GatSegmentList.pyx":748
 *         # empty lists are normalized
 *         if self.nsegments == 0:
 *             self.flag = 1             # <<<<<<<<<<<<<<
 *             return self.flag
 * 
 */
    __pyx_v_self->flag = 1;

    /* "GatSegmentList.pyx":749
 *         if self.nsegments == 0:
 *             self.flag = 1
 *             return self.flag             # <<<<<<<<<<<<<<
 * 
 *         self.flag = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyInt_FromLong(__pyx_v_self->flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":751
 *             return self.flag
 * 
 *         self.flag = 0             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
  __pyx_v_self->flag = 0;

  /* "GatSegmentList.pyx":756
 *         cdef Segment segment
 * 
 *         segment = self.segments[0]             # <<<<<<<<<<<<<<
 *         if segment.start >= segment.end:
 *             raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 */
  __pyx_v_segment = (__pyx_v_self->segments[0]);

  /* "GatSegmentList.pyx":757
 * 
 *         segment = self.segments[0]
 *         if segment.start >= segment.end:             # <<<<<<<<<<<<<<
 *             raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 * 
 */
  __pyx_t_3 = (__pyx_v_segment.start >= __pyx_v_segment.end);
  if (__pyx_t_3) {

    /* "GatSegmentList.pyx":758
 *         segment = self.segments[0]
 *         if segment.start >= segment.end:
 *             raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )             # <<<<<<<<<<<<<<
 * 
 *         for idx from 1 <= idx < self.nsegments:
 */
    __pyx_t_1 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment(__pyx_v_segment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":760
 *             raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 * 
 *         for idx from 1 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             segment = self.segments[idx]
 *             if segment.start >= segment.end:
 */
  __pyx_t_4 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 1; __pyx_v_idx < __pyx_t_4; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":761
 * 
 *         for idx from 1 <= idx < self.nsegments:
 *             segment = self.segments[idx]             # <<<<<<<<<<<<<<
 *             if segment.start >= segment.end:
 *                 raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 */
    __pyx_v_segment = (__pyx_v_self->segments[__pyx_v_idx]);

    /* "GatSegmentList.pyx":762
 *         for idx from 1 <= idx < self.nsegments:
 *             segment = self.segments[idx]
 *             if segment.start >= segment.end:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 *             if self.segments[idx-1].start > segment.start:
 */
    __pyx_t_3 = (__pyx_v_segment.start >= __pyx_v_segment.end);
    if (__pyx_t_3) {

      /* "GatSegmentList.pyx":763
 *             segment = self.segments[idx]
 *             if segment.start >= segment.end:
 *                 raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )             # <<<<<<<<<<<<<<
 *             if self.segments[idx-1].start > segment.start:
 *                 raise ValueError( "segment list is not sorted: %s > %s" % (self.segments[idx-1], segment) )
 */
      __pyx_t_2 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment(__pyx_v_segment); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __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 = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __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 = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "GatSegmentList.pyx":764
 *             if segment.start >= segment.end:
 *                 raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 *             if self.segments[idx-1].start > segment.start:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "segment list is not sorted: %s > %s" % (self.segments[idx-1], segment) )
 *             if self.segments[idx-1].end > segment.start:
 */
    __pyx_t_3 = ((__pyx_v_self->segments[(__pyx_v_idx - 1)]).start > __pyx_v_segment.start);
    if (__pyx_t_3) {

      /* "GatSegmentList.pyx":765
 *                 raise ValueError( "empty/invalid segment in segmentlist: %s" % str( segment ) )
 *             if self.segments[idx-1].start > segment.start:
 *                 raise ValueError( "segment list is not sorted: %s > %s" % (self.segments[idx-1], segment) )             # <<<<<<<<<<<<<<
 *             if self.segments[idx-1].end > segment.start:
 *                 raise ValueError( "segment overlap: %s overlaps %s" % (self.segments[idx-1], segment) )
 */
      __pyx_t_1 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment((__pyx_v_self->segments[(__pyx_v_idx - 1)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment(__pyx_v_segment); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_1 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "GatSegmentList.pyx":766
 *             if self.segments[idx-1].start > segment.start:
 *                 raise ValueError( "segment list is not sorted: %s > %s" % (self.segments[idx-1], segment) )
 *             if self.segments[idx-1].end > segment.start:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "segment overlap: %s overlaps %s" % (self.segments[idx-1], segment) )
 *             #if self.segments[idx-1].end == segment.start:
 */
    __pyx_t_3 = ((__pyx_v_self->segments[(__pyx_v_idx - 1)]).end > __pyx_v_segment.start);
    if (__pyx_t_3) {

      /* "GatSegmentList.pyx":767
 *                 raise ValueError( "segment list is not sorted: %s > %s" % (self.segments[idx-1], segment) )
 *             if self.segments[idx-1].end > segment.start:
 *                 raise ValueError( "segment overlap: %s overlaps %s" % (self.segments[idx-1], segment) )             # <<<<<<<<<<<<<<
 *             #if self.segments[idx-1].end == segment.start:
 *             #    raise ValueError( "segment touch: %s touches %s" % (self.segments[idx-1], segment) )
 */
      __pyx_t_2 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment((__pyx_v_self->segments[(__pyx_v_idx - 1)])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment(__pyx_v_segment); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_2 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_33), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L9;
    }
    __pyx_L9:;
  }

  /* "GatSegmentList.pyx":771
 *             #    raise ValueError( "segment touch: %s touches %s" % (self.segments[idx-1], segment) )
 * 
 *         self.flag = 1             # <<<<<<<<<<<<<<
 * 
 *         return self.flag
 */
  __pyx_v_self->flag = 1;

  /* "GatSegmentList.pyx":773
 *         self.flag = 1
 * 
 *         return self.flag             # <<<<<<<<<<<<<<
 * 
 *     cdef int _getInsertionPoint( self, Segment other ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyInt_FromLong(__pyx_v_self->flag); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __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_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.check", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_23check(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_22check[] = "SegmentList.check(self)\ncheck if segment list is normalized.\n\n        If it is, return True and set flag flag.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_23check(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("check (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_22check(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":740
 *         self.flag = 1
 * 
 *     cpdef check( self ):             # <<<<<<<<<<<<<<
 *         '''check if segment list is normalized.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_22check(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->check(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __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("GatSegmentList.SegmentList.check", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":775
 *         return self.flag
 * 
 *     cdef int _getInsertionPoint( self, Segment other ):             # <<<<<<<<<<<<<<
 *         '''return insertion point for other.
 * 
 */

static int __pyx_f_14GatSegmentList_11SegmentList__getInsertionPoint(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_t_14GatSegmentList_Segment __pyx_v_other) {
  int __pyx_v_idx;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("_getInsertionPoint", 0);

  /* "GatSegmentList.pyx":790
 *         '''
 *         cdef int idx
 *         if self.nsegments == 0: return -1             # <<<<<<<<<<<<<<
 * 
 *         # avoid out of range searches
 */
  __pyx_t_1 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_1) {
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":793
 * 
 *         # avoid out of range searches
 *         if other.start >= self.segments[self.nsegments-1].end:             # <<<<<<<<<<<<<<
 *             return self.nsegments
 *         if other.end <= self.segments[0].start:
 */
  __pyx_t_1 = (__pyx_v_other.start >= (__pyx_v_self->segments[(__pyx_v_self->nsegments - 1)]).end);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":794
 *         # avoid out of range searches
 *         if other.start >= self.segments[self.nsegments-1].end:
 *             return self.nsegments             # <<<<<<<<<<<<<<
 *         if other.end <= self.segments[0].start:
 *             return -1
 */
    __pyx_r = __pyx_v_self->nsegments;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":795
 *         if other.start >= self.segments[self.nsegments-1].end:
 *             return self.nsegments
 *         if other.end <= self.segments[0].start:             # <<<<<<<<<<<<<<
 *             return -1
 * 
 */
  __pyx_t_1 = (__pyx_v_other.end <= (__pyx_v_self->segments[0]).start);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":796
 *             return self.nsegments
 *         if other.end <= self.segments[0].start:
 *             return -1             # <<<<<<<<<<<<<<
 * 
 *         idx = searchsorted( self.segments,
 */
    __pyx_r = -1;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":802
 *                             sizeof( Segment ),
 *                             &other,
 *                             &cmpSegments )             # <<<<<<<<<<<<<<
 * 
 *         if idx == self.nsegments:
 */
  __pyx_v_idx = searchsorted(__pyx_v_self->segments, __pyx_v_self->nsegments, (sizeof(struct __pyx_t_14GatSegmentList_Segment)), (&__pyx_v_other), (&__pyx_f_14GatSegmentList_cmpSegments));

  /* "GatSegmentList.pyx":804
 *                             &cmpSegments )
 * 
 *         if idx == self.nsegments:             # <<<<<<<<<<<<<<
 *             return idx-1
 *         elif self.segments[idx].start != other.start:
 */
  __pyx_t_1 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":805
 * 
 *         if idx == self.nsegments:
 *             return idx-1             # <<<<<<<<<<<<<<
 *         elif self.segments[idx].start != other.start:
 *             return idx-1
 */
    __pyx_r = (__pyx_v_idx - 1);
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "GatSegmentList.pyx":806
 *         if idx == self.nsegments:
 *             return idx-1
 *         elif self.segments[idx].start != other.start:             # <<<<<<<<<<<<<<
 *             return idx-1
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_self->segments[__pyx_v_idx]).start != __pyx_v_other.start);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":807
 *             return idx-1
 *         elif self.segments[idx].start != other.start:
 *             return idx-1             # <<<<<<<<<<<<<<
 *         else:
 *             return idx
 */
    __pyx_r = (__pyx_v_idx - 1);
    goto __pyx_L0;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "GatSegmentList.pyx":809
 *             return idx-1
 *         else:
 *             return idx             # <<<<<<<<<<<<<<
 * 
 *     def getInsertionPoint( self, start, end ):
 */
    __pyx_r = __pyx_v_idx;
    goto __pyx_L0;
  }
  __pyx_L6:;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_25getInsertionPoint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_24getInsertionPoint[] = "SegmentList.getInsertionPoint(self, start, end)";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_25getInsertionPoint(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getInsertionPoint (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getInsertionPoint", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getInsertionPoint") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = values[0];
    __pyx_v_end = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getInsertionPoint", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getInsertionPoint", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_24getInsertionPoint(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_start, __pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":811
 *             return idx
 * 
 *     def getInsertionPoint( self, start, end ):             # <<<<<<<<<<<<<<
 *         assert self.flag & SEG_NORMALIZED, "searching in non-normalized list"
 *         return self._getInsertionPoint( Segment( start, end ) )
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_24getInsertionPoint(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_1;
  __pyx_t_14GatSegmentList_Position __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getInsertionPoint", 0);

  /* "GatSegmentList.pyx":812
 * 
 *     def getInsertionPoint( self, start, end ):
 *         assert self.flag & SEG_NORMALIZED, "searching in non-normalized list"             # <<<<<<<<<<<<<<
 *         return self._getInsertionPoint( Segment( start, end ) )
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_34));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":813
 *     def getInsertionPoint( self, start, end ):
 *         assert self.flag & SEG_NORMALIZED, "searching in non-normalized list"
 *         return self._getInsertionPoint( Segment( start, end ) )             # <<<<<<<<<<<<<<
 * 
 *     property isNormalized:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_start); if (unlikely((__pyx_t_2 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1.start = __pyx_t_2;
  __pyx_t_2 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_end); if (unlikely((__pyx_t_2 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1.end = __pyx_t_2;
  __pyx_t_3 = PyInt_FromLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_getInsertionPoint(__pyx_v_self, __pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __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_3);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getInsertionPoint", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_12isNormalized_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_12isNormalized_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_12isNormalized___get__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":816
 * 
 *     property isNormalized:
 *         def __get__(self): return self.flag & SEG_NORMALIZED             # <<<<<<<<<<<<<<
 * 
 *     property statusflag:
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_12isNormalized___get__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong((__pyx_v_self->flag & 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __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("GatSegmentList.SegmentList.isNormalized.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_10statusflag_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_10statusflag_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_10statusflag___get__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":819
 * 
 *     property statusflag:
 *         def __get__(self): return self.flag             # <<<<<<<<<<<<<<
 * 
 *     property isEmpty:
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_10statusflag___get__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(__pyx_v_self->flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __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("GatSegmentList.SegmentList.statusflag.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_7isEmpty_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_7isEmpty_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_7isEmpty___get__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":822
 * 
 *     property isEmpty:
 *         def __get__(self): return self.nsegments == 0             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position getRandomPosition( self ):
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_7isEmpty___get__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->nsegments == 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __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("GatSegmentList.SegmentList.isEmpty.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":824
 *         def __get__(self): return self.nsegments == 0
 * 
 *     cpdef Position getRandomPosition( self ):             # <<<<<<<<<<<<<<
 *         '''return a random position within the workspace.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_27getRandomPosition(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_getRandomPosition(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  __pyx_t_14GatSegmentList_Position __pyx_v_pos;
  PyObject *__pyx_v_idx = 0;
  __pyx_t_14GatSegmentList_Position __pyx_v_l;
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  size_t __pyx_t_5;
  size_t __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getRandomPosition", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__getRandomPosition); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_27getRandomPosition)) {
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":830
 *         you want to sample repeatedly from the same workspace.
 *         '''
 *         cdef Position pos = numpy.random.randint( 0, self.sum() )             # <<<<<<<<<<<<<<
 *         cdef idx
 *         cdef Position l
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__random); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__randint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_pos = __pyx_t_3;

  /* "GatSegmentList.pyx":833
 *         cdef idx
 *         cdef Position l
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             l = self.segments[idx].end - self.segments[idx].start
 *             if pos > l:
 */
  __pyx_t_5 = __pyx_v_self->nsegments;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) {
    __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_v_idx);
    __pyx_v_idx = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "GatSegmentList.pyx":834
 *         cdef Position l
 *         for idx from 0 <= idx < self.nsegments:
 *             l = self.segments[idx].end - self.segments[idx].start             # <<<<<<<<<<<<<<
 *             if pos > l:
 *                 pos -= l
 */
    __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_l = ((__pyx_v_self->segments[__pyx_t_7]).end - (__pyx_v_self->segments[__pyx_t_8]).start);

    /* "GatSegmentList.pyx":835
 *         for idx from 0 <= idx < self.nsegments:
 *             l = self.segments[idx].end - self.segments[idx].start
 *             if pos > l:             # <<<<<<<<<<<<<<
 *                 pos -= l
 *             else:
 */
    __pyx_t_9 = (__pyx_v_pos > __pyx_v_l);
    if (__pyx_t_9) {

      /* "GatSegmentList.pyx":836
 *             l = self.segments[idx].end - self.segments[idx].start
 *             if pos > l:
 *                 pos -= l             # <<<<<<<<<<<<<<
 *             else:
 *                 return self.segments[idx].start + pos
 */
      __pyx_v_pos = (__pyx_v_pos - __pyx_v_l);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":838
 *                 pos -= l
 *             else:
 *                 return self.segments[idx].start + pos             # <<<<<<<<<<<<<<
 *         assert False
 * 
 */
      __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((__pyx_v_self->segments[__pyx_t_8]).start + __pyx_v_pos);
      goto __pyx_L0;
    }
    __pyx_L5:;
    __pyx_t_6 = __Pyx_PyInt_AsSize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "GatSegmentList.pyx":833
 *         cdef idx
 *         cdef Position l
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             l = self.segments[idx].end - self.segments[idx].start
 *             if pos > l:
 */
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_v_idx);
  __pyx_v_idx = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "GatSegmentList.pyx":839
 *             else:
 *                 return self.segments[idx].start + pos
 *         assert False             # <<<<<<<<<<<<<<
 * 
 *     cdef Position overlap( self, Segment other ):
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!0)) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.getRandomPosition", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_27getRandomPosition(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_26getRandomPosition[] = "SegmentList.getRandomPosition(self) -> Position\nreturn a random position within the workspace.\n\n        Not efficient, see the specialized samplers instead if\n        you want to sample repeatedly from the same workspace.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_27getRandomPosition(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getRandomPosition (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_26getRandomPosition(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":824
 *         def __get__(self): return self.nsegments == 0
 * 
 *     cpdef Position getRandomPosition( self ):             # <<<<<<<<<<<<<<
 *         '''return a random position within the workspace.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_26getRandomPosition(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getRandomPosition", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->getRandomPosition(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __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("GatSegmentList.SegmentList.getRandomPosition", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":841
 *         assert False
 * 
 *     cdef Position overlap( self, Segment other ):             # <<<<<<<<<<<<<<
 *         '''return the size of intersection between
 *            segment list and Segment other'''
 */

static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_overlap(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_t_14GatSegmentList_Segment __pyx_v_other) {
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_count;
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlap", 0);

  /* "GatSegmentList.pyx":844
 *         '''return the size of intersection between
 *            segment list and Segment other'''
 *         assert self.flag & SEG_NORMALIZED, "non-normalized segment list"             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_35));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":847
 * 
 *         cdef int idx
 *         idx = self._getInsertionPoint( other )             # <<<<<<<<<<<<<<
 * 
 *         # deal with border cases
 */
  __pyx_v_idx = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_getInsertionPoint(__pyx_v_self, __pyx_v_other);

  /* "GatSegmentList.pyx":851
 *         # deal with border cases
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1             # <<<<<<<<<<<<<<
 *         elif idx == -1: idx=0
 * 
 */
  __pyx_t_1 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_1) {
    __pyx_v_idx = (__pyx_v_idx - 1);
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":852
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1
 *         elif idx == -1: idx=0             # <<<<<<<<<<<<<<
 * 
 *         cdef Position count
 */
  __pyx_t_1 = (__pyx_v_idx == -1);
  if (__pyx_t_1) {
    __pyx_v_idx = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":855
 * 
 *         cdef Position count
 *         count = 0             # <<<<<<<<<<<<<<
 * 
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:
 */
  __pyx_v_count = 0;

  /* "GatSegmentList.pyx":857
 *         count = 0
 * 
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:             # <<<<<<<<<<<<<<
 *             count += segment_overlap( self.segments[idx], other )
 *             idx += 1
 */
  while (1) {
    __pyx_t_1 = (__pyx_v_idx < __pyx_v_self->nsegments);
    if (__pyx_t_1) {
      __pyx_t_2 = ((__pyx_v_self->segments[__pyx_v_idx]).start <= __pyx_v_other.end);
      __pyx_t_3 = __pyx_t_2;
    } else {
      __pyx_t_3 = __pyx_t_1;
    }
    if (!__pyx_t_3) break;

    /* "GatSegmentList.pyx":858
 * 
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:
 *             count += segment_overlap( self.segments[idx], other )             # <<<<<<<<<<<<<<
 *             idx += 1
 *         return count
 */
    __pyx_v_count = (__pyx_v_count + __pyx_f_14GatSegmentList_segment_overlap((__pyx_v_self->segments[__pyx_v_idx]), __pyx_v_other));

    /* "GatSegmentList.pyx":859
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:
 *             count += segment_overlap( self.segments[idx], other )
 *             idx += 1             # <<<<<<<<<<<<<<
 *         return count
 * 
 */
    __pyx_v_idx = (__pyx_v_idx + 1);
  }

  /* "GatSegmentList.pyx":860
 *             count += segment_overlap( self.segments[idx], other )
 *             idx += 1
 *         return count             # <<<<<<<<<<<<<<
 * 
 *     cdef SegmentList getOverlappingSegments( self, Segment other ):
 */
  __pyx_r = __pyx_v_count;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":862
 *         return count
 * 
 *     cdef SegmentList getOverlappingSegments( self, Segment other ):             # <<<<<<<<<<<<<<
 *         '''return the segments overlapping
 *            segment list and Segment other'''
 */

static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_getOverlappingSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_t_14GatSegmentList_Segment __pyx_v_other) {
  int __pyx_v_idx;
  CYTHON_UNUSED long __pyx_v_count;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_result = 0;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getOverlappingSegments", 0);

  /* "GatSegmentList.pyx":866
 *            segment list and Segment other'''
 * 
 *         assert self.flag & SEG_NORMALIZED, "non-normalized segment list"             # <<<<<<<<<<<<<<
 *         cdef int idx
 *         idx = self._getInsertionPoint( other )
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_35));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":868
 *         assert self.flag & SEG_NORMALIZED, "non-normalized segment list"
 *         cdef int idx
 *         idx = self._getInsertionPoint( other )             # <<<<<<<<<<<<<<
 * 
 *         # deal with border cases
 */
  __pyx_v_idx = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_getInsertionPoint(__pyx_v_self, __pyx_v_other);

  /* "GatSegmentList.pyx":872
 *         # deal with border cases
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1             # <<<<<<<<<<<<<<
 *         elif idx == -1: idx=0
 * 
 */
  __pyx_t_1 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_1) {
    __pyx_v_idx = (__pyx_v_idx - 1);
    goto __pyx_L3;
  }

  /* "GatSegmentList.pyx":873
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1
 *         elif idx == -1: idx=0             # <<<<<<<<<<<<<<
 * 
 *         count = 0
 */
  __pyx_t_1 = (__pyx_v_idx == -1);
  if (__pyx_t_1) {
    __pyx_v_idx = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":875
 *         elif idx == -1: idx=0
 * 
 *         count = 0             # <<<<<<<<<<<<<<
 *         cdef SegmentList result = SegmentList()
 * 
 */
  __pyx_v_count = 0;

  /* "GatSegmentList.pyx":876
 * 
 *         count = 0
 *         cdef SegmentList result = SegmentList()             # <<<<<<<<<<<<<<
 * 
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:
 */
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_result = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "GatSegmentList.pyx":878
 *         cdef SegmentList result = SegmentList()
 * 
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:             # <<<<<<<<<<<<<<
 *             result._add( self.segments[idx] )
 *             idx += 1
 */
  while (1) {
    __pyx_t_1 = (__pyx_v_idx < __pyx_v_self->nsegments);
    if (__pyx_t_1) {
      __pyx_t_3 = ((__pyx_v_self->segments[__pyx_v_idx]).start <= __pyx_v_other.end);
      __pyx_t_4 = __pyx_t_3;
    } else {
      __pyx_t_4 = __pyx_t_1;
    }
    if (!__pyx_t_4) break;

    /* "GatSegmentList.pyx":879
 * 
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:
 *             result._add( self.segments[idx] )             # <<<<<<<<<<<<<<
 *             idx += 1
 *         result.normalize()
 */
    __pyx_t_2 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_result->__pyx_vtab)->_add(__pyx_v_result, (__pyx_v_self->segments[__pyx_v_idx])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "GatSegmentList.pyx":880
 *         while idx < self.nsegments and self.segments[idx].start <= other.end:
 *             result._add( self.segments[idx] )
 *             idx += 1             # <<<<<<<<<<<<<<
 *         result.normalize()
 *         return result
 */
    __pyx_v_idx = (__pyx_v_idx + 1);
  }

  /* "GatSegmentList.pyx":881
 *             result._add( self.segments[idx] )
 *             idx += 1
 *         result.normalize()             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_result->__pyx_vtab)->normalize(__pyx_v_result, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "GatSegmentList.pyx":882
 *             idx += 1
 *         result.normalize()
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position overlapWithRange( self, Position start, Position end ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getOverlappingSegments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":884
 *         return result
 * 
 *     cpdef Position overlapWithRange( self, Position start, Position end ):             # <<<<<<<<<<<<<<
 *         '''return the size of intersection between
 *            segment list and Segment other'''
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_29overlapWithRange(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_overlapWithRange(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end, int __pyx_skip_dispatch) {
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_s;
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_5;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlapWithRange", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__overlapWithRange); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_29overlapWithRange)) {
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_5;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":889
 * 
 *         cdef Segment s
 *         s = Segment( start, end )             # <<<<<<<<<<<<<<
 *         return self.overlap( s )
 * 
 */
  __pyx_t_6.start = __pyx_v_start;
  __pyx_t_6.end = __pyx_v_end;
  __pyx_v_s = __pyx_t_6;

  /* "GatSegmentList.pyx":890
 *         cdef Segment s
 *         s = Segment( start, end )
 *         return self.overlap( s )             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList getOverlappingSegmentsWithRange( self, Position start, Position end ):
 */
  __pyx_r = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->overlap(__pyx_v_self, __pyx_v_s);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.overlapWithRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_29overlapWithRange(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_28overlapWithRange[] = "SegmentList.overlapWithRange(self, Position start, Position end) -> Position\nreturn the size of intersection between\n           segment list and Segment other";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_29overlapWithRange(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_start;
  __pyx_t_14GatSegmentList_Position __pyx_v_end;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlapWithRange (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("overlapWithRange", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "overlapWithRange") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_start == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_end == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("overlapWithRange", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.overlapWithRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_28overlapWithRange(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_start, __pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":884
 *         return result
 * 
 *     cpdef Position overlapWithRange( self, Position start, Position end ):             # <<<<<<<<<<<<<<
 *         '''return the size of intersection between
 *            segment list and Segment other'''
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_28overlapWithRange(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlapWithRange", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->overlapWithRange(__pyx_v_self, __pyx_v_start, __pyx_v_end, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __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("GatSegmentList.SegmentList.overlapWithRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":892
 *         return self.overlap( s )
 * 
 *     cpdef SegmentList getOverlappingSegmentsWithRange( self, Position start, Position end ):             # <<<<<<<<<<<<<<
 *         '''return a list with segments overlapping range.'''
 *         cdef Segment s
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_31getOverlappingSegmentsWithRange(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_getOverlappingSegmentsWithRange(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end, int __pyx_skip_dispatch) {
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_s;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getOverlappingSegmentsWithRange", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_36); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_31getOverlappingSegmentsWithRange)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __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 = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":895
 *         '''return a list with segments overlapping range.'''
 *         cdef Segment s
 *         s = Segment( start, end )             # <<<<<<<<<<<<<<
 *         return self.getOverlappingSegments( s )
 * 
 */
  __pyx_t_5.start = __pyx_v_start;
  __pyx_t_5.end = __pyx_v_end;
  __pyx_v_s = __pyx_t_5;

  /* "GatSegmentList.pyx":896
 *         cdef Segment s
 *         s = Segment( start, end )
 *         return self.getOverlappingSegments( s )             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position overlapWithSegments( self, SegmentList other ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->getOverlappingSegments(__pyx_v_self, __pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getOverlappingSegmentsWithRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_31getOverlappingSegmentsWithRange(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_30getOverlappingSegmentsWithRange[] = "SegmentList.getOverlappingSegmentsWithRange(self, Position start, Position end) -> SegmentList\nreturn a list with segments overlapping range.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_31getOverlappingSegmentsWithRange(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_start;
  __pyx_t_14GatSegmentList_Position __pyx_v_end;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getOverlappingSegmentsWithRange (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getOverlappingSegmentsWithRange", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getOverlappingSegmentsWithRange") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_start == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_end == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getOverlappingSegmentsWithRange", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getOverlappingSegmentsWithRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_30getOverlappingSegmentsWithRange(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_start, __pyx_v_end);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":892
 *         return self.overlap( s )
 * 
 *     cpdef SegmentList getOverlappingSegmentsWithRange( self, Position start, Position end ):             # <<<<<<<<<<<<<<
 *         '''return a list with segments overlapping range.'''
 *         cdef Segment s
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_30getOverlappingSegmentsWithRange(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_Position __pyx_v_end) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getOverlappingSegmentsWithRange", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->getOverlappingSegmentsWithRange(__pyx_v_self, __pyx_v_start, __pyx_v_end, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __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("GatSegmentList.SegmentList.getOverlappingSegmentsWithRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":898
 *         return self.getOverlappingSegments( s )
 * 
 *     cpdef Position overlapWithSegments( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''return the number of nucleotides overlapping between this and *other*.'''
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_33overlapWithSegments(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_overlapWithSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, int __pyx_skip_dispatch) {
  int __pyx_v_this_idx;
  int __pyx_v_other_idx;
  int __pyx_v_last_this_idx;
  int __pyx_v_last_other_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_this_segment;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other_segment;
  __pyx_t_14GatSegmentList_Position __pyx_v_overlap;
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_4;
  int __pyx_t_5;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlapWithSegments", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__overlapWithSegments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_33overlapWithSegments)) {
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_4 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_4;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":901
 *         '''return the number of nucleotides overlapping between this and *other*.'''
 * 
 *         assert self.flag & SEG_NORMALIZED, "intersection from non-normalized list"             # <<<<<<<<<<<<<<
 *         assert other.flag & SEG_NORMALIZED, "intersection with non-normalized list"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_37));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":902
 * 
 *         assert self.flag & SEG_NORMALIZED, "intersection from non-normalized list"
 *         assert other.flag & SEG_NORMALIZED, "intersection with non-normalized list"             # <<<<<<<<<<<<<<
 * 
 *         # avoid self-self comparison
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_other->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_38));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":905
 * 
 *         # avoid self-self comparison
 *         if other.segments == self.segments: return self.sum()             # <<<<<<<<<<<<<<
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 */
  __pyx_t_5 = (__pyx_v_other->segments == __pyx_v_self->segments);
  if (__pyx_t_5) {
    __pyx_r = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":908
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         this_idx = other_idx = 0             # <<<<<<<<<<<<<<
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 */
  __pyx_v_this_idx = 0;
  __pyx_v_other_idx = 0;

  /* "GatSegmentList.pyx":909
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1             # <<<<<<<<<<<<<<
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)
 */
  __pyx_v_last_this_idx = -1;
  __pyx_v_last_other_idx = -1;

  /* "GatSegmentList.pyx":910
 *         this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 *         cdef Segment other_segment = Segment(0,0)
 * 
 */
  __pyx_t_6.start = 0;
  __pyx_t_6.end = 0;
  __pyx_v_this_segment = __pyx_t_6;

  /* "GatSegmentList.pyx":911
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 * 
 *         cdef Position overlap
 */
  __pyx_t_6.start = 0;
  __pyx_t_6.end = 0;
  __pyx_v_other_segment = __pyx_t_6;

  /* "GatSegmentList.pyx":914
 * 
 *         cdef Position overlap
 *         overlap = 0             # <<<<<<<<<<<<<<
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:
 */
  __pyx_v_overlap = 0;

  /* "GatSegmentList.pyx":916
 *         overlap = 0
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:             # <<<<<<<<<<<<<<
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_this_idx < __pyx_v_self->nsegments);
    if (__pyx_t_5) {
      __pyx_t_7 = (__pyx_v_other_idx < __pyx_v_other->nsegments);
      __pyx_t_8 = __pyx_t_7;
    } else {
      __pyx_t_8 = __pyx_t_5;
    }
    if (!__pyx_t_8) break;

    /* "GatSegmentList.pyx":919
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:             # <<<<<<<<<<<<<<
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 */
    __pyx_t_8 = (__pyx_v_last_this_idx != __pyx_v_this_idx);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":920
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]             # <<<<<<<<<<<<<<
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 */
      __pyx_v_this_segment = (__pyx_v_self->segments[__pyx_v_this_idx]);

      /* "GatSegmentList.pyx":921
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx             # <<<<<<<<<<<<<<
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 */
      __pyx_v_last_this_idx = __pyx_v_this_idx;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "GatSegmentList.pyx":922
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:             # <<<<<<<<<<<<<<
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx
 */
    __pyx_t_8 = (__pyx_v_last_other_idx != __pyx_v_other_idx);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":923
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]             # <<<<<<<<<<<<<<
 *                 last_other_idx = other_idx
 * 
 */
      __pyx_v_other_segment = (__pyx_v_other->segments[__pyx_v_other_idx]);

      /* "GatSegmentList.pyx":924
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx             # <<<<<<<<<<<<<<
 * 
 *             # print this_segment, other_segment
 */
      __pyx_v_last_other_idx = __pyx_v_other_idx;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "GatSegmentList.pyx":928
 *             # print this_segment, other_segment
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:             # <<<<<<<<<<<<<<
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 */
    __pyx_t_8 = (__pyx_v_this_segment.end <= __pyx_v_other_segment.start);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":929
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:
 *                 this_idx += 1             # <<<<<<<<<<<<<<
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 */
      __pyx_v_this_idx = (__pyx_v_this_idx + 1);
      goto __pyx_L8;
    }

    /* "GatSegmentList.pyx":931
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:             # <<<<<<<<<<<<<<
 *                 other_idx += 1
 *             else:
 */
    __pyx_t_8 = (__pyx_v_other_segment.end <= __pyx_v_this_segment.start);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":932
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 *                 other_idx += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # deal with overlap
 */
      __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      goto __pyx_L8;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":935
 *             else:
 *                 # deal with overlap
 *                 overlap += segment_overlap_raw( this_segment, other_segment )             # <<<<<<<<<<<<<<
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1
 */
      __pyx_v_overlap = (__pyx_v_overlap + __pyx_f_14GatSegmentList_segment_overlap_raw(__pyx_v_this_segment, __pyx_v_other_segment));

      /* "GatSegmentList.pyx":936
 *                 # deal with overlap
 *                 overlap += segment_overlap_raw( this_segment, other_segment )
 *                 if this_segment.end < other_segment.end:             # <<<<<<<<<<<<<<
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:
 */
      __pyx_t_8 = (__pyx_v_this_segment.end < __pyx_v_other_segment.end);
      if (__pyx_t_8) {

        /* "GatSegmentList.pyx":937
 *                 overlap += segment_overlap_raw( this_segment, other_segment )
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1             # <<<<<<<<<<<<<<
 *                 elif other_segment.end < this_segment.end:
 *                     other_idx += 1
 */
        __pyx_v_this_idx = (__pyx_v_this_idx + 1);
        goto __pyx_L9;
      }

      /* "GatSegmentList.pyx":938
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:             # <<<<<<<<<<<<<<
 *                     other_idx += 1
 *                 else:
 */
      __pyx_t_8 = (__pyx_v_other_segment.end < __pyx_v_this_segment.end);
      if (__pyx_t_8) {

        /* "GatSegmentList.pyx":939
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:
 *                     other_idx += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     this_idx += 1
 */
        __pyx_v_other_idx = (__pyx_v_other_idx + 1);
        goto __pyx_L9;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":941
 *                     other_idx += 1
 *                 else:
 *                     this_idx += 1             # <<<<<<<<<<<<<<
 *                     other_idx += 1
 * 
 */
        __pyx_v_this_idx = (__pyx_v_this_idx + 1);

        /* "GatSegmentList.pyx":942
 *                 else:
 *                     this_idx += 1
 *                     other_idx += 1             # <<<<<<<<<<<<<<
 * 
 *         return overlap
 */
        __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      }
      __pyx_L9:;
    }
    __pyx_L8:;
  }

  /* "GatSegmentList.pyx":944
 *                     other_idx += 1
 * 
 *         return overlap             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position intersectionWithSegments( self,
 */
  __pyx_r = __pyx_v_overlap;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.overlapWithSegments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_33overlapWithSegments(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_32overlapWithSegments[] = "SegmentList.overlapWithSegments(self, SegmentList other) -> Position\nreturn the number of nucleotides overlapping between this and *other*.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_33overlapWithSegments(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlapWithSegments (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_32overlapWithSegments(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_other));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":898
 *         return self.getOverlappingSegments( s )
 * 
 *     cpdef Position overlapWithSegments( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''return the number of nucleotides overlapping between this and *other*.'''
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_32overlapWithSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlapWithSegments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->overlapWithSegments(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __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("GatSegmentList.SegmentList.overlapWithSegments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":946
 *         return overlap
 * 
 *     cpdef Position intersectionWithSegments( self,             # <<<<<<<<<<<<<<
 *                                              SegmentList other,
 *                                              mode = "base" ):
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_35intersectionWithSegments(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_intersectionWithSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, int __pyx_skip_dispatch, struct __pyx_opt_args_14GatSegmentList_11SegmentList_intersectionWithSegments *__pyx_optional_args) {
  PyObject *__pyx_v_mode = ((PyObject *)__pyx_n_s__base);
  int __pyx_v_this_idx;
  int __pyx_v_other_idx;
  int __pyx_v_last_this_idx;
  int __pyx_v_last_other_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_this_segment;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other_segment;
  int __pyx_v_midpoint_overlap;
  __pyx_t_14GatSegmentList_Position __pyx_v_noverlap;
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_4;
  int __pyx_t_5;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  long __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("intersectionWithSegments", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_mode = __pyx_optional_args->mode;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_39); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_35intersectionWithSegments)) {
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __Pyx_INCREF(__pyx_v_mode);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_mode);
      __Pyx_GIVEREF(__pyx_v_mode);
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_4 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_4;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":956
 *         '''
 * 
 *         assert self.flag & SEG_NORMALIZED, "intersection from non-normalized list"             # <<<<<<<<<<<<<<
 *         assert other.flag & SEG_NORMALIZED, "intersection with non-normalized list"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_37));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":957
 * 
 *         assert self.flag & SEG_NORMALIZED, "intersection from non-normalized list"
 *         assert other.flag & SEG_NORMALIZED, "intersection with non-normalized list"             # <<<<<<<<<<<<<<
 * 
 *         # avoid self-self comparison
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_other->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_38));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":960
 * 
 *         # avoid self-self comparison
 *         if other.segments == self.segments: return self.sum()             # <<<<<<<<<<<<<<
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 */
  __pyx_t_5 = (__pyx_v_other->segments == __pyx_v_self->segments);
  if (__pyx_t_5) {
    __pyx_r = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":963
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         this_idx = other_idx = 0             # <<<<<<<<<<<<<<
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 */
  __pyx_v_this_idx = 0;
  __pyx_v_other_idx = 0;

  /* "GatSegmentList.pyx":964
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1             # <<<<<<<<<<<<<<
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)
 */
  __pyx_v_last_this_idx = -1;
  __pyx_v_last_other_idx = -1;

  /* "GatSegmentList.pyx":965
 *         this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 *         cdef Segment other_segment = Segment(0,0)
 * 
 */
  __pyx_t_6.start = 0;
  __pyx_t_6.end = 0;
  __pyx_v_this_segment = __pyx_t_6;

  /* "GatSegmentList.pyx":966
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 * 
 *         cdef int midpoint_overlap = mode == "midpoint"
 */
  __pyx_t_6.start = 0;
  __pyx_t_6.end = 0;
  __pyx_v_other_segment = __pyx_t_6;

  /* "GatSegmentList.pyx":968
 *         cdef Segment other_segment = Segment(0,0)
 * 
 *         cdef int midpoint_overlap = mode == "midpoint"             # <<<<<<<<<<<<<<
 * 
 *         cdef Position noverlap
 */
  __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_mode, ((PyObject *)__pyx_n_s__midpoint), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_midpoint_overlap = __pyx_t_5;

  /* "GatSegmentList.pyx":971
 * 
 *         cdef Position noverlap
 *         noverlap = 0             # <<<<<<<<<<<<<<
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:
 */
  __pyx_v_noverlap = 0;

  /* "GatSegmentList.pyx":973
 *         noverlap = 0
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:             # <<<<<<<<<<<<<<
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_this_idx < __pyx_v_self->nsegments);
    if (__pyx_t_5) {
      __pyx_t_7 = (__pyx_v_other_idx < __pyx_v_other->nsegments);
      __pyx_t_8 = __pyx_t_7;
    } else {
      __pyx_t_8 = __pyx_t_5;
    }
    if (!__pyx_t_8) break;

    /* "GatSegmentList.pyx":976
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:             # <<<<<<<<<<<<<<
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 */
    __pyx_t_8 = (__pyx_v_last_this_idx != __pyx_v_this_idx);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":977
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]             # <<<<<<<<<<<<<<
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 */
      __pyx_v_this_segment = (__pyx_v_self->segments[__pyx_v_this_idx]);

      /* "GatSegmentList.pyx":978
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx             # <<<<<<<<<<<<<<
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 */
      __pyx_v_last_this_idx = __pyx_v_this_idx;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "GatSegmentList.pyx":979
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:             # <<<<<<<<<<<<<<
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx
 */
    __pyx_t_8 = (__pyx_v_last_other_idx != __pyx_v_other_idx);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":980
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]             # <<<<<<<<<<<<<<
 *                 last_other_idx = other_idx
 * 
 */
      __pyx_v_other_segment = (__pyx_v_other->segments[__pyx_v_other_idx]);

      /* "GatSegmentList.pyx":981
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx             # <<<<<<<<<<<<<<
 * 
 *             # skip segments in this not overlapping other
 */
      __pyx_v_last_other_idx = __pyx_v_other_idx;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "GatSegmentList.pyx":984
 * 
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:             # <<<<<<<<<<<<<<
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 */
    __pyx_t_8 = (__pyx_v_this_segment.end <= __pyx_v_other_segment.start);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":985
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:
 *                 this_idx += 1             # <<<<<<<<<<<<<<
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 */
      __pyx_v_this_idx = (__pyx_v_this_idx + 1);
      goto __pyx_L8;
    }

    /* "GatSegmentList.pyx":987
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:             # <<<<<<<<<<<<<<
 *                 other_idx += 1
 *             else:
 */
    __pyx_t_8 = (__pyx_v_other_segment.end <= __pyx_v_this_segment.start);
    if (__pyx_t_8) {

      /* "GatSegmentList.pyx":988
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 *                 other_idx += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # deal with overlap
 */
      __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      goto __pyx_L8;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":991
 *             else:
 *                 # deal with overlap
 *                 if midpoint_overlap:             # <<<<<<<<<<<<<<
 *                     if other_segment.start <= this_segment.start + (this_segment.end - this_segment.start) // 2 \
 *                             < other_segment.end:
 */
      if (__pyx_v_midpoint_overlap) {

        /* "GatSegmentList.pyx":992
 *                 # deal with overlap
 *                 if midpoint_overlap:
 *                     if other_segment.start <= this_segment.start + (this_segment.end - this_segment.start) // 2 \             # <<<<<<<<<<<<<<
 *                             < other_segment.end:
 *                         noverlap += 1
 */
        __pyx_t_9 = (__pyx_v_this_segment.start + __Pyx_div_long((__pyx_v_this_segment.end - __pyx_v_this_segment.start), 2));
        __pyx_t_8 = (__pyx_v_other_segment.start <= __pyx_t_9);
        if (__pyx_t_8) {

          /* "GatSegmentList.pyx":993
 *                 if midpoint_overlap:
 *                     if other_segment.start <= this_segment.start + (this_segment.end - this_segment.start) // 2 \
 *                             < other_segment.end:             # <<<<<<<<<<<<<<
 *                         noverlap += 1
 *                 else:
 */
          __pyx_t_8 = (__pyx_t_9 < __pyx_v_other_segment.end);
        }
        if (__pyx_t_8) {

          /* "GatSegmentList.pyx":994
 *                     if other_segment.start <= this_segment.start + (this_segment.end - this_segment.start) // 2 \
 *                             < other_segment.end:
 *                         noverlap += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     noverlap += 1
 */
          __pyx_v_noverlap = (__pyx_v_noverlap + 1);
          goto __pyx_L10;
        }
        __pyx_L10:;
        goto __pyx_L9;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":996
 *                         noverlap += 1
 *                 else:
 *                     noverlap += 1             # <<<<<<<<<<<<<<
 *                 this_idx += 1
 * 
 */
        __pyx_v_noverlap = (__pyx_v_noverlap + 1);
      }
      __pyx_L9:;

      /* "GatSegmentList.pyx":997
 *                 else:
 *                     noverlap += 1
 *                 this_idx += 1             # <<<<<<<<<<<<<<
 * 
 *         return noverlap
 */
      __pyx_v_this_idx = (__pyx_v_this_idx + 1);
    }
    __pyx_L8:;
  }

  /* "GatSegmentList.pyx":999
 *                 this_idx += 1
 * 
 *         return noverlap             # <<<<<<<<<<<<<<
 * 
 *     def getLengthDistribution( self, bucket_size = 0, nbuckets = 100000):
 */
  __pyx_r = __pyx_v_noverlap;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.intersectionWithSegments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_35intersectionWithSegments(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_34intersectionWithSegments[] = "SegmentList.intersectionWithSegments(self, SegmentList other, mode='base') -> Position\nreturn the number of segments overlapping with *other*.\n\n        *mode* can be either ``base`` or ``midpoint``. With ``base``, an overlap is \n        recorded if a single ``base`` in self overlaps a interval in other. With ``midpoint``,\n        an overlap is counted only if the midpoint of an interval overlaps any interval in ``other``.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_35intersectionWithSegments(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other = 0;
  PyObject *__pyx_v_mode = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__other,&__pyx_n_s__mode,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("intersectionWithSegments (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_n_s__base);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__other);
        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__mode);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "intersectionWithSegments") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_other = ((struct __pyx_obj_14GatSegmentList_SegmentList *)values[0]);
    __pyx_v_mode = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("intersectionWithSegments", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.intersectionWithSegments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_34intersectionWithSegments(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_other, __pyx_v_mode);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":946
 *         return overlap
 * 
 *     cpdef Position intersectionWithSegments( self,             # <<<<<<<<<<<<<<
 *                                              SegmentList other,
 *                                              mode = "base" ):
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_34intersectionWithSegments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, PyObject *__pyx_v_mode) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __pyx_t_14GatSegmentList_Position __pyx_t_1;
  struct __pyx_opt_args_14GatSegmentList_11SegmentList_intersectionWithSegments __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("intersectionWithSegments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.mode = __pyx_v_mode;
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->intersectionWithSegments(__pyx_v_self, __pyx_v_other, 1, &__pyx_t_2); 
  __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __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_3);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.intersectionWithSegments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_37getLengthDistribution(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_36getLengthDistribution[] = "SegmentList.getLengthDistribution(self, bucket_size=0, nbuckets=100000)\nbuild histogram of segments lengths.\n        \n        If bucket_size is 0, the bucket size will be determined automatically\n        to accomodate the largest segment.\n\n        returns a histogram with the bucket_size.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_37getLengthDistribution(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_bucket_size = 0;
  PyObject *__pyx_v_nbuckets = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__bucket_size,&__pyx_n_s__nbuckets,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getLengthDistribution (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)__pyx_int_0);
    values[1] = ((PyObject *)__pyx_int_100000);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bucket_size);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nbuckets);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getLengthDistribution") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_bucket_size = values[0];
    __pyx_v_nbuckets = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getLengthDistribution", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getLengthDistribution", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_36getLengthDistribution(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_bucket_size, __pyx_v_nbuckets);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1001
 *         return noverlap
 * 
 *     def getLengthDistribution( self, bucket_size = 0, nbuckets = 100000):             # <<<<<<<<<<<<<<
 *         '''build histogram of segments lengths.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_36getLengthDistribution(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_bucket_size, PyObject *__pyx_v_nbuckets) {
  int __pyx_v_idx;
  int __pyx_v_i;
  __pyx_t_14GatSegmentList_Position __pyx_v_l;
  PyArrayObject *__pyx_v_histogram = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_histogram;
  __Pyx_Buffer __pyx_pybuffer_histogram;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_12;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_t_13;
  double __pyx_t_14;
  size_t __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getLengthDistribution", 0);
  __Pyx_INCREF(__pyx_v_bucket_size);
  __pyx_pybuffer_histogram.pybuffer.buf = NULL;
  __pyx_pybuffer_histogram.refcount = 0;
  __pyx_pybuffernd_histogram.data = NULL;
  __pyx_pybuffernd_histogram.rcbuffer = &__pyx_pybuffer_histogram;

  /* "GatSegmentList.pyx":1009
 *         returns a histogram with the bucket_size.
 *         '''
 *         assert bucket_size >= 0, 'bucket_size is 0'             # <<<<<<<<<<<<<<
 *         assert nbuckets > 0, 'nbuckets is 0'
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_bucket_size, __pyx_int_0, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_40));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1010
 *         '''
 *         assert bucket_size >= 0, 'bucket_size is 0'
 *         assert nbuckets > 0, 'nbuckets is 0'             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx, i
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_nbuckets, __pyx_int_0, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_41));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1016
 *         cdef Segment s
 *         cdef numpy.ndarray[DTYPE_INT_t, ndim=1] histogram
 *         histogram = numpy.zeros( nbuckets, dtype=numpy.int )             # <<<<<<<<<<<<<<
 *         if bucket_size == 0:
 *             bucket_size = int( math.ceil( segment_length(self.largest()) / float(nbuckets)) )
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_nbuckets);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_nbuckets);
  __Pyx_GIVEREF(__pyx_v_nbuckets);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__int); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_histogram.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_histogram.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_14GatSegmentList_DTYPE_INT_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_histogram.rcbuffer->pybuffer, (PyObject*)__pyx_v_histogram, &__Pyx_TypeInfo_nn___pyx_t_14GatSegmentList_DTYPE_INT_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_histogram.diminfo[0].strides = __pyx_pybuffernd_histogram.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_histogram.diminfo[0].shape = __pyx_pybuffernd_histogram.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_7 = 0;
  __pyx_v_histogram = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "GatSegmentList.pyx":1017
 *         cdef numpy.ndarray[DTYPE_INT_t, ndim=1] histogram
 *         histogram = numpy.zeros( nbuckets, dtype=numpy.int )
 *         if bucket_size == 0:             # <<<<<<<<<<<<<<
 *             bucket_size = int( math.ceil( segment_length(self.largest()) / float(nbuckets)) )
 * 
 */
  __pyx_t_6 = PyObject_RichCompare(__pyx_v_bucket_size, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_2) {

    /* "GatSegmentList.pyx":1018
 *         histogram = numpy.zeros( nbuckets, dtype=numpy.int )
 *         if bucket_size == 0:
 *             bucket_size = int( math.ceil( segment_length(self.largest()) / float(nbuckets)) )             # <<<<<<<<<<<<<<
 * 
 *         for idx from 0 <= idx < self.nsegments:
 */
    __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__math); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__ceil); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__largest); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_12 = __pyx_convert__from_py___pyx_t_14GatSegmentList_Segment(__pyx_t_1); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __pyx_f_14GatSegmentList_segment_length(__pyx_t_12);
    __pyx_t_14 = __Pyx_PyObject_AsDouble(__pyx_v_nbuckets); if (unlikely(__pyx_t_14 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(__pyx_t_14 == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_1 = PyFloat_FromDouble((__pyx_t_13 / __pyx_t_14)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_v_bucket_size);
    __pyx_v_bucket_size = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1020
 *             bucket_size = int( math.ceil( segment_length(self.largest()) / float(nbuckets)) )
 * 
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             l = segment_length(self.segments[idx])
 *             i = <int>((l+bucket_size-1)/bucket_size)
 */
  __pyx_t_15 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_15; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1021
 * 
 *         for idx from 0 <= idx < self.nsegments:
 *             l = segment_length(self.segments[idx])             # <<<<<<<<<<<<<<
 *             i = <int>((l+bucket_size-1)/bucket_size)
 *             if i >= nbuckets:
 */
    __pyx_v_l = __pyx_f_14GatSegmentList_segment_length((__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1022
 *         for idx from 0 <= idx < self.nsegments:
 *             l = segment_length(self.segments[idx])
 *             i = <int>((l+bucket_size-1)/bucket_size)             # <<<<<<<<<<<<<<
 *             if i >= nbuckets:
 *                 raise ValueError( "segment %i-%i too large: %i >= %i, increase nbuckets (%i) or bucket_size (%i) such that nbuckets * bucket_size > %i" %\
 */
    __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_v_bucket_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_Subtract(__pyx_t_6, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_v_bucket_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_i = ((int)__pyx_t_8);

    /* "GatSegmentList.pyx":1023
 *             l = segment_length(self.segments[idx])
 *             i = <int>((l+bucket_size-1)/bucket_size)
 *             if i >= nbuckets:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "segment %i-%i too large: %i >= %i, increase nbuckets (%i) or bucket_size (%i) such that nbuckets * bucket_size > %i" %\
 *                                       ( self.segments[idx].start,
 */
    __pyx_t_6 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_v_nbuckets, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "GatSegmentList.pyx":1025
 *             if i >= nbuckets:
 *                 raise ValueError( "segment %i-%i too large: %i >= %i, increase nbuckets (%i) or bucket_size (%i) such that nbuckets * bucket_size > %i" %\
 *                                       ( self.segments[idx].start,             # <<<<<<<<<<<<<<
 *                                         self.segments[idx].end,
 *                                         l,
 */
      __pyx_t_1 = PyLong_FromUnsignedLong((__pyx_v_self->segments[__pyx_v_idx]).start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);

      /* "GatSegmentList.pyx":1026
 *                 raise ValueError( "segment %i-%i too large: %i >= %i, increase nbuckets (%i) or bucket_size (%i) such that nbuckets * bucket_size > %i" %\
 *                                       ( self.segments[idx].start,
 *                                         self.segments[idx].end,             # <<<<<<<<<<<<<<
 *                                         l,
 *                                         nbuckets * bucket_size,
 */
      __pyx_t_6 = PyLong_FromUnsignedLong((__pyx_v_self->segments[__pyx_v_idx]).end); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);

      /* "GatSegmentList.pyx":1027
 *                                       ( self.segments[idx].start,
 *                                         self.segments[idx].end,
 *                                         l,             # <<<<<<<<<<<<<<
 *                                         nbuckets * bucket_size,
 *                                         nbuckets,
 */
      __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);

      /* "GatSegmentList.pyx":1028
 *                                         self.segments[idx].end,
 *                                         l,
 *                                         nbuckets * bucket_size,             # <<<<<<<<<<<<<<
 *                                         nbuckets,
 *                                         bucket_size,
 */
      __pyx_t_3 = PyNumber_Multiply(__pyx_v_nbuckets, __pyx_v_bucket_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);

      /* "GatSegmentList.pyx":1032
 *                                         bucket_size,
 *                                         l
 *                                         ) )             # <<<<<<<<<<<<<<
 *             histogram[i] += 1
 *         return histogram, bucket_size
 */
      __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_16 = PyTuple_New(7); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_16, 2, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_16, 3, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_nbuckets);
      PyTuple_SET_ITEM(__pyx_t_16, 4, __pyx_v_nbuckets);
      __Pyx_GIVEREF(__pyx_v_nbuckets);
      __Pyx_INCREF(__pyx_v_bucket_size);
      PyTuple_SET_ITEM(__pyx_t_16, 5, __pyx_v_bucket_size);
      __Pyx_GIVEREF(__pyx_v_bucket_size);
      PyTuple_SET_ITEM(__pyx_t_16, 6, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_1 = 0;
      __pyx_t_6 = 0;
      __pyx_t_4 = 0;
      __pyx_t_3 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), ((PyObject *)__pyx_t_16)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __Pyx_DECREF(((PyObject *)__pyx_t_16)); __pyx_t_16 = 0;
      __pyx_t_16 = PyTuple_New(1); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_16, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_16), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(((PyObject *)__pyx_t_16)); __pyx_t_16 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "GatSegmentList.pyx":1033
 *                                         l
 *                                         ) )
 *             histogram[i] += 1             # <<<<<<<<<<<<<<
 *         return histogram, bucket_size
 * 
 */
    __pyx_t_8 = __pyx_v_i;
    __pyx_t_17 = -1;
    if (__pyx_t_8 < 0) {
      __pyx_t_8 += __pyx_pybuffernd_histogram.diminfo[0].shape;
      if (unlikely(__pyx_t_8 < 0)) __pyx_t_17 = 0;
    } else if (unlikely(__pyx_t_8 >= __pyx_pybuffernd_histogram.diminfo[0].shape)) __pyx_t_17 = 0;
    if (unlikely(__pyx_t_17 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_17);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_14GatSegmentList_DTYPE_INT_t *, __pyx_pybuffernd_histogram.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_histogram.diminfo[0].strides) += 1;
  }

  /* "GatSegmentList.pyx":1034
 *                                         ) )
 *             histogram[i] += 1
 *         return histogram, bucket_size             # <<<<<<<<<<<<<<
 * 
 *     cdef SegmentList truncate( self, Segment other ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_histogram));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_histogram));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_histogram));
  __Pyx_INCREF(__pyx_v_bucket_size);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_bucket_size);
  __Pyx_GIVEREF(__pyx_v_bucket_size);
  __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_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_16);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_histogram.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getLengthDistribution", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_histogram.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_histogram);
  __Pyx_XDECREF(__pyx_v_bucket_size);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1036
 *         return histogram, bucket_size
 * 
 *     cdef SegmentList truncate( self, Segment other ):             # <<<<<<<<<<<<<<
 *         '''truncate Segment list to range given by segment *other*.'''
 * 
 */

static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_truncate(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_t_14GatSegmentList_Segment __pyx_v_other) {
  int __pyx_v_idx;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  __pyx_t_14GatSegmentList_Position __pyx_v_start;
  __pyx_t_14GatSegmentList_Position __pyx_v_end;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("truncate", 0);

  /* "GatSegmentList.pyx":1041
 *         cdef int idx
 *         cdef Segment * s
 *         cdef Position start = other.start             # <<<<<<<<<<<<<<
 *         cdef Position end = other.end
 * 
 */
  __pyx_v_start = __pyx_v_other.start;

  /* "GatSegmentList.pyx":1042
 *         cdef Segment * s
 *         cdef Position start = other.start
 *         cdef Position end = other.end             # <<<<<<<<<<<<<<
 * 
 *         for idx from 0 <= idx < self.nsegments:
 */
  __pyx_v_end = __pyx_v_other.end;

  /* "GatSegmentList.pyx":1044
 *         cdef Position end = other.end
 * 
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             s = & self.segments[idx]
 *             if s.end < start: s.start = s.end = 0
 */
  __pyx_t_1 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_1; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1045
 * 
 *         for idx from 0 <= idx < self.nsegments:
 *             s = & self.segments[idx]             # <<<<<<<<<<<<<<
 *             if s.end < start: s.start = s.end = 0
 *             elif s.start > end: s.start = s.end = 0
 */
    __pyx_v_s = (&(__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1046
 *         for idx from 0 <= idx < self.nsegments:
 *             s = & self.segments[idx]
 *             if s.end < start: s.start = s.end = 0             # <<<<<<<<<<<<<<
 *             elif s.start > end: s.start = s.end = 0
 *             else:
 */
    __pyx_t_2 = (__pyx_v_s->end < __pyx_v_start);
    if (__pyx_t_2) {
      __pyx_v_s->start = 0;
      __pyx_v_s->end = 0;
      goto __pyx_L5;
    }

    /* "GatSegmentList.pyx":1047
 *             s = & self.segments[idx]
 *             if s.end < start: s.start = s.end = 0
 *             elif s.start > end: s.start = s.end = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 if s.start < start: s.start = start
 */
    __pyx_t_2 = (__pyx_v_s->start > __pyx_v_end);
    if (__pyx_t_2) {
      __pyx_v_s->start = 0;
      __pyx_v_s->end = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1049
 *             elif s.start > end: s.start = s.end = 0
 *             else:
 *                 if s.start < start: s.start = start             # <<<<<<<<<<<<<<
 *                 if s.end > end: s.end = end
 * 
 */
      __pyx_t_2 = (__pyx_v_s->start < __pyx_v_start);
      if (__pyx_t_2) {
        __pyx_v_s->start = __pyx_v_start;
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "GatSegmentList.pyx":1050
 *             else:
 *                 if s.start < start: s.start = start
 *                 if s.end > end: s.end = end             # <<<<<<<<<<<<<<
 * 
 *         self.normalize()
 */
      __pyx_t_2 = (__pyx_v_s->end > __pyx_v_end);
      if (__pyx_t_2) {
        __pyx_v_s->end = __pyx_v_end;
        goto __pyx_L7;
      }
      __pyx_L7:;
    }
    __pyx_L5:;
  }

  /* "GatSegmentList.pyx":1052
 *                 if s.end > end: s.end = end
 * 
 *         self.normalize()             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->normalize(__pyx_v_self, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "GatSegmentList.pyx":1053
 * 
 *         self.normalize()
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList subtract( self, SegmentList other ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.truncate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1055
 *         return self
 * 
 *     cpdef SegmentList subtract( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''subtract residues in *other* segment list with from this on.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_39subtract(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_subtract(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, int __pyx_skip_dispatch) {
  int __pyx_v_this_idx;
  int __pyx_v_other_idx;
  int __pyx_v_working_idx;
  int __pyx_v_last_this_idx;
  int __pyx_v_last_other_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_this_segment;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other_segment;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_new_segments;
  size_t __pyx_v_allocated;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("subtract", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__subtract); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_39subtract)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1064
 * 
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "subtraction of a non-normalized list"             # <<<<<<<<<<<<<<
 *         assert other.flag & SEG_NORMALIZED, "subtraction with non-normalized list"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_43));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1065
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "subtraction of a non-normalized list"
 *         assert other.flag & SEG_NORMALIZED, "subtraction with non-normalized list"             # <<<<<<<<<<<<<<
 * 
 *         # if self-self comparison, clear all residues
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_other->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_44));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1068
 * 
 *         # if self-self comparison, clear all residues
 *         if other.segments == self.segments:             # <<<<<<<<<<<<<<
 *             self.clear()
 *             return self
 */
  __pyx_t_4 = (__pyx_v_other->segments == __pyx_v_self->segments);
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":1069
 *         # if self-self comparison, clear all residues
 *         if other.segments == self.segments:
 *             self.clear()             # <<<<<<<<<<<<<<
 *             return self
 * 
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->clear(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "GatSegmentList.pyx":1070
 *         if other.segments == self.segments:
 *             self.clear()
 *             return self             # <<<<<<<<<<<<<<
 * 
 *         if self.nsegments == 0: return self
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1072
 *             return self
 * 
 *         if self.nsegments == 0: return self             # <<<<<<<<<<<<<<
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":1075
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         working_idx = this_idx = other_idx = 0             # <<<<<<<<<<<<<<
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 */
  __pyx_v_working_idx = 0;
  __pyx_v_this_idx = 0;
  __pyx_v_other_idx = 0;

  /* "GatSegmentList.pyx":1076
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         working_idx = this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1             # <<<<<<<<<<<<<<
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)
 */
  __pyx_v_last_this_idx = -1;
  __pyx_v_last_other_idx = -1;

  /* "GatSegmentList.pyx":1077
 *         working_idx = this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 *         cdef Segment other_segment = Segment(0,0)
 * 
 */
  __pyx_t_5.start = 0;
  __pyx_t_5.end = 0;
  __pyx_v_this_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":1078
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 * 
 *         cdef Segment * new_segments
 */
  __pyx_t_5.start = 0;
  __pyx_t_5.end = 0;
  __pyx_v_other_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":1083
 *         cdef size_t allocated
 *         # create new list with 10% overhead
 *         allocated = int(lmax( self.nsegments, other.nsegments) * 1.1)             # <<<<<<<<<<<<<<
 * 
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )
 */
  __pyx_v_allocated = ((size_t)(__pyx_f_14GatSegmentList_lmax(__pyx_v_self->nsegments, __pyx_v_other->nsegments) * 1.1));

  /* "GatSegmentList.pyx":1085
 *         allocated = int(lmax( self.nsegments, other.nsegments) * 1.1)
 * 
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *         if not new_segments:
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))
 */
  __pyx_v_new_segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

  /* "GatSegmentList.pyx":1086
 * 
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )
 *         if not new_segments:             # <<<<<<<<<<<<<<
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))
 * 
 */
  __pyx_t_4 = (!(__pyx_v_new_segments != 0));
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":1087
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )
 *         if not new_segments:
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:
 */
    __pyx_t_1 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":1089
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:             # <<<<<<<<<<<<<<
 * 
 *             # re-allocated before adding
 */
  while (1) {
    __pyx_t_4 = (__pyx_v_this_idx < __pyx_v_self->nsegments);
    if (__pyx_t_4) {
      __pyx_t_6 = (__pyx_v_other_idx < __pyx_v_other->nsegments);
      __pyx_t_7 = __pyx_t_6;
    } else {
      __pyx_t_7 = __pyx_t_4;
    }
    if (!__pyx_t_7) break;

    /* "GatSegmentList.pyx":1092
 * 
 *             # re-allocated before adding
 *             if working_idx >= allocated:             # <<<<<<<<<<<<<<
 *                 allocated *= 2
 *                 new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )
 */
    __pyx_t_7 = (__pyx_v_working_idx >= __pyx_v_allocated);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1093
 *             # re-allocated before adding
 *             if working_idx >= allocated:
 *                 allocated *= 2             # <<<<<<<<<<<<<<
 *                 new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )
 *                 assert new_segments != NULL
 */
      __pyx_v_allocated = (__pyx_v_allocated * 2);

      /* "GatSegmentList.pyx":1094
 *             if working_idx >= allocated:
 *                 allocated *= 2
 *                 new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )             # <<<<<<<<<<<<<<
 *                 assert new_segments != NULL
 * 
 */
      __pyx_v_new_segments = ((struct __pyx_t_14GatSegmentList_Segment *)realloc(__pyx_v_new_segments, (__pyx_v_allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

      /* "GatSegmentList.pyx":1095
 *                 allocated *= 2
 *                 new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )
 *                 assert new_segments != NULL             # <<<<<<<<<<<<<<
 * 
 *             # print "this=", this_idx, self.nsegments, this_segment, "other=", other_idx, other.nsegments, other.segments[other_idx]
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!(__pyx_v_new_segments != NULL))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "GatSegmentList.pyx":1098
 * 
 *             # print "this=", this_idx, self.nsegments, this_segment, "other=", other_idx, other.nsegments, other.segments[other_idx]
 *             if last_this_idx != this_idx:             # <<<<<<<<<<<<<<
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 */
    __pyx_t_7 = (__pyx_v_last_this_idx != __pyx_v_this_idx);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1099
 *             # print "this=", this_idx, self.nsegments, this_segment, "other=", other_idx, other.nsegments, other.segments[other_idx]
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]             # <<<<<<<<<<<<<<
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 */
      __pyx_v_this_segment = (__pyx_v_self->segments[__pyx_v_this_idx]);

      /* "GatSegmentList.pyx":1100
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx             # <<<<<<<<<<<<<<
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 */
      __pyx_v_last_this_idx = __pyx_v_this_idx;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "GatSegmentList.pyx":1101
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:             # <<<<<<<<<<<<<<
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx
 */
    __pyx_t_7 = (__pyx_v_last_other_idx != __pyx_v_other_idx);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1102
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]             # <<<<<<<<<<<<<<
 *                 last_other_idx = other_idx
 * 
 */
      __pyx_v_other_segment = (__pyx_v_other->segments[__pyx_v_other_idx]);

      /* "GatSegmentList.pyx":1103
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx             # <<<<<<<<<<<<<<
 * 
 *             # print this_segment, other_segment
 */
      __pyx_v_last_other_idx = __pyx_v_other_idx;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "GatSegmentList.pyx":1107
 *             # print this_segment, other_segment
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:             # <<<<<<<<<<<<<<
 *                 if this_segment.start < this_segment.end:
 *                     new_segments[working_idx] = this_segment
 */
    __pyx_t_7 = (__pyx_v_this_segment.end <= __pyx_v_other_segment.start);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1108
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:
 *                 if this_segment.start < this_segment.end:             # <<<<<<<<<<<<<<
 *                     new_segments[working_idx] = this_segment
 *                     working_idx += 1
 */
      __pyx_t_7 = (__pyx_v_this_segment.start < __pyx_v_this_segment.end);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1109
 *             if this_segment.end <= other_segment.start:
 *                 if this_segment.start < this_segment.end:
 *                     new_segments[working_idx] = this_segment             # <<<<<<<<<<<<<<
 *                     working_idx += 1
 *                 this_idx += 1
 */
        (__pyx_v_new_segments[__pyx_v_working_idx]) = __pyx_v_this_segment;

        /* "GatSegmentList.pyx":1110
 *                 if this_segment.start < this_segment.end:
 *                     new_segments[working_idx] = this_segment
 *                     working_idx += 1             # <<<<<<<<<<<<<<
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 */
        __pyx_v_working_idx = (__pyx_v_working_idx + 1);
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "GatSegmentList.pyx":1111
 *                     new_segments[working_idx] = this_segment
 *                     working_idx += 1
 *                 this_idx += 1             # <<<<<<<<<<<<<<
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 */
      __pyx_v_this_idx = (__pyx_v_this_idx + 1);
      goto __pyx_L11;
    }

    /* "GatSegmentList.pyx":1113
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:             # <<<<<<<<<<<<<<
 *                 other_idx += 1
 *             else:
 */
    __pyx_t_7 = (__pyx_v_other_segment.end <= __pyx_v_this_segment.start);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1114
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 *                 other_idx += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # deal with overlap
 */
      __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      goto __pyx_L11;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1117
 *             else:
 *                 # deal with overlap
 *                 if this_segment.start < other_segment.start:             # <<<<<<<<<<<<<<
 *                     # print "adding", this_segment.start, other_segment.start
 *                     new_segments[working_idx].start = this_segment.start
 */
      __pyx_t_7 = (__pyx_v_this_segment.start < __pyx_v_other_segment.start);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1119
 *                 if this_segment.start < other_segment.start:
 *                     # print "adding", this_segment.start, other_segment.start
 *                     new_segments[working_idx].start = this_segment.start             # <<<<<<<<<<<<<<
 *                     new_segments[working_idx].end = other_segment.start
 *                     working_idx += 1
 */
        (__pyx_v_new_segments[__pyx_v_working_idx]).start = __pyx_v_this_segment.start;

        /* "GatSegmentList.pyx":1120
 *                     # print "adding", this_segment.start, other_segment.start
 *                     new_segments[working_idx].start = this_segment.start
 *                     new_segments[working_idx].end = other_segment.start             # <<<<<<<<<<<<<<
 *                     working_idx += 1
 * 
 */
        (__pyx_v_new_segments[__pyx_v_working_idx]).end = __pyx_v_other_segment.start;

        /* "GatSegmentList.pyx":1121
 *                     new_segments[working_idx].start = this_segment.start
 *                     new_segments[working_idx].end = other_segment.start
 *                     working_idx += 1             # <<<<<<<<<<<<<<
 * 
 *                 this_segment.start = other_segment.end
 */
        __pyx_v_working_idx = (__pyx_v_working_idx + 1);
        goto __pyx_L13;
      }
      __pyx_L13:;

      /* "GatSegmentList.pyx":1123
 *                     working_idx += 1
 * 
 *                 this_segment.start = other_segment.end             # <<<<<<<<<<<<<<
 * 
 *         # output last
 */
      __pyx_v_this_segment.start = __pyx_v_other_segment.end;
    }
    __pyx_L11:;
  }

  /* "GatSegmentList.pyx":1126
 * 
 *         # output last
 *         if this_segment.start < this_segment.end:             # <<<<<<<<<<<<<<
 *             new_segments[working_idx].start = this_segment.start
 *             new_segments[working_idx].end = this_segment.end
 */
  __pyx_t_7 = (__pyx_v_this_segment.start < __pyx_v_this_segment.end);
  if (__pyx_t_7) {

    /* "GatSegmentList.pyx":1127
 *         # output last
 *         if this_segment.start < this_segment.end:
 *             new_segments[working_idx].start = this_segment.start             # <<<<<<<<<<<<<<
 *             new_segments[working_idx].end = this_segment.end
 *             working_idx += 1
 */
    (__pyx_v_new_segments[__pyx_v_working_idx]).start = __pyx_v_this_segment.start;

    /* "GatSegmentList.pyx":1128
 *         if this_segment.start < this_segment.end:
 *             new_segments[working_idx].start = this_segment.start
 *             new_segments[working_idx].end = this_segment.end             # <<<<<<<<<<<<<<
 *             working_idx += 1
 * 
 */
    (__pyx_v_new_segments[__pyx_v_working_idx]).end = __pyx_v_this_segment.end;

    /* "GatSegmentList.pyx":1129
 *             new_segments[working_idx].start = this_segment.start
 *             new_segments[working_idx].end = this_segment.end
 *             working_idx += 1             # <<<<<<<<<<<<<<
 * 
 *         free( self.segments )
 */
    __pyx_v_working_idx = (__pyx_v_working_idx + 1);
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "GatSegmentList.pyx":1131
 *             working_idx += 1
 * 
 *         free( self.segments )             # <<<<<<<<<<<<<<
 *         self.segments = new_segments
 *         self.nsegments = working_idx
 */
  free(__pyx_v_self->segments);

  /* "GatSegmentList.pyx":1132
 * 
 *         free( self.segments )
 *         self.segments = new_segments             # <<<<<<<<<<<<<<
 *         self.nsegments = working_idx
 *         self.allocated = allocated
 */
  __pyx_v_self->segments = __pyx_v_new_segments;

  /* "GatSegmentList.pyx":1133
 *         free( self.segments )
 *         self.segments = new_segments
 *         self.nsegments = working_idx             # <<<<<<<<<<<<<<
 *         self.allocated = allocated
 *         return self
 */
  __pyx_v_self->nsegments = __pyx_v_working_idx;

  /* "GatSegmentList.pyx":1134
 *         self.segments = new_segments
 *         self.nsegments = working_idx
 *         self.allocated = allocated             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_v_self->allocated = __pyx_v_allocated;

  /* "GatSegmentList.pyx":1135
 *         self.nsegments = working_idx
 *         self.allocated = allocated
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cpdef summarize( self ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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("GatSegmentList.SegmentList.subtract", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_39subtract(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_38subtract[] = "SegmentList.subtract(self, SegmentList other) -> SegmentList\nsubtract residues in *other* segment list with from this on.\n\n        Intervals are truncated, any residues overlapping with *other*\n        are removed.\n\n        Both this and other are assumed to have been normalized.\n\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_39subtract(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("subtract (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_38subtract(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_other));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1055
 *         return self
 * 
 *     cpdef SegmentList subtract( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''subtract residues in *other* segment list with from this on.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_38subtract(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("subtract", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->subtract(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __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("GatSegmentList.SegmentList.subtract", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1137
 *         return self
 * 
 *     cpdef summarize( self ):             # <<<<<<<<<<<<<<
 *         '''returns summary statistics for segments.'''
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_41summarize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_summarize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_min_length;
  __pyx_t_14GatSegmentList_Position __pyx_v_max_length;
  __pyx_t_14GatSegmentList_Position __pyx_v_length;
  __pyx_t_14GatSegmentList_Position __pyx_v_total_length;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  double __pyx_v_mean_length;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("summarize", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__summarize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_41summarize)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1145
 *         cdef Segment * s
 * 
 *         if self.nsegments == 0:             # <<<<<<<<<<<<<<
 *             return 0, 0, 0, 0
 * 
 */
  __pyx_t_3 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_3) {

    /* "GatSegmentList.pyx":1146
 * 
 *         if self.nsegments == 0:
 *             return 0, 0, 0, 0             # <<<<<<<<<<<<<<
 * 
 *         # TODO: use maximum integer for Position
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_k_tuple_45));
    __pyx_r = ((PyObject *)__pyx_k_tuple_45);
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1149
 * 
 *         # TODO: use maximum integer for Position
 *         min_length = UINT32_MAX             # <<<<<<<<<<<<<<
 *         max_length = 0
 *         total_length = 0
 */
  __pyx_v_min_length = UINT32_MAX;

  /* "GatSegmentList.pyx":1150
 *         # TODO: use maximum integer for Position
 *         min_length = UINT32_MAX
 *         max_length = 0             # <<<<<<<<<<<<<<
 *         total_length = 0
 * 
 */
  __pyx_v_max_length = 0;

  /* "GatSegmentList.pyx":1151
 *         min_length = UINT32_MAX
 *         max_length = 0
 *         total_length = 0             # <<<<<<<<<<<<<<
 * 
 *         for idx from 0 <= idx < self.nsegments:
 */
  __pyx_v_total_length = 0;

  /* "GatSegmentList.pyx":1153
 *         total_length = 0
 * 
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             s = & self.segments[idx]
 *             length = s.end - s.start
 */
  __pyx_t_4 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_4; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1154
 * 
 *         for idx from 0 <= idx < self.nsegments:
 *             s = & self.segments[idx]             # <<<<<<<<<<<<<<
 *             length = s.end - s.start
 *             total_length += length
 */
    __pyx_v_s = (&(__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1155
 *         for idx from 0 <= idx < self.nsegments:
 *             s = & self.segments[idx]
 *             length = s.end - s.start             # <<<<<<<<<<<<<<
 *             total_length += length
 *             min_length = lmin( length, min_length )
 */
    __pyx_v_length = (__pyx_v_s->end - __pyx_v_s->start);

    /* "GatSegmentList.pyx":1156
 *             s = & self.segments[idx]
 *             length = s.end - s.start
 *             total_length += length             # <<<<<<<<<<<<<<
 *             min_length = lmin( length, min_length )
 *             max_length = lmax( length, max_length )
 */
    __pyx_v_total_length = (__pyx_v_total_length + __pyx_v_length);

    /* "GatSegmentList.pyx":1157
 *             length = s.end - s.start
 *             total_length += length
 *             min_length = lmin( length, min_length )             # <<<<<<<<<<<<<<
 *             max_length = lmax( length, max_length )
 * 
 */
    __pyx_v_min_length = __pyx_f_14GatSegmentList_lmin(__pyx_v_length, __pyx_v_min_length);

    /* "GatSegmentList.pyx":1158
 *             total_length += length
 *             min_length = lmin( length, min_length )
 *             max_length = lmax( length, max_length )             # <<<<<<<<<<<<<<
 * 
 *         cdef double mean_length = <double>total_length / self.nsegments
 */
    __pyx_v_max_length = __pyx_f_14GatSegmentList_lmax(__pyx_v_length, __pyx_v_max_length);
  }

  /* "GatSegmentList.pyx":1160
 *             max_length = lmax( length, max_length )
 * 
 *         cdef double mean_length = <double>total_length / self.nsegments             # <<<<<<<<<<<<<<
 * 
 *         return mean_length, min_length, max_length, total_length
 */
  if (unlikely(__pyx_v_self->nsegments == 0)) {
    PyErr_Format(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_mean_length = (((double)__pyx_v_total_length) / __pyx_v_self->nsegments);

  /* "GatSegmentList.pyx":1162
 *         cdef double mean_length = <double>total_length / self.nsegments
 * 
 *         return mean_length, min_length, max_length, total_length             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList getFilledSegmentsFromStart( self, Position start, PositionDifference remainder ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mean_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_min_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_max_length); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyLong_FromUnsignedLong(__pyx_v_total_length); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_r = ((PyObject *)__pyx_t_7);
  __pyx_t_7 = 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_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.summarize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_41summarize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_40summarize[] = "SegmentList.summarize(self)\nreturns summary statistics for segments.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_41summarize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("summarize (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_40summarize(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1137
 *         return self
 * 
 *     cpdef summarize( self ):             # <<<<<<<<<<<<<<
 *         '''returns summary statistics for segments.'''
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_40summarize(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("summarize", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->summarize(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __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("GatSegmentList.SegmentList.summarize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1164
 *         return mean_length, min_length, max_length, total_length
 * 
 *     cpdef SegmentList getFilledSegmentsFromStart( self, Position start, PositionDifference remainder ):             # <<<<<<<<<<<<<<
 *         '''start filling segment from *start* until *remainder*
 *            bases have been covered.
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_43getFilledSegmentsFromStart(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_getFilledSegmentsFromStart(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder, int __pyx_skip_dispatch) {
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_result = 0;
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_end;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getFilledSegmentsFromStart", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_46); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_43getFilledSegmentsFromStart)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_remainder); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __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 = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1175
 *            '''
 * 
 *         if remainder > self.sum():             # <<<<<<<<<<<<<<
 *             return SegmentList( clone = self )
 * 
 */
  __pyx_t_5 = (__pyx_v_remainder > ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0));
  if (__pyx_t_5) {

    /* "GatSegmentList.pyx":1176
 * 
 *         if remainder > self.sum():
 *             return SegmentList( clone = self )             # <<<<<<<<<<<<<<
 * 
 *         cdef SegmentList result = SegmentList()
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__clone), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1178
 *             return SegmentList( clone = self )
 * 
 *         cdef SegmentList result = SegmentList()             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "GatSegmentList.pyx":1181
 * 
 *         cdef int idx
 *         idx = self.getInsertionPoint( start, start + 1 )             # <<<<<<<<<<<<<<
 *         cdef Position end
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__getInsertionPoint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong((__pyx_v_start + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_idx = __pyx_t_6;

  /* "GatSegmentList.pyx":1186
 *         # deal with border cases
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1             # <<<<<<<<<<<<<<
 *         elif idx == -1: idx=0
 * 
 */
  __pyx_t_5 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_5) {
    __pyx_v_idx = (__pyx_v_idx - 1);
    goto __pyx_L4;
  }

  /* "GatSegmentList.pyx":1187
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1
 *         elif idx == -1: idx=0             # <<<<<<<<<<<<<<
 * 
 *         # add from start until complete
 */
  __pyx_t_5 = (__pyx_v_idx == -1);
  if (__pyx_t_5) {
    __pyx_v_idx = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":1190
 * 
 *         # add from start until complete
 *         while remainder > 0:             # <<<<<<<<<<<<<<
 *             if self.segments[idx].end < start:
 *                 pass
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_remainder > 0);
    if (!__pyx_t_5) break;

    /* "GatSegmentList.pyx":1191
 *         # add from start until complete
 *         while remainder > 0:
 *             if self.segments[idx].end < start:             # <<<<<<<<<<<<<<
 *                 pass
 *             else:
 */
    __pyx_t_5 = ((__pyx_v_self->segments[__pyx_v_idx]).end < __pyx_v_start);
    if (__pyx_t_5) {
      goto __pyx_L7;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1194
 *                 pass
 *             else:
 *                 start = lmax( self.segments[idx].start, start )             # <<<<<<<<<<<<<<
 *                 end = lmin( self.segments[idx].end, start + remainder )
 *                 remainder -= end - start
 */
      __pyx_v_start = __pyx_f_14GatSegmentList_lmax((__pyx_v_self->segments[__pyx_v_idx]).start, __pyx_v_start);

      /* "GatSegmentList.pyx":1195
 *             else:
 *                 start = lmax( self.segments[idx].start, start )
 *                 end = lmin( self.segments[idx].end, start + remainder )             # <<<<<<<<<<<<<<
 *                 remainder -= end - start
 *                 result._add( Segment( start, end ) )
 */
      __pyx_v_end = __pyx_f_14GatSegmentList_lmin((__pyx_v_self->segments[__pyx_v_idx]).end, (__pyx_v_start + __pyx_v_remainder));

      /* "GatSegmentList.pyx":1196
 *                 start = lmax( self.segments[idx].start, start )
 *                 end = lmin( self.segments[idx].end, start + remainder )
 *                 remainder -= end - start             # <<<<<<<<<<<<<<
 *                 result._add( Segment( start, end ) )
 * 
 */
      __pyx_v_remainder = (__pyx_v_remainder - (__pyx_v_end - __pyx_v_start));

      /* "GatSegmentList.pyx":1197
 *                 end = lmin( self.segments[idx].end, start + remainder )
 *                 remainder -= end - start
 *                 result._add( Segment( start, end ) )             # <<<<<<<<<<<<<<
 * 
 *             idx += 1
 */
      __pyx_t_7.start = __pyx_v_start;
      __pyx_t_7.end = __pyx_v_end;
      __pyx_t_4 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_result->__pyx_vtab)->_add(__pyx_v_result, __pyx_t_7); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_L7:;

    /* "GatSegmentList.pyx":1199
 *                 result._add( Segment( start, end ) )
 * 
 *             idx += 1             # <<<<<<<<<<<<<<
 *             if idx == self.nsegments:
 *                 idx = 0
 */
    __pyx_v_idx = (__pyx_v_idx + 1);

    /* "GatSegmentList.pyx":1200
 * 
 *             idx += 1
 *             if idx == self.nsegments:             # <<<<<<<<<<<<<<
 *                 idx = 0
 *                 start = self.segments[idx].start
 */
    __pyx_t_5 = (__pyx_v_idx == __pyx_v_self->nsegments);
    if (__pyx_t_5) {

      /* "GatSegmentList.pyx":1201
 *             idx += 1
 *             if idx == self.nsegments:
 *                 idx = 0             # <<<<<<<<<<<<<<
 *                 start = self.segments[idx].start
 * 
 */
      __pyx_v_idx = 0;

      /* "GatSegmentList.pyx":1202
 *             if idx == self.nsegments:
 *                 idx = 0
 *                 start = self.segments[idx].start             # <<<<<<<<<<<<<<
 * 
 *         result.normalize()
 */
      __pyx_v_start = (__pyx_v_self->segments[__pyx_v_idx]).start;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "GatSegmentList.pyx":1204
 *                 start = self.segments[idx].start
 * 
 *         result.normalize()             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_result->__pyx_vtab)->normalize(__pyx_v_result, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "GatSegmentList.pyx":1205
 * 
 *         result.normalize()
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList getFilledSegmentsFromEnd( self, Position end, PositionDifference remainder ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getFilledSegmentsFromStart", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_43getFilledSegmentsFromStart(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_42getFilledSegmentsFromStart[] = "SegmentList.getFilledSegmentsFromStart(self, Position start, PositionDifference remainder) -> SegmentList\nstart filling segment from *start* until *remainder*\n           bases have been covered. \n\n           This method wraps around at the ends if remainder can not\n           be filled. If *remainder* is larger than the segment list,\n           the segment list itself will be returned.\n\n           return a segment list \n           ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_43getFilledSegmentsFromStart(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_start;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__remainder,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getFilledSegmentsFromStart (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__remainder);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getFilledSegmentsFromStart", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getFilledSegmentsFromStart") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_start == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_remainder = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_remainder == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getFilledSegmentsFromStart", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getFilledSegmentsFromStart", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_42getFilledSegmentsFromStart(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_start, __pyx_v_remainder);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1164
 *         return mean_length, min_length, max_length, total_length
 * 
 *     cpdef SegmentList getFilledSegmentsFromStart( self, Position start, PositionDifference remainder ):             # <<<<<<<<<<<<<<
 *         '''start filling segment from *start* until *remainder*
 *            bases have been covered.
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_42getFilledSegmentsFromStart(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_start, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getFilledSegmentsFromStart", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->getFilledSegmentsFromStart(__pyx_v_self, __pyx_v_start, __pyx_v_remainder, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __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("GatSegmentList.SegmentList.getFilledSegmentsFromStart", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1207
 *         return result
 * 
 *     cpdef SegmentList getFilledSegmentsFromEnd( self, Position end, PositionDifference remainder ):             # <<<<<<<<<<<<<<
 *         '''start filling segment from *end* until *remainder*
 *            bases have been covered. Fill in reverse order.
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_45getFilledSegmentsFromEnd(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_getFilledSegmentsFromEnd(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_end, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder, int __pyx_skip_dispatch) {
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_result = 0;
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_start;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getFilledSegmentsFromEnd", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_47); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_45getFilledSegmentsFromEnd)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyInt_FromLong(__pyx_v_remainder); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __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 = 1207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1218
 *            '''
 * 
 *         if remainder > self.sum():             # <<<<<<<<<<<<<<
 *             return SegmentList( clone = self )
 * 
 */
  __pyx_t_5 = (__pyx_v_remainder > ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 0));
  if (__pyx_t_5) {

    /* "GatSegmentList.pyx":1219
 * 
 *         if remainder > self.sum():
 *             return SegmentList( clone = self )             # <<<<<<<<<<<<<<
 * 
 *         cdef SegmentList result = SegmentList()
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__clone), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1221
 *             return SegmentList( clone = self )
 * 
 *         cdef SegmentList result = SegmentList()             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "GatSegmentList.pyx":1224
 * 
 *         cdef int idx
 *         idx = self.getInsertionPoint( end, end + 1 )             # <<<<<<<<<<<<<<
 *         cdef Position start
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__getInsertionPoint); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong((__pyx_v_end + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_idx = __pyx_t_6;

  /* "GatSegmentList.pyx":1229
 *         # deal with border cases
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1             # <<<<<<<<<<<<<<
 *         elif idx == -1: idx=0
 * 
 */
  __pyx_t_5 = (__pyx_v_idx == __pyx_v_self->nsegments);
  if (__pyx_t_5) {
    __pyx_v_idx = (__pyx_v_idx - 1);
    goto __pyx_L4;
  }

  /* "GatSegmentList.pyx":1230
 *         # permit partial overlap
 *         if idx == self.nsegments: idx -=1
 *         elif idx == -1: idx=0             # <<<<<<<<<<<<<<
 * 
 *         # add from start until complete
 */
  __pyx_t_5 = (__pyx_v_idx == -1);
  if (__pyx_t_5) {
    __pyx_v_idx = 0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":1233
 * 
 *         # add from start until complete
 *         while remainder > 0:             # <<<<<<<<<<<<<<
 *             if self.segments[idx].start > end:
 *                 pass
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_remainder > 0);
    if (!__pyx_t_5) break;

    /* "GatSegmentList.pyx":1234
 *         # add from start until complete
 *         while remainder > 0:
 *             if self.segments[idx].start > end:             # <<<<<<<<<<<<<<
 *                 pass
 *             else:
 */
    __pyx_t_5 = ((__pyx_v_self->segments[__pyx_v_idx]).start > __pyx_v_end);
    if (__pyx_t_5) {
      goto __pyx_L7;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1237
 *                 pass
 *             else:
 *                 end = lmin( self.segments[idx].end, end )             # <<<<<<<<<<<<<<
 *                 start = lmax( self.segments[idx].start, end - remainder )
 *                 remainder -= end - start
 */
      __pyx_v_end = __pyx_f_14GatSegmentList_lmin((__pyx_v_self->segments[__pyx_v_idx]).end, __pyx_v_end);

      /* "GatSegmentList.pyx":1238
 *             else:
 *                 end = lmin( self.segments[idx].end, end )
 *                 start = lmax( self.segments[idx].start, end - remainder )             # <<<<<<<<<<<<<<
 *                 remainder -= end - start
 *                 result._add( Segment( start, end ) )
 */
      __pyx_v_start = __pyx_f_14GatSegmentList_lmax((__pyx_v_self->segments[__pyx_v_idx]).start, (__pyx_v_end - __pyx_v_remainder));

      /* "GatSegmentList.pyx":1239
 *                 end = lmin( self.segments[idx].end, end )
 *                 start = lmax( self.segments[idx].start, end - remainder )
 *                 remainder -= end - start             # <<<<<<<<<<<<<<
 *                 result._add( Segment( start, end ) )
 * 
 */
      __pyx_v_remainder = (__pyx_v_remainder - (__pyx_v_end - __pyx_v_start));

      /* "GatSegmentList.pyx":1240
 *                 start = lmax( self.segments[idx].start, end - remainder )
 *                 remainder -= end - start
 *                 result._add( Segment( start, end ) )             # <<<<<<<<<<<<<<
 * 
 *             idx -= 1
 */
      __pyx_t_7.start = __pyx_v_start;
      __pyx_t_7.end = __pyx_v_end;
      __pyx_t_4 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_result->__pyx_vtab)->_add(__pyx_v_result, __pyx_t_7); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_L7:;

    /* "GatSegmentList.pyx":1242
 *                 result._add( Segment( start, end ) )
 * 
 *             idx -= 1             # <<<<<<<<<<<<<<
 *             if idx < 0:
 *                 idx = self.nsegments - 1
 */
    __pyx_v_idx = (__pyx_v_idx - 1);

    /* "GatSegmentList.pyx":1243
 * 
 *             idx -= 1
 *             if idx < 0:             # <<<<<<<<<<<<<<
 *                 idx = self.nsegments - 1
 *                 end = self.segments[idx].end
 */
    __pyx_t_5 = (__pyx_v_idx < 0);
    if (__pyx_t_5) {

      /* "GatSegmentList.pyx":1244
 *             idx -= 1
 *             if idx < 0:
 *                 idx = self.nsegments - 1             # <<<<<<<<<<<<<<
 *                 end = self.segments[idx].end
 * 
 */
      __pyx_v_idx = (__pyx_v_self->nsegments - 1);

      /* "GatSegmentList.pyx":1245
 *             if idx < 0:
 *                 idx = self.nsegments - 1
 *                 end = self.segments[idx].end             # <<<<<<<<<<<<<<
 * 
 *         result.normalize()
 */
      __pyx_v_end = (__pyx_v_self->segments[__pyx_v_idx]).end;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "GatSegmentList.pyx":1247
 *                 end = self.segments[idx].end
 * 
 *         result.normalize()             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_result->__pyx_vtab)->normalize(__pyx_v_result, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "GatSegmentList.pyx":1248
 * 
 *         result.normalize()
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList filter( self, SegmentList other ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getFilledSegmentsFromEnd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_45getFilledSegmentsFromEnd(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_44getFilledSegmentsFromEnd[] = "SegmentList.getFilledSegmentsFromEnd(self, Position end, PositionDifference remainder) -> SegmentList\nstart filling segment from *end* until *remainder*\n           bases have been covered. Fill in reverse order.\n\n           This method wraps around at the ends if remainder can not\n           be filled. If *remainder* is larger than the segment list,\n           the segment list itself will be returned.\n\n           return a segment list \n           ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_45getFilledSegmentsFromEnd(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  __pyx_t_14GatSegmentList_Position __pyx_v_end;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__end,&__pyx_n_s__remainder,0};
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getFilledSegmentsFromEnd (wrapper)", 0);
  {
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__remainder);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getFilledSegmentsFromEnd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getFilledSegmentsFromEnd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_end = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_end == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_remainder = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_remainder == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getFilledSegmentsFromEnd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.getFilledSegmentsFromEnd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_44getFilledSegmentsFromEnd(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), __pyx_v_end, __pyx_v_remainder);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1207
 *         return result
 * 
 *     cpdef SegmentList getFilledSegmentsFromEnd( self, Position end, PositionDifference remainder ):             # <<<<<<<<<<<<<<
 *         '''start filling segment from *end* until *remainder*
 *            bases have been covered. Fill in reverse order.
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_44getFilledSegmentsFromEnd(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_Position __pyx_v_end, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_remainder) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getFilledSegmentsFromEnd", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->getFilledSegmentsFromEnd(__pyx_v_self, __pyx_v_end, __pyx_v_remainder, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1207; __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("GatSegmentList.SegmentList.getFilledSegmentsFromEnd", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1250
 *         return result
 * 
 *     cpdef SegmentList filter( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''remove all segments that are not in *other*
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_47filter(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_filter(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, int __pyx_skip_dispatch) {
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_new_segments;
  int __pyx_v_this_idx;
  int __pyx_v_other_idx;
  int __pyx_v_working_idx;
  int __pyx_v_last_this_idx;
  int __pyx_v_last_other_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_this_segment;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other_segment;
  __pyx_t_14GatSegmentList_Position __pyx_v_last_start;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("filter", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__filter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_47filter)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1257
 * 
 *         # avoid self-self comparison
 *         if other.segments == self.segments: return self             # <<<<<<<<<<<<<<
 *         if self.nsegments == 0: return self
 * 
 */
  __pyx_t_4 = (__pyx_v_other->segments == __pyx_v_self->segments);
  if (__pyx_t_4) {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1258
 *         # avoid self-self comparison
 *         if other.segments == self.segments: return self
 *         if self.nsegments == 0: return self             # <<<<<<<<<<<<<<
 * 
 *         cdef Segment * new_segments
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":1263
 *         cdef size_t allocated
 *         # create new list
 *         new_segments =<Segment*>malloc( self.nsegments * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *         if not new_segments:
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.nsegments * sizeof( Segment ) ))
 */
  __pyx_v_new_segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

  /* "GatSegmentList.pyx":1264
 *         # create new list
 *         new_segments =<Segment*>malloc( self.nsegments * sizeof( Segment ) )
 *         if not new_segments:             # <<<<<<<<<<<<<<
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.nsegments * sizeof( Segment ) ))
 * 
 */
  __pyx_t_4 = (!(__pyx_v_new_segments != 0));
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":1265
 *         new_segments =<Segment*>malloc( self.nsegments * sizeof( Segment ) )
 *         if not new_segments:
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( self.nsegments * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 */
    __pyx_t_1 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":1268
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         working_idx = this_idx = other_idx = 0             # <<<<<<<<<<<<<<
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 */
  __pyx_v_working_idx = 0;
  __pyx_v_this_idx = 0;
  __pyx_v_other_idx = 0;

  /* "GatSegmentList.pyx":1269
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         working_idx = this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1             # <<<<<<<<<<<<<<
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)
 */
  __pyx_v_last_this_idx = -1;
  __pyx_v_last_other_idx = -1;

  /* "GatSegmentList.pyx":1270
 *         working_idx = this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 *         cdef Segment other_segment = Segment(0,0)
 *         # for negative segments, do not use -1
 */
  __pyx_t_5.start = 0;
  __pyx_t_5.end = 0;
  __pyx_v_this_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":1271
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 *         # for negative segments, do not use -1
 *         cdef Position last_start = self.segments[0].start - 1
 */
  __pyx_t_5.start = 0;
  __pyx_t_5.end = 0;
  __pyx_v_other_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":1273
 *         cdef Segment other_segment = Segment(0,0)
 *         # for negative segments, do not use -1
 *         cdef Position last_start = self.segments[0].start - 1             # <<<<<<<<<<<<<<
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:
 */
  __pyx_v_last_start = ((__pyx_v_self->segments[0]).start - 1);

  /* "GatSegmentList.pyx":1275
 *         cdef Position last_start = self.segments[0].start - 1
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:             # <<<<<<<<<<<<<<
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 */
  while (1) {
    __pyx_t_4 = (__pyx_v_this_idx < __pyx_v_self->nsegments);
    if (__pyx_t_4) {
      __pyx_t_6 = (__pyx_v_other_idx < __pyx_v_other->nsegments);
      __pyx_t_7 = __pyx_t_6;
    } else {
      __pyx_t_7 = __pyx_t_4;
    }
    if (!__pyx_t_7) break;

    /* "GatSegmentList.pyx":1278
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:             # <<<<<<<<<<<<<<
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 */
    __pyx_t_7 = (__pyx_v_last_this_idx != __pyx_v_this_idx);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1279
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]             # <<<<<<<<<<<<<<
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 */
      __pyx_v_this_segment = (__pyx_v_self->segments[__pyx_v_this_idx]);

      /* "GatSegmentList.pyx":1280
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx             # <<<<<<<<<<<<<<
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 */
      __pyx_v_last_this_idx = __pyx_v_this_idx;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "GatSegmentList.pyx":1281
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:             # <<<<<<<<<<<<<<
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx
 */
    __pyx_t_7 = (__pyx_v_last_other_idx != __pyx_v_other_idx);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1282
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]             # <<<<<<<<<<<<<<
 *                 last_other_idx = other_idx
 * 
 */
      __pyx_v_other_segment = (__pyx_v_other->segments[__pyx_v_other_idx]);

      /* "GatSegmentList.pyx":1283
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx             # <<<<<<<<<<<<<<
 * 
 *             # print this_segment, other_segment
 */
      __pyx_v_last_other_idx = __pyx_v_other_idx;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "GatSegmentList.pyx":1287
 *             # print this_segment, other_segment
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:             # <<<<<<<<<<<<<<
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 */
    __pyx_t_7 = (__pyx_v_this_segment.end <= __pyx_v_other_segment.start);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1288
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:
 *                 this_idx += 1             # <<<<<<<<<<<<<<
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 */
      __pyx_v_this_idx = (__pyx_v_this_idx + 1);
      goto __pyx_L10;
    }

    /* "GatSegmentList.pyx":1290
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:             # <<<<<<<<<<<<<<
 *                 other_idx += 1
 *             else:
 */
    __pyx_t_7 = (__pyx_v_other_segment.end <= __pyx_v_this_segment.start);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1291
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 *                 other_idx += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # deal with overlap
 */
      __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      goto __pyx_L10;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1294
 *             else:
 *                 # deal with overlap
 *                 if last_start != this_segment.start:             # <<<<<<<<<<<<<<
 *                     new_segments[working_idx].start = this_segment.start
 *                     new_segments[working_idx].end = this_segment.end
 */
      __pyx_t_7 = (__pyx_v_last_start != __pyx_v_this_segment.start);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1295
 *                 # deal with overlap
 *                 if last_start != this_segment.start:
 *                     new_segments[working_idx].start = this_segment.start             # <<<<<<<<<<<<<<
 *                     new_segments[working_idx].end = this_segment.end
 *                     working_idx += 1
 */
        (__pyx_v_new_segments[__pyx_v_working_idx]).start = __pyx_v_this_segment.start;

        /* "GatSegmentList.pyx":1296
 *                 if last_start != this_segment.start:
 *                     new_segments[working_idx].start = this_segment.start
 *                     new_segments[working_idx].end = this_segment.end             # <<<<<<<<<<<<<<
 *                     working_idx += 1
 *                     last_start = this_segment.start
 */
        (__pyx_v_new_segments[__pyx_v_working_idx]).end = __pyx_v_this_segment.end;

        /* "GatSegmentList.pyx":1297
 *                     new_segments[working_idx].start = this_segment.start
 *                     new_segments[working_idx].end = this_segment.end
 *                     working_idx += 1             # <<<<<<<<<<<<<<
 *                     last_start = this_segment.start
 * 
 */
        __pyx_v_working_idx = (__pyx_v_working_idx + 1);

        /* "GatSegmentList.pyx":1298
 *                     new_segments[working_idx].end = this_segment.end
 *                     working_idx += 1
 *                     last_start = this_segment.start             # <<<<<<<<<<<<<<
 * 
 *                 if this_segment.end < other_segment.end:
 */
        __pyx_v_last_start = __pyx_v_this_segment.start;
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "GatSegmentList.pyx":1300
 *                     last_start = this_segment.start
 * 
 *                 if this_segment.end < other_segment.end:             # <<<<<<<<<<<<<<
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:
 */
      __pyx_t_7 = (__pyx_v_this_segment.end < __pyx_v_other_segment.end);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1301
 * 
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1             # <<<<<<<<<<<<<<
 *                 elif other_segment.end < this_segment.end:
 *                     other_idx += 1
 */
        __pyx_v_this_idx = (__pyx_v_this_idx + 1);
        goto __pyx_L12;
      }

      /* "GatSegmentList.pyx":1302
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:             # <<<<<<<<<<<<<<
 *                     other_idx += 1
 *                 else:
 */
      __pyx_t_7 = (__pyx_v_other_segment.end < __pyx_v_this_segment.end);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1303
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:
 *                     other_idx += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     this_idx += 1
 */
        __pyx_v_other_idx = (__pyx_v_other_idx + 1);
        goto __pyx_L12;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":1305
 *                     other_idx += 1
 *                 else:
 *                     this_idx += 1             # <<<<<<<<<<<<<<
 *                     other_idx += 1
 * 
 */
        __pyx_v_this_idx = (__pyx_v_this_idx + 1);

        /* "GatSegmentList.pyx":1306
 *                 else:
 *                     this_idx += 1
 *                     other_idx += 1             # <<<<<<<<<<<<<<
 * 
 *         free( self.segments )
 */
        __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      }
      __pyx_L12:;
    }
    __pyx_L10:;
  }

  /* "GatSegmentList.pyx":1308
 *                     other_idx += 1
 * 
 *         free( self.segments )             # <<<<<<<<<<<<<<
 *         self.nsegments = working_idx
 *         self.segments = new_segments
 */
  free(__pyx_v_self->segments);

  /* "GatSegmentList.pyx":1309
 * 
 *         free( self.segments )
 *         self.nsegments = working_idx             # <<<<<<<<<<<<<<
 *         self.segments = new_segments
 *         self._resize( self.nsegments )
 */
  __pyx_v_self->nsegments = __pyx_v_working_idx;

  /* "GatSegmentList.pyx":1310
 *         free( self.segments )
 *         self.nsegments = working_idx
 *         self.segments = new_segments             # <<<<<<<<<<<<<<
 *         self._resize( self.nsegments )
 *         return self
 */
  __pyx_v_self->segments = __pyx_v_new_segments;

  /* "GatSegmentList.pyx":1311
 *         self.nsegments = working_idx
 *         self.segments = new_segments
 *         self._resize( self.nsegments )             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->_resize(__pyx_v_self, __pyx_v_self->nsegments); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "GatSegmentList.pyx":1312
 *         self.segments = new_segments
 *         self._resize( self.nsegments )
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cpdef SegmentList intersect( self, SegmentList other ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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("GatSegmentList.SegmentList.filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_47filter(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_46filter[] = "SegmentList.filter(self, SegmentList other) -> SegmentList\nremove all segments that are not in *other*\n\n        Both this and other are assumed to have been normalized.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_47filter(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("filter (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_46filter(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_other));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1250
 *         return result
 * 
 *     cpdef SegmentList filter( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''remove all segments that are not in *other*
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_46filter(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("filter", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->filter(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __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("GatSegmentList.SegmentList.filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1314
 *         return self
 * 
 *     cpdef SegmentList intersect( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''intersect this segment list with another.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_49intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_f_14GatSegmentList_11SegmentList_intersect(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other, int __pyx_skip_dispatch) {
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_new_segments;
  size_t __pyx_v_allocated;
  int __pyx_v_this_idx;
  int __pyx_v_other_idx;
  int __pyx_v_working_idx;
  int __pyx_v_last_this_idx;
  int __pyx_v_last_other_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_this_segment;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_other_segment;
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  struct __pyx_t_14GatSegmentList_Segment __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("intersect", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__intersect); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_49intersect)) {
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_14GatSegmentList_SegmentList))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1327
 * 
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "intersection of a non-normalized list"             # <<<<<<<<<<<<<<
 *         assert other.flag & SEG_NORMALIZED, "intersection with non-normalized list"
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_48));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1328
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "intersection of a non-normalized list"
 *         assert other.flag & SEG_NORMALIZED, "intersection with non-normalized list"             # <<<<<<<<<<<<<<
 * 
 *         # avoid self-self comparison
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_other->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_38));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1331
 * 
 *         # avoid self-self comparison
 *         if other.segments == self.segments: return self             # <<<<<<<<<<<<<<
 * 
 *         if self.nsegments == 0: return self
 */
  __pyx_t_4 = (__pyx_v_other->segments == __pyx_v_self->segments);
  if (__pyx_t_4) {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1333
 *         if other.segments == self.segments: return self
 * 
 *         if self.nsegments == 0: return self             # <<<<<<<<<<<<<<
 * 
 *         cdef Segment * new_segments
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __pyx_r = __pyx_v_self;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "GatSegmentList.pyx":1338
 *         cdef size_t allocated
 *         # create new list with 10% overhead
 *         allocated = int(lmax( self.nsegments, other.nsegments) * 1.1)             # <<<<<<<<<<<<<<
 * 
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )
 */
  __pyx_v_allocated = ((size_t)(__pyx_f_14GatSegmentList_lmax(__pyx_v_self->nsegments, __pyx_v_other->nsegments) * 1.1));

  /* "GatSegmentList.pyx":1340
 *         allocated = int(lmax( self.nsegments, other.nsegments) * 1.1)
 * 
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )             # <<<<<<<<<<<<<<
 *         if not new_segments:
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))
 */
  __pyx_v_new_segments = ((struct __pyx_t_14GatSegmentList_Segment *)malloc((__pyx_v_allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

  /* "GatSegmentList.pyx":1341
 * 
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )
 *         if not new_segments:             # <<<<<<<<<<<<<<
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))
 * 
 */
  __pyx_t_4 = (!(__pyx_v_new_segments != 0));
  if (__pyx_t_4) {

    /* "GatSegmentList.pyx":1342
 *         new_segments =<Segment*>malloc( allocated * sizeof( Segment ) )
 *         if not new_segments:
 *             raise MemoryError( "out of memory when allocation %i bytes" % sizeof( allocated * sizeof( Segment ) ))             # <<<<<<<<<<<<<<
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 */
    __pyx_t_1 = __Pyx_PyInt_FromSize_t((sizeof((__pyx_v_allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "GatSegmentList.pyx":1345
 * 
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         working_idx = this_idx = other_idx = 0             # <<<<<<<<<<<<<<
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 */
  __pyx_v_working_idx = 0;
  __pyx_v_this_idx = 0;
  __pyx_v_other_idx = 0;

  /* "GatSegmentList.pyx":1346
 *         cdef int this_idx, other_idx, working_idx, last_this_idx, last_other_idx
 *         working_idx = this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1             # <<<<<<<<<<<<<<
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)
 */
  __pyx_v_last_this_idx = -1;
  __pyx_v_last_other_idx = -1;

  /* "GatSegmentList.pyx":1347
 *         working_idx = this_idx = other_idx = 0
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 *         cdef Segment other_segment = Segment(0,0)
 * 
 */
  __pyx_t_5.start = 0;
  __pyx_t_5.end = 0;
  __pyx_v_this_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":1348
 *         last_this_idx = last_other_idx = -1
 *         cdef Segment this_segment = Segment(0,0)
 *         cdef Segment other_segment = Segment(0,0)             # <<<<<<<<<<<<<<
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:
 */
  __pyx_t_5.start = 0;
  __pyx_t_5.end = 0;
  __pyx_v_other_segment = __pyx_t_5;

  /* "GatSegmentList.pyx":1350
 *         cdef Segment other_segment = Segment(0,0)
 * 
 *         while this_idx < self.nsegments and other_idx < other.nsegments:             # <<<<<<<<<<<<<<
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 */
  while (1) {
    __pyx_t_4 = (__pyx_v_this_idx < __pyx_v_self->nsegments);
    if (__pyx_t_4) {
      __pyx_t_6 = (__pyx_v_other_idx < __pyx_v_other->nsegments);
      __pyx_t_7 = __pyx_t_6;
    } else {
      __pyx_t_7 = __pyx_t_4;
    }
    if (!__pyx_t_7) break;

    /* "GatSegmentList.pyx":1353
 * 
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:             # <<<<<<<<<<<<<<
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 */
    __pyx_t_7 = (__pyx_v_last_this_idx != __pyx_v_this_idx);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1354
 *             # print "this=", this_idx, self.nsegments, "other=", other_idx, other.nsegments
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]             # <<<<<<<<<<<<<<
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 */
      __pyx_v_this_segment = (__pyx_v_self->segments[__pyx_v_this_idx]);

      /* "GatSegmentList.pyx":1355
 *             if last_this_idx != this_idx:
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx             # <<<<<<<<<<<<<<
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 */
      __pyx_v_last_this_idx = __pyx_v_this_idx;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "GatSegmentList.pyx":1356
 *                 this_segment = self.segments[this_idx]
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:             # <<<<<<<<<<<<<<
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx
 */
    __pyx_t_7 = (__pyx_v_last_other_idx != __pyx_v_other_idx);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1357
 *                 last_this_idx = this_idx
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]             # <<<<<<<<<<<<<<
 *                 last_other_idx = other_idx
 * 
 */
      __pyx_v_other_segment = (__pyx_v_other->segments[__pyx_v_other_idx]);

      /* "GatSegmentList.pyx":1358
 *             if last_other_idx != other_idx:
 *                 other_segment = other.segments[other_idx]
 *                 last_other_idx = other_idx             # <<<<<<<<<<<<<<
 * 
 *             # print this_segment, other_segment
 */
      __pyx_v_last_other_idx = __pyx_v_other_idx;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "GatSegmentList.pyx":1362
 *             # print this_segment, other_segment
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:             # <<<<<<<<<<<<<<
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 */
    __pyx_t_7 = (__pyx_v_this_segment.end <= __pyx_v_other_segment.start);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1363
 *             # skip segments in this not overlapping other
 *             if this_segment.end <= other_segment.start:
 *                 this_idx += 1             # <<<<<<<<<<<<<<
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 */
      __pyx_v_this_idx = (__pyx_v_this_idx + 1);
      goto __pyx_L10;
    }

    /* "GatSegmentList.pyx":1365
 *                 this_idx += 1
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:             # <<<<<<<<<<<<<<
 *                 other_idx += 1
 *             else:
 */
    __pyx_t_7 = (__pyx_v_other_segment.end <= __pyx_v_this_segment.start);
    if (__pyx_t_7) {

      /* "GatSegmentList.pyx":1366
 *             # skip segments in other not overlapping this
 *             elif other_segment.end <= this_segment.start:
 *                 other_idx += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # deal with overlap
 */
      __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      goto __pyx_L10;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1369
 *             else:
 *                 # deal with overlap
 *                 new_segments[working_idx].start = lmax(this_segment.start, other_segment.start )             # <<<<<<<<<<<<<<
 *                 new_segments[working_idx].end = lmin(this_segment.end, other_segment.end )
 *                 working_idx += 1
 */
      (__pyx_v_new_segments[__pyx_v_working_idx]).start = __pyx_f_14GatSegmentList_lmax(__pyx_v_this_segment.start, __pyx_v_other_segment.start);

      /* "GatSegmentList.pyx":1370
 *                 # deal with overlap
 *                 new_segments[working_idx].start = lmax(this_segment.start, other_segment.start )
 *                 new_segments[working_idx].end = lmin(this_segment.end, other_segment.end )             # <<<<<<<<<<<<<<
 *                 working_idx += 1
 *                 if working_idx >= allocated:
 */
      (__pyx_v_new_segments[__pyx_v_working_idx]).end = __pyx_f_14GatSegmentList_lmin(__pyx_v_this_segment.end, __pyx_v_other_segment.end);

      /* "GatSegmentList.pyx":1371
 *                 new_segments[working_idx].start = lmax(this_segment.start, other_segment.start )
 *                 new_segments[working_idx].end = lmin(this_segment.end, other_segment.end )
 *                 working_idx += 1             # <<<<<<<<<<<<<<
 *                 if working_idx >= allocated:
 *                     allocated *= 2
 */
      __pyx_v_working_idx = (__pyx_v_working_idx + 1);

      /* "GatSegmentList.pyx":1372
 *                 new_segments[working_idx].end = lmin(this_segment.end, other_segment.end )
 *                 working_idx += 1
 *                 if working_idx >= allocated:             # <<<<<<<<<<<<<<
 *                     allocated *= 2
 *                     new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )
 */
      __pyx_t_7 = (__pyx_v_working_idx >= __pyx_v_allocated);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1373
 *                 working_idx += 1
 *                 if working_idx >= allocated:
 *                     allocated *= 2             # <<<<<<<<<<<<<<
 *                     new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )
 *                     assert new_segments != NULL
 */
        __pyx_v_allocated = (__pyx_v_allocated * 2);

        /* "GatSegmentList.pyx":1374
 *                 if working_idx >= allocated:
 *                     allocated *= 2
 *                     new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )             # <<<<<<<<<<<<<<
 *                     assert new_segments != NULL
 * 
 */
        __pyx_v_new_segments = ((struct __pyx_t_14GatSegmentList_Segment *)realloc(__pyx_v_new_segments, (__pyx_v_allocated * (sizeof(struct __pyx_t_14GatSegmentList_Segment)))));

        /* "GatSegmentList.pyx":1375
 *                     allocated *= 2
 *                     new_segments = <Segment*>realloc( new_segments, allocated * sizeof(Segment ) )
 *                     assert new_segments != NULL             # <<<<<<<<<<<<<<
 * 
 *                 if this_segment.end < other_segment.end:
 */
        #ifndef CYTHON_WITHOUT_ASSERTIONS
        if (unlikely(!(__pyx_v_new_segments != NULL))) {
          PyErr_SetNone(PyExc_AssertionError);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #endif
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "GatSegmentList.pyx":1377
 *                     assert new_segments != NULL
 * 
 *                 if this_segment.end < other_segment.end:             # <<<<<<<<<<<<<<
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:
 */
      __pyx_t_7 = (__pyx_v_this_segment.end < __pyx_v_other_segment.end);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1378
 * 
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1             # <<<<<<<<<<<<<<
 *                 elif other_segment.end < this_segment.end:
 *                     other_idx += 1
 */
        __pyx_v_this_idx = (__pyx_v_this_idx + 1);
        goto __pyx_L12;
      }

      /* "GatSegmentList.pyx":1379
 *                 if this_segment.end < other_segment.end:
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:             # <<<<<<<<<<<<<<
 *                     other_idx += 1
 *                 else:
 */
      __pyx_t_7 = (__pyx_v_other_segment.end < __pyx_v_this_segment.end);
      if (__pyx_t_7) {

        /* "GatSegmentList.pyx":1380
 *                     this_idx += 1
 *                 elif other_segment.end < this_segment.end:
 *                     other_idx += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     this_idx += 1
 */
        __pyx_v_other_idx = (__pyx_v_other_idx + 1);
        goto __pyx_L12;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":1382
 *                     other_idx += 1
 *                 else:
 *                     this_idx += 1             # <<<<<<<<<<<<<<
 *                     other_idx += 1
 * 
 */
        __pyx_v_this_idx = (__pyx_v_this_idx + 1);

        /* "GatSegmentList.pyx":1383
 *                 else:
 *                     this_idx += 1
 *                     other_idx += 1             # <<<<<<<<<<<<<<
 * 
 *         free( self.segments )
 */
        __pyx_v_other_idx = (__pyx_v_other_idx + 1);
      }
      __pyx_L12:;
    }
    __pyx_L10:;
  }

  /* "GatSegmentList.pyx":1385
 *                     other_idx += 1
 * 
 *         free( self.segments )             # <<<<<<<<<<<<<<
 *         self.segments = new_segments
 *         self.nsegments = working_idx
 */
  free(__pyx_v_self->segments);

  /* "GatSegmentList.pyx":1386
 * 
 *         free( self.segments )
 *         self.segments = new_segments             # <<<<<<<<<<<<<<
 *         self.nsegments = working_idx
 *         self.allocated = allocated
 */
  __pyx_v_self->segments = __pyx_v_new_segments;

  /* "GatSegmentList.pyx":1387
 *         free( self.segments )
 *         self.segments = new_segments
 *         self.nsegments = working_idx             # <<<<<<<<<<<<<<
 *         self.allocated = allocated
 *         return self
 */
  __pyx_v_self->nsegments = __pyx_v_working_idx;

  /* "GatSegmentList.pyx":1388
 *         self.segments = new_segments
 *         self.nsegments = working_idx
 *         self.allocated = allocated             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_v_self->allocated = __pyx_v_allocated;

  /* "GatSegmentList.pyx":1389
 *         self.nsegments = working_idx
 *         self.allocated = allocated
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cpdef extend_segments( self, int extension ):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = ((struct __pyx_obj_14GatSegmentList_SegmentList *)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("GatSegmentList.SegmentList.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_49intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_48intersect[] = "SegmentList.intersect(self, SegmentList other) -> SegmentList\nintersect this segment list with another.\n\n        Intervals are truncated to the overlap between this and\n        other.\n\n        Both this and other are assumed to have been normalized.\n\n        Segments are truncated to the smallest intersection. Thus,\n        the intersection between ``[(0,10), (10,20)]`` and ``[(0,20)]``\n        will be ``[(0,10), (10,20)]`` and not ``[(0,20)]``.\n\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_49intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("intersect (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_48intersect(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_other));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1314
 *         return self
 * 
 *     cpdef SegmentList intersect( self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         '''intersect this segment list with another.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_48intersect(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("intersect", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->intersect(__pyx_v_self, __pyx_v_other, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __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("GatSegmentList.SegmentList.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1391
 *         return self
 * 
 *     cpdef extend_segments( self, int extension ):             # <<<<<<<<<<<<<<
 *         '''extend all intervals by a certain amount.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_51extend_segments(PyObject *__pyx_v_self, PyObject *__pyx_arg_extension); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_extend_segments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_extension, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  size_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend_segments", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__extend_segments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_51extend_segments)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_extension); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __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 = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1401
 *         cdef int idx
 *         cdef Segment * s
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             s = &self.segments[idx]
 *             s.start -= lmin( extension, s.start)
 */
  __pyx_t_4 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_4; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1402
 *         cdef Segment * s
 *         for idx from 0 <= idx < self.nsegments:
 *             s = &self.segments[idx]             # <<<<<<<<<<<<<<
 *             s.start -= lmin( extension, s.start)
 *             s.end += extension
 */
    __pyx_v_s = (&(__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1403
 *         for idx from 0 <= idx < self.nsegments:
 *             s = &self.segments[idx]
 *             s.start -= lmin( extension, s.start)             # <<<<<<<<<<<<<<
 *             s.end += extension
 *         self.flag = False
 */
    __pyx_v_s->start = (__pyx_v_s->start - __pyx_f_14GatSegmentList_lmin(__pyx_v_extension, __pyx_v_s->start));

    /* "GatSegmentList.pyx":1404
 *             s = &self.segments[idx]
 *             s.start -= lmin( extension, s.start)
 *             s.end += extension             # <<<<<<<<<<<<<<
 *         self.flag = False
 * 
 */
    __pyx_v_s->end = (__pyx_v_s->end + __pyx_v_extension);
  }

  /* "GatSegmentList.pyx":1405
 *             s.start -= lmin( extension, s.start)
 *             s.end += extension
 *         self.flag = False             # <<<<<<<<<<<<<<
 * 
 *     cpdef expand_segments( self, double expansion ):
 */
  __pyx_v_self->flag = 0;

  __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("GatSegmentList.SegmentList.extend_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_51extend_segments(PyObject *__pyx_v_self, PyObject *__pyx_arg_extension); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_50extend_segments[] = "SegmentList.extend_segments(self, int extension)\nextend all intervals by a certain amount.\n\n        If the extension causes an interval to extend beyond the chromosome\n        start, the interval is truncated.\n\n        The segment list will not be normalized afterwards.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_51extend_segments(PyObject *__pyx_v_self, PyObject *__pyx_arg_extension) {
  int __pyx_v_extension;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("extend_segments (wrapper)", 0);
  assert(__pyx_arg_extension); {
    __pyx_v_extension = __Pyx_PyInt_AsInt(__pyx_arg_extension); if (unlikely((__pyx_v_extension == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.extend_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_50extend_segments(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((int)__pyx_v_extension));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1391
 *         return self
 * 
 *     cpdef extend_segments( self, int extension ):             # <<<<<<<<<<<<<<
 *         '''extend all intervals by a certain amount.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_50extend_segments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_v_extension) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend_segments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->extend_segments(__pyx_v_self, __pyx_v_extension, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __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("GatSegmentList.SegmentList.extend_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1407
 *         self.flag = False
 * 
 *     cpdef expand_segments( self, double expansion ):             # <<<<<<<<<<<<<<
 *         '''expand all intervals by a certain amount.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_53expand_segments(PyObject *__pyx_v_self, PyObject *__pyx_arg_expansion); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_expand_segments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, double __pyx_v_expansion, int __pyx_skip_dispatch) {
  int __pyx_v_idx;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_l;
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_extension;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  double __pyx_v_e_1;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  size_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("expand_segments", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__expand_segments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_53expand_segments)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyFloat_FromDouble(__pyx_v_expansion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __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 = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1421
 *         cdef PositionDifference l, extension
 *         cdef Segment * s
 *         cdef double e_1 = (expansion - 1.0) / 2.0             # <<<<<<<<<<<<<<
 * 
 *         if expansion <= 0: raise ValueError( "invalid expansion: %f <= 0" % expansion)
 */
  __pyx_v_e_1 = ((__pyx_v_expansion - 1.0) / 2.0);

  /* "GatSegmentList.pyx":1423
 *         cdef double e_1 = (expansion - 1.0) / 2.0
 * 
 *         if expansion <= 0: raise ValueError( "invalid expansion: %f <= 0" % expansion)             # <<<<<<<<<<<<<<
 * 
 *         for idx from 0 <= idx < self.nsegments:
 */
  __pyx_t_4 = (__pyx_v_expansion <= 0.0);
  if (__pyx_t_4) {
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_expansion); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1425
 *         if expansion <= 0: raise ValueError( "invalid expansion: %f <= 0" % expansion)
 * 
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             s = &self.segments[idx]
 *             l = s.end - s.start
 */
  __pyx_t_5 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_5; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1426
 * 
 *         for idx from 0 <= idx < self.nsegments:
 *             s = &self.segments[idx]             # <<<<<<<<<<<<<<
 *             l = s.end - s.start
 *             extension = <PositionDifference>floor(l * e_1 )
 */
    __pyx_v_s = (&(__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1427
 *         for idx from 0 <= idx < self.nsegments:
 *             s = &self.segments[idx]
 *             l = s.end - s.start             # <<<<<<<<<<<<<<
 *             extension = <PositionDifference>floor(l * e_1 )
 *             s.start -= lmin( extension, s.start)
 */
    __pyx_v_l = (__pyx_v_s->end - __pyx_v_s->start);

    /* "GatSegmentList.pyx":1428
 *             s = &self.segments[idx]
 *             l = s.end - s.start
 *             extension = <PositionDifference>floor(l * e_1 )             # <<<<<<<<<<<<<<
 *             s.start -= lmin( extension, s.start)
 *             s.end += extension
 */
    __pyx_v_extension = ((__pyx_t_14GatSegmentList_PositionDifference)floor((__pyx_v_l * __pyx_v_e_1)));

    /* "GatSegmentList.pyx":1429
 *             l = s.end - s.start
 *             extension = <PositionDifference>floor(l * e_1 )
 *             s.start -= lmin( extension, s.start)             # <<<<<<<<<<<<<<
 *             s.end += extension
 *         self.flag = False
 */
    __pyx_v_s->start = (__pyx_v_s->start - __pyx_f_14GatSegmentList_lmin(__pyx_v_extension, __pyx_v_s->start));

    /* "GatSegmentList.pyx":1430
 *             extension = <PositionDifference>floor(l * e_1 )
 *             s.start -= lmin( extension, s.start)
 *             s.end += extension             # <<<<<<<<<<<<<<
 *         self.flag = False
 * 
 */
    __pyx_v_s->end = (__pyx_v_s->end + __pyx_v_extension);
  }

  /* "GatSegmentList.pyx":1431
 *             s.start -= lmin( extension, s.start)
 *             s.end += extension
 *         self.flag = False             # <<<<<<<<<<<<<<
 * 
 *     def shift( self, PositionDifference offset ):
 */
  __pyx_v_self->flag = 0;

  __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("GatSegmentList.SegmentList.expand_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_53expand_segments(PyObject *__pyx_v_self, PyObject *__pyx_arg_expansion); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_52expand_segments[] = "SegmentList.expand_segments(self, double expansion)\nexpand all intervals by a certain amount.\n\n        The interval length is multiplied by *expansion* and \n        extended around the mid-point.\n\n        If the expansion causes an interval to extend beyond the chromosome\n        start, the interval is truncated.\n\n        The segment list will not be normalized afterwards.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_53expand_segments(PyObject *__pyx_v_self, PyObject *__pyx_arg_expansion) {
  double __pyx_v_expansion;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("expand_segments (wrapper)", 0);
  assert(__pyx_arg_expansion); {
    __pyx_v_expansion = __pyx_PyFloat_AsDouble(__pyx_arg_expansion); if (unlikely((__pyx_v_expansion == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.expand_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_52expand_segments(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((double)__pyx_v_expansion));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1407
 *         self.flag = False
 * 
 *     cpdef expand_segments( self, double expansion ):             # <<<<<<<<<<<<<<
 *         '''expand all intervals by a certain amount.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_52expand_segments(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, double __pyx_v_expansion) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("expand_segments", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->expand_segments(__pyx_v_self, __pyx_v_expansion, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __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("GatSegmentList.SegmentList.expand_segments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_55shift(PyObject *__pyx_v_self, PyObject *__pyx_arg_offset); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_54shift[] = "SegmentList.shift(self, PositionDifference offset)\nshift segments by a certain offset.\n        \n        raises ValueError if segment coordinates become negative.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_55shift(PyObject *__pyx_v_self, PyObject *__pyx_arg_offset) {
  __pyx_t_14GatSegmentList_PositionDifference __pyx_v_offset;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("shift (wrapper)", 0);
  assert(__pyx_arg_offset); {
    __pyx_v_offset = __Pyx_PyInt_AsInt(__pyx_arg_offset); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1433; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentList.shift", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_54shift(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((__pyx_t_14GatSegmentList_PositionDifference)__pyx_v_offset));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1433
 *         self.flag = False
 * 
 *     def shift( self, PositionDifference offset ):             # <<<<<<<<<<<<<<
 *         '''shift segments by a certain offset.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_54shift(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, __pyx_t_14GatSegmentList_PositionDifference __pyx_v_offset) {
  int __pyx_v_idx;
  struct __pyx_t_14GatSegmentList_Segment *__pyx_v_s;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("shift", 0);

  /* "GatSegmentList.pyx":1440
 *         cdef int idx
 *         cdef Segment * s
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             s = &self.segments[idx]
 *             s.end += offset
 */
  __pyx_t_1 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_1; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1441
 *         cdef Segment * s
 *         for idx from 0 <= idx < self.nsegments:
 *             s = &self.segments[idx]             # <<<<<<<<<<<<<<
 *             s.end += offset
 *             s.start += offset
 */
    __pyx_v_s = (&(__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1442
 *         for idx from 0 <= idx < self.nsegments:
 *             s = &self.segments[idx]
 *             s.end += offset             # <<<<<<<<<<<<<<
 *             s.start += offset
 *             if s.start < 0: raise ValueError( "shift creates negative coordinates" )
 */
    __pyx_v_s->end = (__pyx_v_s->end + __pyx_v_offset);

    /* "GatSegmentList.pyx":1443
 *             s = &self.segments[idx]
 *             s.end += offset
 *             s.start += offset             # <<<<<<<<<<<<<<
 *             if s.start < 0: raise ValueError( "shift creates negative coordinates" )
 * 
 */
    __pyx_v_s->start = (__pyx_v_s->start + __pyx_v_offset);

    /* "GatSegmentList.pyx":1444
 *             s.end += offset
 *             s.start += offset
 *             if s.start < 0: raise ValueError( "shift creates negative coordinates" )             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position sum( self ):
 */
    __pyx_t_2 = (__pyx_v_s->start < 0);
    if (__pyx_t_2) {
      __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.shift", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1446
 *             if s.start < 0: raise ValueError( "shift creates negative coordinates" )
 * 
 *     cpdef Position sum( self ):             # <<<<<<<<<<<<<<
 *         '''return total length of all segments.'''
 *         cdef Position total
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_57sum(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_sum(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  __pyx_t_14GatSegmentList_Position __pyx_v_total;
  int __pyx_v_idx;
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_s;
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_3;
  size_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sum", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__sum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_57sum)) {
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1451
 *         cdef int idx
 *         cdef Segment s
 *         total = 0             # <<<<<<<<<<<<<<
 *         for idx from 0 <= idx < self.nsegments:
 *             s = self.segments[idx]
 */
  __pyx_v_total = 0;

  /* "GatSegmentList.pyx":1452
 *         cdef Segment s
 *         total = 0
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             s = self.segments[idx]
 *             total += s.end - s.start
 */
  __pyx_t_4 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_4; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1453
 *         total = 0
 *         for idx from 0 <= idx < self.nsegments:
 *             s = self.segments[idx]             # <<<<<<<<<<<<<<
 *             total += s.end - s.start
 *         return total
 */
    __pyx_v_s = (__pyx_v_self->segments[__pyx_v_idx]);

    /* "GatSegmentList.pyx":1454
 *         for idx from 0 <= idx < self.nsegments:
 *             s = self.segments[idx]
 *             total += s.end - s.start             # <<<<<<<<<<<<<<
 *         return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + (__pyx_v_s.end - __pyx_v_s.start));
  }

  /* "GatSegmentList.pyx":1455
 *             s = self.segments[idx]
 *             total += s.end - s.start
 *         return total             # <<<<<<<<<<<<<<
 * 
 *     def largest( self ):
 */
  __pyx_r = __pyx_v_total;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_57sum(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_56sum[] = "SegmentList.sum(self) -> Position\nreturn total length of all segments.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_57sum(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sum (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_56sum(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1446
 *             if s.start < 0: raise ValueError( "shift creates negative coordinates" )
 * 
 *     cpdef Position sum( self ):             # <<<<<<<<<<<<<<
 *         '''return total length of all segments.'''
 *         cdef Position total
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_56sum(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sum", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->sum(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1446; __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("GatSegmentList.SegmentList.sum", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_59largest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_58largest[] = "SegmentList.largest(self)\nreturn largest segment.\n\n        If there are multiple segments of the same size, the first\n        will be returned.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_59largest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("largest (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_58largest(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1457
 *         return total
 * 
 *     def largest( self ):             # <<<<<<<<<<<<<<
 *         '''return largest segment.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_58largest(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  int __pyx_v_idx;
  int __pyx_v_max_idx;
  __pyx_t_14GatSegmentList_Position __pyx_v_max_value;
  __pyx_t_14GatSegmentList_Position __pyx_v_l;
  CYTHON_UNUSED long __pyx_v_total;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  size_t __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("largest", 0);

  /* "GatSegmentList.pyx":1463
 *         will be returned.
 *         '''
 *         if self.nsegments == 0: raise ValueError( "largest segment from empty list" )             # <<<<<<<<<<<<<<
 *         cdef int idx
 *         cdef int max_idx = 0
 */
  __pyx_t_1 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_1) {
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1465
 *         if self.nsegments == 0: raise ValueError( "largest segment from empty list" )
 *         cdef int idx
 *         cdef int max_idx = 0             # <<<<<<<<<<<<<<
 *         cdef Position max_value = 0
 *         cdef Position l
 */
  __pyx_v_max_idx = 0;

  /* "GatSegmentList.pyx":1466
 *         cdef int idx
 *         cdef int max_idx = 0
 *         cdef Position max_value = 0             # <<<<<<<<<<<<<<
 *         cdef Position l
 *         total = 0
 */
  __pyx_v_max_value = 0;

  /* "GatSegmentList.pyx":1468
 *         cdef Position max_value = 0
 *         cdef Position l
 *         total = 0             # <<<<<<<<<<<<<<
 *         for idx from 0 <= idx < self.nsegments:
 *             l = segment_length( self.segments[idx] )
 */
  __pyx_v_total = 0;

  /* "GatSegmentList.pyx":1469
 *         cdef Position l
 *         total = 0
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             l = segment_length( self.segments[idx] )
 *             if l > max_value:
 */
  __pyx_t_3 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_3; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1470
 *         total = 0
 *         for idx from 0 <= idx < self.nsegments:
 *             l = segment_length( self.segments[idx] )             # <<<<<<<<<<<<<<
 *             if l > max_value:
 *                 max_idx = idx
 */
    __pyx_v_l = __pyx_f_14GatSegmentList_segment_length((__pyx_v_self->segments[__pyx_v_idx]));

    /* "GatSegmentList.pyx":1471
 *         for idx from 0 <= idx < self.nsegments:
 *             l = segment_length( self.segments[idx] )
 *             if l > max_value:             # <<<<<<<<<<<<<<
 *                 max_idx = idx
 *                 max_value = l
 */
    __pyx_t_1 = (__pyx_v_l > __pyx_v_max_value);
    if (__pyx_t_1) {

      /* "GatSegmentList.pyx":1472
 *             l = segment_length( self.segments[idx] )
 *             if l > max_value:
 *                 max_idx = idx             # <<<<<<<<<<<<<<
 *                 max_value = l
 *         return self.segments[max_idx]
 */
      __pyx_v_max_idx = __pyx_v_idx;

      /* "GatSegmentList.pyx":1473
 *             if l > max_value:
 *                 max_idx = idx
 *                 max_value = l             # <<<<<<<<<<<<<<
 *         return self.segments[max_idx]
 * 
 */
      __pyx_v_max_value = __pyx_v_l;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "GatSegmentList.pyx":1474
 *                 max_idx = idx
 *                 max_value = l
 *         return self.segments[max_idx]             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position max( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment((__pyx_v_self->segments[__pyx_v_max_idx])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __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("GatSegmentList.SegmentList.largest", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1476
 *         return self.segments[max_idx]
 * 
 *     cpdef Position max( self ):             # <<<<<<<<<<<<<<
 *         '''return maximum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "maximum from non-normalized list"
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_61max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_max(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("max", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__max); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_61max)) {
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1478
 *     cpdef Position max( self ):
 *         '''return maximum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "maximum from non-normalized list"             # <<<<<<<<<<<<<<
 *         if self.nsegments == 0: return 0
 *         return self.segments[self.nsegments - 1].end
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_54));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1479
 *         '''return maximum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "maximum from non-normalized list"
 *         if self.nsegments == 0: return 0             # <<<<<<<<<<<<<<
 *         return self.segments[self.nsegments - 1].end
 * 
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1480
 *         assert self.flag & SEG_NORMALIZED, "maximum from non-normalized list"
 *         if self.nsegments == 0: return 0
 *         return self.segments[self.nsegments - 1].end             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position min( self ):
 */
  __pyx_r = (__pyx_v_self->segments[(__pyx_v_self->nsegments - 1)]).end;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.max", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_61max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_60max[] = "SegmentList.max(self) -> Position\nreturn maximum coordinate.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_61max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("max (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_60max(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1476
 *         return self.segments[max_idx]
 * 
 *     cpdef Position max( self ):             # <<<<<<<<<<<<<<
 *         '''return maximum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "maximum from non-normalized list"
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_60max(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("max", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->max(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1476; __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("GatSegmentList.SegmentList.max", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1482
 *         return self.segments[self.nsegments - 1].end
 * 
 *     cpdef Position min( self ):             # <<<<<<<<<<<<<<
 *         '''return minimum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "minimum from non-normalized list"
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_63min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static __pyx_t_14GatSegmentList_Position __pyx_f_14GatSegmentList_11SegmentList_min(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  __pyx_t_14GatSegmentList_Position __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __pyx_t_14GatSegmentList_Position __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("min", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__min); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_63min)) {
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyInt_AsUnsignedInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1484
 *     cpdef Position min( self ):
 *         '''return minimum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "minimum from non-normalized list"             # <<<<<<<<<<<<<<
 *         if self.nsegments == 0: return 0
 *         return self.segments[0].start
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_self->flag & 1))) {
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_55));
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "GatSegmentList.pyx":1485
 *         '''return minimum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "minimum from non-normalized list"
 *         if self.nsegments == 0: return 0             # <<<<<<<<<<<<<<
 *         return self.segments[0].start
 * 
 */
  __pyx_t_4 = (__pyx_v_self->nsegments == 0);
  if (__pyx_t_4) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1486
 *         assert self.flag & SEG_NORMALIZED, "minimum from non-normalized list"
 *         if self.nsegments == 0: return 0
 *         return self.segments[0].start             # <<<<<<<<<<<<<<
 * 
 *     cpdef clear( self ):
 */
  __pyx_r = (__pyx_v_self->segments[0]).start;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("GatSegmentList.SegmentList.min", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_63min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_62min[] = "SegmentList.min(self) -> Position\nreturn minimum coordinate.";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_63min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("min (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_62min(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1482
 *         return self.segments[self.nsegments - 1].end
 * 
 *     cpdef Position min( self ):             # <<<<<<<<<<<<<<
 *         '''return minimum coordinate.'''
 *         assert self.flag & SEG_NORMALIZED, "minimum from non-normalized list"
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_62min(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("min", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->min(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1482; __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("GatSegmentList.SegmentList.min", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1488
 *         return self.segments[0].start
 * 
 *     cpdef clear( self ):             # <<<<<<<<<<<<<<
 *         '''removes all segments from list.
 * 
 */

static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_65clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_14GatSegmentList_11SegmentList_clear(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clear", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overriden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__clear); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_65clear)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1493
 *         Note that this method does not shrink the allocated memory.
 *         '''
 *         self.nsegments = 0             # <<<<<<<<<<<<<<
 *         self.flag = 1
 * 
 */
  __pyx_v_self->nsegments = 0;

  /* "GatSegmentList.pyx":1494
 *         '''
 *         self.nsegments = 0
 *         self.flag = 1             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __pyx_v_self->flag = 1;

  __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("GatSegmentList.SegmentList.clear", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_65clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_64clear[] = "SegmentList.clear(self)\nremoves all segments from list.\n\n        Note that this method does not shrink the allocated memory.\n        ";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_65clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clear (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_64clear(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1488
 *         return self.segments[0].start
 * 
 *     cpdef clear( self ):             # <<<<<<<<<<<<<<
 *         '''removes all segments from list.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_64clear(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clear", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_14GatSegmentList_SegmentList *)__pyx_v_self->__pyx_vtab)->clear(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __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("GatSegmentList.SegmentList.clear", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static Py_ssize_t __pyx_pw_14GatSegmentList_11SegmentList_67__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_14GatSegmentList_11SegmentList_67__len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_66__len__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1496
 *         self.flag = 1
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self.nsegments
 * 
 */

static Py_ssize_t __pyx_pf_14GatSegmentList_11SegmentList_66__len__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__", 0);

  /* "GatSegmentList.pyx":1497
 * 
 *     def __len__(self):
 *         return self.nsegments             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_r = __pyx_v_self->nsegments;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static void __pyx_pw_14GatSegmentList_11SegmentList_69__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_14GatSegmentList_11SegmentList_69__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_14GatSegmentList_11SegmentList_68__dealloc__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
}

/* "GatSegmentList.pyx":1499
 *         return self.nsegments
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef int fd
 * 
 */

static void __pyx_pf_14GatSegmentList_11SegmentList_68__dealloc__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  int __pyx_v_fd;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  long __pyx_t_2;
  char *__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "GatSegmentList.pyx":1502
 *         cdef int fd
 * 
 *         if self.segments != NULL:             # <<<<<<<<<<<<<<
 *             # unshared memory
 *             if self.flag & SEG_SHARED:
 */
  __pyx_t_1 = (__pyx_v_self->segments != NULL);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":1504
 *         if self.segments != NULL:
 *             # unshared memory
 *             if self.flag & SEG_SHARED:             # <<<<<<<<<<<<<<
 *                 if self.flag & SEG_SLAVE:
 *                     pass
 */
    __pyx_t_2 = (__pyx_v_self->flag & 2);
    if (__pyx_t_2) {

      /* "GatSegmentList.pyx":1505
 *             # unshared memory
 *             if self.flag & SEG_SHARED:
 *                 if self.flag & SEG_SLAVE:             # <<<<<<<<<<<<<<
 *                     pass
 *                 else:
 */
      __pyx_t_2 = (__pyx_v_self->flag & 4);
      if (__pyx_t_2) {
        goto __pyx_L5;
      }
      /*else*/ {

        /* "GatSegmentList.pyx":1510
 *                     # free shared memory as master
 *                     munmap( self.segments,
 *                             self.nsegments * sizeof(Segment))             # <<<<<<<<<<<<<<
 *             else:
 *                 # free private copy
 */
        munmap(__pyx_v_self->segments, (__pyx_v_self->nsegments * (sizeof(struct __pyx_t_14GatSegmentList_Segment))));
      }
      __pyx_L5:;
      goto __pyx_L4;
    }
    /*else*/ {

      /* "GatSegmentList.pyx":1513
 *             else:
 *                 # free private copy
 *                 free( self.segments )             # <<<<<<<<<<<<<<
 * 
 *         if self.shared_fd != -1:
 */
      free(__pyx_v_self->segments);
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1515
 *                 free( self.segments )
 * 
 *         if self.shared_fd != -1:             # <<<<<<<<<<<<<<
 *             fd = shm_unlink( self.key )
 *             if fd == -1:
 */
  __pyx_t_1 = (__pyx_v_self->shared_fd != -1);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":1516
 * 
 *         if self.shared_fd != -1:
 *             fd = shm_unlink( self.key )             # <<<<<<<<<<<<<<
 *             if fd == -1:
 *                 raise OSError( "could not unlink shared memory" )
 */
    __pyx_t_3 = PyBytes_AsString(__pyx_v_self->key); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_fd = shm_unlink(__pyx_t_3);

    /* "GatSegmentList.pyx":1517
 *         if self.shared_fd != -1:
 *             fd = shm_unlink( self.key )
 *             if fd == -1:             # <<<<<<<<<<<<<<
 *                 raise OSError( "could not unlink shared memory" )
 * 
 */
    __pyx_t_1 = (__pyx_v_fd == -1);
    if (__pyx_t_1) {

      /* "GatSegmentList.pyx":1518
 *             fd = shm_unlink( self.key )
 *             if fd == -1:
 *                 raise OSError( "could not unlink shared memory" )             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
      __pyx_t_4 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;
    goto __pyx_L6;
  }
  __pyx_L6:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_71__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_71__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_70__str__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1520
 *                 raise OSError( "could not unlink shared memory" )
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return str(self.asList())
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_70__str__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);

  /* "GatSegmentList.pyx":1521
 * 
 *     def __str__(self):
 *         return str(self.asList())             # <<<<<<<<<<<<<<
 * 
 *     def asList( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__asList); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1521; __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("GatSegmentList.SegmentList.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_73asList(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_72asList[] = "SegmentList.asList(self)";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_73asList(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("asList (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_72asList(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1523
 *         return str(self.asList())
 * 
 *     def asList( self ):             # <<<<<<<<<<<<<<
 * 
 *         cdef int idx
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_72asList(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  int __pyx_v_idx;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("asList", 0);

  /* "GatSegmentList.pyx":1526
 * 
 *         cdef int idx
 *         result = []             # <<<<<<<<<<<<<<
 *         for idx from 0 <= idx < self.nsegments:
 *             result.append( (self.segments[idx].start, self.segments[idx].end) )
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":1527
 *         cdef int idx
 *         result = []
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             result.append( (self.segments[idx].start, self.segments[idx].end) )
 *         return result
 */
  __pyx_t_2 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_2; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1528
 *         result = []
 *         for idx from 0 <= idx < self.nsegments:
 *             result.append( (self.segments[idx].start, self.segments[idx].end) )             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
    __pyx_t_1 = PyLong_FromUnsignedLong((__pyx_v_self->segments[__pyx_v_idx]).start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyLong_FromUnsignedLong((__pyx_v_self->segments[__pyx_v_idx]).end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __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 = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_1 = 0;
    __pyx_t_3 = 0;
    __pyx_t_5 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_4)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  }

  /* "GatSegmentList.pyx":1529
 *         for idx from 0 <= idx < self.nsegments:
 *             result.append( (self.segments[idx].start, self.segments[idx].end) )
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def asLengths( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__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_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.asList", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_75asLengths(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_14GatSegmentList_11SegmentList_74asLengths[] = "SegmentList.asLengths(self)";
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_75asLengths(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("asLengths (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_74asLengths(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1531
 *         return result
 * 
 *     def asLengths( self ):             # <<<<<<<<<<<<<<
 *         cdef int idx
 *         result = []
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_74asLengths(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  int __pyx_v_idx;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("asLengths", 0);

  /* "GatSegmentList.pyx":1533
 *     def asLengths( self ):
 *         cdef int idx
 *         result = []             # <<<<<<<<<<<<<<
 *         for idx from 0 <= idx < self.nsegments:
 *             result.append( self.segments[idx].end - self.segments[idx].start)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":1534
 *         cdef int idx
 *         result = []
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             result.append( self.segments[idx].end - self.segments[idx].start)
 *         return result
 */
  __pyx_t_2 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_2; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1535
 *         result = []
 *         for idx from 0 <= idx < self.nsegments:
 *             result.append( self.segments[idx].end - self.segments[idx].start)             # <<<<<<<<<<<<<<
 *         return result
 * 
 */
    __pyx_t_1 = PyLong_FromUnsignedLong(((__pyx_v_self->segments[__pyx_v_idx]).end - (__pyx_v_self->segments[__pyx_v_idx]).start)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "GatSegmentList.pyx":1536
 *         for idx from 0 <= idx < self.nsegments:
 *             result.append( self.segments[idx].end - self.segments[idx].start)
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def __iter__( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__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_AddTraceback("GatSegmentList.SegmentList.asLengths", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_77__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_77__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_76__iter__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1538
 *         return result
 * 
 *     def __iter__( self ):             # <<<<<<<<<<<<<<
 *         return SegmentListIterator( self )
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_76__iter__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);

  /* "GatSegmentList.pyx":1539
 * 
 *     def __iter__( self ):
 *         return SegmentListIterator( self )             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, key ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentListIterator)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1539; __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("GatSegmentList.SegmentList.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_79__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_11SegmentList_79__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_78__getitem__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((PyObject *)__pyx_v_key));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1541
 *         return SegmentListIterator( self )
 * 
 *     def __getitem__(self, key ):             # <<<<<<<<<<<<<<
 *         if key >= self.nsegments:
 *             raise IndexError( "index out of range" )
 */

static PyObject *__pyx_pf_14GatSegmentList_11SegmentList_78__getitem__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 0);

  /* "GatSegmentList.pyx":1542
 * 
 *     def __getitem__(self, key ):
 *         if key >= self.nsegments:             # <<<<<<<<<<<<<<
 *             raise IndexError( "index out of range" )
 *         return self.segments[key].start, self.segments[key].end
 */
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->nsegments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_key, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "GatSegmentList.pyx":1543
 *     def __getitem__(self, key ):
 *         if key >= self.nsegments:
 *             raise IndexError( "index out of range" )             # <<<<<<<<<<<<<<
 *         return self.segments[key].start, self.segments[key].end
 * 
 */
    __pyx_t_2 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1544
 *         if key >= self.nsegments:
 *             raise IndexError( "index out of range" )
 *         return self.segments[key].start, self.segments[key].end             # <<<<<<<<<<<<<<
 * 
 *     def __cmp__(self, SegmentList other ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_key); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyLong_FromUnsignedLong((__pyx_v_self->segments[__pyx_t_4]).start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_key); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyLong_FromUnsignedLong((__pyx_v_self->segments[__pyx_t_4]).end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1544; __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 = 1544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__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);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __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_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
#if PY_MAJOR_VERSION < 3
static int __pyx_pw_14GatSegmentList_11SegmentList_81__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static int __pyx_pw_14GatSegmentList_11SegmentList_81__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_14GatSegmentList_SegmentList, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_11SegmentList_80__cmp__(((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_self), ((struct __pyx_obj_14GatSegmentList_SegmentList *)__pyx_v_other));
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
#endif /*!(#if PY_MAJOR_VERSION < 3)*/

/* "GatSegmentList.pyx":1546
 *         return self.segments[key].start, self.segments[key].end
 * 
 *     def __cmp__(self, SegmentList other ):             # <<<<<<<<<<<<<<
 *         cdef int idx
 *         x = self.__len__().__cmp__(len(other))
 */

#if PY_MAJOR_VERSION < 3
static int __pyx_pf_14GatSegmentList_11SegmentList_80__cmp__(struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_other) {
  int __pyx_v_idx;
  PyObject *__pyx_v_x = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  size_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cmp__", 0);

  /* "GatSegmentList.pyx":1548
 *     def __cmp__(self, SegmentList other ):
 *         cdef int idx
 *         x = self.__len__().__cmp__(len(other))             # <<<<<<<<<<<<<<
 *         if x != 0: return x
 *         for idx from 0 <= idx < self.nsegments:
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____len__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____cmp__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = PyObject_Length(((PyObject *)__pyx_v_other)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __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 = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__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(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_v_x = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "GatSegmentList.pyx":1549
 *         cdef int idx
 *         x = self.__len__().__cmp__(len(other))
 *         if x != 0: return x             # <<<<<<<<<<<<<<
 *         for idx from 0 <= idx < self.nsegments:
 *             x = cmpSegmentsStartAndEnd( &self.segments[idx], &other.segments[idx] )
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_x); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = __pyx_t_6;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1550
 *         x = self.__len__().__cmp__(len(other))
 *         if x != 0: return x
 *         for idx from 0 <= idx < self.nsegments:             # <<<<<<<<<<<<<<
 *             x = cmpSegmentsStartAndEnd( &self.segments[idx], &other.segments[idx] )
 *             if x != 0: return x
 */
  __pyx_t_7 = __pyx_v_self->nsegments;
  for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_7; __pyx_v_idx++) {

    /* "GatSegmentList.pyx":1551
 *         if x != 0: return x
 *         for idx from 0 <= idx < self.nsegments:
 *             x = cmpSegmentsStartAndEnd( &self.segments[idx], &other.segments[idx] )             # <<<<<<<<<<<<<<
 *             if x != 0: return x
 *         return 0
 */
    __pyx_t_2 = PyInt_FromLong(__pyx_f_14GatSegmentList_cmpSegmentsStartAndEnd((&(__pyx_v_self->segments[__pyx_v_idx])), (&(__pyx_v_other->segments[__pyx_v_idx])))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "GatSegmentList.pyx":1552
 *         for idx from 0 <= idx < self.nsegments:
 *             x = cmpSegmentsStartAndEnd( &self.segments[idx], &other.segments[idx] )
 *             if x != 0: return x             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_5) {
      __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_x); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_r = __pyx_t_6;
      goto __pyx_L0;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "GatSegmentList.pyx":1553
 *             x = cmpSegmentsStartAndEnd( &self.segments[idx], &other.segments[idx] )
 *             if x != 0: return x
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * def buildSegmentList( *args ):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentList.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
#endif /*!(#if PY_MAJOR_VERSION < 3)*/

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_3buildSegmentList(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_14GatSegmentList_2buildSegmentList[] = "buildSegmentList(*args)\npickling helper function.\n    \n    Return a re-constructed SegmentList object.\n    ";
static PyMethodDef __pyx_mdef_14GatSegmentList_3buildSegmentList = {__Pyx_NAMESTR("buildSegmentList"), (PyCFunction)__pyx_pw_14GatSegmentList_3buildSegmentList, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_2buildSegmentList)};
static PyObject *__pyx_pw_14GatSegmentList_3buildSegmentList(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("buildSegmentList (wrapper)", 0);
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "buildSegmentList", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_14GatSegmentList_2buildSegmentList(__pyx_self, __pyx_v_args);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1555
 *         return 0
 * 
 * def buildSegmentList( *args ):             # <<<<<<<<<<<<<<
 *     '''pickling helper function.
 * 
 */

static PyObject *__pyx_pf_14GatSegmentList_2buildSegmentList(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("buildSegmentList", 0);

  /* "GatSegmentList.pyx":1560
 *     Return a re-constructed SegmentList object.
 *     '''
 *     return SegmentList( unreduce = args )             # <<<<<<<<<<<<<<
 * 
 * # SegmentTuple = collections.namedtuple( "SegmentTuple", "start, end" )
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__unreduce), ((PyObject *)__pyx_v_args)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14GatSegmentList_SegmentList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __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("GatSegmentList.buildSegmentList", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_14GatSegmentList_19SegmentListIterator_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_14GatSegmentList_19SegmentListIterator_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_container = 0;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__container,0};
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__container);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_container = ((struct __pyx_obj_14GatSegmentList_SegmentList *)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("GatSegmentList.SegmentListIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_container), __pyx_ptype_14GatSegmentList_SegmentList, 1, "container", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_14GatSegmentList_19SegmentListIterator___init__(((struct __pyx_obj_14GatSegmentList_SegmentListIterator *)__pyx_v_self), __pyx_v_container);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1569
 *     cdef Position idx
 * 
 *     def __init__(self, SegmentList container ):             # <<<<<<<<<<<<<<
 *         self.idx = 0
 *         self.segment_list = container
 */

static int __pyx_pf_14GatSegmentList_19SegmentListIterator___init__(struct __pyx_obj_14GatSegmentList_SegmentListIterator *__pyx_v_self, struct __pyx_obj_14GatSegmentList_SegmentList *__pyx_v_container) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "GatSegmentList.pyx":1570
 * 
 *     def __init__(self, SegmentList container ):
 *         self.idx = 0             # <<<<<<<<<<<<<<
 *         self.segment_list = container
 * 
 */
  __pyx_v_self->idx = 0;

  /* "GatSegmentList.pyx":1571
 *     def __init__(self, SegmentList container ):
 *         self.idx = 0
 *         self.segment_list = container             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self): return self
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_container));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_container));
  __Pyx_GOTREF(__pyx_v_self->segment_list);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->segment_list));
  __pyx_v_self->segment_list = __pyx_v_container;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_19SegmentListIterator_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_19SegmentListIterator_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_19SegmentListIterator_2__iter__(((struct __pyx_obj_14GatSegmentList_SegmentListIterator *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1573
 *         self.segment_list = container
 * 
 *     def __iter__(self): return self             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */

static PyObject *__pyx_pf_14GatSegmentList_19SegmentListIterator_2__iter__(struct __pyx_obj_14GatSegmentList_SegmentListIterator *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

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

/* Python wrapper */
static PyObject *__pyx_pw_14GatSegmentList_19SegmentListIterator_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_14GatSegmentList_19SegmentListIterator_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_14GatSegmentList_19SegmentListIterator_4__next__(((struct __pyx_obj_14GatSegmentList_SegmentListIterator *)__pyx_v_self));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "GatSegmentList.pyx":1575
 *     def __iter__(self): return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef Position t
 *         cdef Segment v
 */

static PyObject *__pyx_pf_14GatSegmentList_19SegmentListIterator_4__next__(struct __pyx_obj_14GatSegmentList_SegmentListIterator *__pyx_v_self) {
  struct __pyx_t_14GatSegmentList_Segment __pyx_v_v;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);

  /* "GatSegmentList.pyx":1578
 *         cdef Position t
 *         cdef Segment v
 *         if self.idx >= self.segment_list.nsegments:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         v = self.segment_list.segments[self.idx]
 */
  __pyx_t_1 = (__pyx_v_self->idx >= __pyx_v_self->segment_list->nsegments);
  if (__pyx_t_1) {

    /* "GatSegmentList.pyx":1579
 *         cdef Segment v
 *         if self.idx >= self.segment_list.nsegments:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         v = self.segment_list.segments[self.idx]
 *         self.idx += 1
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "GatSegmentList.pyx":1580
 *         if self.idx >= self.segment_list.nsegments:
 *             raise StopIteration
 *         v = self.segment_list.segments[self.idx]             # <<<<<<<<<<<<<<
 *         self.idx += 1
 *         return v.start, v.end
 */
  __pyx_v_v = (__pyx_v_self->segment_list->segments[__pyx_v_self->idx]);

  /* "GatSegmentList.pyx":1581
 *             raise StopIteration
 *         v = self.segment_list.segments[self.idx]
 *         self.idx += 1             # <<<<<<<<<<<<<<
 *         return v.start, v.end
 * 
 */
  __pyx_v_self->idx = (__pyx_v_self->idx + 1);

  /* "GatSegmentList.pyx":1582
 *         v = self.segment_list.segments[self.idx]
 *         self.idx += 1
 *         return v.start, v.end             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_v.start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_v.end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __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 = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__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_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_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("GatSegmentList.SegmentListIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":193
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_copy_shape;
  int __pyx_v_i;
  int __pyx_v_ndim;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  int __pyx_v_t;
  char *__pyx_v_f;
  PyArray_Descr *__pyx_v_descr = 0;
  int __pyx_v_offset;
  int __pyx_v_hasfields;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  char *__pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  if (__pyx_v_info != NULL) {
    __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(__pyx_v_info->obj);
  }

  /* "numpy.pxd":199
 *             # of flags
 * 
 *             if info == NULL: return             # <<<<<<<<<<<<<<
 * 
 *             cdef int copy_shape, i, ndim
 */
  __pyx_t_1 = (__pyx_v_info == NULL);
  if (__pyx_t_1) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "numpy.pxd":202
 * 
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __pyx_v_endian_detector = 1;

  /* "numpy.pxd":203
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "numpy.pxd":205
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "numpy.pxd":207
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
  __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t)));
  if (__pyx_t_1) {

    /* "numpy.pxd":208
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 copy_shape = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 copy_shape = 0
 */
    __pyx_v_copy_shape = 1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "numpy.pxd":210
 *                 copy_shape = 1
 *             else:
 *                 copy_shape = 0             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
    __pyx_v_copy_shape = 0;
  }
  __pyx_L4:;

  /* "numpy.pxd":212
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS);
  if (__pyx_t_1) {

    /* "numpy.pxd":213
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 */
    __pyx_t_2 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS));
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "numpy.pxd":214
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "numpy.pxd":216
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __pyx_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS);
  if (__pyx_t_3) {

    /* "numpy.pxd":217
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 */
    __pyx_t_1 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS));
    __pyx_t_2 = __pyx_t_1;
  } else {
    __pyx_t_2 = __pyx_t_3;
  }
  if (__pyx_t_2) {

    /* "numpy.pxd":218
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_62), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "numpy.pxd":220
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if copy_shape:
 */
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "numpy.pxd":221
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if copy_shape:
 *                 # Allocate new buffer for strides and shape info.
 */
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "numpy.pxd":222
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  if (__pyx_v_copy_shape) {

    /* "numpy.pxd":225
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2)));

    /* "numpy.pxd":226
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "numpy.pxd":227
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):             # <<<<<<<<<<<<<<
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 */
    __pyx_t_5 = __pyx_v_ndim;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "numpy.pxd":228
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]             # <<<<<<<<<<<<<<
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 */
      (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "numpy.pxd":229
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 */
      (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }
    goto __pyx_L7;
  }
  /*else*/ {

    /* "numpy.pxd":231
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)             # <<<<<<<<<<<<<<
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 */
    __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "numpy.pxd":232
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)             # <<<<<<<<<<<<<<
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 */
    __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L7:;

  /* "numpy.pxd":233
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 */
  __pyx_v_info->suboffsets = NULL;

  /* "numpy.pxd":234
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "numpy.pxd":235
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(__pyx_v_self));

  /* "numpy.pxd":238
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef list stack
 */
  __pyx_v_f = NULL;

  /* "numpy.pxd":239
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef list stack
 *             cdef int offset
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self->descr));
  __pyx_v_descr = __pyx_v_self->descr;

  /* "numpy.pxd":243
 *             cdef int offset
 * 
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields and not copy_shape:
 */
  __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr);

  /* "numpy.pxd":245
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
  __pyx_t_2 = (!__pyx_v_hasfields);
  if (__pyx_t_2) {
    __pyx_t_3 = (!__pyx_v_copy_shape);
    __pyx_t_1 = __pyx_t_3;
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {

    /* "numpy.pxd":247
 *             if not hasfields and not copy_shape:
 *                 # do not call releasebuffer
 *                 info.obj = None             # <<<<<<<<<<<<<<
 *             else:
 *                 # need to call releasebuffer
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = Py_None;
    goto __pyx_L10;
  }
  /*else*/ {

    /* "numpy.pxd":250
 *             else:
 *                 # need to call releasebuffer
 *                 info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields:
 */
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
  }
  __pyx_L10:;

  /* "numpy.pxd":252
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == '>' and little_endian) or
 */
  __pyx_t_1 = (!__pyx_v_hasfields);
  if (__pyx_t_1) {

    /* "numpy.pxd":253
 * 
 *             if not hasfields:
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == '>' and little_endian) or
 *                     (descr.byteorder == '<' and not little_endian)):
 */
    __pyx_v_t = __pyx_v_descr->type_num;

    /* "numpy.pxd":254
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == '>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == '<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_1 = (__pyx_v_descr->byteorder == '>');
    if (__pyx_t_1) {
      __pyx_t_2 = __pyx_v_little_endian;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (!__pyx_t_2) {

      /* "numpy.pxd":255
 *                 t = descr.type_num
 *                 if ((descr.byteorder == '>' and little_endian) or
 *                     (descr.byteorder == '<' and not little_endian)):             # <<<<<<<<<<<<<<
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 */
      __pyx_t_1 = (__pyx_v_descr->byteorder == '<');
      if (__pyx_t_1) {
        __pyx_t_3 = (!__pyx_v_little_endian);
        __pyx_t_7 = __pyx_t_3;
      } else {
        __pyx_t_7 = __pyx_t_1;
      }
      __pyx_t_1 = __pyx_t_7;
    } else {
      __pyx_t_1 = __pyx_t_2;
    }
    if (__pyx_t_1) {

      /* "numpy.pxd":256
 *                 if ((descr.byteorder == '>' and little_endian) or
 *                     (descr.byteorder == '<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
      __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_64), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "numpy.pxd":257
 *                     (descr.byteorder == '<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_BYTE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__b;
      goto __pyx_L13;
    }

    /* "numpy.pxd":258
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_UBYTE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__B;
      goto __pyx_L13;
    }

    /* "numpy.pxd":259
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_SHORT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__h;
      goto __pyx_L13;
    }

    /* "numpy.pxd":260
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_USHORT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__H;
      goto __pyx_L13;
    }

    /* "numpy.pxd":261
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_INT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__i;
      goto __pyx_L13;
    }

    /* "numpy.pxd":262
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_UINT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__I;
      goto __pyx_L13;
    }

    /* "numpy.pxd":263
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_LONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__l;
      goto __pyx_L13;
    }

    /* "numpy.pxd":264
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_ULONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__L;
      goto __pyx_L13;
    }

    /* "numpy.pxd":265
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_LONGLONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__q;
      goto __pyx_L13;
    }

    /* "numpy.pxd":266
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_ULONGLONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Q;
      goto __pyx_L13;
    }

    /* "numpy.pxd":267
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_FLOAT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__f;
      goto __pyx_L13;
    }

    /* "numpy.pxd":268
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_DOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__d;
      goto __pyx_L13;
    }

    /* "numpy.pxd":269
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_LONGDOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__g;
      goto __pyx_L13;
    }

    /* "numpy.pxd":270
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_CFLOAT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Zf;
      goto __pyx_L13;
    }

    /* "numpy.pxd":271
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_CDOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Zd;
      goto __pyx_L13;
    }

    /* "numpy.pxd":272
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 */
    __pyx_t_1 = (__pyx_v_t == NPY_CLONGDOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Zg;
      goto __pyx_L13;
    }

    /* "numpy.pxd":273
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
    __pyx_t_1 = (__pyx_v_t == NPY_OBJECT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__O;
      goto __pyx_L13;
    }
    /*else*/ {

      /* "numpy.pxd":275
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_65), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
      __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L13:;

    /* "numpy.pxd":276
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __pyx_v_info->format = __pyx_v_f;

    /* "numpy.pxd":277
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L11;
  }
  /*else*/ {

    /* "numpy.pxd":279
 *                 return
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = '^' # Native data types, manual alignment
 *                 offset = 0
 */
    __pyx_v_info->format = ((char *)malloc(255));

    /* "numpy.pxd":280
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = '^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    (__pyx_v_info->format[0]) = '^';

    /* "numpy.pxd":281
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = '^' # Native data types, manual alignment
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 */
    __pyx_v_offset = 0;

    /* "numpy.pxd":284
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)             # <<<<<<<<<<<<<<
 *                 f[0] = 0 # Terminate format string
 * 
 */
    __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_f = __pyx_t_9;

    /* "numpy.pxd":285
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = 0 # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    (__pyx_v_f[0]) = 0;
  }
  __pyx_L11:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.ndarray.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(Py_None);
    __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_descr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));
  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":287
 *                 f[0] = 0 # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "numpy.pxd":288
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_t_1 = PyArray_HASFIELDS(__pyx_v_self);
  if (__pyx_t_1) {

    /* "numpy.pxd":289
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)
 */
    free(__pyx_v_info->format);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "numpy.pxd":290
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t)));
  if (__pyx_t_1) {

    /* "numpy.pxd":291
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    free(__pyx_v_info->strides);
    goto __pyx_L4;
  }
  __pyx_L4:;

  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":767
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "numpy.pxd":768
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 768; __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("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":770
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "numpy.pxd":771
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 771; __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("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":773
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "numpy.pxd":774
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 774; __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("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":776
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "numpy.pxd":777
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 777; __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("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":779
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "numpy.pxd":780
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 780; __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("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":782
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) {
  PyArray_Descr *__pyx_v_child = 0;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_childname = NULL;
  PyObject *__pyx_v_new_offset = NULL;
  PyObject *__pyx_v_t = NULL;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  long __pyx_t_10;
  char *__pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);

  /* "numpy.pxd":789
 *     cdef int delta_offset
 *     cdef tuple i
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __pyx_v_endian_detector = 1;

  /* "numpy.pxd":790
 *     cdef tuple i
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "numpy.pxd":793
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  if (unlikely(((PyObject *)__pyx_v_descr->names) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_1 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
    __Pyx_XDECREF(__pyx_v_childname);
    __pyx_v_childname = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "numpy.pxd":794
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF(((PyObject *)__pyx_v_fields));
    __pyx_v_fields = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "numpy.pxd":795
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 */
    if (likely(PyTuple_CheckExact(((PyObject *)__pyx_v_fields)))) {
      PyObject* sequence = ((PyObject *)__pyx_v_fields);
      if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
        if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
        else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
    } else {
      __Pyx_UnpackTupleError(((PyObject *)__pyx_v_fields), 2);
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((PyArray_Descr *)__pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_v_new_offset);
    __pyx_v_new_offset = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "numpy.pxd":797
 *         child, new_offset = fields
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_6) {

      /* "numpy.pxd":798
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == '>' and little_endian) or
 */
      __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "numpy.pxd":800
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == '>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == '<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_6 = (__pyx_v_child->byteorder == '>');
    if (__pyx_t_6) {
      __pyx_t_7 = __pyx_v_little_endian;
    } else {
      __pyx_t_7 = __pyx_t_6;
    }
    if (!__pyx_t_7) {

      /* "numpy.pxd":801
 * 
 *         if ((child.byteorder == '>' and little_endian) or
 *             (child.byteorder == '<' and not little_endian)):             # <<<<<<<<<<<<<<
 *             raise ValueError(u"Non-native byte order not supported")
 *             # One could encode it in the format string and have Cython
 */
      __pyx_t_6 = (__pyx_v_child->byteorder == '<');
      if (__pyx_t_6) {
        __pyx_t_8 = (!__pyx_v_little_endian);
        __pyx_t_9 = __pyx_t_8;
      } else {
        __pyx_t_9 = __pyx_t_6;
      }
      __pyx_t_6 = __pyx_t_9;
    } else {
      __pyx_t_6 = __pyx_t_7;
    }
    if (__pyx_t_6) {

      /* "numpy.pxd":802
 *         if ((child.byteorder == '>' and little_endian) or
 *             (child.byteorder == '<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_68), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "numpy.pxd":812
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    while (1) {
      __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_6) break;

      /* "numpy.pxd":813
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      (__pyx_v_f[0]) = 120;

      /* "numpy.pxd":814
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "numpy.pxd":815
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __pyx_t_10 = 0;
      (__pyx_v_offset[__pyx_t_10]) = ((__pyx_v_offset[__pyx_t_10]) + 1);
    }

    /* "numpy.pxd":817
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __pyx_t_10 = 0;
    (__pyx_v_offset[__pyx_t_10]) = ((__pyx_v_offset[__pyx_t_10]) + __pyx_v_child->elsize);

    /* "numpy.pxd":819
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __pyx_t_6 = (!PyDataType_HASFIELDS(__pyx_v_child));
    if (__pyx_t_6) {

      /* "numpy.pxd":820
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_v_t);
      __pyx_v_t = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "numpy.pxd":821
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __pyx_t_6 = ((__pyx_v_end - __pyx_v_f) < 5);
      if (__pyx_t_6) {

        /* "numpy.pxd":822
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
        __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_70), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "numpy.pxd":825
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L11;
      }

      /* "numpy.pxd":826
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"             # <<<<<<<<<<<<<<
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L11;
      }

      /* "numpy.pxd":827
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"             # <<<<<<<<<<<<<<
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 104;
        goto __pyx_L11;
      }

      /* "numpy.pxd":828
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"             # <<<<<<<<<<<<<<
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L11;
      }

      /* "numpy.pxd":829
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 105;
        goto __pyx_L11;
      }

      /* "numpy.pxd":830
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L11;
      }

      /* "numpy.pxd":831
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 108;
        goto __pyx_L11;
      }

      /* "numpy.pxd":832
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L11;
      }

      /* "numpy.pxd":833
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 113;
        goto __pyx_L11;
      }

      /* "numpy.pxd":834
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L11;
      }

      /* "numpy.pxd":835
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"             # <<<<<<<<<<<<<<
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 102;
        goto __pyx_L11;
      }

      /* "numpy.pxd":836
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 */
      __pyx_t_5 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 100;
        goto __pyx_L11;
      }

      /* "numpy.pxd":837
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"             # <<<<<<<<<<<<<<
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 */
      __pyx_t_3 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 103;
        goto __pyx_L11;
      }

      /* "numpy.pxd":838
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf             # <<<<<<<<<<<<<<
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 */
      __pyx_t_5 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 102;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L11;
      }

      /* "numpy.pxd":839
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd             # <<<<<<<<<<<<<<
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 100;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L11;
      }

      /* "numpy.pxd":840
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg             # <<<<<<<<<<<<<<
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 */
      __pyx_t_5 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 103;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L11;
      }

      /* "numpy.pxd":841
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __pyx_t_3 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L11;
      }
      /*else*/ {

        /* "numpy.pxd":843
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_65), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_5));
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
        __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
        __Pyx_Raise(__pyx_t_5, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_L11:;

      /* "numpy.pxd":844
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __pyx_v_f = (__pyx_v_f + 1);
      goto __pyx_L9;
    }
    /*else*/ {

      /* "numpy.pxd":848
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
      __pyx_t_11 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_f = __pyx_t_11;
    }
    __pyx_L9:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "numpy.pxd":849
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_childname);
  __Pyx_XDECREF(__pyx_v_new_offset);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":964
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  PyObject *__pyx_v_baseptr;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "numpy.pxd":966
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __pyx_t_1 = (__pyx_v_base == Py_None);
  if (__pyx_t_1) {

    /* "numpy.pxd":967
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __pyx_v_baseptr = NULL;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "numpy.pxd":969
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
    Py_INCREF(__pyx_v_base);

    /* "numpy.pxd":970
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "numpy.pxd":971
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  Py_XDECREF(__pyx_v_arr->base);

  /* "numpy.pxd":972
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __pyx_v_arr->base = __pyx_v_baseptr;

  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":974
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "numpy.pxd":975
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __pyx_t_1 = (__pyx_v_arr->base == NULL);
  if (__pyx_t_1) {

    /* "numpy.pxd":976
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "numpy.pxd":978
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_14GatSegmentList_SegmentList __pyx_vtable_14GatSegmentList_SegmentList;

static PyObject *__pyx_tp_new_14GatSegmentList_SegmentList(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_14GatSegmentList_SegmentList *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_14GatSegmentList_SegmentList *)o);
  p->__pyx_vtab = __pyx_vtabptr_14GatSegmentList_SegmentList;
  p->key = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_14GatSegmentList_SegmentList(PyObject *o) {
  struct __pyx_obj_14GatSegmentList_SegmentList *p = (struct __pyx_obj_14GatSegmentList_SegmentList *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_14GatSegmentList_11SegmentList_69__dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->key);
  (*Py_TYPE(o)->tp_free)(o);
}

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

static int __pyx_tp_clear_14GatSegmentList_SegmentList(PyObject *o) {
  struct __pyx_obj_14GatSegmentList_SegmentList *p = (struct __pyx_obj_14GatSegmentList_SegmentList *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->key);
  p->key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}
static PyObject *__pyx_sq_item_14GatSegmentList_SegmentList(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static PyObject *__pyx_getprop_14GatSegmentList_11SegmentList_isNormalized(PyObject *o, void *x) {
  return __pyx_pw_14GatSegmentList_11SegmentList_12isNormalized_1__get__(o);
}

static PyObject *__pyx_getprop_14GatSegmentList_11SegmentList_statusflag(PyObject *o, void *x) {
  return __pyx_pw_14GatSegmentList_11SegmentList_10statusflag_1__get__(o);
}

static PyObject *__pyx_getprop_14GatSegmentList_11SegmentList_isEmpty(PyObject *o, void *x) {
  return __pyx_pw_14GatSegmentList_11SegmentList_7isEmpty_1__get__(o);
}

static PyMethodDef __pyx_methods_14GatSegmentList_SegmentList[] = {
  {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_3__reduce__, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_2__reduce__)},
  {__Pyx_NAMESTR("share"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_5share, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_4share)},
  {__Pyx_NAMESTR("unshare"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_7unshare, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_6unshare)},
  {__Pyx_NAMESTR("sort"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_9sort, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_8sort)},
  {__Pyx_NAMESTR("extend"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_11extend, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_10extend)},
  {__Pyx_NAMESTR("add"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_13add, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_12add)},
  {__Pyx_NAMESTR("trim_ends"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_15trim_ends, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_14trim_ends)},
  {__Pyx_NAMESTR("trim"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_17trim, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_16trim)},
  {__Pyx_NAMESTR("normalize"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_19normalize, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_18normalize)},
  {__Pyx_NAMESTR("merge"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_21merge, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_20merge)},
  {__Pyx_NAMESTR("check"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_23check, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_22check)},
  {__Pyx_NAMESTR("getInsertionPoint"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_25getInsertionPoint, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_24getInsertionPoint)},
  {__Pyx_NAMESTR("getRandomPosition"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_27getRandomPosition, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_26getRandomPosition)},
  {__Pyx_NAMESTR("overlapWithRange"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_29overlapWithRange, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_28overlapWithRange)},
  {__Pyx_NAMESTR("getOverlappingSegmentsWithRange"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_31getOverlappingSegmentsWithRange, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_30getOverlappingSegmentsWithRange)},
  {__Pyx_NAMESTR("overlapWithSegments"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_33overlapWithSegments, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_32overlapWithSegments)},
  {__Pyx_NAMESTR("intersectionWithSegments"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_35intersectionWithSegments, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_34intersectionWithSegments)},
  {__Pyx_NAMESTR("getLengthDistribution"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_37getLengthDistribution, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_36getLengthDistribution)},
  {__Pyx_NAMESTR("subtract"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_39subtract, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_38subtract)},
  {__Pyx_NAMESTR("summarize"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_41summarize, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_40summarize)},
  {__Pyx_NAMESTR("getFilledSegmentsFromStart"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_43getFilledSegmentsFromStart, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_42getFilledSegmentsFromStart)},
  {__Pyx_NAMESTR("getFilledSegmentsFromEnd"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_45getFilledSegmentsFromEnd, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_44getFilledSegmentsFromEnd)},
  {__Pyx_NAMESTR("filter"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_47filter, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_46filter)},
  {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_49intersect, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_48intersect)},
  {__Pyx_NAMESTR("extend_segments"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_51extend_segments, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_50extend_segments)},
  {__Pyx_NAMESTR("expand_segments"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_53expand_segments, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_52expand_segments)},
  {__Pyx_NAMESTR("shift"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_55shift, METH_O, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_54shift)},
  {__Pyx_NAMESTR("sum"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_57sum, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_56sum)},
  {__Pyx_NAMESTR("largest"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_59largest, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_58largest)},
  {__Pyx_NAMESTR("max"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_61max, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_60max)},
  {__Pyx_NAMESTR("min"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_63min, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_62min)},
  {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_65clear, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_64clear)},
  {__Pyx_NAMESTR("asList"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_73asList, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_72asList)},
  {__Pyx_NAMESTR("asLengths"), (PyCFunction)__pyx_pw_14GatSegmentList_11SegmentList_75asLengths, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_14GatSegmentList_11SegmentList_74asLengths)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_14GatSegmentList_SegmentList[] = {
  {(char *)"isNormalized", __pyx_getprop_14GatSegmentList_11SegmentList_isNormalized, 0, 0, 0},
  {(char *)"statusflag", __pyx_getprop_14GatSegmentList_11SegmentList_statusflag, 0, 0, 0},
  {(char *)"isEmpty", __pyx_getprop_14GatSegmentList_11SegmentList_isEmpty, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_SegmentList = {
  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_SegmentList = {
  __pyx_pw_14GatSegmentList_11SegmentList_67__len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_14GatSegmentList_SegmentList, /*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_SegmentList = {
  __pyx_pw_14GatSegmentList_11SegmentList_67__len__, /*mp_length*/
  __pyx_pw_14GatSegmentList_11SegmentList_79__getitem__, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_SegmentList = {
  #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_14GatSegmentList_SegmentList = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("GatSegmentList.SegmentList"), /*tp_name*/
  sizeof(struct __pyx_obj_14GatSegmentList_SegmentList), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_14GatSegmentList_SegmentList, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  __pyx_pw_14GatSegmentList_11SegmentList_81__cmp__, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_SegmentList, /*tp_as_number*/
  &__pyx_tp_as_sequence_SegmentList, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_SegmentList, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_14GatSegmentList_11SegmentList_71__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_SegmentList, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("SegmentList(int allocate=0, SegmentList clone=None, iter=None, normalize=False, SegmentList share=None, unreduce=None)\nlist of segments.\n\n    A list of (non-overlapping) segments.\n\n    The intersection algorithms assume that segments\n    are non-overlapping and sorted by start.\n\n    Call normalize to merge overlapping segments.\n    "), /*tp_doc*/
  __pyx_tp_traverse_14GatSegmentList_SegmentList, /*tp_traverse*/
  __pyx_tp_clear_14GatSegmentList_SegmentList, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_14GatSegmentList_11SegmentList_77__iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_14GatSegmentList_SegmentList, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_14GatSegmentList_SegmentList, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_14GatSegmentList_11SegmentList_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_14GatSegmentList_SegmentList, /*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 PyObject *__pyx_tp_new_14GatSegmentList_SegmentListIterator(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_14GatSegmentList_SegmentListIterator *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_14GatSegmentList_SegmentListIterator *)o);
  p->segment_list = ((struct __pyx_obj_14GatSegmentList_SegmentList *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_14GatSegmentList_SegmentListIterator(PyObject *o) {
  struct __pyx_obj_14GatSegmentList_SegmentListIterator *p = (struct __pyx_obj_14GatSegmentList_SegmentListIterator *)o;
  Py_XDECREF(((PyObject *)p->segment_list));
  (*Py_TYPE(o)->tp_free)(o);
}

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

static int __pyx_tp_clear_14GatSegmentList_SegmentListIterator(PyObject *o) {
  struct __pyx_obj_14GatSegmentList_SegmentListIterator *p = (struct __pyx_obj_14GatSegmentList_SegmentListIterator *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->segment_list);
  p->segment_list = ((struct __pyx_obj_14GatSegmentList_SegmentList *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_14GatSegmentList_SegmentListIterator[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_14GatSegmentList_19SegmentListIterator_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_SegmentListIterator = {
  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_SegmentListIterator = {
  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_SegmentListIterator = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_SegmentListIterator = {
  #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_14GatSegmentList_SegmentListIterator = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("GatSegmentList.SegmentListIterator"), /*tp_name*/
  sizeof(struct __pyx_obj_14GatSegmentList_SegmentListIterator), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_14GatSegmentList_SegmentListIterator, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_SegmentListIterator, /*tp_as_number*/
  &__pyx_tp_as_sequence_SegmentListIterator, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_SegmentListIterator, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_SegmentListIterator, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("SegmentListIterator(SegmentList container)"), /*tp_doc*/
  __pyx_tp_traverse_14GatSegmentList_SegmentListIterator, /*tp_traverse*/
  __pyx_tp_clear_14GatSegmentList_SegmentListIterator, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_14GatSegmentList_19SegmentListIterator_3__iter__, /*tp_iter*/
  __pyx_pw_14GatSegmentList_19SegmentListIterator_5__next__, /*tp_iternext*/
  __pyx_methods_14GatSegmentList_SegmentListIterator, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_14GatSegmentList_19SegmentListIterator_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_14GatSegmentList_SegmentListIterator, /*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("GatSegmentList"),
    0, /* 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_10, __pyx_k_10, sizeof(__pyx_k_10), 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_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
  {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 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_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
  {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
  {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0},
  {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
  {&__pyx_kp_s_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0},
  {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 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_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
  {&__pyx_n_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 1},
  {&__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_n_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 1},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0},
  {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
  {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0},
  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
  {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0},
  {&__pyx_n_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 1},
  {&__pyx_n_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 1},
  {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 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_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
  {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0},
  {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0},
  {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0},
  {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0},
  {&__pyx_kp_u_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 1, 0, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_u_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 1, 0, 0},
  {&__pyx_kp_u_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 1, 0, 0},
  {&__pyx_kp_u_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 1, 0, 0},
  {&__pyx_kp_u_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 1, 0, 0},
  {&__pyx_kp_u_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 1, 0, 0},
  {&__pyx_kp_s_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 1, 0},
  {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__DTYPE_FLOAT, __pyx_k__DTYPE_FLOAT, sizeof(__pyx_k__DTYPE_FLOAT), 0, 0, 1, 1},
  {&__pyx_n_s__DTYPE_INT, __pyx_k__DTYPE_INT, sizeof(__pyx_k__DTYPE_INT), 0, 0, 1, 1},
  {&__pyx_n_s__GatSegmentList, __pyx_k__GatSegmentList, sizeof(__pyx_k__GatSegmentList), 0, 0, 1, 1},
  {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1},
  {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1},
  {&__pyx_n_s__OSError, __pyx_k__OSError, sizeof(__pyx_k__OSError), 0, 0, 1, 1},
  {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s____cmp__, __pyx_k____cmp__, sizeof(__pyx_k____cmp__), 0, 0, 1, 1},
  {&__pyx_n_s____len__, __pyx_k____len__, sizeof(__pyx_k____len__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s__add, __pyx_k__add, sizeof(__pyx_k__add), 0, 0, 1, 1},
  {&__pyx_n_s__allocate, __pyx_k__allocate, sizeof(__pyx_k__allocate), 0, 0, 1, 1},
  {&__pyx_n_s__args, __pyx_k__args, sizeof(__pyx_k__args), 0, 0, 1, 1},
  {&__pyx_n_s__asList, __pyx_k__asList, sizeof(__pyx_k__asList), 0, 0, 1, 1},
  {&__pyx_n_s__base, __pyx_k__base, sizeof(__pyx_k__base), 0, 0, 1, 1},
  {&__pyx_n_s__bucket_size, __pyx_k__bucket_size, sizeof(__pyx_k__bucket_size), 0, 0, 1, 1},
  {&__pyx_n_s__buildSegmentList, __pyx_k__buildSegmentList, sizeof(__pyx_k__buildSegmentList), 0, 0, 1, 1},
  {&__pyx_n_s__ceil, __pyx_k__ceil, sizeof(__pyx_k__ceil), 0, 0, 1, 1},
  {&__pyx_n_s__check, __pyx_k__check, sizeof(__pyx_k__check), 0, 0, 1, 1},
  {&__pyx_n_s__clear, __pyx_k__clear, sizeof(__pyx_k__clear), 0, 0, 1, 1},
  {&__pyx_n_s__clone, __pyx_k__clone, sizeof(__pyx_k__clone), 0, 0, 1, 1},
  {&__pyx_n_s__collections, __pyx_k__collections, sizeof(__pyx_k__collections), 0, 0, 1, 1},
  {&__pyx_n_s__container, __pyx_k__container, sizeof(__pyx_k__container), 0, 0, 1, 1},
  {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1},
  {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
  {&__pyx_n_s__expand_segments, __pyx_k__expand_segments, sizeof(__pyx_k__expand_segments), 0, 0, 1, 1},
  {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1},
  {&__pyx_n_s__extend_segments, __pyx_k__extend_segments, sizeof(__pyx_k__extend_segments), 0, 0, 1, 1},
  {&__pyx_n_s__filter, __pyx_k__filter, sizeof(__pyx_k__filter), 0, 0, 1, 1},
  {&__pyx_n_s__float, __pyx_k__float, sizeof(__pyx_k__float), 0, 0, 1, 1},
  {&__pyx_n_s__forward, __pyx_k__forward, sizeof(__pyx_k__forward), 0, 0, 1, 1},
  {&__pyx_n_s__getInsertionPoint, __pyx_k__getInsertionPoint, sizeof(__pyx_k__getInsertionPoint), 0, 0, 1, 1},
  {&__pyx_n_s__getRandomPosition, __pyx_k__getRandomPosition, sizeof(__pyx_k__getRandomPosition), 0, 0, 1, 1},
  {&__pyx_n_s__getSegmentSize, __pyx_k__getSegmentSize, sizeof(__pyx_k__getSegmentSize), 0, 0, 1, 1},
  {&__pyx_n_s__int, __pyx_k__int, sizeof(__pyx_k__int), 0, 0, 1, 1},
  {&__pyx_n_s__intersect, __pyx_k__intersect, sizeof(__pyx_k__intersect), 0, 0, 1, 1},
  {&__pyx_n_s__iter, __pyx_k__iter, sizeof(__pyx_k__iter), 0, 0, 1, 1},
  {&__pyx_n_s__largest, __pyx_k__largest, sizeof(__pyx_k__largest), 0, 0, 1, 1},
  {&__pyx_n_s__math, __pyx_k__math, sizeof(__pyx_k__math), 0, 0, 1, 1},
  {&__pyx_n_s__max, __pyx_k__max, sizeof(__pyx_k__max), 0, 0, 1, 1},
  {&__pyx_n_s__merge, __pyx_k__merge, sizeof(__pyx_k__merge), 0, 0, 1, 1},
  {&__pyx_n_s__midpoint, __pyx_k__midpoint, sizeof(__pyx_k__midpoint), 0, 0, 1, 1},
  {&__pyx_n_s__min, __pyx_k__min, sizeof(__pyx_k__min), 0, 0, 1, 1},
  {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
  {&__pyx_n_s__nbuckets, __pyx_k__nbuckets, sizeof(__pyx_k__nbuckets), 0, 0, 1, 1},
  {&__pyx_n_s__normalize, __pyx_k__normalize, sizeof(__pyx_k__normalize), 0, 0, 1, 1},
  {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1},
  {&__pyx_n_s__os, __pyx_k__os, sizeof(__pyx_k__os), 0, 0, 1, 1},
  {&__pyx_n_s__other, __pyx_k__other, sizeof(__pyx_k__other), 0, 0, 1, 1},
  {&__pyx_n_s__overlapWithRange, __pyx_k__overlapWithRange, sizeof(__pyx_k__overlapWithRange), 0, 0, 1, 1},
  {&__pyx_n_s__overlapWithSegments, __pyx_k__overlapWithSegments, sizeof(__pyx_k__overlapWithSegments), 0, 0, 1, 1},
  {&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1},
  {&__pyx_n_s__randint, __pyx_k__randint, sizeof(__pyx_k__randint), 0, 0, 1, 1},
  {&__pyx_n_s__random, __pyx_k__random, sizeof(__pyx_k__random), 0, 0, 1, 1},
  {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
  {&__pyx_n_s__re, __pyx_k__re, sizeof(__pyx_k__re), 0, 0, 1, 1},
  {&__pyx_n_s__remainder, __pyx_k__remainder, sizeof(__pyx_k__remainder), 0, 0, 1, 1},
  {&__pyx_n_s__share, __pyx_k__share, sizeof(__pyx_k__share), 0, 0, 1, 1},
  {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1},
  {&__pyx_n_s__sort, __pyx_k__sort, sizeof(__pyx_k__sort), 0, 0, 1, 1},
  {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1},
  {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1},
  {&__pyx_n_s__subtract, __pyx_k__subtract, sizeof(__pyx_k__subtract), 0, 0, 1, 1},
  {&__pyx_n_s__sum, __pyx_k__sum, sizeof(__pyx_k__sum), 0, 0, 1, 1},
  {&__pyx_n_s__summarize, __pyx_k__summarize, sizeof(__pyx_k__summarize), 0, 0, 1, 1},
  {&__pyx_n_s__trim, __pyx_k__trim, sizeof(__pyx_k__trim), 0, 0, 1, 1},
  {&__pyx_n_s__trim_ends, __pyx_k__trim_ends, sizeof(__pyx_k__trim_ends), 0, 0, 1, 1},
  {&__pyx_n_s__types, __pyx_k__types, sizeof(__pyx_k__types), 0, 0, 1, 1},
  {&__pyx_n_s__unreduce, __pyx_k__unreduce, sizeof(__pyx_k__unreduce), 0, 0, 1, 1},
  {&__pyx_n_s__zeros, __pyx_k__zeros, sizeof(__pyx_k__zeros), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 227; __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[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "GatSegmentList.pyx":286
 *         '''
 *         assert self.flag & SEG_NORMALIZED, "sharing in non-normalized list"
 *         assert key.startswith( "/" )             # <<<<<<<<<<<<<<
 *         assert self.shared_fd == -1, "SegmentList already shared"
 *         cdef int error
 */
  __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_7);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
  PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_s_6));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7));

  /* "GatSegmentList.pyx":316
 * 
 *         if p == MAP_FAILED:
 *             raise ValueError("could not create memory mapped file" )             # <<<<<<<<<<<<<<
 * 
 *         # copy data to shared memory location
 */
  __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__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));

  /* "GatSegmentList.pyx":341
 * 
 *         if self.shared_fd == -1:
 *             raise ValueError("unsharing unshared SegmentList")             # <<<<<<<<<<<<<<
 * 
 *         fd = shm_unlink( self.key )
 */
  __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_14);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
  PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));

  /* "GatSegmentList.pyx":345
 *         fd = shm_unlink( self.key )
 *         if fd == -1:
 *             raise OSError( "could not unlink shared memory" )             # <<<<<<<<<<<<<<
 * 
 *         # copy data back to unshared memory
 */
  __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_16);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_15));
  PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_kp_s_15));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16));

  /* "GatSegmentList.pyx":352
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:
 *             raise ValueError( "could not allocate memory when unsharing" )             # <<<<<<<<<<<<<<
 * 
 *         memcpy( s, self.segments, nbytes )
 */
  __pyx_k_tuple_18 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_18);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
  PyTuple_SET_ITEM(__pyx_k_tuple_18, 0, ((PyObject *)__pyx_kp_s_17));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18));

  /* "GatSegmentList.pyx":358
 *         # unmap
 *         if munmap( self.segments, nbytes ) == -1:
 *             raise ValueError( "error while unmapping memory")             # <<<<<<<<<<<<<<
 * 
 *         self.segments = s
 */
  __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__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));

  /* "GatSegmentList.pyx":377
 *         s = <Segment *>malloc( nbytes )
 *         if s == NULL:
 *             raise ValueError( "could not allocate memory when unsharing" )             # <<<<<<<<<<<<<<
 * 
 *         memcpy( s, self.segments, nbytes )
 */
  __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_21);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
  PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_17));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21));

  /* "GatSegmentList.pyx":393
 *         '''
 *         if self.shared_fd != -1:
 *             raise ValueError("can not move shared segmentlist to mmap")             # <<<<<<<<<<<<<<
 * 
 *         if self.nsegments == 0:
 */
  __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_23);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
  PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_22));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));

  /* "GatSegmentList.pyx":1146
 * 
 *         if self.nsegments == 0:
 *             return 0, 0, 0, 0             # <<<<<<<<<<<<<<
 * 
 *         # TODO: use maximum integer for Position
 */
  __pyx_k_tuple_45 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_45);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 2, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 3, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));

  /* "GatSegmentList.pyx":1444
 *             s.end += offset
 *             s.start += offset
 *             if s.start < 0: raise ValueError( "shift creates negative coordinates" )             # <<<<<<<<<<<<<<
 * 
 *     cpdef Position sum( self ):
 */
  __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_51);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
  PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_50));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51));

  /* "GatSegmentList.pyx":1463
 *         will be returned.
 *         '''
 *         if self.nsegments == 0: raise ValueError( "largest segment from empty list" )             # <<<<<<<<<<<<<<
 *         cdef int idx
 *         cdef int max_idx = 0
 */
  __pyx_k_tuple_53 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_53);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_52));
  PyTuple_SET_ITEM(__pyx_k_tuple_53, 0, ((PyObject *)__pyx_kp_s_52));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_52));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53));

  /* "GatSegmentList.pyx":1518
 *             fd = shm_unlink( self.key )
 *             if fd == -1:
 *                 raise OSError( "could not unlink shared memory" )             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_k_tuple_56 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_56);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_15));
  PyTuple_SET_ITEM(__pyx_k_tuple_56, 0, ((PyObject *)__pyx_kp_s_15));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56));

  /* "GatSegmentList.pyx":1543
 *     def __getitem__(self, key ):
 *         if key >= self.nsegments:
 *             raise IndexError( "index out of range" )             # <<<<<<<<<<<<<<
 *         return self.segments[key].start, self.segments[key].end
 * 
 */
  __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_58);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_57));
  PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_kp_s_57));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_57));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58));

  /* "numpy.pxd":214
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
  __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_60);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_59));
  PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_u_59));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_59));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60));

  /* "numpy.pxd":218
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
  __pyx_k_tuple_62 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_62)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_62);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_61));
  PyTuple_SET_ITEM(__pyx_k_tuple_62, 0, ((PyObject *)__pyx_kp_u_61));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_61));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_62));

  /* "numpy.pxd":256
 *                 if ((descr.byteorder == '>' and little_endian) or
 *                     (descr.byteorder == '<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
  __pyx_k_tuple_64 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_64)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_64);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_63));
  PyTuple_SET_ITEM(__pyx_k_tuple_64, 0, ((PyObject *)__pyx_kp_u_63));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_63));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_64));

  /* "numpy.pxd":798
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == '>' and little_endian) or
 */
  __pyx_k_tuple_67 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_67);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_66));
  PyTuple_SET_ITEM(__pyx_k_tuple_67, 0, ((PyObject *)__pyx_kp_u_66));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_66));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));

  /* "numpy.pxd":802
 *         if ((child.byteorder == '>' and little_endian) or
 *             (child.byteorder == '<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
  __pyx_k_tuple_68 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_68)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_68);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_63));
  PyTuple_SET_ITEM(__pyx_k_tuple_68, 0, ((PyObject *)__pyx_kp_u_63));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_63));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_68));

  /* "numpy.pxd":822
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
  __pyx_k_tuple_70 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_70)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_70);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_69));
  PyTuple_SET_ITEM(__pyx_k_tuple_70, 0, ((PyObject *)__pyx_kp_u_69));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_69));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_70));

  /* "GatSegmentList.pyx":26
 * ctypedef numpy.float_t DTYPE_FLOAT_t
 * 
 * def getSegmentSize():             # <<<<<<<<<<<<<<
 *     '''return size of coordinate and size of a segment.'''
 *     return sizeof(Segment) // 2, sizeof(Segment)
 */
  __pyx_k_codeobj_71 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_72, __pyx_n_s__getSegmentSize, 26, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "GatSegmentList.pyx":1555
 *         return 0
 * 
 * def buildSegmentList( *args ):             # <<<<<<<<<<<<<<
 *     '''pickling helper function.
 * 
 */
  __pyx_k_tuple_73 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_73);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_73, 1, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73));
  __pyx_k_codeobj_74 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_72, __pyx_n_s__buildSegmentList, 1555, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_74)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __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;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_100000 = PyInt_FromLong(100000); if (unlikely(!__pyx_int_100000)) {__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 initGatSegmentList(void); /*proto*/
PyMODINIT_FUNC initGatSegmentList(void)
#else
PyMODINIT_FUNC PyInit_GatSegmentList(void); /*proto*/
PyMODINIT_FUNC PyInit_GatSegmentList(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_GatSegmentList(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_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("GatSegmentList"), __pyx_methods, 0, 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_GatSegmentList) {
    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 ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_ptype_14GatSegmentList_file = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "file", sizeof(PyFileObject), 0); if (unlikely(!__pyx_ptype_14GatSegmentList_file)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_14GatSegmentList_SegmentList = &__pyx_vtable_14GatSegmentList_SegmentList;
  __pyx_vtable_14GatSegmentList_SegmentList.share = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, PyObject *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_share;
  __pyx_vtable_14GatSegmentList_SegmentList.sort = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_sort;
  __pyx_vtable_14GatSegmentList_SegmentList.extend = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_extend;
  __pyx_vtable_14GatSegmentList_SegmentList.add = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_add;
  __pyx_vtable_14GatSegmentList_SegmentList.trim_ends = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_trim_ends;
  __pyx_vtable_14GatSegmentList_SegmentList.trim = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_trim;
  __pyx_vtable_14GatSegmentList_SegmentList.normalize = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_normalize;
  __pyx_vtable_14GatSegmentList_SegmentList.merge = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_PositionDifference, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_merge;
  __pyx_vtable_14GatSegmentList_SegmentList.check = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_check;
  __pyx_vtable_14GatSegmentList_SegmentList.getRandomPosition = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_getRandomPosition;
  __pyx_vtable_14GatSegmentList_SegmentList.overlapWithRange = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_overlapWithRange;
  __pyx_vtable_14GatSegmentList_SegmentList.getOverlappingSegmentsWithRange = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_Position, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_getOverlappingSegmentsWithRange;
  __pyx_vtable_14GatSegmentList_SegmentList.overlapWithSegments = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_overlapWithSegments;
  __pyx_vtable_14GatSegmentList_SegmentList.intersectionWithSegments = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch, struct __pyx_opt_args_14GatSegmentList_11SegmentList_intersectionWithSegments *__pyx_optional_args))__pyx_f_14GatSegmentList_11SegmentList_intersectionWithSegments;
  __pyx_vtable_14GatSegmentList_SegmentList.getFilledSegmentsFromStart = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_PositionDifference, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_getFilledSegmentsFromStart;
  __pyx_vtable_14GatSegmentList_SegmentList.getFilledSegmentsFromEnd = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, __pyx_t_14GatSegmentList_Position, __pyx_t_14GatSegmentList_PositionDifference, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_getFilledSegmentsFromEnd;
  __pyx_vtable_14GatSegmentList_SegmentList.filter = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_filter;
  __pyx_vtable_14GatSegmentList_SegmentList.intersect = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_intersect;
  __pyx_vtable_14GatSegmentList_SegmentList.subtract = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_subtract;
  __pyx_vtable_14GatSegmentList_SegmentList.extend_segments = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_extend_segments;
  __pyx_vtable_14GatSegmentList_SegmentList.expand_segments = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, double, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_expand_segments;
  __pyx_vtable_14GatSegmentList_SegmentList.sum = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_sum;
  __pyx_vtable_14GatSegmentList_SegmentList.max = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_max;
  __pyx_vtable_14GatSegmentList_SegmentList.min = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_min;
  __pyx_vtable_14GatSegmentList_SegmentList.clear = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_clear;
  __pyx_vtable_14GatSegmentList_SegmentList.summarize = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int __pyx_skip_dispatch))__pyx_f_14GatSegmentList_11SegmentList_summarize;
  __pyx_vtable_14GatSegmentList_SegmentList._add = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment))__pyx_f_14GatSegmentList_11SegmentList__add;
  __pyx_vtable_14GatSegmentList_SegmentList._resize = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int))__pyx_f_14GatSegmentList_11SegmentList__resize;
  __pyx_vtable_14GatSegmentList_SegmentList.insert = (PyObject *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, int, struct __pyx_t_14GatSegmentList_Segment))__pyx_f_14GatSegmentList_11SegmentList_insert;
  __pyx_vtable_14GatSegmentList_SegmentList._getInsertionPoint = (int (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment))__pyx_f_14GatSegmentList_11SegmentList__getInsertionPoint;
  __pyx_vtable_14GatSegmentList_SegmentList.overlap = (__pyx_t_14GatSegmentList_Position (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment))__pyx_f_14GatSegmentList_11SegmentList_overlap;
  __pyx_vtable_14GatSegmentList_SegmentList.getOverlappingSegments = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment))__pyx_f_14GatSegmentList_11SegmentList_getOverlappingSegments;
  __pyx_vtable_14GatSegmentList_SegmentList.truncate = (struct __pyx_obj_14GatSegmentList_SegmentList *(*)(struct __pyx_obj_14GatSegmentList_SegmentList *, struct __pyx_t_14GatSegmentList_Segment))__pyx_f_14GatSegmentList_11SegmentList_truncate;
  __pyx_vtable_14GatSegmentList_SegmentList.toMMAP = (off_t (*)(struct __pyx_obj_14GatSegmentList_SegmentList *, void *, int, off_t))__pyx_f_14GatSegmentList_11SegmentList_toMMAP;
  __pyx_vtable_14GatSegmentList_SegmentList.fromMMAP = (void (*)(struct __pyx_obj_14GatSegmentList_SegmentList *))__pyx_f_14GatSegmentList_11SegmentList_fromMMAP;
  if (PyType_Ready(&__pyx_type_14GatSegmentList_SegmentList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_14GatSegmentList_SegmentList, "__init__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_14GatSegmentList_11SegmentList___init__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_14GatSegmentList_11SegmentList___init__.doc = __pyx_doc_14GatSegmentList_11SegmentList___init__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_14GatSegmentList_11SegmentList___init__;
    }
  }
  if (__Pyx_SetVtable(__pyx_type_14GatSegmentList_SegmentList.tp_dict, __pyx_vtabptr_14GatSegmentList_SegmentList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "SegmentList", (PyObject *)&__pyx_type_14GatSegmentList_SegmentList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_14GatSegmentList_SegmentList = &__pyx_type_14GatSegmentList_SegmentList;
  if (PyType_Ready(&__pyx_type_14GatSegmentList_SegmentListIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "SegmentListIterator", (PyObject *)&__pyx_type_14GatSegmentList_SegmentListIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_14GatSegmentList_SegmentListIterator = &__pyx_type_14GatSegmentList_SegmentListIterator;
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "GatSegmentList.pyx":4
 * # cython: profile=False
 * 
 * import types, collections, re, os, math, random             # <<<<<<<<<<<<<<
 * 
 * from cpython cimport PyString_AsString, PyString_FromStringAndSize
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__types), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__types, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__collections), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__collections, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__re), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__re, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__os), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__os, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__math), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__math, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__random), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__random, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":19
 * ## both import and cimport are necessary
 * #####################################################
 * import numpy             # <<<<<<<<<<<<<<
 * cimport numpy
 * DTYPE_INT = numpy.int
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__numpy, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":21
 * import numpy
 * cimport numpy
 * DTYPE_INT = numpy.int             # <<<<<<<<<<<<<<
 * ctypedef numpy.int_t DTYPE_INT_t
 * DTYPE_FLOAT = numpy.float
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__int); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DTYPE_INT, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "GatSegmentList.pyx":23
 * DTYPE_INT = numpy.int
 * ctypedef numpy.int_t DTYPE_INT_t
 * DTYPE_FLOAT = numpy.float             # <<<<<<<<<<<<<<
 * ctypedef numpy.float_t DTYPE_FLOAT_t
 * 
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__float); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DTYPE_FLOAT, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":26
 * ctypedef numpy.float_t DTYPE_FLOAT_t
 * 
 * def getSegmentSize():             # <<<<<<<<<<<<<<
 *     '''return size of coordinate and size of a segment.'''
 *     return sizeof(Segment) // 2, sizeof(Segment)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14GatSegmentList_1getSegmentSize, NULL, __pyx_n_s__GatSegmentList); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__getSegmentSize, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":111
 *                  SegmentList clone = None,
 *                  iter = None,
 *                  normalize = False,             # <<<<<<<<<<<<<<
 *                  SegmentList share = None,
 *                  unreduce = None ):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_1 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":1555
 *         return 0
 * 
 * def buildSegmentList( *args ):             # <<<<<<<<<<<<<<
 *     '''pickling helper function.
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14GatSegmentList_3buildSegmentList, NULL, __pyx_n_s__GatSegmentList); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__buildSegmentList, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "GatSegmentList.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=False
 * 
 */
  __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;

  /* "numpy.pxd":974
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    __Pyx_AddTraceback("init GatSegmentList", __pyx_clineno, __pyx_lineno, __pyx_filename);
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init GatSegmentList");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif /* CYTHON_REFNANNY */

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

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_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_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 {
                    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 *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (Py_TYPE(obj) == type) return 1;
    }
    else {
        if (PyObject_TypeCheck(obj, type)) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    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;
    }
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        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, PyObject *cause) {
    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;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        }
        else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        }
        else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        if (!value) {
            value = PyObject_CallObject(type, NULL);
        }
        PyException_SetCause(value, fixed_cause);
    }
    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 CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack",
                 index, (index == 1) ? "" : "s");
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected);
}

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else if (PyErr_Occurred()) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}



static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static CYTHON_INLINE int __Pyx_IsLittleEndian(void) {
  unsigned int n = 1;
  return *(unsigned char*)(&n) != 0;
}
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type) {
  stack[0].field = &ctx->root;
  stack[0].parent_offset = 0;
  ctx->root.type = type;
  ctx->root.name = "buffer dtype";
  ctx->root.offset = 0;
  ctx->head = stack;
  ctx->head->field = &ctx->root;
  ctx->fmt_offset = 0;
  ctx->head->parent_offset = 0;
  ctx->new_packmode = '@';
  ctx->enc_packmode = '@';
  ctx->new_count = 1;
  ctx->enc_count = 0;
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  ctx->is_valid_array = 0;
  ctx->struct_alignment = 0;
  while (type->typegroup == 'S') {
    ++ctx->head;
    ctx->head->field = type->fields;
    ctx->head->parent_offset = 0;
    type = type->fields->type;
  }
}
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
    int count;
    const char* t = *ts;
    if (*t < '0' || *t > '9') {
      return -1;
    } else {
        count = *t++ - '0';
        while (*t >= '0' && *t < '9') {
            count *= 10;
            count += *t++ - '0';
        }
    }
    *ts = t;
    return count;
}
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
    int number = __Pyx_BufFmt_ParseNumber(ts);
    if (number == -1) /* First char was not a digit */
        PyErr_Format(PyExc_ValueError,\
                     "Does not understand character buffer dtype format string ('%c')", **ts);
    return number;
}
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
  PyErr_Format(PyExc_ValueError,
               "Unexpected format string character: '%c'", ch);
}
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
  switch (ch) {
    case 'b': return "'char'";
    case 'B': return "'unsigned char'";
    case 'h': return "'short'";
    case 'H': return "'unsigned short'";
    case 'i': return "'int'";
    case 'I': return "'unsigned int'";
    case 'l': return "'long'";
    case 'L': return "'unsigned long'";
    case 'q': return "'long long'";
    case 'Q': return "'unsigned long long'";
    case 'f': return (is_complex ? "'complex float'" : "'float'");
    case 'd': return (is_complex ? "'complex double'" : "'double'");
    case 'g': return (is_complex ? "'complex long double'" : "'long double'");
    case 'T': return "a struct";
    case 'O': return "Python object";
    case 'P': return "a pointer";
    case 's': case 'p': return "a string";
    case 0: return "end";
    default: return "unparseable format string";
  }
}
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return 2;
    case 'i': case 'I': case 'l': case 'L': return 4;
    case 'q': case 'Q': return 8;
    case 'f': return (is_complex ? 8 : 4);
    case 'd': return (is_complex ? 16 : 8);
    case 'g': {
      PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
      return 0;
    }
    case 'O': case 'P': return sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
  switch (ch) {
    case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(short);
    case 'i': case 'I': return sizeof(int);
    case 'l': case 'L': return sizeof(long);
    #ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(PY_LONG_LONG);
    #endif
    case 'f': return sizeof(float) * (is_complex ? 2 : 1);
    case 'd': return sizeof(double) * (is_complex ? 2 : 1);
    case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
    case 'O': case 'P': return sizeof(void*);
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
typedef struct { char c; short x; } __Pyx_st_short;
typedef struct { char c; int x; } __Pyx_st_int;
typedef struct { char c; long x; } __Pyx_st_long;
typedef struct { char c; float x; } __Pyx_st_float;
typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
/* These are for computing the padding at the end of the struct to align
   on the first member of the struct. This will probably the same as above,
   but we don't have any guarantees.
 */
typedef struct { short x; char c; } __Pyx_pad_short;
typedef struct { int x; char c; } __Pyx_pad_int;
typedef struct { long x; char c; } __Pyx_pad_long;
typedef struct { float x; char c; } __Pyx_pad_float;
typedef struct { double x; char c; } __Pyx_pad_double;
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
typedef struct { void *x; char c; } __Pyx_pad_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
  switch (ch) {
    case 'c': case 'b': case 'h': case 'i':
    case 'l': case 'q': case 's': case 'p':
        return 'I';
    case 'B': case 'H': case 'I': case 'L': case 'Q':
        return 'U';
    case 'f': case 'd': case 'g':
        return (is_complex ? 'C' : 'R');
    case 'O':
        return 'O';
    case 'P':
        return 'P';
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
  if (ctx->head == NULL || ctx->head->field == &ctx->root) {
    const char* expected;
    const char* quote;
    if (ctx->head == NULL) {
      expected = "end";
      quote = "";
    } else {
      expected = ctx->head->field->type->name;
      quote = "'";
    }
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected %s%s%s but got %s",
                 quote, expected, quote,
                 __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
  } else {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_StructField* parent = (ctx->head - 1)->field;
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
                 field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
                 parent->type->name, field->name);
  }
}
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
  char group;
  size_t size, offset, arraysize = 1;
  if (ctx->enc_type == 0) return 0;
  if (ctx->head->field->type->arraysize[0]) {
    int i, ndim = 0;
    if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
        ctx->is_valid_array = ctx->head->field->type->ndim == 1;
        ndim = 1;
        if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
            PyErr_Format(PyExc_ValueError,
                         "Expected a dimension of size %zu, got %zu",
                         ctx->head->field->type->arraysize[0], ctx->enc_count);
            return -1;
        }
    }
    if (!ctx->is_valid_array) {
      PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
                   ctx->head->field->type->ndim, ndim);
      return -1;
    }
    for (i = 0; i < ctx->head->field->type->ndim; i++) {
      arraysize *= ctx->head->field->type->arraysize[i];
    }
    ctx->is_valid_array = 0;
    ctx->enc_count = 1;
  }
  group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
  do {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_TypeInfo* type = field->type;
    if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
      size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
    } else {
      size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
    }
    if (ctx->enc_packmode == '@') {
      size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
      size_t align_mod_offset;
      if (align_at == 0) return -1;
      align_mod_offset = ctx->fmt_offset % align_at;
      if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
      if (ctx->struct_alignment == 0)
          ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
                                                                 ctx->is_complex);
    }
    if (type->size != size || type->typegroup != group) {
      if (type->typegroup == 'C' && type->fields != NULL) {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        ++ctx->head;
        ctx->head->field = type->fields;
        ctx->head->parent_offset = parent_offset;
        continue;
      }
      __Pyx_BufFmt_RaiseExpected(ctx);
      return -1;
    }
    offset = ctx->head->parent_offset + field->offset;
    if (ctx->fmt_offset != offset) {
      PyErr_Format(PyExc_ValueError,
                   "Buffer dtype mismatch; next field is at offset %"PY_FORMAT_SIZE_T"d but %"PY_FORMAT_SIZE_T"d expected",
                   (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
      return -1;
    }
    ctx->fmt_offset += size;
    if (arraysize)
      ctx->fmt_offset += (arraysize - 1) * size;
    --ctx->enc_count; /* Consume from buffer string */
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break; /* breaks both loops as ctx->enc_count == 0 */
      }
      ctx->head->field = ++field;
      if (field->type == NULL) {
        --ctx->head;
        field = ctx->head->field;
        continue;
      } else if (field->type->typegroup == 'S') {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        if (field->type->fields->type == NULL) continue; /* empty struct */
        field = field->type->fields;
        ++ctx->head;
        ctx->head->field = field;
        ctx->head->parent_offset = parent_offset;
        break;
      } else {
        break;
      }
    }
  } while (ctx->enc_count);
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  return 0;
}
static CYTHON_INLINE PyObject *
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
{
    const char *ts = *tsp;
    int i = 0, number;
    int ndim = ctx->head->field->type->ndim;
;
    ++ts;
    if (ctx->new_count != 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Cannot handle repeated arrays in format string");
        return NULL;
    }
    if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
    while (*ts && *ts != ')') {
        if (isspace(*ts))
            continue;
        number = __Pyx_BufFmt_ExpectNumber(&ts);
        if (number == -1) return NULL;
        if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
            return PyErr_Format(PyExc_ValueError,
                        "Expected a dimension of size %zu, got %d",
                        ctx->head->field->type->arraysize[i], number);
        if (*ts != ',' && *ts != ')')
            return PyErr_Format(PyExc_ValueError,
                                "Expected a comma in format string, got '%c'", *ts);
        if (*ts == ',') ts++;
        i++;
    }
    if (i != ndim)
        return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
                            ctx->head->field->type->ndim, i);
    if (!*ts) {
        PyErr_SetString(PyExc_ValueError,
                        "Unexpected end of format string, expected ')'");
        return NULL;
    }
    ctx->is_valid_array = 1;
    ctx->new_count = 1;
    *tsp = ++ts;
    return Py_None;
}
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
  int got_Z = 0;
  while (1) {
    switch(*ts) {
      case 0:
        if (ctx->enc_type != 0 && ctx->head == NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        if (ctx->head != NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
                return ts;
      case ' ':
      case 10:
      case 13:
        ++ts;
        break;
      case '<':
        if (!__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '=':
      case '@':
      case '^':
        ctx->new_packmode = *ts++;
        break;
      case 'T': /* substruct */
        {
          const char* ts_after_sub;
          size_t i, struct_count = ctx->new_count;
          size_t struct_alignment = ctx->struct_alignment;
          ctx->new_count = 1;
          ++ts;
          if (*ts != '{') {
            PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
            return NULL;
          }
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0; /* Erase processed last struct element */
          ctx->enc_count = 0;
          ctx->struct_alignment = 0;
          ++ts;
          ts_after_sub = ts;
          for (i = 0; i != struct_count; ++i) {
            ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
            if (!ts_after_sub) return NULL;
          }
          ts = ts_after_sub;
          if (struct_alignment) ctx->struct_alignment = struct_alignment;
        }
        break;
      case '}': /* end of substruct; either repeat or move on */
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0; /* Erase processed last struct element */
          if (alignment && ctx->fmt_offset % alignment) {
            ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
          }
        }
        return ts;
      case 'x':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->fmt_offset += ctx->new_count;
        ctx->new_count = 1;
        ctx->enc_count = 0;
        ctx->enc_type = 0;
        ctx->enc_packmode = ctx->new_packmode;
        ++ts;
        break;
      case 'Z':
        got_Z = 1;
        ++ts;
        if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
          __Pyx_BufFmt_RaiseUnexpectedChar('Z');
          return NULL;
        }        /* fall through */
      case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
      case 'l': case 'L': case 'q': case 'Q':
      case 'f': case 'd': case 'g':
      case 'O': case 's': case 'p':
        if (ctx->enc_type == *ts && got_Z == ctx->is_complex &&
            ctx->enc_packmode == ctx->new_packmode) {
          ctx->enc_count += ctx->new_count;
        } else {
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_count = ctx->new_count;
          ctx->enc_packmode = ctx->new_packmode;
          ctx->enc_type = *ts;
          ctx->is_complex = got_Z;
        }
        ++ts;
        ctx->new_count = 1;
        got_Z = 0;
        break;
      case ':':
        ++ts;
        while(*ts != ':') ++ts;
        ++ts;
        break;
      case '(':
        if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
        break;
      default:
        {
          int number = __Pyx_BufFmt_ExpectNumber(&ts);
          if (number == -1) return NULL;
          ctx->new_count = (size_t)number;
        }
    }
  }
}
static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
  buf->buf = NULL;
  buf->obj = NULL;
  buf->strides = __Pyx_zeros;
  buf->shape = __Pyx_zeros;
  buf->suboffsets = __Pyx_minusones;
}
static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  if (obj == Py_None || obj == NULL) {
    __Pyx_ZeroBuffer(buf);
    return 0;
  }
  buf->buf = NULL;
  if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail;
  if (buf->ndim != nd) {
    PyErr_Format(PyExc_ValueError,
                 "Buffer has wrong number of dimensions (expected %d, got %d)",
                 nd, buf->ndim);
    goto fail;
  }
  if (!cast) {
    __Pyx_BufFmt_Context ctx;
    __Pyx_BufFmt_Init(&ctx, stack, dtype);
    if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
  }
  if ((unsigned)buf->itemsize != dtype->size) {
    PyErr_Format(PyExc_ValueError,
      "Item size of buffer (%"PY_FORMAT_SIZE_T"d byte%s) does not match size of '%s' (%"PY_FORMAT_SIZE_T"d byte%s)",
      buf->itemsize, (buf->itemsize > 1) ? "s" : "",
      dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
    goto fail;
  }
  if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
  return 0;
fail:;
  __Pyx_ZeroBuffer(buf);
  return -1;
}
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (info->buf == NULL) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}

static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_Format(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

static double __Pyx__PyObject_AsDouble(PyObject* obj) {
    PyObject* float_value;
    if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) {
        return PyFloat_AsDouble(obj);
    } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
#if PY_MAJOR_VERSION >= 3
        float_value = PyFloat_FromString(obj);
#else
        float_value = PyFloat_FromString(obj, 0);
#endif
    } else {
        PyObject* args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        PyTuple_SET_ITEM(args, 0, obj);
        float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0);
        PyTuple_SET_ITEM(args, 0, 0);
        Py_DECREF(args);
    }
    if (likely(float_value)) {
        double value = PyFloat_AS_DOUBLE(float_value);
        Py_DECREF(float_value);
        return value;
    }
bad:
    return (double)-1;
}

static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #else
        if (unlikely(!PyUnicode_Check(key)))
        #endif
            goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    return 0;
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
    return 0;
}

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
    if (t == Py_None) {
      __Pyx_RaiseNoneNotIterableError();
    } else if (PyTuple_GET_SIZE(t) < index) {
      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
    } else {
      __Pyx_RaiseTooManyValuesError(index);
    }
}

#if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
    PyObject *getbuffer_cobj;

  #if PY_VERSION_HEX >= 0x02060000
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
  #endif

        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags);

  #if PY_VERSION_HEX < 0x02060000
    if (obj->ob_type->tp_dict &&
        (getbuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict,
                                             "__pyx_getbuffer"))) {
        getbufferproc func;

      #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0)
        func = (getbufferproc) PyCapsule_GetPointer(getbuffer_cobj, "getbuffer(obj, view, flags)");
      #else
        func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj);
      #endif
        Py_DECREF(getbuffer_cobj);
        if (!func)
            goto fail;

        return func(obj, view, flags);
    } else {
        PyErr_Clear();
    }
  #endif

    PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name);

#if PY_VERSION_HEX < 0x02060000
fail:
#endif

    return -1;
}

static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    PyObject *releasebuffer_cobj;

    if (!obj) return;

  #if PY_VERSION_HEX >= 0x02060000
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
  #endif

        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) { __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view); return; }

  #if PY_VERSION_HEX < 0x02060000
    if (obj->ob_type->tp_dict &&
        (releasebuffer_cobj = PyMapping_GetItemString(obj->ob_type->tp_dict,
                                                      "__pyx_releasebuffer"))) {
        releasebufferproc func;

      #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 0)
        func = (releasebufferproc) PyCapsule_GetPointer(releasebuffer_cobj, "releasebuffer(obj, view)");
      #else
        func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj);
      #endif

        Py_DECREF(releasebuffer_cobj);

        if (!func)
            goto fail;

        func(obj, view);
        return;
    } else {
        PyErr_Clear();
    }
  #endif

    goto nofail;

#if PY_VERSION_HEX < 0x02060000
fail:
#endif
    PyErr_WriteUnraisable(obj);

nofail:
    Py_DECREF(obj);
    view->obj = NULL;
}

#endif /*  PY_MAJOR_VERSION < 3 */

    static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    #if PY_VERSION_HEX >= 0x02050000
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                /* try package relative import first */
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0; /* try absolute import on failure */
        }
        #endif
        if (!module) {
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
        }
    }
    #else
    if (level>0) {
        PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
        goto bad;
    }
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
    #endif
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject* __pyx_convert__to_py___pyx_t_14GatSegmentList_Segment(struct __pyx_t_14GatSegmentList_Segment s) {
      PyObject* res;
      PyObject* member;
      res = PyDict_New(); if (res == NULL) return NULL;
      member = PyLong_FromUnsignedLong(s.start); if (member == NULL) goto bad;
      if (PyDict_SetItem(res, __pyx_n_s__start, member) < 0) goto bad;
      Py_DECREF(member);
      member = PyLong_FromUnsignedLong(s.end); if (member == NULL) goto bad;
      if (PyDict_SetItem(res, __pyx_n_s__end, member) < 0) goto bad;
      Py_DECREF(member);
      return res;
      bad:
      Py_XDECREF(member);
      Py_DECREF(res);
      return NULL;
    }
    static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        if (PyBytes_GET_SIZE(s1) != PyBytes_GET_SIZE(s2)) {
            return (equals == Py_NE);
        } else if (PyBytes_GET_SIZE(s1) == 1) {
            if (equals == Py_EQ)
                return (PyBytes_AS_STRING(s1)[0] == PyBytes_AS_STRING(s2)[0]);
            else
                return (PyBytes_AS_STRING(s1)[0] != PyBytes_AS_STRING(s2)[0]);
        } else {
            int result = memcmp(PyBytes_AS_STRING(s1), PyBytes_AS_STRING(s2), (size_t)PyBytes_GET_SIZE(s1));
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
}

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) {
        #if CYTHON_PEP393_ENABLED
        if ((PyUnicode_READY(s1) < 0) || (PyUnicode_READY(s2) < 0))
            return -1;
        if (PyUnicode_GET_LENGTH(s1) != PyUnicode_GET_LENGTH(s2)) {
            return (equals == Py_NE);
        } else if (PyUnicode_GET_LENGTH(s1) == 1) {
            Py_UCS4 ch1 = PyUnicode_READ_CHAR(s1, 0);
            Py_UCS4 ch2 = PyUnicode_READ_CHAR(s2, 0);
            return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2);
        #else
        if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) {
            return (equals == Py_NE);
        } else if (PyUnicode_GET_SIZE(s1) == 1) {
            Py_UNICODE ch1 = PyUnicode_AS_UNICODE(s1)[0];
            Py_UNICODE ch2 = PyUnicode_AS_UNICODE(s2)[0];
            return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2);
        #endif
        } else {
            int result = PyUnicode_Compare(s1, s2);
            if ((result == -1) && unlikely(PyErr_Occurred()))
                return -1;
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyUnicode_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
}

static struct __pyx_t_14GatSegmentList_Segment __pyx_convert__from_py___pyx_t_14GatSegmentList_Segment(PyObject * o) {
    struct __pyx_t_14GatSegmentList_Segment result = { 0 };
    PyObject *value = NULL;
    if (!PyMapping_Check(o)) {
        PyErr_Format(PyExc_TypeError, "Expected a mapping, not %s", o->ob_type->tp_name);
        goto bad;
    }
        value = PyMapping_GetItemString(o, (char *) "start");
        if (!value) {
            PyErr_SetString(PyExc_ValueError, "No value specified for struct "
                                              "attribute 'start'");
            goto bad;
        }
        result.start = __Pyx_PyInt_AsUnsignedInt(value);
        if ((result.start == (unsigned int)-1) && PyErr_Occurred())
            goto bad;
        Py_DECREF(value);
        value = PyMapping_GetItemString(o, (char *) "end");
        if (!value) {
            PyErr_SetString(PyExc_ValueError, "No value specified for struct "
                                              "attribute 'end'");
            goto bad;
        }
        result.end = __Pyx_PyInt_AsUnsignedInt(value);
        if ((result.end == (unsigned int)-1) && PyErr_Occurred())
            goto bad;
        Py_DECREF(value);
    return result;
bad:
    Py_XDECREF(value);
    return result;
}

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        float denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(a, a);
                    case 3:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, a);
                    case 4:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_absf(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        double denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(a, a);
                    case 3:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, a);
                    case 4:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

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 (unsigned long)PyLong_AsUnsignedLong(x);
        } else {
            return (unsigned long)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 (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (unsigned PY_LONG_LONG)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 (long)PyLong_AsUnsignedLong(x);
        } else {
            return (long)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 (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (PY_LONG_LONG)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 (signed long)PyLong_AsUnsignedLong(x);
        } else {
            return (signed long)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 (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (signed PY_LONG_LONG)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 void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        #if PY_VERSION_HEX < 0x02050000
        return PyErr_Warn(NULL, message);
        #else
        return PyErr_WarnEx(NULL, message, 1);
        #endif
    }
    return 0;
}

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%s.%s is not a type object",
            module_name, class_name);
        goto bad;
    }
    if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        #if PY_VERSION_HEX < 0x02050000
        if (PyErr_Warn(NULL, warning) < 0) goto bad;
        #else
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
        #endif
    }
    else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%s.%s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

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;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = (start + end) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,            /*int argcount,*/
        0,            /*int kwonlyargcount,*/
        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,*/
        py_line,      /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_globals = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) 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 = py_line;
    PyTraceBack_Here(py_frame);
bad:
    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 */
