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

Go to the source code of this file.

Typedefs

typedef struct s_list t_queue
 Represents a first-in-first-out (FIFO) queue of generic items. More...
 

Functions

void queue_enqueue (t_queue *queue, const void *data)
 Copies the item and adds the copy to the queue. More...
 
void * queue_dequeue (t_queue *queue)
 Removes and returns the item on this queue that was least recently added. More...
 
void * queue_peek (const t_queue *queue)
 Returns the item in this queue that was least recently added. More...
 
void queue_delete (t_queue *queue)
 Deletes the queue and frees all memory taken by its contents, or does nothing if the argument is NULL. More...
 
size_t queue_size (const t_queue *queue)
 Returns the number of items in this queue. More...
 
t_queuequeue_new (const t_type *type)
 Allocates memory and initializes an empty queue. More...
 
t_queuequeue_copy (const t_queue *queue)
 Copies a queue and all it contents. More...
 

Typedef Documentation

◆ t_queue

typedef struct s_list t_queue

Represents a first-in-first-out (FIFO) queue of generic items.

This implementation uses a doubly-linked list.

Definition at line 29 of file queue.h.

Function Documentation

◆ queue_copy()

t_queue* queue_copy ( const t_queue queue)

Copies a queue and all it contents.

Returns
A copy of the queue

Definition at line 16 of file queue_copy.c.

◆ queue_delete()

void queue_delete ( t_queue queue)

Deletes the queue and frees all memory taken by its contents, or does nothing if the argument is NULL.

Definition at line 16 of file queue_delete.c.

◆ queue_dequeue()

void* queue_dequeue ( t_queue queue)

Removes and returns the item on this queue that was least recently added.

Returns
The item that was least recently added, or NULL if the queue is empty.

Definition at line 16 of file queue_dequeue.c.

◆ queue_enqueue()

void queue_enqueue ( t_queue queue,
const void *  data 
)

Copies the item and adds the copy to the queue.

Parameters
dataThe item to add

Definition at line 16 of file queue_enqueue.c.

◆ queue_new()

t_queue* queue_new ( const t_type type)

Allocates memory and initializes an empty queue.

Parameters
thetype of items that this queue will hold
Returns
The new queue

Definition at line 16 of file queue_new.c.

◆ queue_peek()

void* queue_peek ( const t_queue queue)

Returns the item in this queue that was least recently added.

The item is kepts on the queue.

Returns
The item that was least recently added, or NULL if the queue is empty.

Definition at line 16 of file queue_peek.c.

◆ queue_size()

size_t queue_size ( const t_queue queue)

Returns the number of items in this queue.

Returns
The number of items in this queue

Definition at line 16 of file queue_size.c.