apr_ssize_t size;
apr_ssize_t avail;
apr_ssize_t step;
- cache_pqueue_get_priority* pri;
- cache_pqueue_getpos* get;
- cache_pqueue_setpos* set;
+ cache_pqueue_get_priority pri;
+ cache_pqueue_getpos get;
+ cache_pqueue_setpos set;
void **d;
};
cache_pqueue_t *cache_pq_init(apr_ssize_t n,
- cache_pqueue_get_priority* pri,
+ cache_pqueue_get_priority pri,
cache_pqueue_getpos get,
cache_pqueue_setpos set)
{
void *cache_pq_pop(cache_pqueue_t *q)
{
- void *tmp;
- void *d;
- int i = 1;
- int j;
+ void *head;
if (!q || q->size == 1)
return NULL;
- d = q->d[1];
- tmp = q->d[--q->size];
- while (i <= q->size / 2) {
- j = 2 * i;
- if (j < q->size && q->pri(q->d[j]) < q->pri(q->d[j + 1])) {
- j++;
- }
- if (q->pri(q->d[j]) <= q->pri(tmp)) {
- break;
- }
- q->d[i] = q->d[j];
- q->set(q->d[i], i);
- i = j;
- }
- q->d[i] = tmp;
- q->set(q->d[i], i);
- return d;
+ head = q->d[1];
+ q->d[1] = q->d[--q->size];
+ cache_pq_percolate_down(q, 1);
+
+ return head;
}
void *cache_pq_peek(cache_pqueue_t *q)
* @param a the element
* @return the score (the lower the score the longer it is kept int the queue)
*/
-typedef long cache_pqueue_set_priority(long queue_clock, void*a);
-typedef long cache_pqueue_get_priority(void*a);
+typedef long (*cache_pqueue_set_priority)(long queue_clock, void *a);
+typedef long (*cache_pqueue_get_priority)(void *a);
/** callback function to get a position of a element */
-typedef apr_ssize_t cache_pqueue_getpos(void *a);
+typedef apr_ssize_t (*cache_pqueue_getpos)(void *a);
/**
* callback function to set a position of a element
* @param a the element
* @param pos the position to set it to
*/
-typedef void cache_pqueue_setpos(void *a, apr_ssize_t pos);
+typedef void (*cache_pqueue_setpos)(void *a, apr_ssize_t pos);
/** debug callback function to print a entry */
-typedef void cache_pqueue_print_entry(FILE *out, void *a);
+typedef void (*cache_pqueue_print_entry)(FILE *out, void *a);
/**
* initialize the queue
* @Return the handle or NULL for insufficent memory
*/
cache_pqueue_t *cache_pq_init(apr_ssize_t n,
- cache_pqueue_get_priority *pri,
+ cache_pqueue_get_priority pri,
cache_pqueue_getpos get,
cache_pqueue_setpos set);
/**