-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
70 lines (58 loc) · 1.39 KB
/
queue.h
File metadata and controls
70 lines (58 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2024, Andrei Rusanescu <andreirusanescu154gmail.com>
*/
#ifndef QUEUE_H
#define QUEUE_H
typedef struct queue_t queue_t;
struct queue_t
{
/* Max size for queue */
unsigned int max_size;
/* Actual size of queue */
unsigned int size;
/* Size in bytes of the data added in queue */
unsigned int data_size;
/* Index for dequeue and front operations */
unsigned int read_idx;
/* Index for enqueue */
unsigned int write_idx;
/* Buffer that contains queue elements */
void **buff;
};
/*
* Creates a queue of max_size elements of data_size size in bytes
*/
queue_t *q_create(unsigned int data_size, unsigned int max_size);
/*
* Returns the size of the queue.
*/
unsigned int q_get_size(queue_t *q);
/*
* Returns 1 if queue is empty and 0 on the contrary.
*/
unsigned int q_is_empty(queue_t *q);
/*
* Returns the first element of the queue.
*/
void *q_front(queue_t *q);
/*
* Removes an element from queue. Returns 1 if
* the element was removed successfully (queue is not empty)
* and 0 on the contrary
*/
int q_dequeue(queue_t *q);
/*
* Adds a new element in queue. Returns 1 if
* the element was added successfully (queue is not full)
* and 0 on the contrary
*/
int q_enqueue(queue_t *q, void *new_data);
/*
* Eliminates all of the elements from the queue
*/
void q_clear(queue_t *q);
/*
* Frees the queue entirely
*/
void q_free(queue_t *q);
#endif /* QUEUE_H */