Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
priorityq-sort.h File Reference
#include "priorityq-heap.h"
+ Include dependency graph for priorityq-sort.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PriorityQ
 

Macros

#define PQkey   PQSortKey
 
#define PQhandle   PQSortHandle
 
#define PriorityQ   PriorityQSort
 
#define pqNewPriorityQ(leq)   __gl_pqSortNewPriorityQ(leq)
 
#define pqDeletePriorityQ(pq)   __gl_pqSortDeletePriorityQ(pq)
 
#define pqInit(pq)   __gl_pqSortInit(pq)
 
#define pqInsert(pq, key)   __gl_pqSortInsert(pq,key)
 
#define pqMinimum(pq)   __gl_pqSortMinimum(pq)
 
#define pqExtractMin(pq)   __gl_pqSortExtractMin(pq)
 
#define pqDelete(pq, handle)   __gl_pqSortDelete(pq,handle)
 
#define pqIsEmpty(pq)   __gl_pqSortIsEmpty(pq)
 

Typedefs

typedef PQHeapKey PQkey
 
typedef PQHeapHandle PQhandle
 
typedef struct PriorityQ PriorityQ
 

Functions

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

Macro Definition Documentation

◆ pqDelete

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

◆ pqDeletePriorityQ

#define pqDeletePriorityQ (   pq)    __gl_pqSortDeletePriorityQ(pq)

◆ pqExtractMin

#define pqExtractMin (   pq)    __gl_pqSortExtractMin(pq)

◆ PQhandle

#define PQhandle   PQSortHandle

◆ pqInit

#define pqInit (   pq)    __gl_pqSortInit(pq)

◆ pqInsert

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

◆ pqIsEmpty

#define pqIsEmpty (   pq)    __gl_pqSortIsEmpty(pq)

◆ PQkey

#define PQkey   PQSortKey

◆ pqMinimum

#define pqMinimum (   pq)    __gl_pqSortMinimum(pq)

◆ pqNewPriorityQ

#define pqNewPriorityQ (   leq)    __gl_pqSortNewPriorityQ(leq)

◆ PriorityQ

#define PriorityQ   PriorityQSort

Typedef Documentation

◆ PQhandle

typedef PQHeapHandle PQhandle

◆ PQkey

typedef PQHeapKey PQkey

◆ PriorityQ

typedef struct PriorityQ PriorityQ

Function Documentation

◆ pqDelete()

void pqDelete ( PriorityQ pq,
PQhandle  handle 
)
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 LEQ(x, y)
Definition priorityq-heap.c:54
static void FloatDown(PriorityQ *pq, long curr)
Definition priorityq-heap.c:96
static void FloatUp(PriorityQ *pq, long curr)
Definition priorityq-heap.c:126
PQhandle handle
Definition priorityq-heap.h:83
PQkey key
Definition priorityq-heap.h:84
PQhandle node
Definition priorityq-heap.h:84
Definition priorityq-heap.h:84
Definition priorityq-heap.h:83
PQnode * nodes
Definition priorityq-heap.h:87
PQhandleElem * handles
Definition priorityq-heap.h:88
PQhandle freeList
Definition priorityq-heap.h:90
long size
Definition priorityq-heap.h:89

◆ pqDeletePriorityQ()

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

◆ pqExtractMin()

PQkey pqExtractMin ( PriorityQ pq)
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}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() min(const half &a, const half &b)
Definition Half.h:507
long PQhandle
Definition priorityq-heap.h:80
void * PQkey
Definition priorityq-heap.h:79

◆ pqInit()

int pqInit ( PriorityQ pq)
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}
#define TRUE
Definition priorityq-heap.c:43
int initialized
Definition priorityq-heap.h:91

◆ pqInsert()

PQhandle pqInsert ( PriorityQ pq,
PQkey  key 
)
164{
165 long curr;
166 PQhandle free_handle;
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 }
206 assert(free_handle != LONG_MAX);
207 return free_handle;
208}
#define memRealloc
Definition memalloc.h:40
long max
Definition priorityq-heap.h:89

◆ pqIsEmpty()

int pqIsEmpty ( PriorityQ pq)
243{
244 return (pq->size == 0) && __gl_pqHeapIsEmpty( pq->heap );
245}
#define __gl_pqHeapIsEmpty(pq)
Definition priorityq-heap.h:105
PriorityQHeap * heap
Definition priorityq-sort.h:98

References __gl_pqHeapIsEmpty, PriorityQ::heap, and PriorityQ::size.

◆ pqMinimum()

PQkey pqMinimum ( PriorityQ pq)
225{
226 PQkey sortMin, heapMin;
227
228 if( pq->size == 0 ) {
229 return __gl_pqHeapMinimum( pq->heap );
230 }
231 sortMin = *(pq->order[pq->size-1]);
232 if( ! __gl_pqHeapIsEmpty( pq->heap )) {
233 heapMin = __gl_pqHeapMinimum( pq->heap );
234 if( LEQ( heapMin, sortMin )) {
235 return heapMin;
236 }
237 }
238 return sortMin;
239}
#define __gl_pqHeapMinimum(pq)
Definition priorityq-heap.h:104
PQkey ** order
Definition priorityq-sort.h:100

References __gl_pqHeapIsEmpty, __gl_pqHeapMinimum, PriorityQ::heap, LEQ, PriorityQ::order, and PriorityQ::size.

◆ pqNewPriorityQ()

PriorityQ * pqNewPriorityQ ( int(*)(PQkey key1, PQkey key2)  leq)
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
Definition priorityq-heap.c:40
#define FALSE
Definition priorityq-heap.c:46
Definition priorityq-heap.h:86
int(* leq)(PQkey key1, PQkey key2)
Definition priorityq-heap.h:92