#include <stdlib.h>
#include "queue.h"
#include "types/err.h"
Go to the source code of this file.
|
#define | MIN(a, b) |
|
#define | MAX(a, b) |
|
◆ MAX
Value:
Definition at line 7 of file cqueue.c.
◆ MIN
Value:
Definition at line 6 of file cqueue.c.
◆ cqueue_add()
Add a value to the circular queue.
- Parameters
-
queue | The queue where to add the item. |
item | The value to add. |
- Returns
- ERR_MAX_SIZE_EXCEEDED on queue is full.
-
ERR_OK on added successful.
Definition at line 20 of file cqueue.c.
21{
24 }
25
28
30
32}
int cqueue_isfull(const cqueue_t *queue)
Check if the given circular queue is full.
unsigned int _max_length
The maximum number of items that fits on the queue.
int _last
The index of the last item.
int * data
Pointer to queue data with allocated space to fit max_size items.
unsigned int length
The current number of items on the queue.
◆ cqueue_close()
Close the given circular queue.
- Parameters
-
Definition at line 80 of file cqueue.c.
◆ cqueue_get()
Get the current value from the circular queue, removing it from the queue.
- Parameters
-
queue | The queue where to remove the value. |
item | The pointer where the value will be saved. |
- Returns
- ERR_EMPTY on queue is empty.
-
ERR_OK on value as get successful.
Definition at line 35 of file cqueue.c.
36{
39 }
40
42
45
47}
int cqueue_isempty(const cqueue_t *queue)
Check if the given circular queue is empty.
int _current
The index for the current item.
◆ cqueue_init()
void cqueue_init |
( |
cqueue_t * | queue, |
|
|
unsigned int | max_length ) |
Initializes a circular queue.
- Parameters
-
queue | The queue to be initialized. |
max_length | The maximum number of items to fit inside the queue. |
Definition at line 10 of file cqueue.c.
11{
16 queue->
data = malloc(
sizeof(
int) * max_length);
17}
◆ cqueue_isempty()
int cqueue_isempty |
( |
const cqueue_t * | queue | ) |
|
Check if the given circular queue is empty.
- Parameters
-
queue | The queue to check if it's empty. |
- Returns
- 1 on the queue is empty.
-
0 on the queue has items.
Definition at line 68 of file cqueue.c.
◆ cqueue_isfull()
int cqueue_isfull |
( |
const cqueue_t * | queue | ) |
|
Check if the given circular queue is full.
- Parameters
-
queue | The queue to check if it's full. |
- Returns
- 1 on the queue is full.
-
0 on the queue is not full.
Definition at line 74 of file cqueue.c.
◆ cqueue_lookup()
Get a value from the circular queue, without removing it from the queue.
- Parameters
-
queue | The queue where to get the value. |
item | The pointer where the value will be saved. |
seek | The index of the value to get (0 means the current, 1 the next and so one). |
- Returns
- ERR_EMPTY on queue is empty.
-
ERR_INVALID_INDEX on the
seek
is invalid.
-
ERR_OK on value as get successful.
Definition at line 50 of file cqueue.c.
51{
54 }
55
57
61 }
62
63 *item = queue->
data[index];
65}