88 |
|
|
89 |
/* returns a heap pointer with sz size */ |
/* returns a heap pointer with sz size */ |
90 |
pq_node ** new_heap(int sz){ |
pq_node ** new_heap(int sz){ |
|
//pq_node **h=(pq_node**)malloc(sizeof(pq_node*)); |
|
91 |
pq_node **h=(pq_node**)calloc(sz+1,sizeof(pq_node*)); |
pq_node **h=(pq_node**)calloc(sz+1,sizeof(pq_node*)); |
92 |
int i=0; |
int i=0; |
93 |
for(; i<sz+1; i++) |
for(; i<sz+1; i++) |
97 |
|
|
98 |
/* |
/* |
99 |
* adds the data d in the queue with priority p |
* adds the data d in the queue with priority p |
100 |
* negatives priorities are ok |
* negative priorities are ok |
101 |
*/ |
*/ |
102 |
prio_t pq_add(prio_t p,void * d,pqueue *q){ |
prio_t pq_add(prio_t p,void * d,pqueue *q){ |
103 |
if(!q) |
if(!q) |
141 |
return POK; |
return POK; |
142 |
} |
} |
143 |
|
|
144 |
/* return the minor prority element */ |
/* return the minor priority element */ |
145 |
void * pq_min(pqueue *q){ |
void * pq_min(pqueue *q){ |
146 |
if(q->csize==0) |
if(q->csize==0) |
147 |
return NULL; |
return NULL; |
148 |
return q->heap[1]->data; |
return q->heap[1]->data; |
149 |
} |
} |
150 |
|
|
151 |
/* delete the minor prority element */ |
/* delete the minor priority element */ |
152 |
void * pq_del_min(pqueue *q){ |
void * pq_del_min(pqueue *q){ |
153 |
if(q->csize==0) |
if(q->csize==0) |
154 |
return NULL; |
return NULL; |
164 |
return data; |
return data; |
165 |
} |
} |
166 |
|
|
167 |
/* sink the node to it's correct position */ |
/* sink the node to its correct position */ |
168 |
void sink(int pos, pqueue *q){ |
void sink(int pos, pqueue *q){ |
169 |
if(!q || pos<=0 || pos > q->csize) |
if(!q || pos<=0 || pos > q->csize) |
170 |
return; |
return; |
287 |
|
|
288 |
/* |
/* |
289 |
* change the priority to p, of the first node which |
* change the priority to p, of the first node which |
290 |
* data is equals to data |
* data is equal to data |
291 |
*/ |
*/ |
292 |
int pq_chpri(void *data, prio_t p, pqueue *q){ |
int pq_chpri(void *data, prio_t p, pqueue *q){ |
293 |
if(!data || !q) |
if(!data || !q) |