Exemple #1
0
static void remove_successor(pcu_aa_tree* t, struct remove_vars* v)
{
  assert(*t);
  if (*t != &pcu_aa_bottom)
  { /* search down the tree and set pointers last and deleted */
    v->last = *t;
    if (v->less(v->x,*t))
      remove_successor(&((*t)->left),v);
    else
    {
      v->deleted = *t;
      remove_successor(&((*t)->right),v);
    }
  }
  /* at the bottom of the tree we remove the element (if it is present) */
  if ((*t == v->last)&&(v->deleted != &pcu_aa_bottom)
    &&(!v->less(v->x,v->deleted))&&(!v->less(v->deleted,v->x)))
  {
    v->successor = *t;
    *t = (*t)->right;
  }
  /* on the way back, we rebalance */
  else if (((*t)->left->level < (*t)->level-1)
       ||((*t)->right->level < (*t)->level-1))
  {
    --((*t)->level);
    if ((*t)->right->level > (*t)->level)
      (*t)->right->level = (*t)->level;
    skew(t);
    skew(&((*t)->right));
    skew(&((*t)->right->right));
    split(t);
    split(&((*t)->right));
  }
}
Exemple #2
0
pcu_aa_node* pcu_aa_remove(pcu_aa_node* x, pcu_aa_tree* t, pcu_aa_less* less)
{
  struct remove_vars v;
  v.x = x;
  v.less = less;
  v.deleted = &pcu_aa_bottom;
  v.last = 0;
  v.successor = 0;
  remove_successor(t,&v);
  if (!v.successor)
    return 0;
  if (v.successor != v.deleted)
    swap_successor(t,&v);
  return v.deleted;
}
void	ProcessingStep::remove_successor(ProcessingStepPtr step) {
	remove_successor(&*step);
}