Commit | Line | Data |
---|---|---|
a7868768 BA |
1 | /** |
2 | * @file Queue.c | |
3 | */ | |
4 | ||
5 | #include "cgds/Queue.h" | |
6 | ||
7 | void _queue_init(Queue* queue, size_t dataSize) | |
8 | { | |
a7868768 | 9 | queue->dataSize = dataSize; |
012c97dd | 10 | _vector_init(queue->array, dataSize); |
a7868768 BA |
11 | } |
12 | ||
13 | Queue* _queue_new(size_t dataSize) | |
14 | { | |
15 | Queue* queue = (Queue*) safe_malloc(sizeof (Queue)); | |
ea7acb53 | 16 | queue->array = _vector_new(dataSize); |
a7868768 BA |
17 | _queue_init(queue, dataSize); |
18 | return queue; | |
19 | } | |
20 | ||
21 | Queue* queue_copy(Queue* queue) | |
22 | { | |
012c97dd BA |
23 | Queue* queueCopy = (Queue*) safe_malloc(sizeof (Queue)); |
24 | queueCopy->dataSize = queue->dataSize; | |
25 | Vector* arrayCopy = vector_copy(queue->array); | |
26 | queueCopy->array = arrayCopy; | |
a7868768 BA |
27 | return queueCopy; |
28 | } | |
29 | ||
30 | Bool queue_empty(Queue* queue) | |
31 | { | |
012c97dd | 32 | return vector_empty(queue->array); |
a7868768 BA |
33 | } |
34 | ||
35 | UInt queue_size(Queue* queue) | |
36 | { | |
012c97dd | 37 | return vector_size(queue->array); |
a7868768 BA |
38 | } |
39 | ||
40 | void _queue_push(Queue* queue, void* data) | |
41 | { | |
012c97dd | 42 | _vector_push(queue->array, data); |
a7868768 BA |
43 | } |
44 | ||
45 | void* _queue_peek(Queue* queue) | |
46 | { | |
bbd242d4 | 47 | return _vector_get(queue->array, 0); |
a7868768 BA |
48 | } |
49 | ||
50 | void queue_pop(Queue* queue) | |
51 | { | |
8306616e BA |
52 | vector_pop_first(queue->array); |
53 | ||
a7868768 BA |
54 | } |
55 | ||
56 | void queue_clear(Queue* queue) | |
57 | { | |
012c97dd | 58 | vector_clear(queue->array); |
a7868768 BA |
59 | } |
60 | ||
61 | void queue_destroy(Queue* queue) | |
62 | { | |
ea7acb53 | 63 | vector_destroy(queue->array); |
a7868768 BA |
64 | safe_free(queue); |
65 | } |