Graphviz 2.29.20120208.0545
lib/cdt/dtrenew.c
Go to the documentation of this file.
00001 #include        "dthdr.h"
00002 
00003 
00004 /*      Renew the object at the current finger.
00005 **
00006 **      Written by Kiem-Phong Vo (5/25/96)
00007 */
00008 
00009 #if __STD_C
00010 Void_t* dtrenew(Dt_t* dt, reg Void_t* obj)
00011 #else
00012 Void_t* dtrenew(dt, obj)
00013 Dt_t*           dt;
00014 reg Void_t*     obj;
00015 #endif
00016 {
00017         reg Void_t*     key;
00018         reg Dtlink_t    *e, *t, **s;
00019         reg Dtdisc_t*   disc = dt->disc;
00020 
00021         UNFLATTEN(dt);
00022 
00023         if(!(e = dt->data->here) || _DTOBJ(e,disc->link) != obj)
00024                 return NIL(Void_t*);
00025 
00026         if(dt->data->type&(DT_STACK|DT_QUEUE|DT_LIST))
00027                 return obj;
00028         else if(dt->data->type&(DT_OSET|DT_OBAG) )
00029         {       if(!e->right )  /* make left child the new root */
00030                         dt->data->here = e->left;
00031                 else            /* make right child the new root */
00032                 {       dt->data->here = e->right;
00033 
00034                         /* merge left subtree to right subtree */
00035                         if(e->left)
00036                         {       for(t = e->right; t->left; t = t->left)
00037                                         ;
00038                                 t->left = e->left;
00039                         }
00040                 }
00041         }
00042         else /*if(dt->data->type&(DT_SET|DT_BAG))*/
00043         {       s = dt->data->htab + HINDEX(dt->data->ntab,e->hash);
00044                 if((t = *s) == e)
00045                         *s = e->right;
00046                 else
00047                 {       for(; t->right != e; t = t->right)
00048                                 ;
00049                         t->right = e->right;
00050                 }
00051                 key = _DTKEY(obj,disc->key,disc->size);
00052                 e->hash = _DTHSH(dt,key,disc,disc->size);
00053                 dt->data->here = NIL(Dtlink_t*);
00054         }
00055 
00056         dt->data->size -= 1;
00057         return (*dt->meth->searchf)(dt,(Void_t*)e,DT_RENEW) ? obj : NIL(Void_t*);
00058 }