/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/neatogen/heap.c

Go to the documentation of this file.
00001 /* $Id: heap.c,v 1.3 2005/03/30 23:17:05 erg Exp $ $Revision: 1.3 $ */
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 
00018 #include "render.h"
00019 #include <stdio.h>
00020 
00021 #include "mem.h"
00022 #include "hedges.h"
00023 #include "heap.h"
00024 
00025 
00026 static Halfedge *PQhash;
00027 static int PQhashsize;
00028 static int PQcount;
00029 static int PQmin;
00030 
00031 static int PQbucket(Halfedge * he)
00032 {
00033     int bucket;
00034     double b;
00035 
00036     b = (he->ystar - ymin) / deltay * PQhashsize;
00037     if (b < 0)
00038         bucket = 0;
00039     else if (b >= PQhashsize)
00040         bucket = PQhashsize - 1;
00041     else
00042         bucket = b;
00043     if (bucket < PQmin)
00044         PQmin = bucket;
00045     return (bucket);
00046 }
00047 
00048 void PQinsert(Halfedge * he, Site * v, double offset)
00049 {
00050     Halfedge *last, *next;
00051 
00052     he->vertex = v;
00053     ref(v);
00054     he->ystar = v->coord.y + offset;
00055     last = &PQhash[PQbucket(he)];
00056     while ((next = last->PQnext) != (struct Halfedge *) NULL &&
00057            (he->ystar > next->ystar ||
00058             (he->ystar == next->ystar
00059              && v->coord.x > next->vertex->coord.x))) {
00060         last = next;
00061     }
00062     he->PQnext = last->PQnext;
00063     last->PQnext = he;
00064     PQcount += 1;
00065 }
00066 
00067 void PQdelete(Halfedge * he)
00068 {
00069     Halfedge *last;
00070 
00071     if (he->vertex != (Site *) NULL) {
00072         last = &PQhash[PQbucket(he)];
00073         while (last->PQnext != he)
00074             last = last->PQnext;
00075         last->PQnext = he->PQnext;
00076         PQcount -= 1;
00077         deref(he->vertex);
00078         he->vertex = (Site *) NULL;
00079     }
00080 }
00081 
00082 
00083 int PQempty(void)
00084 {
00085     return (PQcount == 0);
00086 }
00087 
00088 
00089 Point PQ_min(void)
00090 {
00091     Point answer;
00092 
00093     while (PQhash[PQmin].PQnext == (struct Halfedge *) NULL) {
00094         PQmin += 1;
00095     }
00096     answer.x = PQhash[PQmin].PQnext->vertex->coord.x;
00097     answer.y = PQhash[PQmin].PQnext->ystar;
00098     return (answer);
00099 }
00100 
00101 Halfedge *PQextractmin(void)
00102 {
00103     Halfedge *curr;
00104 
00105     curr = PQhash[PQmin].PQnext;
00106     PQhash[PQmin].PQnext = curr->PQnext;
00107     PQcount -= 1;
00108     return (curr);
00109 }
00110 
00111 void PQcleanup(void)
00112 {
00113     free(PQhash);
00114     PQhash = NULL;
00115 }
00116 
00117 void PQinitialize(void)
00118 {
00119     int i;
00120 
00121     PQcount = 0;
00122     PQmin = 0;
00123     PQhashsize = 4 * sqrt_nsites;
00124     if (PQhash == NULL)
00125         PQhash = N_GNEW(PQhashsize, Halfedge);
00126     for (i = 0; i < PQhashsize; i += 1)
00127         PQhash[i].PQnext = (Halfedge *) NULL;
00128 }
00129 
00130 static void PQdumphe(Halfedge * p)
00131 {
00132     printf("  [%p] %p %p %d %d %d %d %f\n",
00133            p, p->ELleft, p->ELright, p->ELedge->edgenbr,
00134            p->ELrefcnt, p->ELpm, (p->vertex ? p->vertex->sitenbr : -1),
00135            p->ystar);
00136 }
00137 
00138 void PQdump(void)
00139 {
00140     int i;
00141     Halfedge *p;
00142 
00143     for (i = 0; i < PQhashsize; i += 1) {
00144         printf("[%d]\n", i);
00145         p = PQhash[i].PQnext;
00146         while (p != NULL) {
00147             PQdumphe(p);
00148             p = p->PQnext;
00149         }
00150     }
00151 
00152 }

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