/* Generated by Pyrex 0.9.3.1 on Wed Jun 14 22:43:50 2006 */

#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#include "stdio.h"
#include "rbtree.h"


typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
static int __Pyx_PrintItem(PyObject *); /*proto*/
static int __Pyx_PrintNewline(void); /*proto*/
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static void __Pyx_ReRaise(void); /*proto*/
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
static PyObject *__Pyx_GetExcValue(void); /*proto*/
static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
static void __Pyx_WriteUnraisable(char *name); /*proto*/
static void __Pyx_AddTraceback(char *funcname); /*proto*/
static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
staticforward char **__pyx_f;

static char __pyx_mdoc[] = "\nrbtree\n~~~~~~~~~~~~~~~~~~~~\na fast rbtree impl for python using pyrex\n\n";

/* Declarations from rbtree */

typedef enum {
  __pyx_e_6rbtree_KEYS = 1,
  __pyx_e_6rbtree_VALUES = 2,
  __pyx_e_6rbtree_ITEMS = 4,
  __pyx_e_6rbtree_NODES = 8,
} __pyx_t_6rbtree_ITER_TYPE;

staticforward PyTypeObject __pyx_type_6rbtree_RBTree;

struct __pyx_obj_6rbtree_RBTree {
  PyObject_HEAD
  rbtree_t (*_tree);
};

staticforward PyTypeObject __pyx_type_6rbtree_RBTreeIterator;

struct __pyx_obj_6rbtree_RBTreeIterator {
  PyObject_HEAD
  struct __pyx_vtabstruct_6rbtree_RBTreeIterator *__pyx_vtab;
  struct __pyx_obj_6rbtree_RBTree *_T;
  rbtree_node_t (*_iter);
  __pyx_t_6rbtree_ITER_TYPE _type;
  int _done;
  iter_direction _direction;
};

struct __pyx_vtabstruct_6rbtree_RBTreeIterator {
  PyObject *((*_position)(struct __pyx_obj_6rbtree_RBTreeIterator *,iter_direction ));
  rbtree_node_t (*((*walk)(struct __pyx_obj_6rbtree_RBTreeIterator *,iter_direction )));
  PyObject *((*step)(struct __pyx_obj_6rbtree_RBTreeIterator *,iter_direction ));
};
static struct __pyx_vtabstruct_6rbtree_RBTreeIterator *__pyx_vtabptr_6rbtree_RBTreeIterator;

static PyTypeObject *__pyx_ptype_6rbtree_RBTree = 0;
static PyTypeObject *__pyx_ptype_6rbtree_RBTreeIterator = 0;
static PyObject *__pyx_k5;
static PyObject *__pyx_k6;
static PyObject *__pyx_k7;
static PyObject *__pyx_k8;
static int __pyx_k9;

/* Implementation of rbtree */

static char (__pyx_k1[]) = "Benjamin Saller <bcsaller@objectrealms.net>";
static char (__pyx_k3[]) = "Copyright Benjamin Saller, 2004.";
static char (__pyx_k4[]) = "The GNU Public License V2+";

static PyObject *__pyx_n___author__;
static PyObject *__pyx_n___docformat__;
static PyObject *__pyx_n___copyright__;
static PyObject *__pyx_n___license__;
static PyObject *__pyx_n_restructuredtext;
static PyObject *__pyx_n_False;

static PyObject *__pyx_k1p;
static PyObject *__pyx_k3p;
static PyObject *__pyx_k4p;

static PyObject *__pyx_n_direction;

static int __pyx_f_6rbtree_14RBTreeIterator___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_6rbtree_14RBTreeIterator___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_6rbtree_RBTree *__pyx_v_tree = 0;
  int __pyx_v_itype;
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {"tree","itype",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "Oi", __pyx_argnames, &__pyx_v_tree, &__pyx_v_itype)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_tree);
  if (!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tree), __pyx_ptype_6rbtree_RBTree, 1, "tree")) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":88 */
  Py_INCREF(((PyObject *)__pyx_v_tree));
  Py_DECREF(((PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T));
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T = ((PyObject *)__pyx_v_tree);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":89 */
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":90 */
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_type = __pyx_v_itype;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":91 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;}
  __pyx_2 = PyInt_AsLong(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_done = __pyx_2;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":92 */
  __pyx_1 = PyInt_FromLong(FORWARD); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_direction, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.__new__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_tree);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_9direction___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_9direction___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":96 */
  __pyx_1 = PyInt_FromLong(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_direction); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.direction.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6rbtree_14RBTreeIterator_9direction___set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_value); /*proto*/
static int __pyx_f_6rbtree_14RBTreeIterator_9direction___set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_value) {
  int __pyx_v_value;
  int __pyx_r;
  Py_INCREF(__pyx_v_self);
  __pyx_v_value = PyInt_AsLong(__pyx_arg_value); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":98 */
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_direction = __pyx_v_value;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTreeIterator.direction.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_StopIteration;

static PyObject *__pyx_f_6rbtree_14RBTreeIterator__position(struct __pyx_obj_6rbtree_RBTreeIterator *__pyx_v_self,iter_direction __pyx_v_direction) {
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":101 */
  __pyx_1 = __pyx_v_self->_done;
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":102 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_StopIteration); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; goto __pyx_L1;}
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":104 */
  __pyx_1 = (__pyx_v_direction == FORWARD);
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":105 */
    __pyx_v_self->_iter = tree_min(__pyx_v_self->_T->_tree,0);
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":107 */
    __pyx_v_self->_iter = tree_max(__pyx_v_self->_T->_tree,0);
  }
  __pyx_L3:;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTreeIterator._position");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static rbtree_node_t (*__pyx_f_6rbtree_14RBTreeIterator_walk(struct __pyx_obj_6rbtree_RBTreeIterator *__pyx_v_self,iter_direction __pyx_v_direction)) {
  rbtree_node_t (*__pyx_v_n);
  rbtree_node_t (*__pyx_r);
  int __pyx_1;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":111 */
  __pyx_1 = (__pyx_v_direction == FORWARD);
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":112 */
    __pyx_v_n = tree_successor(__pyx_v_self->_T->_tree,__pyx_v_self->_iter);
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":114 */
    __pyx_v_n = tree_predecessor(__pyx_v_self->_T->_tree,__pyx_v_self->_iter);
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":115 */
  __pyx_r = __pyx_v_n;
  goto __pyx_L0;

  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_WriteUnraisable("rbtree.RBTreeIterator.walk");
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_14RBTreeIterator___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":119 */
  Py_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTreeIterator.__iter__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_True;
static PyObject *__pyx_n_key;
static PyObject *__pyx_n_value;
static PyObject *__pyx_n_item;

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_step(struct __pyx_obj_6rbtree_RBTreeIterator *__pyx_v_self,iter_direction __pyx_v_direction) {
  PyObject *__pyx_v_r;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_r = Py_None; Py_INCREF(__pyx_v_r);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":123 */
  __pyx_1 = (__pyx_v_self->_iter == 0);
  if (__pyx_1) {
    __pyx_2 = ((struct __pyx_vtabstruct_6rbtree_RBTreeIterator *)__pyx_v_self->__pyx_vtab)->_position(__pyx_v_self,__pyx_v_direction); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    goto __pyx_L2;
  }
  /*else*/ {
    __pyx_v_self->_iter = ((struct __pyx_vtabstruct_6rbtree_RBTreeIterator *)__pyx_v_self->__pyx_vtab)->walk(__pyx_v_self,__pyx_v_direction);
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":126 */
  __pyx_1 = (__pyx_v_self->_iter == 0);
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":127 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
    __pyx_1 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_v_self->_done = __pyx_1;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":128 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_StopIteration); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; goto __pyx_L1;}
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":130 */
  __pyx_1 = (__pyx_v_self->_type == __pyx_e_6rbtree_KEYS);
  if (__pyx_1) {
    __pyx_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_key); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; goto __pyx_L1;}
    Py_DECREF(__pyx_v_r);
    __pyx_v_r = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L4;
  }
  __pyx_1 = (__pyx_v_self->_type == __pyx_e_6rbtree_VALUES);
  if (__pyx_1) {
    __pyx_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_value); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; goto __pyx_L1;}
    Py_DECREF(__pyx_v_r);
    __pyx_v_r = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L4;
  }
  __pyx_1 = (__pyx_v_self->_type == __pyx_e_6rbtree_NODES);
  if (__pyx_1) {
    Py_INCREF(((PyObject *)__pyx_v_self));
    Py_DECREF(__pyx_v_r);
    __pyx_v_r = ((PyObject *)__pyx_v_self);
    goto __pyx_L4;
  }
  /*else*/ {
    __pyx_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_item); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; goto __pyx_L1;}
    Py_DECREF(__pyx_v_r);
    __pyx_v_r = __pyx_2;
    __pyx_2 = 0;
  }
  __pyx_L4:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":134 */
  Py_INCREF(__pyx_v_r);
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.step");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_r);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_14RBTreeIterator___next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator___next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  iter_direction __pyx_2;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_direction); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
  __pyx_2 = PyInt_AsLong(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = ((struct __pyx_vtabstruct_6rbtree_RBTreeIterator *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->__pyx_vtab)->step(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self),__pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.__next__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_prev(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_prev(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  iter_direction __pyx_4;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_direction); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;}
  __pyx_2 = PyInt_FromLong((-1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;}
  __pyx_3 = PyNumber_Multiply(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_1 = ((struct __pyx_vtabstruct_6rbtree_RBTreeIterator *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->__pyx_vtab)->step(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self),__pyx_4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.prev");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_KeyError;

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_goto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_goto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_v_near = 0;
  rbtree_node_t (*__pyx_v_n);
  int __pyx_v_rc;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"key","near",0};
  __pyx_v_near = __pyx_k5;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_key, &__pyx_v_near)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  Py_INCREF(__pyx_v_near);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":146 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; goto __pyx_L1;}
  __pyx_2 = __pyx_v_near == __pyx_1;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_2) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":147 */
    __pyx_v_n = rbtree_search(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,__pyx_v_key);
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":149 */
    __pyx_v_n = rbtree_get_node(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,__pyx_v_key);
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":150 */
  __pyx_2 = (__pyx_v_n == 0);
  if (__pyx_2) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":151 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
    __pyx_2 = PyInt_AsLong(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_done = __pyx_2;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":152 */
    ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":153 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
    __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; goto __pyx_L1;}
    goto __pyx_L3;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":155 */
    ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter = __pyx_v_n;
  }
  __pyx_L3:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":156 */
  Py_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.goto");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_near);
  return __pyx_r;
}

static PyObject *__pyx_n_abs;
static PyObject *__pyx_n_xrange;

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_byOffset(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_byOffset(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_offset = 0;
  rbtree_node_t (*__pyx_v_n);
  PyObject *__pyx_v_forward;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"offset",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_offset)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_offset);
  __pyx_v_forward = Py_None; Py_INCREF(__pyx_v_forward);
  __pyx_v_i = Py_None; Py_INCREF(__pyx_v_i);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":161 */
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_v_offset, __pyx_1, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; goto __pyx_L1;}
  __pyx_2 = __pyx_2 >= 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_2) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":162 */
    __pyx_v_n = tree_min(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,0);

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":163 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; goto __pyx_L1;}
    Py_DECREF(__pyx_v_forward);
    __pyx_v_forward = __pyx_1;
    __pyx_1 = 0;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":165 */
    __pyx_v_n = tree_max(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,0);

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":166 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; goto __pyx_L1;}
    Py_DECREF(__pyx_v_forward);
    __pyx_v_forward = __pyx_1;
    __pyx_1 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":167 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_abs); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; goto __pyx_L1;}
    Py_INCREF(__pyx_v_offset);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_offset);
    __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; goto __pyx_L1;}
    __pyx_3 = PyNumber_Subtract(__pyx_4, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_v_offset);
    __pyx_v_offset = __pyx_3;
    __pyx_3 = 0;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":169 */
  __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_xrange); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; goto __pyx_L1;}
  Py_INCREF(__pyx_v_offset);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_offset);
  __pyx_3 = PyObject_CallObject(__pyx_4, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_4 = PyObject_GetIter(__pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  for (;;) {
    __pyx_L3:;
    __pyx_1 = PyIter_Next(__pyx_4);
    if (!__pyx_1) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; goto __pyx_L1;}
      break;
    }
    Py_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_1;
    __pyx_1 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":170 */
    __pyx_2 = PyObject_IsTrue(__pyx_v_forward); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; goto __pyx_L1;}
    if (__pyx_2) {

      /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":171 */
      __pyx_v_n = tree_successor(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,__pyx_v_n);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":173 */
      __pyx_v_n = tree_predecessor(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,__pyx_v_n);
    }
    __pyx_L5:;
  }
  __pyx_L4:;
  Py_DECREF(__pyx_4); __pyx_4 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":174 */
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter = __pyx_v_n;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":175 */
  Py_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.byOffset");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_forward);
  Py_DECREF(__pyx_v_i);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_offset);
  return __pyx_r;
}

static PyObject *__pyx_k10p;

static char (__pyx_k10[]) = "Iterator has no current value";

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_3key___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_3key___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_result = Py_None; Py_INCREF(__pyx_v_result);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":180 */
  __pyx_1 = (((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter != 0);
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":181 */
    __pyx_2 = (PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter->key;
    Py_INCREF(__pyx_2);
    Py_DECREF(__pyx_v_result);
    __pyx_v_result = __pyx_2;
    __pyx_2 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":182 */
    Py_INCREF(__pyx_v_result);
    __pyx_r = __pyx_v_result;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":183 */
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; goto __pyx_L1;}
  Py_INCREF(__pyx_k10p);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k10p);
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __Pyx_Raise(__pyx_4, 0, 0);
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; goto __pyx_L1;}

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.key.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_k11p;

static char (__pyx_k11[]) = "Iterator has no current value";

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_5value___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_5value___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_result = Py_None; Py_INCREF(__pyx_v_result);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":187 */
  __pyx_1 = (((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter != 0);
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":188 */
    __pyx_2 = (PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter->value;
    Py_INCREF(__pyx_2);
    Py_DECREF(__pyx_v_result);
    __pyx_v_result = __pyx_2;
    __pyx_2 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":189 */
    Py_INCREF(__pyx_v_result);
    __pyx_r = __pyx_v_result;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":190 */
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; goto __pyx_L1;}
  Py_INCREF(__pyx_k11p);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k11p);
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __Pyx_Raise(__pyx_4, 0, 0);
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; goto __pyx_L1;}

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.value.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_k12p;

static char (__pyx_k12[]) = "Iterator has no current value";

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_4item___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_4item___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_result = Py_None; Py_INCREF(__pyx_v_result);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":194 */
  __pyx_1 = (((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter != 0);
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":195 */
    __pyx_2 = (PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter->key;
    Py_INCREF(__pyx_2);
    __pyx_3 = (PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter->value;
    Py_INCREF(__pyx_3);
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
    __pyx_2 = 0;
    __pyx_3 = 0;
    Py_DECREF(__pyx_v_result);
    __pyx_v_result = __pyx_4;
    __pyx_4 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":197 */
    Py_INCREF(__pyx_v_result);
    __pyx_r = __pyx_v_result;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":198 */
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}
  Py_INCREF(__pyx_k12p);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k12p);
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __Pyx_Raise(__pyx_4, 0, 0);
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; goto __pyx_L1;}

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.item.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_delete(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_delete(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  rbtree_node_t (*__pyx_v_n);
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  int __pyx_3;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":206 */
  __pyx_v_n = rbtree_node_del(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":208 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_direction); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  __pyx_2 = PyInt_FromLong(BACKWARD); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
  __pyx_3 = __pyx_1 == __pyx_2;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (__pyx_3) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":209 */
    __pyx_v_n = tree_predecessor(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,__pyx_v_n);
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":210 */
  ((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter = __pyx_v_n;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.delete");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_14RBTreeIterator_dump(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_14RBTreeIterator_dump(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":213 */
  rbtree_dump_node(((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T->_tree,((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_iter);

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTreeIterator.dump");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_len;

static int __pyx_f_6rbtree_14RBTreeIterator___len__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_f_6rbtree_14RBTreeIterator___len__(PyObject *__pyx_v_self) {
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":216 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
  Py_INCREF(((PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T));
  PyTuple_SET_ITEM(__pyx_2, 0, ((PyObject *)((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_T));
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_r = __pyx_4;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.__len__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6rbtree_14RBTreeIterator___nonzero__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_f_6rbtree_14RBTreeIterator___nonzero__(PyObject *__pyx_v_self) {
  int __pyx_r;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":219 */
  __pyx_r = (!((struct __pyx_obj_6rbtree_RBTreeIterator *)__pyx_v_self)->_done);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTreeIterator.__nonzero__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_cmp;

static int __pyx_f_6rbtree_14RBTreeIterator___cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static int __pyx_f_6rbtree_14RBTreeIterator___cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  int __pyx_5;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_other);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":222 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_cmp); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_key); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
  __pyx_3 = PyObject_GetAttr(__pyx_v_other, __pyx_n_key); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
  __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
  PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
  __pyx_2 = 0;
  __pyx_3 = 0;
  __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  __pyx_5 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_5;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTreeIterator.__cmp__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_other);
  return __pyx_r;
}

static PyObject *__pyx_n_update;

static int __pyx_f_6rbtree_6RBTree___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_6rbtree_6RBTree___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_mapping = 0;
  PyObject *__pyx_v_cmp = 0;
  int __pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"mapping","cmp",0};
  __pyx_v_mapping = __pyx_k6;
  __pyx_v_cmp = __pyx_k7;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|OO", __pyx_argnames, &__pyx_v_mapping, &__pyx_v_cmp)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_mapping);
  Py_INCREF(__pyx_v_cmp);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":238 */
  ((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree = rbtree_alloc();

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":239 */
  rbtree_init(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":241 */
  __pyx_1 = __pyx_v_cmp != Py_None;
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":242 */
    rbtree_set_compare(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_cmp);
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":244 */
  __pyx_1 = PyObject_IsTrue(__pyx_v_mapping); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":245 */
    __pyx_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_update); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; goto __pyx_L1;}
    Py_INCREF(__pyx_v_mapping);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_mapping);
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.__new__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_mapping);
  Py_DECREF(__pyx_v_cmp);
  return __pyx_r;
}

static void __pyx_f_6rbtree_6RBTree___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_f_6rbtree_6RBTree___dealloc__(PyObject *__pyx_v_self) {
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":249 */
  rbtree_dealloc(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":250 */
  rbtree_free(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree);

  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTree.__dealloc__");
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
}

static PyObject *__pyx_f_6rbtree_6RBTree___getnewargs__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___getnewargs__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {0};
  if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 0, &__pyx_v_args, 0) < 0) return 0;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) {
    Py_XDECREF(__pyx_args);
    Py_XDECREF(__pyx_kwds);
    Py_XDECREF(__pyx_v_args);
    return 0;
  }
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":254 */
  __pyx_1 = PyTuple_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree.RBTree.__getnewargs__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_XDECREF(__pyx_v_args);
  Py_DECREF(__pyx_v_self);
  Py_XDECREF(__pyx_args);
  Py_XDECREF(__pyx_kwds);
  return __pyx_r;
}

static PyObject *__pyx_n_dict;
static PyObject *__pyx_n_data;
static PyObject *__pyx_n_compare;


static PyObject *__pyx_f_6rbtree_6RBTree___getstate__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___getstate__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_d;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_d = Py_None; Py_INCREF(__pyx_v_d);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":257 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_dict); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_v_d);
  __pyx_v_d = __pyx_3;
  __pyx_3 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":258 */
  __pyx_1 = PyDict_New(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; goto __pyx_L1;}
  if (PyDict_SetItem(__pyx_1, __pyx_n_data, __pyx_v_d) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; goto __pyx_L1;}
  __pyx_2 = (PyObject *)((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree->compare;
  Py_INCREF(__pyx_2);
  if (PyDict_SetItem(__pyx_1, __pyx_n_compare, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.__getstate__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_d);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}


static PyObject *__pyx_f_6rbtree_6RBTree___setstate__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___setstate__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"state",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_state)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_state);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":265 */
  __pyx_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_compare); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; goto __pyx_L1;}
  __pyx_2 = __pyx_1 != Py_None;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_2) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":266 */
    __pyx_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_compare); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; goto __pyx_L1;}
    rbtree_set_compare(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_1);
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":268 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_update); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; goto __pyx_L1;}
  __pyx_3 = PyObject_GetItem(__pyx_v_state, __pyx_n_data); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; goto __pyx_L1;}
  __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_4, 0, __pyx_3);
  __pyx_3 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.__setstate__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_state);
  return __pyx_r;
}

static PyObject *__pyx_n_isinstance;
static PyObject *__pyx_n_ValueError;
static PyObject *__pyx_n_iternodes;
static PyObject *__pyx_n_next;

static PyObject *__pyx_k18p;

static char (__pyx_k18[]) = "Can only test equality of two RBTrees";

static PyObject *__pyx_f_6rbtree_6RBTree___richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_arg_mode); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_arg_mode) {
  PyObject *__pyx_v_mode = 0;
  PyObject *__pyx_v_s;
  PyObject *__pyx_v_o;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  int __pyx_5;
  PyObject *__pyx_6 = 0;
  PyObject *__pyx_7 = 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_other);
  __pyx_v_mode = PyInt_FromLong(__pyx_arg_mode); if (!__pyx_v_mode) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
  __pyx_v_s = Py_None; Py_INCREF(__pyx_v_s);
  __pyx_v_o = Py_None; Py_INCREF(__pyx_v_o);
  __pyx_v_i = Py_None; Py_INCREF(__pyx_v_i);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":272 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_isinstance); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; goto __pyx_L1;}
  Py_INCREF(__pyx_v_other);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_other);
  Py_INCREF(((PyObject*)__pyx_ptype_6rbtree_RBTree));
  PyTuple_SET_ITEM(__pyx_2, 1, ((PyObject*)__pyx_ptype_6rbtree_RBTree));
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_4 = PyObject_IsTrue(__pyx_3); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_5 = (!__pyx_4);
  if (__pyx_5) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":273 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    Py_INCREF(__pyx_k18p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k18p);
    __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":275 */
  __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_v_mode, __pyx_1, &__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
  __pyx_4 = __pyx_4 != 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_4) {
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
    __pyx_r = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":276 */
  __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  Py_INCREF(__pyx_v_other);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_other);
  __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_self);
  __pyx_6 = PyObject_CallObject(__pyx_3, __pyx_1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (PyObject_Cmp(__pyx_2, __pyx_6, &__pyx_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
  __pyx_5 = __pyx_5 != 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_6); __pyx_6 = 0;
  if (__pyx_5) {
    __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
    __pyx_r = __pyx_3;
    __pyx_3 = 0;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":277 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_iternodes); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; goto __pyx_L1;}
  __pyx_6 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_v_s);
  __pyx_v_s = __pyx_6;
  __pyx_6 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":278 */
  __pyx_3 = PyObject_GetAttr(__pyx_v_other, __pyx_n_iternodes); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_o);
  __pyx_v_o = __pyx_2;
  __pyx_2 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":279 */
  __pyx_6 = PyObject_GetIter(__pyx_v_self); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; goto __pyx_L1;}
  for (;;) {
    __pyx_L5:;
    __pyx_3 = PyIter_Next(__pyx_6);
    if (!__pyx_3) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; goto __pyx_L1;}
      break;
    }
    Py_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_3;
    __pyx_3 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":280 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_s, __pyx_n_next); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_1 = PyObject_GetAttr(__pyx_3, __pyx_n_item); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_2 = PyObject_GetAttr(__pyx_v_o, __pyx_n_next); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    __pyx_7 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_2 = PyObject_GetAttr(__pyx_7, __pyx_n_item); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    Py_DECREF(__pyx_7); __pyx_7 = 0;
    if (PyObject_Cmp(__pyx_1, __pyx_2, &__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
    __pyx_4 = __pyx_4 != 0;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    if (__pyx_4) {
      __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; goto __pyx_L1;}
      __pyx_r = __pyx_3;
      __pyx_3 = 0;
      goto __pyx_L0;
      goto __pyx_L7;
    }
    __pyx_L7:;
  }
  __pyx_L6:;
  Py_DECREF(__pyx_6); __pyx_6 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":281 */
  __pyx_7 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; goto __pyx_L1;}
  __pyx_r = __pyx_7;
  __pyx_7 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  __Pyx_AddTraceback("rbtree.RBTree.__richcmp__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_mode);
  Py_DECREF(__pyx_v_s);
  Py_DECREF(__pyx_v_o);
  Py_DECREF(__pyx_v_i);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_other);
  return __pyx_r;
}

static int __pyx_f_6rbtree_6RBTree___len__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_f_6rbtree_6RBTree___len__(PyObject *__pyx_v_self) {
  int __pyx_r;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":284 */
  __pyx_r = ((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree->ct;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTree.__len__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_slice;
static PyObject *__pyx_n_hash;

static PyObject *__pyx_k19p;

static char (__pyx_k19[]) = "setslice is unsupported";

static int __pyx_f_6rbtree_6RBTree___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/
static int __pyx_f_6rbtree_6RBTree___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) {
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  Py_INCREF(__pyx_v_value);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":289 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_isinstance); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_slice); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
  Py_INCREF(__pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
  __pyx_2 = 0;
  __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_4 = PyObject_IsTrue(__pyx_2); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":290 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
    Py_INCREF(__pyx_k19p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k19p);
    __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":292 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_hash); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; goto __pyx_L1;}
  Py_INCREF(__pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
  __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":293 */
  rbtree_add(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_key,__pyx_v_value);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.__setitem__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_value);
  return __pyx_r;
}

static PyObject *__pyx_n___doslice__;

static PyObject *__pyx_f_6rbtree_6RBTree___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  void (*__pyx_v_v);
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":298 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_isinstance); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_slice); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
  Py_INCREF(__pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
  __pyx_2 = 0;
  __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_4 = PyObject_IsTrue(__pyx_2); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":299 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___doslice__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
    __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_r = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":301 */
  __pyx_v_v = rbtree_get(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":302 */
  __pyx_4 = (__pyx_v_v == 0);
  if (__pyx_4) {
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
    __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":303 */
  __pyx_1 = (PyObject *)__pyx_v_v;
  Py_INCREF(__pyx_1);
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.__getitem__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_n___dodeleteslice__;

static int __pyx_f_6rbtree_6RBTree___delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static int __pyx_f_6rbtree_6RBTree___delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  int __pyx_v_rc;
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":308 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_isinstance); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_slice); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
  Py_INCREF(__pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
  __pyx_2 = 0;
  __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_4 = PyObject_IsTrue(__pyx_2); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":309 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___dodeleteslice__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
    __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":310 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":312 */
  __pyx_v_rc = rbtree_del(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":313 */
  __pyx_4 = (__pyx_v_rc != 0);
  if (__pyx_4) {
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
    __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.__delitem__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_n___class__;
static PyObject *__pyx_n_start;
static PyObject *__pyx_n_stop;
static PyObject *__pyx_n_step;


static PyObject *__pyx_f_6rbtree_6RBTree___doslice__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___doslice__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_slice = 0;
  PyObject *__pyx_v_compare;
  PyObject *__pyx_v_instance;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"slice",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_slice)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_slice);
  __pyx_v_compare = Py_None; Py_INCREF(__pyx_v_compare);
  __pyx_v_instance = Py_None; Py_INCREF(__pyx_v_instance);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":322 */
  __pyx_1 = (PyObject *)((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree->compare;
  Py_INCREF(__pyx_1);
  Py_DECREF(__pyx_v_compare);
  __pyx_v_compare = __pyx_1;
  __pyx_1 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":324 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; goto __pyx_L1;}
  __pyx_3 = PyDict_New(); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; goto __pyx_L1;}
  if (PyDict_SetItem(__pyx_3, __pyx_n_cmp, __pyx_v_compare) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; goto __pyx_L1;}
  __pyx_4 = PyEval_CallObjectWithKeywords(__pyx_1, __pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_v_instance);
  __pyx_v_instance = __pyx_4;
  __pyx_4 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":325 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_slice, __pyx_n_start); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_slice, __pyx_n_stop); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; goto __pyx_L1;}
  __pyx_3 = PyObject_GetAttr(__pyx_v_slice, __pyx_n_step); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; goto __pyx_L1;}
  rbtree_do_slice(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_1,__pyx_2,__pyx_3,((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_instance)->_tree);
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":330 */
  Py_INCREF(__pyx_v_instance);
  __pyx_r = __pyx_v_instance;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.__doslice__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_compare);
  Py_DECREF(__pyx_v_instance);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_slice);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree___dodeleteslice__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___dodeleteslice__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_slice = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {"slice",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_slice)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_slice);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":333 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_slice, __pyx_n_start); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_slice, __pyx_n_stop); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; goto __pyx_L1;}
  __pyx_3 = PyObject_GetAttr(__pyx_v_slice, __pyx_n_step); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; goto __pyx_L1;}
  rbtree_do_del_slice(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_1,__pyx_2,__pyx_3);
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.__dodeleteslice__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_slice);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_v_default = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {"key","default",0};
  __pyx_v_default = __pyx_k8;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_key, &__pyx_v_default)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  Py_INCREF(__pyx_v_default);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":336 */
  /*try:*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":337 */
    __pyx_1 = PyObject_GetItem(__pyx_v_self, __pyx_v_key); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; goto __pyx_L2;}
    __pyx_r = __pyx_1;
    __pyx_1 = 0;
    goto __pyx_L0;
  }
  goto __pyx_L3;
  __pyx_L2:;
  Py_XDECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":338 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; goto __pyx_L1;}
  __pyx_2 = PyErr_ExceptionMatches(__pyx_1);
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_2) {
    __Pyx_AddTraceback("rbtree.get");
    __pyx_1 = __Pyx_GetExcValue(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":339 */
    Py_INCREF(__pyx_v_default);
    __pyx_r = __pyx_v_default;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  goto __pyx_L1;
  __pyx_L3:;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree.RBTree.get");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_default);
  return __pyx_r;
}

static int __pyx_f_6rbtree_6RBTree___contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static int __pyx_f_6rbtree_6RBTree___contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  void (*__pyx_v_v);
  int __pyx_r;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":343 */
  __pyx_v_v = rbtree_get(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":344 */
  __pyx_r = (__pyx_v_v != 0);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTree.__contains__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_has_key(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_has_key(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  void (*__pyx_v_v);
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {"key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_key)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":348 */
  __pyx_v_v = rbtree_get(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_key);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":349 */
  __pyx_1 = PyInt_FromLong((__pyx_v_v != 0)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree.RBTree.has_key");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong(__pyx_e_6rbtree_KEYS); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_1);
  __pyx_1 = 0;
  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6rbtree_RBTreeIterator), __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTree.__iter__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_iterkeys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_iterkeys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong(__pyx_e_6rbtree_KEYS); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_1);
  __pyx_1 = 0;
  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6rbtree_RBTreeIterator), __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTree.iterkeys");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_itervalues(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_itervalues(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong(__pyx_e_6rbtree_VALUES); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_1);
  __pyx_1 = 0;
  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6rbtree_RBTreeIterator), __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTree.itervalues");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_iteritems(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_iteritems(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong(__pyx_e_6rbtree_ITEMS); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_1);
  __pyx_1 = 0;
  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6rbtree_RBTreeIterator), __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTree.iteritems");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_iternodes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_iternodes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong(__pyx_e_6rbtree_NODES); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_1);
  __pyx_1 = 0;
  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6rbtree_RBTreeIterator), __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTree.iternodes");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_list;
static PyObject *__pyx_n___iter__;

static PyObject *__pyx_f_6rbtree_6RBTree_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_list); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n___iter__); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_4);
  __pyx_4 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.keys");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_itervalues;

static PyObject *__pyx_f_6rbtree_6RBTree_values(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_values(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_list); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_itervalues); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; goto __pyx_L1;}
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_4);
  __pyx_4 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.values");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_iteritems;

static PyObject *__pyx_f_6rbtree_6RBTree_items(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_items(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_list); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_iteritems); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_4);
  __pyx_4 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.items");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_tuple;
static PyObject *__pyx_n_TypeError;

static PyObject *__pyx_k21p;

static char (__pyx_k21[]) = "Unsupported type in ctor (need dict/sequence)";

static PyObject *__pyx_f_6rbtree_6RBTree_update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_mapping = 0;
  PyObject *__pyx_v_k;
  PyObject *__pyx_v_v;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  PyObject *__pyx_5 = 0;
  static char *__pyx_argnames[] = {"mapping",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_mapping)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_mapping);
  __pyx_v_k = Py_None; Py_INCREF(__pyx_v_k);
  __pyx_v_v = Py_None; Py_INCREF(__pyx_v_v);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":362 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_isinstance); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; goto __pyx_L1;}
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_dict); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
  Py_INCREF(((PyObject*)__pyx_ptype_6rbtree_RBTree));
  PyTuple_SET_ITEM(__pyx_3, 1, ((PyObject*)__pyx_ptype_6rbtree_RBTree));
  __pyx_2 = 0;
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; goto __pyx_L1;}
  Py_INCREF(__pyx_v_mapping);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_mapping);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_3);
  __pyx_3 = 0;
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_4 = PyObject_IsTrue(__pyx_3); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":363 */
    __pyx_1 = PyObject_GetAttr(__pyx_v_mapping, __pyx_n_iteritems); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
    __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_1 = PyObject_GetIter(__pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    for (;;) {
      __pyx_L3:;
      __pyx_2 = PyIter_Next(__pyx_1);
      if (!__pyx_2) {
        if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
        break;
      }
      __pyx_3 = __Pyx_UnpackItem(__pyx_2, 0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
      Py_DECREF(__pyx_v_k);
      __pyx_v_k = __pyx_3;
      __pyx_3 = 0;
      __pyx_5 = __Pyx_UnpackItem(__pyx_2, 1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
      Py_DECREF(__pyx_v_v);
      __pyx_v_v = __pyx_5;
      __pyx_5 = 0;
      if (__Pyx_EndUnpack(__pyx_2, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;

      /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":364 */
      if (PyObject_SetItem(__pyx_v_self, __pyx_v_k, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; goto __pyx_L1;}
    }
    __pyx_L4:;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    goto __pyx_L2;
  }
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_isinstance); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_list); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  __pyx_5 = __Pyx_GetName(__pyx_b, __pyx_n_tuple); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_5);
  __pyx_3 = 0;
  __pyx_5 = 0;
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  Py_INCREF(__pyx_v_mapping);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_mapping);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_1);
  __pyx_1 = 0;
  __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_4 = PyObject_IsTrue(__pyx_5); if (__pyx_4 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
  Py_DECREF(__pyx_5); __pyx_5 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":367 */
    __pyx_1 = PyObject_GetIter(__pyx_v_mapping); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; goto __pyx_L1;}
    for (;;) {
      __pyx_L5:;
      __pyx_2 = PyIter_Next(__pyx_1);
      if (!__pyx_2) {
        if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; goto __pyx_L1;}
        break;
      }
      __pyx_3 = __Pyx_UnpackItem(__pyx_2, 0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; goto __pyx_L1;}
      Py_DECREF(__pyx_v_k);
      __pyx_v_k = __pyx_3;
      __pyx_3 = 0;
      __pyx_5 = __Pyx_UnpackItem(__pyx_2, 1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; goto __pyx_L1;}
      Py_DECREF(__pyx_v_v);
      __pyx_v_v = __pyx_5;
      __pyx_5 = 0;
      if (__Pyx_EndUnpack(__pyx_2, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;

      /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":368 */
      if (PyObject_SetItem(__pyx_v_self, __pyx_v_k, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; goto __pyx_L1;}
    }
    __pyx_L6:;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":370 */
    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_TypeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
    Py_INCREF(__pyx_k21p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k21p);
    __pyx_5 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_5, 0, 0);
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; goto __pyx_L1;}
  }
  __pyx_L2:;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("rbtree.RBTree.update");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_k);
  Py_DECREF(__pyx_v_v);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_mapping);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_v;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_key = Py_None; Py_INCREF(__pyx_v_key);
  __pyx_v_v = Py_None; Py_INCREF(__pyx_v_v);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":373 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___iter__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_1 = PyObject_GetAttr(__pyx_3, __pyx_n_next); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_v_key);
  __pyx_v_key = __pyx_3;
  __pyx_3 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":374 */
  __pyx_1 = PyObject_GetItem(__pyx_v_self, __pyx_v_key); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; goto __pyx_L1;}
  Py_DECREF(__pyx_v_v);
  __pyx_v_v = __pyx_1;
  __pyx_1 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":375 */
  if (PyObject_DelItem(__pyx_v_self, __pyx_v_key) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":376 */
  Py_INCREF(__pyx_v_v);
  __pyx_r = __pyx_v_v;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.pop");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_v);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_dumpDot(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_dumpDot(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char (*__pyx_v_filename);
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {"filename",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "s", __pyx_argnames, &__pyx_v_filename)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":379 */
  rbtree_dump_dot(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_filename);

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTree.dumpDot");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_validate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_validate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_verbose;
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {"verbose",0};
  __pyx_v_verbose = __pyx_k9;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|i", __pyx_argnames, &__pyx_v_verbose)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":382 */
  rbtree_validate(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_verbose);

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTree.validate");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_copy(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_copy(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":385 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.copy");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_clear(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_clear(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":388 */
  rbtree_dealloc(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":389 */
  rbtree_free(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":390 */
  ((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree = rbtree_alloc();

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":391 */
  rbtree_init(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree);

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("rbtree.RBTree.clear");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_setdefault(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_setdefault(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_v_default = 0;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"key","default",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_key, &__pyx_v_default)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);
  Py_INCREF(__pyx_v_default);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":394 */
  __pyx_1 = PySequence_Contains(__pyx_v_self, __pyx_v_key); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; goto __pyx_L1;}
  __pyx_1 = !__pyx_1;
  if (__pyx_1) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":395 */
    if (PyObject_SetItem(__pyx_v_self, __pyx_v_key, __pyx_v_default) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; goto __pyx_L1;}

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":396 */
    Py_INCREF(__pyx_v_default);
    __pyx_r = __pyx_v_default;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":397 */
  __pyx_2 = PyObject_GetItem(__pyx_v_self, __pyx_v_key); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("rbtree.RBTree.setdefault");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_default);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_byOffset(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_byOffset(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_offset = 0;
  rbtree_node_t (*__pyx_v_n);
  PyObject *__pyx_v_forward;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"offset",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_offset)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_offset);
  __pyx_v_forward = Py_None; Py_INCREF(__pyx_v_forward);
  __pyx_v_i = Py_None; Py_INCREF(__pyx_v_i);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":402 */
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_v_offset, __pyx_1, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; goto __pyx_L1;}
  __pyx_2 = __pyx_2 >= 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_2) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":403 */
    __pyx_v_n = tree_min(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,0);

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":404 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; goto __pyx_L1;}
    Py_DECREF(__pyx_v_forward);
    __pyx_v_forward = __pyx_1;
    __pyx_1 = 0;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":406 */
    __pyx_v_n = tree_max(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,0);

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":407 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; goto __pyx_L1;}
    Py_DECREF(__pyx_v_forward);
    __pyx_v_forward = __pyx_1;
    __pyx_1 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":408 */
    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_abs); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; goto __pyx_L1;}
    Py_INCREF(__pyx_v_offset);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_offset);
    __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; goto __pyx_L1;}
    __pyx_3 = PyNumber_Subtract(__pyx_4, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_v_offset);
    __pyx_v_offset = __pyx_3;
    __pyx_3 = 0;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":410 */
  __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_xrange); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
  Py_INCREF(__pyx_v_offset);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_offset);
  __pyx_3 = PyObject_CallObject(__pyx_4, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_4 = PyObject_GetIter(__pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  for (;;) {
    __pyx_L3:;
    __pyx_1 = PyIter_Next(__pyx_4);
    if (!__pyx_1) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; goto __pyx_L1;}
      break;
    }
    Py_DECREF(__pyx_v_i);
    __pyx_v_i = __pyx_1;
    __pyx_1 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":411 */
    __pyx_2 = PyObject_IsTrue(__pyx_v_forward); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 411; goto __pyx_L1;}
    if (__pyx_2) {

      /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":412 */
      __pyx_v_n = tree_successor(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_n);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":414 */
      __pyx_v_n = tree_predecessor(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,__pyx_v_n);
    }
    __pyx_L5:;
  }
  __pyx_L4:;
  Py_DECREF(__pyx_4); __pyx_4 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":416 */
  __pyx_3 = (PyObject *)__pyx_v_n->key;
  Py_INCREF(__pyx_3);
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.byOffset");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_forward);
  Py_DECREF(__pyx_v_i);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_offset);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_min(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_min(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  rbtree_node_t (*__pyx_v_n);
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":420 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_3, __pyx_1, &__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; goto __pyx_L1;}
  __pyx_4 = __pyx_4 == 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":421 */
    Py_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":422 */
  __pyx_2 = (PyObject *)tree_min(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,0)->key;
  Py_INCREF(__pyx_2);
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.min");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6rbtree_6RBTree_max(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree_max(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  rbtree_node_t (*__pyx_v_n);
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":426 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; goto __pyx_L1;}
  Py_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_3, __pyx_1, &__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; goto __pyx_L1;}
  __pyx_4 = __pyx_4 == 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (__pyx_4) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":427 */
    Py_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":428 */
  __pyx_2 = (PyObject *)tree_max(((struct __pyx_obj_6rbtree_RBTree *)__pyx_v_self)->_tree,0)->key;
  Py_INCREF(__pyx_2);
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("rbtree.RBTree.max");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_n_append;
static PyObject *__pyx_n_join;
static PyObject *__pyx_n___name__;

static PyObject *__pyx_k22p;
static PyObject *__pyx_k24p;
static PyObject *__pyx_k23p;
static PyObject *__pyx_k25p;
static PyObject *__pyx_k26p;

static char (__pyx_k22[]) = "%r : %r";
static char (__pyx_k23[]) = " ";
static char (__pyx_k24[]) = ", ";
static char (__pyx_k25[]) = "";
static char (__pyx_k26[]) = "<%s%s>";

static PyObject *__pyx_f_6rbtree_6RBTree___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6rbtree_6RBTree___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_res;
  PyObject *__pyx_v_k;
  PyObject *__pyx_v_v;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  int __pyx_5;
  Py_INCREF(__pyx_v_self);
  __pyx_v_res = Py_None; Py_INCREF(__pyx_v_res);
  __pyx_v_k = Py_None; Py_INCREF(__pyx_v_k);
  __pyx_v_v = Py_None; Py_INCREF(__pyx_v_v);

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":431 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; goto __pyx_L1;}
  Py_DECREF(__pyx_v_res);
  __pyx_v_res = __pyx_1;
  __pyx_1 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":432 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_iteritems); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_1 = PyObject_GetIter(__pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  for (;;) {
    __pyx_L2:;
    __pyx_2 = PyIter_Next(__pyx_1);
    if (!__pyx_2) {
      if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
      break;
    }
    __pyx_3 = __Pyx_UnpackItem(__pyx_2, 0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
    Py_DECREF(__pyx_v_k);
    __pyx_v_k = __pyx_3;
    __pyx_3 = 0;
    __pyx_4 = __Pyx_UnpackItem(__pyx_2, 1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
    Py_DECREF(__pyx_v_v);
    __pyx_v_v = __pyx_4;
    __pyx_4 = 0;
    if (__Pyx_EndUnpack(__pyx_2, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":433 */
    __pyx_2 = PyObject_GetAttr(__pyx_v_res, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; goto __pyx_L1;}
    Py_INCREF(__pyx_v_k);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_k);
    Py_INCREF(__pyx_v_v);
    PyTuple_SET_ITEM(__pyx_3, 1, __pyx_v_v);
    __pyx_4 = PyNumber_Remainder(__pyx_k22p, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_4); __pyx_4 = 0;
  }
  __pyx_L3:;
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":434 */
  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; goto __pyx_L1;}
  Py_INCREF(__pyx_v_res);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_res);
  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_5 = PyObject_IsTrue(__pyx_4); if (__pyx_5 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (__pyx_5) {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":435 */
    __pyx_1 = PyObject_GetAttr(__pyx_k24p, __pyx_n_join); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
    Py_INCREF(__pyx_v_res);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_res);
    __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_4 = PyNumber_Add(__pyx_k23p, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_v_res);
    __pyx_v_res = __pyx_4;
    __pyx_4 = 0;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":437 */
    Py_INCREF(__pyx_k25p);
    Py_DECREF(__pyx_v_res);
    __pyx_v_res = __pyx_k25p;
  }
  __pyx_L4:;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":438 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___class__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; goto __pyx_L1;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n___name__); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
  Py_INCREF(__pyx_v_res);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_v_res);
  __pyx_2 = 0;
  __pyx_4 = PyNumber_Remainder(__pyx_k26p, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_r = __pyx_4;
  __pyx_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(__pyx_r);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("rbtree.RBTree.__repr__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_res);
  Py_DECREF(__pyx_v_k);
  Py_DECREF(__pyx_v_v);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static __Pyx_InternTabEntry __pyx_intern_tab[] = {
  {&__pyx_n_False, "False"},
  {&__pyx_n_KeyError, "KeyError"},
  {&__pyx_n_StopIteration, "StopIteration"},
  {&__pyx_n_True, "True"},
  {&__pyx_n_TypeError, "TypeError"},
  {&__pyx_n_ValueError, "ValueError"},
  {&__pyx_n___author__, "__author__"},
  {&__pyx_n___class__, "__class__"},
  {&__pyx_n___copyright__, "__copyright__"},
  {&__pyx_n___docformat__, "__docformat__"},
  {&__pyx_n___dodeleteslice__, "__dodeleteslice__"},
  {&__pyx_n___doslice__, "__doslice__"},
  {&__pyx_n___iter__, "__iter__"},
  {&__pyx_n___license__, "__license__"},
  {&__pyx_n___name__, "__name__"},
  {&__pyx_n_abs, "abs"},
  {&__pyx_n_append, "append"},
  {&__pyx_n_cmp, "cmp"},
  {&__pyx_n_compare, "compare"},
  {&__pyx_n_data, "data"},
  {&__pyx_n_dict, "dict"},
  {&__pyx_n_direction, "direction"},
  {&__pyx_n_hash, "hash"},
  {&__pyx_n_isinstance, "isinstance"},
  {&__pyx_n_item, "item"},
  {&__pyx_n_iteritems, "iteritems"},
  {&__pyx_n_iternodes, "iternodes"},
  {&__pyx_n_itervalues, "itervalues"},
  {&__pyx_n_join, "join"},
  {&__pyx_n_key, "key"},
  {&__pyx_n_len, "len"},
  {&__pyx_n_list, "list"},
  {&__pyx_n_next, "next"},
  {&__pyx_n_restructuredtext, "restructuredtext"},
  {&__pyx_n_slice, "slice"},
  {&__pyx_n_start, "start"},
  {&__pyx_n_step, "step"},
  {&__pyx_n_stop, "stop"},
  {&__pyx_n_tuple, "tuple"},
  {&__pyx_n_update, "update"},
  {&__pyx_n_value, "value"},
  {&__pyx_n_xrange, "xrange"},
  {0, 0}
};

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_k1p, __pyx_k1, sizeof(__pyx_k1)},
  {&__pyx_k3p, __pyx_k3, sizeof(__pyx_k3)},
  {&__pyx_k4p, __pyx_k4, sizeof(__pyx_k4)},
  {&__pyx_k10p, __pyx_k10, sizeof(__pyx_k10)},
  {&__pyx_k11p, __pyx_k11, sizeof(__pyx_k11)},
  {&__pyx_k12p, __pyx_k12, sizeof(__pyx_k12)},
  {&__pyx_k18p, __pyx_k18, sizeof(__pyx_k18)},
  {&__pyx_k19p, __pyx_k19, sizeof(__pyx_k19)},
  {&__pyx_k21p, __pyx_k21, sizeof(__pyx_k21)},
  {&__pyx_k22p, __pyx_k22, sizeof(__pyx_k22)},
  {&__pyx_k24p, __pyx_k24, sizeof(__pyx_k24)},
  {&__pyx_k23p, __pyx_k23, sizeof(__pyx_k23)},
  {&__pyx_k25p, __pyx_k25, sizeof(__pyx_k25)},
  {&__pyx_k26p, __pyx_k26, sizeof(__pyx_k26)},
  {0, 0, 0}
};

static PyObject *__pyx_tp_new_6rbtree_RBTree(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  struct __pyx_obj_6rbtree_RBTree *p = (struct __pyx_obj_6rbtree_RBTree *)o;
  if (__pyx_f_6rbtree_6RBTree___new__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_6rbtree_RBTree(PyObject *o) {
  struct __pyx_obj_6rbtree_RBTree *p = (struct __pyx_obj_6rbtree_RBTree *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++o->ob_refcnt;
    __pyx_f_6rbtree_6RBTree___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --o->ob_refcnt;
    PyErr_Restore(etype, eval, etb);
  }
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_6rbtree_RBTree(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6rbtree_RBTree *p = (struct __pyx_obj_6rbtree_RBTree *)o;
  return 0;
}

static int __pyx_tp_clear_6rbtree_RBTree(PyObject *o) {
  struct __pyx_obj_6rbtree_RBTree *p = (struct __pyx_obj_6rbtree_RBTree *)o;
  return 0;
}
static PyObject *__pyx_sq_item_6rbtree_RBTree(PyObject *o, int i) {
  PyObject *r;
  PyObject *x = PyInt_FromLong(i); if(!x) return 0;
  r = o->ob_type->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_6rbtree_RBTree(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_f_6rbtree_6RBTree___setitem__(o, i, v);
  }
  else {
    return __pyx_f_6rbtree_6RBTree___delitem__(o, i);
  }
}

static struct PyMethodDef __pyx_methods_6rbtree_RBTree[] = {
  {"__getnewargs__", (PyCFunction)__pyx_f_6rbtree_6RBTree___getnewargs__, METH_VARARGS|METH_KEYWORDS, 0},
  {"__getstate__", (PyCFunction)__pyx_f_6rbtree_6RBTree___getstate__, METH_VARARGS|METH_KEYWORDS, 0},
  {"__setstate__", (PyCFunction)__pyx_f_6rbtree_6RBTree___setstate__, METH_VARARGS|METH_KEYWORDS, 0},
  {"__doslice__", (PyCFunction)__pyx_f_6rbtree_6RBTree___doslice__, METH_VARARGS|METH_KEYWORDS, 0},
  {"__dodeleteslice__", (PyCFunction)__pyx_f_6rbtree_6RBTree___dodeleteslice__, METH_VARARGS|METH_KEYWORDS, 0},
  {"get", (PyCFunction)__pyx_f_6rbtree_6RBTree_get, METH_VARARGS|METH_KEYWORDS, 0},
  {"has_key", (PyCFunction)__pyx_f_6rbtree_6RBTree_has_key, METH_VARARGS|METH_KEYWORDS, 0},
  {"iterkeys", (PyCFunction)__pyx_f_6rbtree_6RBTree_iterkeys, METH_VARARGS|METH_KEYWORDS, 0},
  {"itervalues", (PyCFunction)__pyx_f_6rbtree_6RBTree_itervalues, METH_VARARGS|METH_KEYWORDS, 0},
  {"iteritems", (PyCFunction)__pyx_f_6rbtree_6RBTree_iteritems, METH_VARARGS|METH_KEYWORDS, 0},
  {"iternodes", (PyCFunction)__pyx_f_6rbtree_6RBTree_iternodes, METH_VARARGS|METH_KEYWORDS, 0},
  {"keys", (PyCFunction)__pyx_f_6rbtree_6RBTree_keys, METH_VARARGS|METH_KEYWORDS, 0},
  {"values", (PyCFunction)__pyx_f_6rbtree_6RBTree_values, METH_VARARGS|METH_KEYWORDS, 0},
  {"items", (PyCFunction)__pyx_f_6rbtree_6RBTree_items, METH_VARARGS|METH_KEYWORDS, 0},
  {"update", (PyCFunction)__pyx_f_6rbtree_6RBTree_update, METH_VARARGS|METH_KEYWORDS, 0},
  {"pop", (PyCFunction)__pyx_f_6rbtree_6RBTree_pop, METH_VARARGS|METH_KEYWORDS, 0},
  {"dumpDot", (PyCFunction)__pyx_f_6rbtree_6RBTree_dumpDot, METH_VARARGS|METH_KEYWORDS, 0},
  {"validate", (PyCFunction)__pyx_f_6rbtree_6RBTree_validate, METH_VARARGS|METH_KEYWORDS, 0},
  {"copy", (PyCFunction)__pyx_f_6rbtree_6RBTree_copy, METH_VARARGS|METH_KEYWORDS, 0},
  {"clear", (PyCFunction)__pyx_f_6rbtree_6RBTree_clear, METH_VARARGS|METH_KEYWORDS, 0},
  {"setdefault", (PyCFunction)__pyx_f_6rbtree_6RBTree_setdefault, METH_VARARGS|METH_KEYWORDS, 0},
  {"byOffset", (PyCFunction)__pyx_f_6rbtree_6RBTree_byOffset, METH_VARARGS|METH_KEYWORDS, 0},
  {"min", (PyCFunction)__pyx_f_6rbtree_6RBTree_min, METH_VARARGS|METH_KEYWORDS, 0},
  {"max", (PyCFunction)__pyx_f_6rbtree_6RBTree_max, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_RBTree = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  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*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  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*/
};

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

static PyMappingMethods __pyx_tp_as_mapping_RBTree = {
  __pyx_f_6rbtree_6RBTree___len__, /*mp_length*/
  __pyx_f_6rbtree_6RBTree___getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_6rbtree_RBTree, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_RBTree = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

statichere PyTypeObject __pyx_type_6rbtree_RBTree = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "rbtree.RBTree", /*tp_name*/
  sizeof(struct __pyx_obj_6rbtree_RBTree), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6rbtree_RBTree, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  __pyx_f_6rbtree_6RBTree___repr__, /*tp_repr*/
  &__pyx_tp_as_number_RBTree, /*tp_as_number*/
  &__pyx_tp_as_sequence_RBTree, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_RBTree, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_RBTree, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6rbtree_RBTree, /*tp_traverse*/
  __pyx_tp_clear_6rbtree_RBTree, /*tp_clear*/
  __pyx_f_6rbtree_6RBTree___richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_f_6rbtree_6RBTree___iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6rbtree_RBTree, /*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*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6rbtree_RBTree, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};
static struct __pyx_vtabstruct_6rbtree_RBTreeIterator __pyx_vtable_6rbtree_RBTreeIterator;

static PyObject *__pyx_tp_new_6rbtree_RBTreeIterator(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  struct __pyx_obj_6rbtree_RBTreeIterator *p = (struct __pyx_obj_6rbtree_RBTreeIterator *)o;
  p->__pyx_vtab = (struct __pyx_vtabstruct_6rbtree_RBTreeIterator *)__pyx_vtabptr_6rbtree_RBTreeIterator;
  p->_T = Py_None; Py_INCREF((PyObject *) p->_T);
  if (__pyx_f_6rbtree_14RBTreeIterator___new__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_6rbtree_RBTreeIterator(PyObject *o) {
  struct __pyx_obj_6rbtree_RBTreeIterator *p = (struct __pyx_obj_6rbtree_RBTreeIterator *)o;
  Py_XDECREF(p->_T);
  (*o->ob_type->tp_free)(o);
}

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

static int __pyx_tp_clear_6rbtree_RBTreeIterator(PyObject *o) {
  struct __pyx_obj_6rbtree_RBTreeIterator *p = (struct __pyx_obj_6rbtree_RBTreeIterator *)o;
  Py_XDECREF(p->_T);
  p->_T = Py_None; Py_INCREF((PyObject *) p->_T);
  return 0;
}

static PyObject *__pyx_getprop_6rbtree_14RBTreeIterator_direction(PyObject *o, void *x) {
  return __pyx_f_6rbtree_14RBTreeIterator_9direction___get__(o);
}

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

static PyObject *__pyx_getprop_6rbtree_14RBTreeIterator_key(PyObject *o, void *x) {
  return __pyx_f_6rbtree_14RBTreeIterator_3key___get__(o);
}

static PyObject *__pyx_getprop_6rbtree_14RBTreeIterator_value(PyObject *o, void *x) {
  return __pyx_f_6rbtree_14RBTreeIterator_5value___get__(o);
}

static PyObject *__pyx_getprop_6rbtree_14RBTreeIterator_item(PyObject *o, void *x) {
  return __pyx_f_6rbtree_14RBTreeIterator_4item___get__(o);
}

static struct PyMethodDef __pyx_methods_6rbtree_RBTreeIterator[] = {
  {"prev", (PyCFunction)__pyx_f_6rbtree_14RBTreeIterator_prev, METH_VARARGS|METH_KEYWORDS, 0},
  {"goto", (PyCFunction)__pyx_f_6rbtree_14RBTreeIterator_goto, METH_VARARGS|METH_KEYWORDS, 0},
  {"byOffset", (PyCFunction)__pyx_f_6rbtree_14RBTreeIterator_byOffset, METH_VARARGS|METH_KEYWORDS, 0},
  {"delete", (PyCFunction)__pyx_f_6rbtree_14RBTreeIterator_delete, METH_VARARGS|METH_KEYWORDS, 0},
  {"dump", (PyCFunction)__pyx_f_6rbtree_14RBTreeIterator_dump, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6rbtree_RBTreeIterator[] = {
  {"direction", __pyx_getprop_6rbtree_14RBTreeIterator_direction, __pyx_setprop_6rbtree_14RBTreeIterator_direction, 0, 0},
  {"key", __pyx_getprop_6rbtree_14RBTreeIterator_key, 0, 0, 0},
  {"value", __pyx_getprop_6rbtree_14RBTreeIterator_value, 0, 0, 0},
  {"item", __pyx_getprop_6rbtree_14RBTreeIterator_item, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_RBTreeIterator = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  __pyx_f_6rbtree_14RBTreeIterator___nonzero__, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  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*/
};

static PySequenceMethods __pyx_tp_as_sequence_RBTreeIterator = {
  __pyx_f_6rbtree_14RBTreeIterator___len__, /*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_RBTreeIterator = {
  __pyx_f_6rbtree_14RBTreeIterator___len__, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_RBTreeIterator = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

statichere PyTypeObject __pyx_type_6rbtree_RBTreeIterator = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "rbtree.RBTreeIterator", /*tp_name*/
  sizeof(struct __pyx_obj_6rbtree_RBTreeIterator), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6rbtree_RBTreeIterator, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  __pyx_f_6rbtree_14RBTreeIterator___cmp__, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_RBTreeIterator, /*tp_as_number*/
  &__pyx_tp_as_sequence_RBTreeIterator, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_RBTreeIterator, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_RBTreeIterator, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_6rbtree_RBTreeIterator, /*tp_traverse*/
  __pyx_tp_clear_6rbtree_RBTreeIterator, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_f_6rbtree_14RBTreeIterator___iter__, /*tp_iter*/
  __pyx_f_6rbtree_14RBTreeIterator___next__, /*tp_iternext*/
  __pyx_methods_6rbtree_RBTreeIterator, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_6rbtree_RBTreeIterator, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6rbtree_RBTreeIterator, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

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

DL_EXPORT(void) initrbtree(void); /*proto*/
DL_EXPORT(void) initrbtree(void) {
  PyObject *__pyx_1 = 0;
  __pyx_m = Py_InitModule4("rbtree", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (PyType_Ready(&__pyx_type_6rbtree_RBTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "RBTree", (PyObject *)&__pyx_type_6rbtree_RBTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; goto __pyx_L1;}
  __pyx_ptype_6rbtree_RBTree = &__pyx_type_6rbtree_RBTree;
  __pyx_vtabptr_6rbtree_RBTreeIterator = &__pyx_vtable_6rbtree_RBTreeIterator;
  __pyx_vtable_6rbtree_RBTreeIterator._position = (void *)__pyx_f_6rbtree_14RBTreeIterator__position;
  __pyx_vtable_6rbtree_RBTreeIterator.walk = (void *)__pyx_f_6rbtree_14RBTreeIterator_walk;
  __pyx_vtable_6rbtree_RBTreeIterator.step = (void *)__pyx_f_6rbtree_14RBTreeIterator_step;
  __pyx_type_6rbtree_RBTreeIterator.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6rbtree_RBTreeIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;}
  if (__Pyx_SetVtable(__pyx_type_6rbtree_RBTreeIterator.tp_dict, __pyx_vtabptr_6rbtree_RBTreeIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "RBTreeIterator", (PyObject *)&__pyx_type_6rbtree_RBTreeIterator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; goto __pyx_L1;}
  __pyx_ptype_6rbtree_RBTreeIterator = &__pyx_type_6rbtree_RBTreeIterator;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":8 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___author__, __pyx_k1p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":9 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___docformat__, __pyx_n_restructuredtext) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":10 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___copyright__, __pyx_k3p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":11 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n___license__, __pyx_k4p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;}

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":140 */
  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; goto __pyx_L1;}
  __pyx_k5 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":237 */
  Py_INCREF(Py_None);
  __pyx_k6 = Py_None;
  Py_INCREF(Py_None);
  __pyx_k7 = Py_None;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":335 */
  Py_INCREF(Py_None);
  __pyx_k8 = Py_None;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":381 */
  __pyx_k9 = 0;

  /* "/home/bcsaller/src/rbtree/src/rbtree.pyx":430 */
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("rbtree");
}

static char *__pyx_filenames[] = {
  "rbtree.pyx",
};
statichere char **__pyx_f = __pyx_filenames;

/* Runtime support code */

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name) {
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if ((none_allowed && obj == Py_None) || PyObject_TypeCheck(obj, type))
        return 1;
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, obj->ob_type->tp_name);
    return 0;
}

static int __Pyx_GetStarArgs(
    PyObject **args, 
    PyObject **kwds,
    char *kwd_list[], 
    int nargs,
    PyObject **args2, 
    PyObject **kwds2)
{
    PyObject *x = 0, *args1 = 0, *kwds1 = 0;
    
    if (args2)
        *args2 = 0;
    if (kwds2)
        *kwds2 = 0;
    
    if (args2) {
        args1 = PyTuple_GetSlice(*args, 0, nargs);
        if (!args1)
            goto bad;
        *args2 = PyTuple_GetSlice(*args, nargs, PyTuple_Size(*args));
        if (!*args2)
            goto bad;
    }
    else {
        args1 = *args;
        Py_INCREF(args1);
    }
    
    if (kwds2) {
        if (*kwds) {
            char **p;
            kwds1 = PyDict_New();
            if (!kwds)
                goto bad;
            *kwds2 = PyDict_Copy(*kwds);
            if (!*kwds2)
                goto bad;
            for (p = kwd_list; *p; p++) {
                x = PyDict_GetItemString(*kwds, *p);
                if (x) {
                    if (PyDict_SetItemString(kwds1, *p, x) < 0)
                        goto bad;
                    if (PyDict_DelItemString(*kwds2, *p) < 0)
                        goto bad;
                }
            }
        }
        else {
            *kwds2 = PyDict_New();
            if (!*kwds2)
                goto bad;
        }
    }
    else {
        kwds1 = *kwds;
        Py_XINCREF(kwds1);
    }
    
    *args = args1;
    *kwds = kwds1;
    return 0;
bad:
    Py_XDECREF(args1);
    Py_XDECREF(kwds1);
    if (*args2)
        Py_XDECREF(*args2);
    if (*kwds2)
        Py_XDECREF(*kwds2);
    return -1;
}

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

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    /* Next, repeatedly, replace a tuple exception with its first item */
    while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
        PyObject *tmp = type;
        type = PyTuple_GET_ITEM(type, 0);
        Py_INCREF(type);
        Py_DECREF(tmp);
    }
    if (PyString_Check(type))
        ;
    else if (PyClass_Check(type))
        ; /*PyErr_NormalizeException(&type, &value, &tb);*/
    else if (PyInstance_Check(type)) {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
              "instance exception may not have a separate value");
            goto raise_error;
        }
        else {
            /* Normalize to raise <class>, <instance> */
            Py_DECREF(value);
            value = type;
            type = (PyObject*) ((PyInstanceObject*)type)->in_class;
            Py_INCREF(type);
        }
    }
    else {
        /* Not something you can raise.  You get an exception
           anyway, just not what you specified :-) */
        PyErr_Format(PyExc_TypeError,
                 "exceptions must be strings, classes, or "
                 "instances, not %s", type->ob_type->tp_name);
        goto raise_error;
    }
    PyErr_Restore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static void __Pyx_WriteUnraisable(char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    PyErr_Fetch(&old_exc, &old_val, &old_tb);
    ctx = PyString_FromString(name);
    PyErr_Restore(old_exc, old_val, old_tb);
    if (!ctx)
        ctx = Py_None;
    PyErr_WriteUnraisable(ctx);
}

static PyObject *__Pyx_GetExcValue(void) {
    PyObject *type = 0, *value = 0, *tb = 0;
    PyObject *result = 0;
    PyThreadState *tstate = PyThreadState_Get();
    PyErr_Fetch(&type, &value, &tb);
    PyErr_NormalizeException(&type, &value, &tb);
    if (PyErr_Occurred())
        goto bad;
    if (!value) {
        value = Py_None;
        Py_INCREF(value);
    }
    Py_XDECREF(tstate->exc_type);
    Py_XDECREF(tstate->exc_value);
    Py_XDECREF(tstate->exc_traceback);
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    result = value;
    Py_XINCREF(result);
    type = 0;
    value = 0;
    tb = 0;
bad:
    Py_XDECREF(type);
    Py_XDECREF(value);
    Py_XDECREF(tb);
    return result;
}

static void __Pyx_UnpackError(void) {
    PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size");
}

static PyObject *__Pyx_UnpackItem(PyObject *seq, int i) {
  PyObject *item;
  if (!(item = PySequence_GetItem(seq, i))) {
    if (PyErr_ExceptionMatches(PyExc_IndexError))
    	__Pyx_UnpackError();
  }
  return item;
}

static int __Pyx_EndUnpack(PyObject *seq, int i) {
  PyObject *item;
  if (item = PySequence_GetItem(seq, i)) {
    Py_DECREF(item);
    __Pyx_UnpackError();
    return -1;
  }
  PyErr_Clear();
    return 0;
}

static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
    while (t->p) {
        *t->p = PyString_InternFromString(t->s);
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
    PyObject *pycobj = 0;
    int result;
    
    pycobj = PyCObject_FromVoidPtr(vtable, 0);
    if (!pycobj)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0)
        goto bad;
    result = 0;
    goto done;

bad:
    result = -1;
done:
    Py_XDECREF(pycobj);
    return result;
}

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

static void __Pyx_AddTraceback(char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_tuple = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    
    py_srcfile = PyString_FromString(__pyx_filename);
    if (!py_srcfile) goto bad;
    py_funcname = PyString_FromString(funcname);
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    empty_tuple = PyTuple_New(0);
    if (!empty_tuple) goto bad;
    empty_string = PyString_FromString("");
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        empty_tuple,  /*PyObject *consts,*/
        empty_tuple,  /*PyObject *names,*/
        empty_tuple,  /*PyObject *varnames,*/
        empty_tuple,  /*PyObject *freevars,*/
        empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_Get(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_tuple);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
