53 if (pq == NULL)
return NULL;
56 if (pq->heap == NULL) {
62 if (pq->keys == NULL) {
71 pq->initialized =
FALSE;
81 if (pq->order != NULL)
memFree( pq->order );
82 if (pq->keys != NULL)
memFree( pq->keys );
87#define LT(x,y) (! LEQ(y,x))
88#define GT(x,y) (! LEQ(x,y))
89#define Swap(a,b) do{PQkey *tmp = *a; *a = *b; *b = tmp;}while(0)
95 struct {
PQkey **
p, **
r; } Stack[50], *top = Stack;
96 unsigned long seed = 2016473283;
106 ((pq->size+1) *
sizeof(pq->order[0])) );
111 if (pq->order == NULL)
return 0;
114 r =
p + pq->size - 1;
115 for( piv = pq->keys, i =
p; i <=
r; ++piv, ++i ) {
122 top->p =
p; top->r =
r; ++top;
123 while( --top >= Stack ) {
126 while(
r >
p + 10 ) {
127 seed = seed * 1539415821 + 1;
128 i =
p + seed % (
r -
p + 1);
135 do { ++i; }
while(
GT( **i, *piv ));
136 do { --j; }
while(
LT( **j, *piv ));
140 if( i -
p <
r - j ) {
141 top->p = j+1; top->r =
r; ++top;
144 top->p =
p; top->r = i-1; ++top;
149 for( i =
p+1; i <=
r; ++i ) {
151 for( j = i; j >
p &&
LT( **(j-1), *piv ); --j ) {
158 pq->initialized =
TRUE;
163 r =
p + pq->size - 1;
164 for( i =
p; i <
r; ++i ) {
165 assert(
LEQ( **(i+1), **i ));
178 if( pq->initialized ) {
182 if( ++ pq->size >= pq->max ) {
183 PQkey *saveKey= pq->keys;
189 (pq->max *
sizeof( pq->keys[0] )));
190 if (pq->keys == NULL) {
195 assert(curr != LONG_MAX);
196 pq->keys[curr] = keyNew;
205 PQkey sortMin, heapMin;
207 if( pq->size == 0 ) {
210 sortMin = *(pq->order[pq->size-1]);
213 if(
LEQ( heapMin, sortMin )) {
219 }
while( pq->size > 0 && *(pq->order[pq->size-1]) == NULL );
226 PQkey sortMin, heapMin;
228 if( pq->size == 0 ) {
231 sortMin = *(pq->order[pq->size-1]);
234 if(
LEQ( heapMin, sortMin )) {
255 assert( curr < pq->max && pq->keys[curr] != NULL );
257 pq->keys[curr] = NULL;
258 while( pq->size > 0 && *(pq->order[pq->size-1]) == NULL ) {
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
void __gl_pqHeapDelete(PriorityQHeap *pq, PQHeapHandle hCurr)
void __gl_pqHeapInit(PriorityQHeap *pq)
PQHeapHandle __gl_pqHeapInsert(PriorityQHeap *pq, PQHeapKey keyNew)
PQHeapKey __gl_pqHeapExtractMin(PriorityQHeap *pq)
void __gl_pqHeapDeletePriorityQ(PriorityQHeap *pq)
PriorityQHeap * __gl_pqHeapNewPriorityQ(int(*leq)(PQHeapKey key1, PQHeapKey key2))
#define pqNewPriorityQ(leq)
#define pqDeletePriorityQ(pq)
#define pqDelete(pq, handle)
#define __gl_pqHeapMinimum(pq)
#define __gl_pqHeapIsEmpty(pq)
#define pqInsert(pq, key)