Nagios 4.5.4
Dev docs for Nagios core and neb-module hackers
Loading...
Searching...
No Matches
prqueue.h File Reference

Priority Queue function declarations. More...

#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  prqueue_t
 the priority queue handle More...
 
typedef unsigned long long prqueue_pri_t
 priority data type (used to be double, but ull is 107 times faster)
 
typedef prqueue_pri_t(* prqueue_get_pri_f) (void *a)
 callback functions to get/set/compare the priority of an element
 
typedef void(* prqueue_set_pri_f) (void *a, prqueue_pri_t pri)
 
typedef int(* prqueue_cmp_pri_f) (prqueue_pri_t next, prqueue_pri_t curr)
 
typedef unsigned int(* prqueue_get_pos_f) (void *a)
 callback functions to get/set the position of an element
 
typedef void(* prqueue_set_pos_f) (void *a, unsigned int pos)
 
typedef void(* prqueue_print_entry_f) (FILE *out, void *a)
 debug callback function to print a entry
 
typedef struct prqueue_t prqueue_t
 the priority queue handle
 
prqueue_tprqueue_init (unsigned int n, prqueue_cmp_pri_f cmppri, prqueue_get_pri_f getpri, prqueue_set_pri_f setpri, prqueue_get_pos_f getpos, prqueue_set_pos_f setpos)
 initialize the queue
 
void prqueue_free (prqueue_t *q)
 free all memory used by the queue
 
unsigned int prqueue_size (prqueue_t *q)
 return the size of the queue.
 
int prqueue_insert (prqueue_t *q, void *d)
 insert an item into the queue.
 
void prqueue_change_priority (prqueue_t *q, prqueue_pri_t new_pri, void *d)
 move an existing entry to a different priority
 
void * prqueue_pop (prqueue_t *q)
 pop the highest-ranking item from the queue.
 
int prqueue_remove (prqueue_t *q, void *d)
 remove an item from the queue.
 
void * prqueue_peek (prqueue_t *q)
 access highest-ranking item without removing it.
 
void prqueue_print (prqueue_t *q, FILE *out, prqueue_print_entry_f print)
 print the queue
 
void prqueue_dump (prqueue_t *q, FILE *out, prqueue_print_entry_f print)
 dump the queue and it's internal structure
 
int prqueue_is_valid (prqueue_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 prqueue_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

◆ prqueue_change_priority()

void prqueue_change_priority ( prqueue_t * q,
prqueue_pri_t new_pri,
void * d )

move an existing entry to a different priority

Parameters
qthe queue
new_prithe new priority
dthe entry

◆ prqueue_free()

void prqueue_free ( prqueue_t * q)

free all memory used by the queue

Parameters
qthe queue

◆ prqueue_init()

prqueue_t * prqueue_init ( unsigned int n,
prqueue_cmp_pri_f cmppri,
prqueue_get_pri_f getpri,
prqueue_set_pri_f setpri,
prqueue_get_pos_f getpos,
prqueue_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

◆ prqueue_insert()

int prqueue_insert ( prqueue_t * q,
void * d )

insert an item into the queue.

Parameters
qthe queue
dthe item
Returns
0 on success

◆ prqueue_peek()

void * prqueue_peek ( prqueue_t * q)

access highest-ranking item without removing it.

Parameters
qthe queue
Returns
NULL on error, otherwise the entry

◆ prqueue_pop()

void * prqueue_pop ( prqueue_t * q)

pop the highest-ranking item from the queue.

Parameters
qthe queue
Returns
NULL on error, otherwise the entry

◆ prqueue_remove()

int prqueue_remove ( prqueue_t * q,
void * d )

remove an item from the queue.

Parameters
qthe queue
dthe entry
Returns
0 on success

◆ prqueue_size()

unsigned int prqueue_size ( prqueue_t * q)

return the size of the queue.

Parameters
qthe queue