From 195fd722d1d22a3a6163de16dd827770b3d9d39e Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.a@mailoo.org>
Date: Fri, 15 May 2015 15:24:00 +0200
Subject: [PATCH] fix Queue tests issue by returning to List implementation

---
 src/Queue.c  | 23 +++++++++++------------
 src/Queue.h  |  4 ++--
 src/Vector.c | 17 -----------------
 src/Vector.h |  7 -------
 4 files changed, 13 insertions(+), 38 deletions(-)

diff --git a/src/Queue.c b/src/Queue.c
index b85cf39..3e61381 100644
--- a/src/Queue.c
+++ b/src/Queue.c
@@ -7,13 +7,13 @@
 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;
 }
@@ -22,44 +22,43 @@ Queue* queue_copy(Queue* 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);
 }
diff --git a/src/Queue.h b/src/Queue.h
index 619ae4a..0cd9766 100644
--- a/src/Queue.h
+++ b/src/Queue.h
@@ -9,7 +9,7 @@
 #include <string.h>
 #include "cgds/types.h"
 #include "cgds/safe_alloc.h"
-#include "cgds/Vector.h"
+#include "cgds/List.h"
 
 /**
  * @brief Queue containing generic data.
@@ -17,7 +17,7 @@
  */
 typedef struct Queue {
 	size_t dataSize; ///< Size in bytes of a queue element.
-	Vector* array; ///< Internal vector representation
+	List* list; ///< Internal list representation
 } Queue;
 
 /**
diff --git a/src/Vector.c b/src/Vector.c
index cf45cb9..2d00985 100644
--- a/src/Vector.c
+++ b/src/Vector.c
@@ -82,23 +82,6 @@ void vector_pop(Vector* vector)
 		_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];
diff --git a/src/Vector.h b/src/Vector.h
index 985ac10..d3fe04c 100644
--- a/src/Vector.h
+++ b/src/Vector.h
@@ -105,13 +105,6 @@ void vector_pop(
 	Vector* vector ///< "this" pointer.
 );
 
-/**
- * @brief Remove the first element.
- */
-void vector_pop_first(
-	Vector* vector ///< "this" pointer.
-);
-
 /**
  * @brief Get the element at given index.
  */
-- 
2.44.0