X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=src%2FQueue.h;h=9aae379fbba78e740c9245cf836e12ca6f6e5825;hb=1ff641f9960fa6c6081817a5641afb22fad91dcd;hp=db715793ae8c8a70dc7614bed13e508070adbdb7;hpb=a78687686f5b490d99fae21f9fa8aaa9a34f1812;p=cgds.git diff --git a/src/Queue.h b/src/Queue.h index db71579..9aae379 100644 --- a/src/Queue.h +++ b/src/Queue.h @@ -9,24 +9,15 @@ #include #include "cgds/types.h" #include "cgds/safe_alloc.h" - -/** - * @brief Generic internal queue cell. - */ -typedef struct QueueCell { - void* data; ///< Generic data contained in the cell. - struct QueueCell* next; ///< Next cell in the internal single-linked list. -} QueueCell; +#include "cgds/List.h" /** * @brief Queue containing generic data. * @param dataSize Size in bytes of a queue element. */ typedef struct Queue { - UInt size; ///< Count elements in the queue. size_t dataSize; ///< Size in bytes of a queue element. - QueueCell* front; ///< Pointer to the next dequeued element. - QueueCell* back; ///< Pointer to the last enqueued element. + List* list; ///< Internal list representation } Queue; /** @@ -39,24 +30,24 @@ void _queue_init( size_t dataSize ///< Size in bytes of a queue element. ); -/** +/** * @brief Return an allocated and initialized queue. */ Queue* _queue_new( size_t dataSize ///< Size in bytes of a queue element. ); -/** +/** * @brief Return an allocated and initialized queue. * @param type Type of a queue element (int, char*, ...). - * + * * Usage: Queue* queue_new( type) */ #define queue_new(type) \ _queue_new(sizeof(type)) /** - * @brief Copy constructor (works well if items do not have allocated sub-pointers). + * @brief Copy constructor (shallow copy, ok for basic types). */ Queue* queue_copy( Queue* queue ///< "this" pointer. @@ -65,7 +56,7 @@ Queue* queue_copy( /** * @brief Check if the queue is empty. */ -Bool queue_empty( +bool queue_empty( Queue* queue ///< "this" pointer. ); @@ -88,7 +79,7 @@ void _queue_push( * @brief Add something at the end of the queue. * @param queue "this" pointer * @param data Data to be pushed. - * + * * Usage: void queue_push(Queue* queue, void data) */ #define queue_push(queue, data) \ @@ -108,7 +99,7 @@ void* _queue_peek( * @brief Return what is at the beginning of the queue. * @param queue "this" pointer. * @param data Data to be assigned. - * + * * Usage: void queue_peek(Queue* queue, void data) */ #define queue_peek(queue, data) \