ReactOS 0.4.15-dev-7907-g95bf896
priorityq-heap.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PQnode
 
struct  PQhandleElem
 
struct  PriorityQ
 

Macros

#define PQkey   PQHeapKey
 
#define PQhandle   PQHeapHandle
 
#define PriorityQ   PriorityQHeap
 
#define pqNewPriorityQ(leq)   __gl_pqHeapNewPriorityQ(leq)
 
#define pqDeletePriorityQ(pq)   __gl_pqHeapDeletePriorityQ(pq)
 
#define pqInit(pq)   __gl_pqHeapInit(pq)
 
#define pqInsert(pq, key)   __gl_pqHeapInsert(pq,key)
 
#define pqMinimum(pq)   __gl_pqHeapMinimum(pq)
 
#define pqExtractMin(pq)   __gl_pqHeapExtractMin(pq)
 
#define pqDelete(pq, handle)   __gl_pqHeapDelete(pq,handle)
 
#define pqIsEmpty(pq)   __gl_pqHeapIsEmpty(pq)
 
#define __gl_pqHeapMinimum(pq)   ((pq)->handles[(pq)->nodes[1].handle].key)
 
#define __gl_pqHeapIsEmpty(pq)   ((pq)->size == 0)
 

Typedefs

typedef voidPQkey
 
typedef long PQhandle
 
typedef struct PriorityQ PriorityQ
 

Functions

PriorityQpqNewPriorityQ (int(*leq)(PQkey key1, PQkey key2))
 
void pqDeletePriorityQ (PriorityQ *pq)
 
void pqInit (PriorityQ *pq)
 
PQhandle pqInsert (PriorityQ *pq, PQkey key)
 
PQkey pqExtractMin (PriorityQ *pq)
 
void pqDelete (PriorityQ *pq, PQhandle handle)
 

Macro Definition Documentation

◆ __gl_pqHeapIsEmpty

#define __gl_pqHeapIsEmpty (   pq)    ((pq)->size == 0)

Definition at line 105 of file priorityq-heap.h.

◆ __gl_pqHeapMinimum

#define __gl_pqHeapMinimum (   pq)    ((pq)->handles[(pq)->nodes[1].handle].key)

Definition at line 104 of file priorityq-heap.h.

◆ pqDelete

#define pqDelete (   pq,
  handle 
)    __gl_pqHeapDelete(pq,handle)

Definition at line 64 of file priorityq-heap.h.

◆ pqDeletePriorityQ

#define pqDeletePriorityQ (   pq)    __gl_pqHeapDeletePriorityQ(pq)

Definition at line 45 of file priorityq-heap.h.

◆ pqExtractMin

#define pqExtractMin (   pq)    __gl_pqHeapExtractMin(pq)

Definition at line 63 of file priorityq-heap.h.

◆ PQhandle

#define PQhandle   PQHeapHandle

Definition at line 41 of file priorityq-heap.h.

◆ pqInit

#define pqInit (   pq)    __gl_pqHeapInit(pq)

Definition at line 60 of file priorityq-heap.h.

◆ pqInsert

#define pqInsert (   pq,
  key 
)    __gl_pqHeapInsert(pq,key)

Definition at line 61 of file priorityq-heap.h.

◆ pqIsEmpty

#define pqIsEmpty (   pq)    __gl_pqHeapIsEmpty(pq)

Definition at line 65 of file priorityq-heap.h.

◆ PQkey

#define PQkey   PQHeapKey

Definition at line 40 of file priorityq-heap.h.

◆ pqMinimum

#define pqMinimum (   pq)    __gl_pqHeapMinimum(pq)

Definition at line 62 of file priorityq-heap.h.

◆ pqNewPriorityQ

#define pqNewPriorityQ (   leq)    __gl_pqHeapNewPriorityQ(leq)

Definition at line 44 of file priorityq-heap.h.

◆ PriorityQ

#define PriorityQ   PriorityQHeap

Definition at line 42 of file priorityq-heap.h.

Typedef Documentation

◆ PQhandle

typedef long PQhandle

Definition at line 80 of file priorityq-heap.h.

◆ PQkey

typedef void* PQkey

Definition at line 79 of file priorityq-heap.h.

◆ PriorityQ

Definition at line 81 of file priorityq-heap.h.

Function Documentation

◆ pqDelete()

void pqDelete ( PriorityQ pq,
PQhandle  handle 
)

Definition at line 234 of file priorityq-heap.c.

235{
236 PQnode *n = pq->nodes;
237 PQhandleElem *h = pq->handles;
238 long curr;
239
240 assert( hCurr >= 1 && hCurr <= pq->max && h[hCurr].key != NULL );
241
242 curr = h[hCurr].node;
243 n[curr].handle = n[pq->size].handle;
244 h[n[curr].handle].node = curr;
245
246 if( curr <= -- pq->size ) {
247 if( curr <= 1 || LEQ( h[n[curr>>1].handle].key, h[n[curr].handle].key )) {
248 FloatDown( pq, curr );
249 } else {
250 FloatUp( pq, curr );
251 }
252 }
253 h[hCurr].key = NULL;
254 h[hCurr].node = pq->freeList;
255 pq->freeList = hCurr;
256}
#define NULL
Definition: types.h:112
#define assert(x)
Definition: debug.h:53
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define LEQ(x, y)
static void FloatDown(PriorityQ *pq, long curr)
static void FloatUp(PriorityQ *pq, long curr)
PQnode * nodes
PQhandleElem * handles
PQhandle freeList
Definition: copy.c:22
#define max(a, b)
Definition: svc.c:63

◆ pqDeletePriorityQ()

void pqDeletePriorityQ ( PriorityQ pq)

Definition at line 88 of file priorityq-heap.c.

89{
90 memFree( pq->handles );
91 memFree( pq->nodes );
92 memFree( pq );
93}
#define memFree
Definition: memalloc.h:41

◆ pqExtractMin()

PQkey pqExtractMin ( PriorityQ pq)

Definition at line 211 of file priorityq-heap.c.

212{
213 PQnode *n = pq->nodes;
214 PQhandleElem *h = pq->handles;
215 PQhandle hMin = n[1].handle;
216 PQkey min = h[hMin].key;
217
218 if( pq->size > 0 ) {
219 n[1].handle = n[pq->size].handle;
220 h[n[1].handle].node = 1;
221
222 h[hMin].key = NULL;
223 h[hMin].node = pq->freeList;
224 pq->freeList = hMin;
225
226 if( -- pq->size > 0 ) {
227 FloatDown( pq, 1 );
228 }
229 }
230 return min;
231}
#define min(a, b)
Definition: monoChain.cc:55
long PQhandle

◆ pqInit()

void pqInit ( PriorityQ pq)

Definition at line 149 of file priorityq-heap.c.

150{
151 long i;
152
153 /* This method of building a heap is O(n), rather than O(n lg n). */
154
155 for( i = pq->size; i >= 1; --i ) {
156 FloatDown( pq, i );
157 }
158 pq->initialized = TRUE;
159}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define TRUE

◆ pqInsert()

PQhandle pqInsert ( PriorityQ pq,
PQkey  key 
)

Definition at line 163 of file priorityq-heap.c.

164{
165 long curr;
167
168 curr = ++ pq->size;
169 if( (curr*2) > pq->max ) {
170 PQnode *saveNodes= pq->nodes;
171 PQhandleElem *saveHandles= pq->handles;
172
173 /* If the heap overflows, double its size. */
174 pq->max <<= 1;
175 pq->nodes = (PQnode *)memRealloc( pq->nodes,
176 (size_t)
177 ((pq->max + 1) * sizeof( pq->nodes[0] )));
178 if (pq->nodes == NULL) {
179 pq->nodes = saveNodes; /* restore ptr to free upon return */
180 return LONG_MAX;
181 }
183 (size_t)
184 ((pq->max + 1) *
185 sizeof( pq->handles[0] )));
186 if (pq->handles == NULL) {
187 pq->handles = saveHandles; /* restore ptr to free upon return */
188 return LONG_MAX;
189 }
190 }
191
192 if( pq->freeList == 0 ) {
193 free_handle = curr;
194 } else {
195 free_handle = pq->freeList;
196 pq->freeList = pq->handles[free_handle].node;
197 }
198
199 pq->nodes[curr].handle = free_handle;
200 pq->handles[free_handle].node = curr;
201 pq->handles[free_handle].key = keyNew;
202
203 if( pq->initialized ) {
204 FloatUp( pq, curr );
205 }
207 return free_handle;
208}
BOOL free_handle(HINTERNET hinternet)
Definition: handle.c:123
#define LONG_MAX
Definition: limits.h:43
#define memRealloc
Definition: memalloc.h:40
PQhandle node
PQhandle handle

◆ pqNewPriorityQ()

PriorityQ * pqNewPriorityQ ( int(*)(PQkey key1, PQkey key2)  leq)

Definition at line 58 of file priorityq-heap.c.

59{
60 PriorityQ *pq = (PriorityQ *)memAlloc( sizeof( PriorityQ ));
61 if (pq == NULL) return NULL;
62
63 pq->size = 0;
64 pq->max = INIT_SIZE;
65 pq->nodes = (PQnode *)memAlloc( (INIT_SIZE + 1) * sizeof(pq->nodes[0]) );
66 if (pq->nodes == NULL) {
67 memFree(pq);
68 return NULL;
69 }
70
71 pq->handles = (PQhandleElem *)memAlloc( (INIT_SIZE + 1) * sizeof(pq->handles[0]) );
72 if (pq->handles == NULL) {
73 memFree(pq->nodes);
74 memFree(pq);
75 return NULL;
76 }
77
78 pq->initialized = FALSE;
79 pq->freeList = 0;
80 pq->leq = leq;
81
82 pq->nodes[1].handle = 1; /* so that Minimum() returns NULL */
83 pq->handles[1].key = NULL;
84 return pq;
85}
#define memAlloc
Definition: memalloc.h:48
#define INIT_SIZE
#define FALSE
int(* leq)(PQkey key1, PQkey key2)