-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.h
More file actions
23 lines (18 loc) · 705 Bytes
/
queue.h
File metadata and controls
23 lines (18 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// A dynamically-resized queue implemented in a circular buffer
typedef struct Queue {
void **buf;
size_t buf_len;
// Indices [start,end[ hold elements. The position just before 'start'
// (modulo wrapping) is never used, which removes the need to distinguish
// between empty and full buffers.
size_t start, end;
} Queue;
void queue_init(Queue *queue);
void queue_free(Queue *queue);
// Returns the number of elements stored in 'queue'
size_t queue_len(Queue *queue);
// Appends a new element to 'queue'
void queue_add(Queue *queue, void *val);
// Removes and returns the first element in 'queue'. Must not be called with an
// empty queue.
void *queue_remove(Queue *queue);