2023-06-25 15:14:06 +02:00
|
|
|
#ifndef __LIBCPROJECT_QUEUE__
|
|
|
|
#define __LIBCPROJECT_QUEUE__
|
2023-01-05 19:28:05 +01:00
|
|
|
|
2023-08-07 00:11:07 +02:00
|
|
|
#include <errno.h>
|
2023-01-07 19:38:01 +01:00
|
|
|
#include <stdio.h>
|
2023-01-05 19:28:05 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-06-25 15:07:34 +02:00
|
|
|
#include "types.h"
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Queue structure => FIFO (First In First Out).
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct queue {
|
|
|
|
struct queue_node *first;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Queue node structure.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct queue_node {
|
|
|
|
void *data;
|
|
|
|
struct queue_node *next;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Queue initialization.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @return struct queue*
|
2023-06-24 21:06:45 +02:00
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct queue *queue_initialization();
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Push data to queue.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param queue
|
|
|
|
* @param data
|
2023-06-24 21:06:45 +02:00
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
void queue_push(struct queue *queue, void *data);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Pop data from queue.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param queue
|
|
|
|
* @return void*
|
2023-06-24 21:06:45 +02:00
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
void *queue_pop(struct queue *queue);
|
|
|
|
|
2023-08-03 22:57:32 +02:00
|
|
|
/**
|
|
|
|
* @brief Frees the queue.
|
2023-08-09 21:08:15 +02:00
|
|
|
*
|
|
|
|
* @param queue
|
2023-08-05 15:03:53 +02:00
|
|
|
* @since v3.0.0
|
2023-08-03 22:57:32 +02:00
|
|
|
*/
|
|
|
|
void queue_free(struct queue *queue);
|
|
|
|
|
2023-01-05 19:28:05 +01:00
|
|
|
#endif
|