data_structures
Typedefs | Functions
min_pq.h File Reference
#include <errno.h>
#include <sys/types.h>
#include "types.h"
#include "array.h"
#include "utils.h"
+ Include dependency graph for min_pq.h:

Go to the source code of this file.

Typedefs

typedef t_array t_min_pq
 A priority queue of generic keys. More...
 

Functions

t_min_pqmin_pq_new (const t_type *type)
 Initializes a new empty priority queue. More...
 
void * min_pq_peek (const t_min_pq *pq)
 Returns the smallest key in the queue. More...
 
void * min_pq_pop (t_min_pq *pq)
 Removes and returns the smallest key in this queue. More...
 
void min_pq_add (t_min_pq *pq, const void *data)
 Adds a copy of the specified element to the queue. More...
 
size_t min_pq_size (const t_min_pq *pq)
 Returns the number of keys in this queue. More...
 
void min_pq_delete (t_min_pq *pq)
 Deletes this queue and free all its items and the associated data. More...
 
t_min_pqmin_pq_copy (const t_min_pq *pq)
 Copies the queue and all it contents. More...
 

Typedef Documentation

◆ t_min_pq

typedef t_array t_min_pq

A priority queue of generic keys.

Implemented with a resizing array.

Definition at line 29 of file min_pq.h.

Function Documentation

◆ min_pq_add()

void min_pq_add ( t_min_pq pq,
const void *  data 
)

Adds a copy of the specified element to the queue.

Parameters
dataThe element to be copied

Definition at line 30 of file min_pq_add.c.

◆ min_pq_copy()

t_min_pq* min_pq_copy ( const t_min_pq pq)

Copies the queue and all it contents.

Returns
The copy of the queue

Definition at line 16 of file min_pq_copy.c.

◆ min_pq_delete()

void min_pq_delete ( t_min_pq pq)

Deletes this queue and free all its items and the associated data.

Definition at line 16 of file min_pq_delete.c.

◆ min_pq_new()

t_min_pq* min_pq_new ( const t_type type)

Initializes a new empty priority queue.

Parameters
typeThe type of items that this queue can hold
Returns
The new priority queue
Note
For this function to work, the datatype in this array must be comparable (i.e. implement the cmp function).

Definition at line 16 of file min_pq_new.c.

◆ min_pq_peek()

void* min_pq_peek ( const t_min_pq pq)

Returns the smallest key in the queue.

Returns
The smallest key or NULL if the queue is empty.

Definition at line 16 of file min_pq_peek.c.

◆ min_pq_pop()

void* min_pq_pop ( t_min_pq pq)

Removes and returns the smallest key in this queue.

Returns
The smallest item in the queue, or NULL if the array is empty.

Definition at line 38 of file min_pq_pop.c.

◆ min_pq_size()

size_t min_pq_size ( const t_min_pq pq)

Returns the number of keys in this queue.

Returns
the number of keys in this queue.

Definition at line 16 of file min_pq_size.c.