Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
heap.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <cgraph/alloc.h>
12#include <common/render.h>
13#include <stdbool.h>
14
15#include <neatogen/mem.h>
16#include <neatogen/hedges.h>
17#include <neatogen/heap.h>
18
19
21static int PQhashsize;
22static int PQcount;
23static int PQmin;
24
25static int PQbucket(Halfedge * he)
26{
27 int bucket;
28 double b;
29
30 b = (he->ystar - ymin) / deltay * PQhashsize;
31 if (b < 0)
32 bucket = 0;
33 else if (b >= PQhashsize)
34 bucket = PQhashsize - 1;
35 else
36 bucket = b;
37 if (bucket < PQmin)
38 PQmin = bucket;
39 return bucket;
40}
41
42void PQinsert(Halfedge * he, Site * v, double offset)
43{
44 Halfedge *last, *next;
45
46 he->vertex = v;
47 ref(v);
48 he->ystar = v->coord.y + offset;
49 last = &PQhash[PQbucket(he)];
50 while ((next = last->PQnext) != NULL &&
51 (he->ystar > next->ystar ||
52 (he->ystar == next->ystar
53 && v->coord.x > next->vertex->coord.x))) {
54 last = next;
55 }
56 he->PQnext = last->PQnext;
57 last->PQnext = he;
58 ++PQcount;
59}
60
62{
64
65 if (he->vertex != NULL) {
66 last = &PQhash[PQbucket(he)];
67 while (last->PQnext != he)
68 last = last->PQnext;
69 last->PQnext = he->PQnext;
70 --PQcount;
71 deref(he->vertex);
72 he->vertex = NULL;
73 }
74}
75
76
77bool PQempty(void)
78{
79 return PQcount == 0;
80}
81
82
84{
85 Point answer;
86
87 while (PQhash[PQmin].PQnext == NULL) {
88 ++PQmin;
89 }
90 answer.x = PQhash[PQmin].PQnext->vertex->coord.x;
91 answer.y = PQhash[PQmin].PQnext->ystar;
92 return answer;
93}
94
96{
97 Halfedge *curr;
98
99 curr = PQhash[PQmin].PQnext;
100 PQhash[PQmin].PQnext = curr->PQnext;
101 --PQcount;
102 return curr;
103}
104
105void PQcleanup(void)
106{
107 free(PQhash);
108 PQhash = NULL;
109}
110
111void PQinitialize(void)
112{
113 int i;
114
115 PQcount = 0;
116 PQmin = 0;
118 if (PQhash == NULL)
120 for (i = 0; i < PQhashsize; ++i)
121 PQhash[i].PQnext = NULL;
122}
static agxbuf last
last message
Definition agerror.c:29
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
static Agobj_t * deref(Expr_t *pgm, Exnode_t *x, Exref_t *ref, Agobj_t *objp, Gpr_t *state)
Definition compile.c:278
double ymin
Definition geometry.c:15
int sqrt_nsites
Definition geometry.c:20
double deltay
Definition geometry.c:17
void free(void *)
node NULL
Definition grammar.y:149
swig_ptr_object_handlers offset
Definition gv_php.cpp:5915
void PQdelete(Halfedge *he)
Definition heap.c:61
bool PQempty(void)
Definition heap.c:77
static int PQcount
Definition heap.c:22
Halfedge * PQextractmin(void)
Definition heap.c:95
void PQinitialize(void)
Definition heap.c:111
Point PQ_min(void)
Definition heap.c:83
void PQinsert(Halfedge *he, Site *v, double offset)
Definition heap.c:42
static int PQhashsize
Definition heap.c:21
void PQcleanup(void)
Definition heap.c:105
static Halfedge * PQhash
Definition heap.c:20
static int PQbucket(Halfedge *he)
Definition heap.c:25
static int PQmin
Definition heap.c:23
void ref(Site *v)
Definition site.c:59
double ystar
Definition hedges.h:26
struct Halfedge * PQnext
Definition hedges.h:27
Site * vertex
Definition hedges.h:25
double x
Definition geometry.h:23
double y
Definition geometry.h:23
Definition site.h:22
Point coord
Definition site.h:23