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

Go to the source code of this file.

Typedefs

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

Functions

t_max_pqmax_pq_new (const t_type *type)
 Initializes a new empty priority queue. More...
 
void * max_pq_peek (const t_max_pq *pq)
 Returns the largest key in the queue. More...
 
void * max_pq_pop (t_max_pq *pq)
 Removes and returns the largest key in this queue. More...
 
void max_pq_add (t_max_pq *pq, const void *data)
 Adds a copy of the specified element to the queue. More...
 
size_t max_pq_size (const t_max_pq *pq)
 Returns the number of keys in this queue. More...
 
void max_pq_delete (t_max_pq *pq)
 Deletes this queue and free all its items and the associated data. More...
 
t_max_pqmax_pq_copy (const t_max_pq *pq)
 Copies the queue and all it contents. More...
 

Typedef Documentation

◆ t_max_pq

typedef t_array t_max_pq

A priority queue of generic keys.

Implemented with a resizing array.

Definition at line 29 of file max_pq.h.

Function Documentation

◆ max_pq_add()

void max_pq_add ( t_max_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 max_pq_add.c.

◆ max_pq_copy()

t_max_pq* max_pq_copy ( const t_max_pq pq)

Copies the queue and all it contents.

Returns
The copy of the queue

Definition at line 16 of file max_pq_copy.c.

◆ max_pq_delete()

void max_pq_delete ( t_max_pq pq)

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

Definition at line 16 of file max_pq_delete.c.

◆ max_pq_new()

t_max_pq* max_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 max_pq_new.c.

◆ max_pq_peek()

void* max_pq_peek ( const t_max_pq pq)

Returns the largest key in the queue.

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

Definition at line 16 of file max_pq_peek.c.

◆ max_pq_pop()

void* max_pq_pop ( t_max_pq pq)

Removes and returns the largest key in this queue.

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

Definition at line 38 of file max_pq_pop.c.

◆ max_pq_size()

size_t max_pq_size ( const t_max_pq pq)

Returns the number of keys in this queue.

Returns
the number of keys in this queue.

Definition at line 16 of file max_pq_size.c.