Nagios  4.4.3
Dev docs for Nagios core and neb-module hackers
Data Structures
pqueue.h File Reference

Priority Queue function declarations. More...

#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  pqueue_t
 the priority queue handle More...
 
typedef unsigned long long pqueue_pri_t
 priority data type (used to be double, but ull is 107 times faster)
 
typedef pqueue_pri_t(* pqueue_get_pri_f) (void *a)
 callback functions to get/set/compare the priority of an element
 
typedef void(* pqueue_set_pri_f) (void *a, pqueue_pri_t pri)
 
typedef int(* pqueue_cmp_pri_f) (pqueue_pri_t next, pqueue_pri_t curr)
 
typedef unsigned int(* pqueue_get_pos_f) (void *a)
 callback functions to get/set the position of an element
 
typedef void(* pqueue_set_pos_f) (void *a, unsigned int pos)
 
typedef void(* pqueue_print_entry_f) (FILE *out, void *a)
 debug callback function to print a entry
 
typedef struct pqueue_t pqueue_t
 the priority queue handle
 
pqueue_tpqueue_init (unsigned int 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 More...
 
void pqueue_free (pqueue_t *q)
 free all memory used by the queue More...
 
unsigned int pqueue_size (pqueue_t *q)
 return the size of the queue. More...
 
int pqueue_insert (pqueue_t *q, void *d)
 insert an item into the queue. More...
 
void pqueue_change_priority (pqueue_t *q, pqueue_pri_t new_pri, void *d)
 move an existing entry to a different priority More...
 
void * pqueue_pop (pqueue_t *q)
 pop the highest-ranking item from the queue. More...
 
int pqueue_remove (pqueue_t *q, void *d)
 remove an item from the queue. More...
 
void * pqueue_peek (pqueue_t *q)
 access highest-ranking item without removing it. More...
 
void pqueue_print (pqueue_t *q, FILE *out, pqueue_print_entry_f print)
 print the queue
 
void pqueue_dump (pqueue_t *q, FILE *out, pqueue_print_entry_f print)
 dump the queue and it's internal structure
 
int pqueue_is_valid (pqueue_t *q)
 checks that the pq is in the right order, etc
 

Detailed Description

Priority Queue function declarations.

This priority queue library was originally written by Volkan Yazici volka.nosp@m.n.ya.nosp@m.zici@.nosp@m.gmai.nosp@m.l.com. It was lated adapted for Nagios by Andreas Ericsson ae@op.nosp@m.5.se. Changes compared to the original version are pretty much limited to changing pqueue_pri_t to be an unsigned long long instead of a double, since ULL comparisons are 107 times faster on my 64-bit laptop.

Function Documentation

◆ pqueue_change_priority()

void pqueue_change_priority ( pqueue_t q,
pqueue_pri_t  new_pri,
void *  d 
)

move an existing entry to a different priority

Parameters
qthe queue
new_prithe new priority
dthe entry

◆ pqueue_free()

void pqueue_free ( pqueue_t q)

free all memory used by the queue

Parameters
qthe queue

◆ pqueue_init()

pqueue_t* pqueue_init ( unsigned int  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

Parameters
nthe initial estimate of the number of queue items for which memory should be preallocated
cmppriThe 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
setprithe callback function to run to assign a score to an element
getprithe callback function to run to set a score to an element
getposthe callback function to get the current element's position
setposthe callback function to set the current element's position
Returns
the handle or NULL for insufficient memory

◆ pqueue_insert()

int pqueue_insert ( pqueue_t q,
void *  d 
)

insert an item into the queue.

Parameters
qthe queue
dthe item
Returns
0 on success

◆ pqueue_peek()

void* pqueue_peek ( pqueue_t q)

access highest-ranking item without removing it.

Parameters
qthe queue
Returns
NULL on error, otherwise the entry

◆ pqueue_pop()

void* pqueue_pop ( pqueue_t q)

pop the highest-ranking item from the queue.

Parameters
qthe queue
Returns
NULL on error, otherwise the entry

◆ pqueue_remove()

int pqueue_remove ( pqueue_t q,
void *  d 
)

remove an item from the queue.

Parameters
qthe queue
dthe entry
Returns
0 on success

◆ pqueue_size()

unsigned int pqueue_size ( pqueue_t q)

return the size of the queue.

Parameters
qthe queue