remove obsolete TODO
[cgds.git] / src / Queue.c
1 /**
2 * @file Queue.c
3 */
4
5 #include "cgds/Queue.h"
6
7 void _queue_init(Queue* queue, size_t dataSize)
8 {
9 queue->dataSize = dataSize;
10 _vector_init(queue->array, dataSize);
11 }
12
13 Queue* _queue_new(size_t dataSize)
14 {
15 Queue* queue = (Queue*) safe_malloc(sizeof (Queue));
16 _queue_init(queue, dataSize);
17 return queue;
18 }
19
20 Queue* queue_copy(Queue* queue)
21 {
22 Queue* queueCopy = (Queue*) safe_malloc(sizeof (Queue));
23 queueCopy->dataSize = queue->dataSize;
24 Vector* arrayCopy = vector_copy(queue->array);
25 queueCopy->array = arrayCopy;
26 return queueCopy;
27 }
28
29 Bool queue_empty(Queue* queue)
30 {
31 return vector_empty(queue->array);
32 }
33
34 UInt queue_size(Queue* queue)
35 {
36 return vector_size(queue->array);
37 }
38
39 void _queue_push(Queue* queue, void* data)
40 {
41 _vector_push(queue->array, data);
42 }
43
44 void* _queue_peek(Queue* queue)
45 {
46 return vector_get(queue->array, 0);
47 }
48
49 void queue_pop(Queue* queue)
50 {
51 //remove first vector element and shift its internal array
52 safe_free(queue->array->datas[0]);
53 queue->array->datas++;
54 //NOTE: we remove first element, so capacity decrease too
55 queue->array->size--;
56 queue->array->capacity--;
57 }
58
59 void queue_clear(Queue* queue)
60 {
61 vector_clear(queue->array);
62 }
63
64 void queue_destroy(Queue* queue)
65 {
66 queue_clear(queue);
67 safe_free(queue);
68 }