-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.h
66 lines (54 loc) · 1.54 KB
/
queue.h
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
#ifndef __QUEUE_H__
#define __QUEUE_H__
#include <stdbool.h>
#include <stdlib.h>
#if defined(HOME) || defined(QUEUE_C_MODULE) || defined(PREPROCESING_FOR_ODEVSYS)
#include "arrays.h"
/* Queue structure which holds all necessary data */
typedef struct {
Array* array;
bool dynamic;
// this is where we grab bitches
// after we get closer to tail
size_t head;
// This is where we put bitches
// afterwards, tail grows
size_t tail;
bool debug;
} queue_t;
#else
typedef void queue_t;
#endif
typedef queue_t Queue;
/* creates a new queue with a given size */
Queue* create_queue(int capacity);
/* deletes the queue and all allocated memory */
void delete_queue(Queue *queue);
/*
* PUSHES TO THE FUCKING TAIL
* returns: true on success; false otherwise
*/
bool push_to_queue(Queue* queue, void* data);
/*
* RETRIEVES FROM THE FUCKING HEAD
* returns: the first element on success; NULL otherwise
*/
void* pop_from_queue(Queue* queue);
/*
* LOOPS OVER QUEUE AS A FUCKING IDIOT!
* returns: the idx-th element on success; NULL otherwise
*/
void* get_from_queue(Queue* queue, int idx);
/* Size is cached */
int get_queue_size(Queue* q);
void queue_print(Queue* q, const char* const prefix);
bool queue_push(Queue* q, void* data);
void* queue_pop(Queue* q);
void* queue_get(Queue* q, int offset);
int queue_length(Queue* q);
void queue_free_empty_space(Queue* q);
#if defined(PREPROCESING_FOR_ODEVSYS) || defined(TESTING_HW)
#define QUEUE_C_QMAKE_IS_PROBLEMATIC "queue.c"
#include QUEUE_C_QMAKE_IS_PROBLEMATIC
#endif
#endif /* __QUEUE_H__ */