void _queue_init(Queue* queue, size_t dataSize)
{
queue->dataSize = dataSize;
- _vector_init(queue->array, dataSize);
+ _list_init(queue->list, dataSize);
}
Queue* _queue_new(size_t dataSize)
{
Queue* queue = (Queue*) safe_malloc(sizeof (Queue));
- queue->array = _vector_new(dataSize);
+ queue->list = _list_new(dataSize);
_queue_init(queue, dataSize);
return queue;
}
{
Queue* queueCopy = (Queue*) safe_malloc(sizeof (Queue));
queueCopy->dataSize = queue->dataSize;
- Vector* arrayCopy = vector_copy(queue->array);
- queueCopy->array = arrayCopy;
+ List* listCopy = list_copy(queue->list);
+ queueCopy->list = listCopy;
return queueCopy;
}
Bool queue_empty(Queue* queue)
{
- return vector_empty(queue->array);
+ return list_empty(queue->list);
}
UInt queue_size(Queue* queue)
{
- return vector_size(queue->array);
+ return list_size(queue->list);
}
void _queue_push(Queue* queue, void* data)
{
- _vector_push(queue->array, data);
+ _list_insert_back(queue->list, data);
}
void* _queue_peek(Queue* queue)
{
- return _vector_get(queue->array, 0);
+ return _list_get(queue->list->head);
}
void queue_pop(Queue* queue)
{
- vector_pop_first(queue->array);
-
+ list_remove_front(queue->list);
}
void queue_clear(Queue* queue)
{
- vector_clear(queue->array);
+ list_clear(queue->list);
}
void queue_destroy(Queue* queue)
{
- vector_destroy(queue->array);
+ list_destroy(queue->list);
safe_free(queue);
}
_vector_realloc(vector, vector->capacity >> 1);
}
-void vector_pop_first(Vector* vector)
-{
- safe_free(vector->datas[0]);
-
-
- //HACK: next 3 lines move vector head
- void** nextDatas = vector->datas + 1;
- safe_free(vector->datas);
- vector->datas = nextDatas;
-//but memory can then be reallocated : TODO
-
-
- vector->size--;
- if (vector->size <= (vector->capacity >> 1))
- _vector_realloc(vector, vector->capacity >> 1);
-}
-
void* _vector_get(Vector* vector, UInt index)
{
return vector->datas[index];