-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque.h
45 lines (28 loc) · 1.06 KB
/
deque.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
#ifndef C_COLLECTIONS_DEQUE_H
#define C_COLLECTIONS_DEQUE_H
#include "collection.h"
typedef struct {
// the number of elements currently inserted into the deque
size_t size;
// the allocated capacity of the deque's array
size_t capacity;
// the head of the deque. if size > 0 it points to the first element in the deque.
size_t head;
// the tail of the deque. if size > 0 it points to the spot after the last element in the deque.
size_t tail;
// used to mark if the deque is resizeable.
bool resizeable;
// the array backing the deque
void** array;
} deque;
deque deque_new(size_t capacity);
deque deque_wrap(void** array, size_t capacity);
bool deque_append(deque* d, void* element);
bool deque_prepend(deque* d, void* element);
void* deque_shift(deque* d);
void* deque_pop(deque* d);
bool deque_ensure_capacity(deque* d, size_t capacity);
// optional operations, might get removed
bool deque_insert_at(deque* d, void* element, size_t pos);
void* deque_get_at(deque* d, size_t pos);
#endif // C_COLLECTIONS_DEQUE_H