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_init(queue
, dataSize
);
20 Queue
* queue_copy(Queue
* queue
)
22 Queue
* queueCopy
= (Queue
*) safe_malloc(sizeof (Queue
));
23 queueCopy
->dataSize
= queue
->dataSize
;
24 Vector
* arrayCopy
= vector_copy(queue
->array
);
25 queueCopy
->array
= arrayCopy
;
29 Bool
queue_empty(Queue
* queue
)
31 return vector_empty(queue
->array
);
34 UInt
queue_size(Queue
* queue
)
36 return vector_size(queue
->array
);
39 void _queue_push(Queue
* queue
, void* data
)
41 _vector_push(queue
->array
, data
);
44 void* _queue_peek(Queue
* queue
)
46 return vector_get(queue
->array
, 0);
49 void queue_pop(Queue
* queue
)
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
56 queue
->array
->capacity
--;
59 void queue_clear(Queue
* queue
)
61 vector_clear(queue
->array
);
64 void queue_destroy(Queue
* queue
)