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

Go to the documentation of this file.
00001 /* $Id: dtdisc.c,v 1.1.1.1 2004/12/23 04:03:59 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 /*      Change discipline.
00024 **      dt :    dictionary
00025 **      disc :  discipline
00026 **
00027 **      Written by Kiem-Phong Vo (5/26/96)
00028 */
00029 
00030 #if __STD_C
00031 static Void_t *dtmemory(Dt_t * dt, Void_t * addr, size_t size,
00032                         Dtdisc_t * disc)
00033 #else
00034 static Void_t *dtmemory(dt, addr, size, disc)
00035 Dt_t *dt;                       /* dictionary                   */
00036 Void_t *addr;                   /* address to be manipulate     */
00037 size_t size;                    /* size to obtain               */
00038 Dtdisc_t *disc;                 /* discipline                   */
00039 #endif
00040 {
00041     if (addr) {
00042         if (size == 0) {
00043             free(addr);
00044             return NIL(Void_t *);
00045         } else
00046             return realloc(addr, size);
00047     } else
00048         return size > 0 ? malloc(size) : NIL(Void_t *);
00049 }
00050 
00051 #if __STD_C
00052 Dtdisc_t *dtdisc(Dt_t * dt, Dtdisc_t * disc, int type)
00053 #else
00054 Dtdisc_t *dtdisc(dt, disc, type)
00055 Dt_t *dt;
00056 Dtdisc_t *disc;
00057 int type;
00058 #endif
00059 {
00060     reg Dtsearch_f searchf;
00061     reg Dtlink_t *r, *t;
00062     reg char *k;
00063     reg Dtdisc_t *old;
00064 
00065     if (!(old = dt->disc)) {    /* initialization call from dtopen() */
00066         dt->disc = disc;
00067         if (!(dt->memoryf = disc->memoryf))
00068             dt->memoryf = dtmemory;
00069         return disc;
00070     }
00071 
00072     if (!disc)                  /* only want to know current discipline */
00073         return old;
00074 
00075     searchf = dt->meth->searchf;
00076 
00077     UNFLATTEN(dt);
00078 
00079     if (old->eventf
00080         && (*old->eventf) (dt, DT_DISC, (Void_t *) disc, old) < 0)
00081         return NIL(Dtdisc_t *);
00082 
00083     dt->disc = disc;
00084     if (!(dt->memoryf = disc->memoryf))
00085         dt->memoryf = dtmemory;
00086 
00087     if (dt->data->type & (DT_STACK | DT_QUEUE | DT_LIST))
00088         goto done;
00089     else if (dt->data->type & DT_BAG) {
00090         if (type & DT_SAMEHASH)
00091             goto done;
00092         else
00093             goto dt_renew;
00094     } else if (dt->data->type & (DT_SET | DT_BAG)) {
00095         if ((type & DT_SAMEHASH) && (type & DT_SAMECMP))
00096             goto done;
00097         else
00098             goto dt_renew;
00099     } else {                    /*if(dt->data->type&(DT_OSET|DT_OBAG)) */
00100         if (type & DT_SAMECMP)
00101             goto done;
00102       dt_renew:
00103         r = dtflatten(dt);
00104         dt->data->type &= ~DT_FLATTEN;
00105         dt->data->here = NIL(Dtlink_t *);
00106         dt->data->size = 0;
00107 
00108         if (dt->data->type & (DT_SET | DT_BAG)) {
00109             reg Dtlink_t **s, **ends;
00110             ends = (s = dt->data->htab) + dt->data->ntab;
00111             while (s < ends)
00112                 *s++ = NIL(Dtlink_t *);
00113         }
00114 
00115         /* reinsert them */
00116         while (r) {
00117             t = r->right;
00118             if (!(type & DT_SAMEHASH)) {        /* new hash value */
00119                 k = (char *) OBJ(r, disc->link);
00120                 k = KEY((Void_t *) k, disc->key, disc->size);
00121                 r->hash = HASH(dt, k, disc, disc->size);
00122             }
00123             (void) (*searchf) (dt, (Void_t *) r, DT_RENEW);
00124             r = t;
00125         }
00126     }
00127 
00128   done:
00129     return old;
00130 }

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