5 #include "cgds/Queue.h"
7 void _queue_init(Queue
* queue
, size_t dataSize
)
9 queue
->dataSize
= dataSize
;
10 _vector_init(queue
->array
, dataSize
);
13 Queue
* _queue_new(size_t dataSize
)
15 Queue
* queue
= (Queue
*) safe_malloc(sizeof (Queue
));
16 queue
->array
= _vector_new(dataSize
);
17 _queue_init(queue
, dataSize
);
21 Queue
* queue_copy(Queue
* queue
)
23 Queue
* queueCopy
= (Queue
*) safe_malloc(sizeof (Queue
));
24 queueCopy
->dataSize
= queue
->dataSize
;
25 Vector
* arrayCopy
= vector_copy(queue
->array
);
26 queueCopy
->array
= arrayCopy
;
30 Bool
queue_empty(Queue
* queue
)
32 return vector_empty(queue
->array
);
35 UInt
queue_size(Queue
* queue
)
37 return vector_size(queue
->array
);
40 void _queue_push(Queue
* queue
, void* data
)
42 _vector_push(queue
->array
, data
);
45 void* _queue_peek(Queue
* queue
)
47 return _vector_get(queue
->array
, 0);
50 void queue_pop(Queue
* queue
)
52 //remove first vector element and shift its internal array
53 safe_free(queue
->array
->datas
[0]);
54 queue
->array
->datas
++;
55 //NOTE: we remove first element, so capacity decrease too
57 queue
->array
->capacity
--;
60 void queue_clear(Queue
* queue
)
62 vector_clear(queue
->array
);
65 void queue_destroy(Queue
* queue
)
67 vector_destroy(queue
->array
);