static void _avl_walk_init(uu_avl_walk_t *wp, uu_avl_t *ap, uint32_t flags) { uu_avl_walk_t *next, *prev; int robust = (flags & UU_WALK_ROBUST); int direction = (flags & UU_WALK_REVERSE)? -1 : 1; (void) memset(wp, 0, sizeof (*wp)); wp->uaw_avl = ap; wp->uaw_robust = robust; wp->uaw_dir = direction; if (direction > 0) wp->uaw_next_result = avl_first(&ap->ua_tree); else wp->uaw_next_result = avl_last(&ap->ua_tree); if (ap->ua_debug || robust) { wp->uaw_next = next = &ap->ua_null_walk; wp->uaw_prev = prev = next->uaw_prev; next->uaw_prev = wp; prev->uaw_next = wp; } }
avl_node *avl_prev(avl_node *n){ if(n->left){ return avl_last(n->left); } avl_node *p = n;//inorder predecessor of n while(p->parent && p->parent->right != p){ p = p->parent; } return p->parent; }
Py_LOCAL(PyObject *) avl_tree_max(avl_tree_Object * self, PyObject * args) { void *res; PyObject *rv; if (!PyArg_ParseTuple(args, "")) { return NULL; } if ((res = avl_last(self->tree)) == NULL) { PyErr_SetString(PyExc_ValueError, "Attempted to get max of empty tree"); return NULL; } rv = objectAt(res); Py_INCREF(rv); return rv; }
void * uu_avl_last(uu_avl_t *ap) { return (avl_last(&ap->ua_tree)); }