Data Structures | Functions

src/pqueue.h File Reference

STATUS: stable Priority queue. More...

#include "definitions.h"
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PQnode
 a node in the PQueue. More...
struct  PriorityQueue
 the head of the PQueue. More...

Functions

void pq_free (PriorityQueue *pq)
PriorityQueuepq_init ()
void pq_insert (PriorityQueue *pq, void *c, double prior)
void * pq_pop (PriorityQueue *pq)
PQnode * pq_pop_node (PriorityQueue *pq)
void pq_print (FILE *out, PriorityQueue *pq)

Detailed Description

STATUS: stable Priority queue.

Smaller priority values indicate higher priority.

The implementation is based on a single-linked list. Popping elements is therefore in O(1), inserting in O(N).

Usage is as follows:

  PriorityQueue *pq=pq_init();
  int stuff[] = {1, 2, 3, 4};
  
  pq_insert( pq, (void*)&(stuff[0]), 10 );
  ...
  pq_insert( pq, (void*)&(stuff[3]), 1 );

  int priorel=*((int*)pq_pop( pq ));
  int nextprior=*((int*)pq_pop( pq ));
  ...

  pq_free( pq );

Definition in file pqueue.h.


Function Documentation

void pq_free ( PriorityQueue pq  ) 

Definition at line 126 of file pqueue.c.

PriorityQueue* pq_init (  ) 

TEMPLATE

Parameters:
\param 
Returns:

Definition at line 29 of file pqueue.c.

void pq_insert ( PriorityQueue pq,
void *  c,
double  prior 
)

Definition at line 44 of file pqueue.c.

void* pq_pop ( PriorityQueue pq  ) 

pop the data with highest priority in the PQ. if you need access to the priority as well, use pq_pop_node(). The corresponding node is removed from the PQ;

Parameters:
pq the PQ

Definition at line 91 of file pqueue.c.

PQnode* pq_pop_node ( PriorityQueue pq  ) 

pop a node in the PQ. use it if you need access to the priority value as well. You will need to free the node after usage yourself;

Parameters:
pq the PQ

Definition at line 74 of file pqueue.c.

void pq_print ( FILE *  out,
PriorityQueue pq 
)

Definition at line 103 of file pqueue.c.