Some fixes + improvements (Vector) + code reformatting
[cgds.git] / src / Queue.c
CommitLineData
a7868768
BA
1/**
2 * @file Queue.c
3 */
4
5#include "cgds/Queue.h"
6
7void _queue_init(Queue* queue, size_t dataSize)
8{
e45132ac
BA
9 queue->dataSize = dataSize;
10 _list_init(queue->list, dataSize);
a7868768
BA
11}
12
13Queue* _queue_new(size_t dataSize)
14{
e45132ac
BA
15 Queue* queue = (Queue*) safe_malloc(sizeof (Queue));
16 queue->list = _list_new(dataSize);
17 _queue_init(queue, dataSize);
18 return queue;
a7868768
BA
19}
20
21Queue* queue_copy(Queue* queue)
22{
e45132ac
BA
23 Queue* queueCopy = (Queue*) safe_malloc(sizeof (Queue));
24 queueCopy->dataSize = queue->dataSize;
25 List* listCopy = list_copy(queue->list);
26 queueCopy->list = listCopy;
27 return queueCopy;
a7868768
BA
28}
29
1ff641f9 30bool queue_empty(Queue* queue)
a7868768 31{
e45132ac 32 return list_empty(queue->list);
a7868768
BA
33}
34
35UInt queue_size(Queue* queue)
36{
e45132ac 37 return list_size(queue->list);
a7868768
BA
38}
39
40void _queue_push(Queue* queue, void* data)
41{
e45132ac 42 _list_insert_back(queue->list, data);
a7868768
BA
43}
44
45void* _queue_peek(Queue* queue)
46{
e45132ac 47 return _list_get(queue->list->head);
a7868768
BA
48}
49
50void queue_pop(Queue* queue)
51{
e45132ac 52 list_remove_front(queue->list);
a7868768
BA
53}
54
55void queue_clear(Queue* queue)
56{
e45132ac 57 list_clear(queue->list);
a7868768
BA
58}
59
60void queue_destroy(Queue* queue)
61{
e45132ac
BA
62 list_destroy(queue->list);
63 safe_free(queue);
a7868768 64}