/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/cdt/dtrenew.c

Go to the documentation of this file.
00001 /* $Id: dtrenew.c,v 1.1.1.1 2004/12/23 04:04:00 ellson Exp $ $Revision: 1.1.1.1 $ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /**********************************************************
00005 *      This software is part of the graphviz package      *
00006 *                http://www.graphviz.org/                 *
00007 *                                                         *
00008 *            Copyright (c) 1994-2004 AT&T Corp.           *
00009 *                and is licensed under the                *
00010 *            Common Public License, Version 1.0           *
00011 *                      by AT&T Corp.                      *
00012 *                                                         *
00013 *        Information and Software Systems Research        *
00014 *              AT&T Research, Florham Park NJ             *
00015 **********************************************************/
00016 
00017 #include        "dthdr.h"
00018 
00019 #ifdef DMALLOC
00020 #include "dmalloc.h"
00021 #endif
00022 
00023 /*      Renew the object at the current finger.
00024 **
00025 **      Written by Kiem-Phong Vo (5/25/96)
00026 */
00027 
00028 #if __STD_C
00029 Void_t *dtrenew(Dt_t * dt, reg Void_t * obj)
00030 #else
00031 Void_t *dtrenew(dt, obj)
00032 Dt_t *dt;
00033 reg Void_t *obj;
00034 #endif
00035 {
00036     reg Void_t *key;
00037     reg Dtlink_t *e, *t, **s;
00038     reg Dtdisc_t *disc = dt->disc;
00039 
00040     UNFLATTEN(dt);
00041 
00042     if (!(e = dt->data->here) || OBJ(e, disc->link) != obj)
00043         return NIL(Void_t *);
00044 
00045     if (dt->data->type & (DT_STACK | DT_QUEUE | DT_LIST))
00046         return obj;
00047     else if (dt->data->type & (DT_OSET | DT_OBAG)) {
00048         if (!e->right)          /* make left child the new root */
00049             dt->data->here = e->left;
00050         else {                  /* make right child the new root */
00051             dt->data->here = e->right;
00052 
00053             /* merge left subtree to right subtree */
00054             if (e->left) {
00055                 for (t = e->right; t->left; t = t->left);
00056                 t->left = e->left;
00057             }
00058         }
00059     } else {                    /*if(dt->data->type&(DT_SET|DT_BAG)) */
00060         s = dt->data->htab + HINDEX(dt->data->ntab, e->hash);
00061         if ((t = *s) == e)
00062             *s = e->right;
00063         else {
00064             for (; t->right != e; t = t->right);
00065             t->right = e->right;
00066         }
00067         key = KEY(obj, disc->key, disc->size);
00068         e->hash = HASH(dt, key, disc, disc->size);
00069         dt->data->here = NIL(Dtlink_t *);
00070     }
00071 
00072     dt->data->size -= 1;
00073     return (*dt->meth->searchf) (dt, (Void_t *) e,
00074                                  DT_RENEW) ? obj : NIL(Void_t *);
00075 }

Generated on Mon Mar 31 19:03:23 2008 for Graphviz by  doxygen 1.5.1