libstd v0.1.0
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
queue.h File Reference
#include <stdbool.h>
#include <stddef.h>
Include dependency graph for queue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  QueueNode
 Node structure representing an element in the queue. More...
 
struct  Queue
 Structure representing a generic linked-list-based Queue. More...
 

Typedefs

typedef struct QueueNode QueueNode
 Node structure representing an element in the queue.
 

Functions

void queue_init (Queue *queue, size_t element_size)
 Initializes an empty Queue.
 
void queue_destroy (Queue *queue)
 Destroys the Queue and frees all allocated nodes and their associated data.
 
bool queue_push (Queue *queue, const void *data)
 Enqueues (pushes) a new element to the back of the queue.
 
bool queue_pop (Queue *queue)
 Dequeues (removes) the element at the front of the queue.
 
void * queue_front (Queue *queue)
 Accesses the element at the front of the queue without removing it.
 
void * queue_back (Queue *queue)
 Accesses the element at the back of the queue without removing it.
 
int queue_search (Queue *queue, int(*cmp_fn)(void *, void *), void *key)
 Searches for an element in the queue using a comparison function.
 
int queue_size (const Queue *queue)
 Retrieves the total number of elements currently stored in the queue.
 

Typedef Documentation

◆ QueueNode

typedef struct QueueNode QueueNode

Node structure representing an element in the queue.

Function Documentation

◆ queue_back()

void * queue_back ( Queue queue)

Accesses the element at the back of the queue without removing it.

Parameters
queuePointer to the Queue.
Returns
Pointer to the data at the back of the queue, or NULL if the queue is empty.

◆ queue_destroy()

void queue_destroy ( Queue queue)

Destroys the Queue and frees all allocated nodes and their associated data.

Parameters
queuePointer to the Queue to destroy.

◆ queue_front()

void * queue_front ( Queue queue)

Accesses the element at the front of the queue without removing it.

Parameters
queuePointer to the Queue.
Returns
Pointer to the data at the front of the queue, or NULL if the queue is empty.

◆ queue_init()

void queue_init ( Queue queue,
size_t  element_size 
)

Initializes an empty Queue.

Parameters
queuePointer to the Queue structure to initialize.
element_sizeSize of each element in bytes.

◆ queue_pop()

bool queue_pop ( Queue queue)

Dequeues (removes) the element at the front of the queue.

Parameters
queuePointer to the Queue.
Returns
true if an element was successfully removed, or false if the queue was empty.

◆ queue_push()

bool queue_push ( Queue queue,
const void *  data 
)

Enqueues (pushes) a new element to the back of the queue.

Parameters
queuePointer to the Queue.
dataPointer to the element data to insert.
Returns
true if insertion was successful, or false on memory allocation failure.

◆ queue_search()

int queue_search ( Queue queue,
int(*)(void *, void *)  cmp_fn,
void *  key 
)

Searches for an element in the queue using a comparison function.

Parameters
queuePointer to the Queue.
cmp_fnPointer to the comparison function (should return 0 when elements match).
keyPointer to the value/key being searched for.
Returns
The zero-based index of the element if found, or -1 if not found.

◆ queue_size()

int queue_size ( const Queue queue)

Retrieves the total number of elements currently stored in the queue.

Parameters
queuePointer to the Queue.
Returns
Total number of elements.