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

Go to the documentation of this file.
00001 /* $Id: dtflatten.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 /*      Flatten a dictionary into a linked list.
00024 **      This may be used when many traversals are likely.
00025 **
00026 **      Written by Kiem-Phong Vo (5/25/96).
00027 */
00028 
00029 #if __STD_C
00030 Dtlink_t *dtflatten(Dt_t * dt)
00031 #else
00032 Dtlink_t *dtflatten(dt)
00033 Dt_t *dt;
00034 #endif
00035 {
00036     reg Dtlink_t *t, *r, *list, *last, **s, **ends;
00037 
00038     /* already flattened */
00039     if (dt->data->type & DT_FLATTEN)
00040         return dt->data->here;
00041 
00042     list = last = NIL(Dtlink_t *);
00043     if (dt->data->type & (DT_SET | DT_BAG)) {
00044         for (ends = (s = dt->data->htab) + dt->data->ntab; s < ends; ++s) {
00045             if ((t = *s)) {
00046                 if (last)
00047                     last->right = t;
00048                 else
00049                     list = last = t;
00050                 while (last->right)
00051                     last = last->right;
00052                 *s = last;
00053             }
00054         }
00055     } else if (dt->data->type & (DT_LIST | DT_STACK | DT_QUEUE))
00056         list = dt->data->head;
00057     else if ((r = dt->data->here)) {    /*if(dt->data->type&(DT_OSET|DT_OBAG)) */
00058         while ((t = r->left))
00059             RROTATE(r, t);
00060         for (list = last = r, r = r->right; r; last = r, r = r->right) {
00061             if ((t = r->left)) {
00062                 do
00063                     RROTATE(r, t);
00064                 while ((t = r->left));
00065 
00066                 last->right = r;
00067             }
00068         }
00069     }
00070 
00071     dt->data->here = list;
00072     dt->data->type |= DT_FLATTEN;
00073 
00074     return list;
00075 }

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