宏定义 | |
#define | left(i) ((i) << 1) |
#define | right(i) (((i) << 1) + 1) |
#define | parent(i) ((i) >> 1) |
函数 | |
pqueue_t * | pqueue_init (size_t n, pqueue_cmp_pri_f cmppri, pqueue_get_pri_f getpri, pqueue_set_pri_f setpri, pqueue_get_pos_f getpos, pqueue_set_pos_f setpos) |
void | pqueue_free (pqueue_t *q) |
size_t | pqueue_size (pqueue_t *q) |
static void | bubble_up (pqueue_t *q, size_t i) |
static size_t | maxchild (pqueue_t *q, size_t i) |
static void | percolate_down (pqueue_t *q, size_t i) |
int | pqueue_insert (pqueue_t *q, void *d) |
void | pqueue_change_priority (pqueue_t *q, pqueue_pri_t new_pri, void *d) |
int | pqueue_remove (pqueue_t *q, void *d) |
void * | pqueue_pop (pqueue_t *q) |
void * | pqueue_peek (pqueue_t *q) |
void | pqueue_dump (pqueue_t *q, FILE *out, pqueue_print_entry_f print) |
static void | set_pos (void *d, size_t val) |
static void | set_pri (void *d, pqueue_pri_t pri) |
void | pqueue_print (pqueue_t *q, FILE *out, pqueue_print_entry_f print) |
static int | subtree_is_valid (pqueue_t *q, int pos) |
int | pqueue_is_valid (pqueue_t *q) |
#define left | ( | i | ) | ((i) << 1) |
#define parent | ( | i | ) | ((i) >> 1) |
#define right | ( | i | ) | (((i) << 1) + 1) |
|
static |
|
static |
|
static |
void pqueue_change_priority | ( | pqueue_t * | q, |
pqueue_pri_t | new_pri, | ||
void * | d | ||
) |
move an existing entry to a different priority
q | the queue |
new_pri | the new priority |
d | the entry |
void pqueue_dump | ( | pqueue_t * | q, |
FILE * | out, | ||
pqueue_print_entry_f | |||
) |
dump the queue and it's internal structure
void pqueue_free | ( | pqueue_t * | q | ) |
free all memory used by the queue
q | the queue |
pqueue_t* pqueue_init | ( | size_t | n, |
pqueue_cmp_pri_f | cmppri, | ||
pqueue_get_pri_f | getpri, | ||
pqueue_set_pri_f | setpri, | ||
pqueue_get_pos_f | getpos, | ||
pqueue_set_pos_f | setpos | ||
) |
initialize the queue
n | the initial estimate of the number of queue items for which memory should be preallocated |
cmppri | The callback function to run to compare two elements This callback should return 0 for 'lower' and non-zero for 'higher', or vice versa if reverse priority is desired |
setpri | the callback function to run to assign a score to an element |
getpri | the callback function to run to set a score to an element |
getpos | the callback function to get the current element's position |
setpos | the callback function to set the current element's position |
int pqueue_insert | ( | pqueue_t * | q, |
void * | d | ||
) |
insert an item into the queue.
q | the queue |
d | the item |
int pqueue_is_valid | ( | pqueue_t * | q | ) |
checks that the pq is in the right order, etc
void* pqueue_peek | ( | pqueue_t * | q | ) |
access highest-ranking item without removing it.
q | the queue |
void* pqueue_pop | ( | pqueue_t * | q | ) |
pop the highest-ranking item from the queue.
q | the queue |
void pqueue_print | ( | pqueue_t * | q, |
FILE * | out, | ||
pqueue_print_entry_f | |||
) |
print the queue
int pqueue_remove | ( | pqueue_t * | q, |
void * | d | ||
) |
remove an item from the queue.
q | the queue |
d | the entry |
size_t pqueue_size | ( | pqueue_t * | q | ) |
return the size of the queue.
q | the queue |
|
static |
|
static |
|
static |