From e85bc722037932198c27f94d64e412f778c1cc54 Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Fri, 5 Jun 2020 10:47:57 -0300 Subject: [PATCH] Moving more stuff to EXT and fixing typo --- src/cmc/hashmultiset.h | 2 +- src/cmc/queue.h | 274 +-------------------------------- src/ext/cmc/queue.h | 329 ++++++++++++++++++++++++++++++++++++++++ src/macro_collections.h | 1 + tests/to_string.c | 11 ++ 5 files changed, 343 insertions(+), 274 deletions(-) create mode 100644 src/ext/cmc/queue.h diff --git a/src/cmc/hashmultiset.h b/src/cmc/hashmultiset.h index 3ebb891..64553e8 100644 --- a/src/cmc/hashmultiset.h +++ b/src/cmc/hashmultiset.h @@ -171,7 +171,7 @@ \ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val) \ { \ - return CMC_(PFX, _new_custom)(capaccapacity, load, f_val, NULL, NULL); \ + return CMC_(PFX, _new_custom)(capacity, load, f_val, NULL, NULL); \ } \ \ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val, \ diff --git a/src/cmc/queue.h b/src/cmc/queue.h index dda6d1f..e2cd5ad 100644 --- a/src/cmc/queue.h +++ b/src/cmc/queue.h @@ -48,22 +48,6 @@ * ------------------------------------------------------------------------- */ #include "../cor/core.h" -/* ------------------------------------------------------------------------- - * Queue specific - * ------------------------------------------------------------------------- */ -/* to_string format */ -static const char *cmc_cmc_string_fmt_queue = "struct %s<%s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "front:%" PRIuMAX ", " - "back:%" PRIuMAX ", " - "flag:%d, " - "f_val:%p, " - "alloc:%p, " - "callbacks:%p }"; - /** * Core Queue implementation */ @@ -179,29 +163,7 @@ static const char *cmc_cmc_string_fmt_queue = "struct %s<%s> " /* Collection Utility */ \ bool CMC_(PFX, _resize)(struct SNAME * _queue_, size_t capacity); \ struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _queue_); \ - bool CMC_(PFX, _equals)(struct SNAME * _queue1_, struct SNAME * _queue2_); \ - struct cmc_string CMC_(PFX, _to_string)(struct SNAME * _queue_); \ - bool CMC_(PFX, _print)(struct SNAME * _queue_, FILE * fptr); \ -\ - /* Iterator Functions */ \ - /* Iterator Initialization */ \ - struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \ - struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \ - /* Iterator State */ \ - bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \ - bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \ - /* Iterator Movement */ \ - bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \ - bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \ - bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \ - bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \ - bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \ - bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \ - bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \ - /* Iterator Access */ \ - V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \ - V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \ - size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter); + bool CMC_(PFX, _equals)(struct SNAME * _queue1_, struct SNAME * _queue2_); /* ------------------------------------------------------------------------- * Source @@ -508,240 +470,6 @@ static const char *cmc_cmc_string_fmt_queue = "struct %s<%s> " } \ \ return true; \ - } \ -\ - struct cmc_string CMC_(PFX, _to_string)(struct SNAME * _queue_) \ - { \ - struct cmc_string str; \ - struct SNAME *q_ = _queue_; \ -\ - int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_queue, #SNAME, #V, q_, q_->buffer, q_->capacity, \ - q_->count, q_->front, q_->back, q_->flag, q_->f_val, q_->alloc, q_->callbacks); \ -\ - return n >= 0 ? str : (struct cmc_string){ 0 }; \ - } \ -\ - bool CMC_(PFX, _print)(struct SNAME * _queue_, FILE * fptr) \ - { \ - for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++) \ - { \ - if (!_queue_->f_val->str(fptr, _queue_->buffer[i])) \ - return false; \ -\ - i = (i + 1) % _queue_->capacity; \ - } \ -\ - return true; \ - } \ -\ - struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \ - { \ - struct CMC_DEF_ITER(SNAME) iter; \ -\ - iter.target = target; \ - iter.cursor = target->front; \ - iter.index = 0; \ - iter.start = true; \ - iter.end = CMC_(PFX, _empty)(target); \ -\ - return iter; \ - } \ -\ - struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \ - { \ - struct CMC_DEF_ITER(SNAME) iter; \ -\ - iter.target = target; \ -\ - if (!CMC_(PFX, _empty)(target)) \ - { \ - if (iter.target->back == 0) \ - iter.cursor = iter.target->capacity - 1; \ - else \ - iter.cursor = iter.target->back - 1; \ -\ - iter.index = iter.target->count - 1; \ - } \ - else \ - { \ - iter.cursor = 0; \ - iter.index = 0; \ - } \ -\ - iter.start = CMC_(PFX, _empty)(target); \ - iter.end = true; \ -\ - return iter; \ - } \ -\ - bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - return CMC_(PFX, _empty)(iter->target) || iter->start; \ - } \ -\ - bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - return CMC_(PFX, _empty)(iter->target) || iter->end; \ - } \ -\ - bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - if (!CMC_(PFX, _empty)(iter->target)) \ - { \ - iter->cursor = iter->target->front; \ - iter->index = 0; \ - iter->start = true; \ - iter->end = false; \ -\ - return true; \ - } \ -\ - return false; \ - } \ -\ - bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - if (!CMC_(PFX, _empty)(iter->target)) \ - { \ - if (iter->target->back == 0) \ - iter->cursor = iter->target->capacity - 1; \ - else \ - iter->cursor = iter->target->back - 1; \ -\ - iter->index = iter->target->count - 1; \ -\ - iter->start = false; \ - iter->end = true; \ -\ - return true; \ - } \ -\ - return false; \ - } \ -\ - bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - if (iter->end) \ - return false; \ -\ - if (iter->index + 1 == iter->target->count) \ - { \ - iter->end = true; \ - return false; \ - } \ -\ - iter->start = CMC_(PFX, _empty)(iter->target); \ -\ - iter->cursor = (iter->cursor + 1) % (iter->target->capacity); \ - iter->index++; \ -\ - return true; \ - } \ -\ - bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - if (iter->start) \ - return false; \ -\ - if (iter->index == 0) \ - { \ - iter->start = true; \ - return false; \ - } \ -\ - iter->end = CMC_(PFX, _empty)(iter->target); \ -\ - iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1; \ - iter->index--; \ -\ - return true; \ - } \ -\ - /* Returns true only if the iterator moved */ \ - bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \ - { \ - if (iter->end) \ - return false; \ -\ - if (iter->index + 1 == iter->target->count) \ - { \ - iter->end = true; \ - return false; \ - } \ -\ - if (steps == 0 || iter->index + steps >= iter->target->count) \ - return false; \ -\ - iter->start = CMC_(PFX, _empty)(iter->target); \ -\ - iter->index += steps; \ - iter->cursor = (iter->cursor + steps) % iter->target->capacity; \ -\ - return true; \ - } \ -\ - /* Returns true only if the iterator moved */ \ - bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \ - { \ - if (iter->start) \ - return false; \ -\ - if (iter->index == 0) \ - { \ - iter->start = true; \ - return false; \ - } \ -\ - if (steps == 0 || iter->index < steps) \ - return false; \ -\ - iter->end = CMC_(PFX, _empty)(iter->target); \ -\ - iter->index -= steps; \ -\ - /* Prevent underflow */ \ - if (iter->cursor < steps) \ - iter->cursor += iter->target->capacity; \ -\ - iter->cursor -= steps; \ -\ - return true; \ - } \ -\ - /* Returns true only if the iterator was able to be positioned at the */ \ - /* given index */ \ - bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \ - { \ - if (index >= iter->target->count) \ - return false; \ -\ - if (iter->index > index) \ - return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \ - else if (iter->index < index) \ - return CMC_(PFX, _iter_advance)(iter, index - iter->index); \ -\ - return true; \ - } \ -\ - V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - if (CMC_(PFX, _empty)(iter->target)) \ - return (V){ 0 }; \ -\ - return iter->target->buffer[iter->cursor]; \ - } \ -\ - V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - if (CMC_(PFX, _empty)(iter->target)) \ - return NULL; \ -\ - return &(iter->target->buffer[iter->cursor]); \ - } \ -\ - size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \ - { \ - return iter->index; \ } #endif /* CMC_CMC_QUEUE_H */ diff --git a/src/ext/cmc/queue.h b/src/ext/cmc/queue.h new file mode 100644 index 0000000..655e895 --- /dev/null +++ b/src/ext/cmc/queue.h @@ -0,0 +1,329 @@ +/** + * ext/cmc/queue.h + * + * Creation Date: 05/06/2020 + * + * Authors: + * Leonardo Vencovsky (https://github.com/LeoVen) + * + */ + +#ifndef CMC_EXT_CMC_QUEUE_H +#define CMC_EXT_CMC_QUEUE_H + +#include "../../cor/core.h" + +/** + * All the EXT parts of CMC Queue. + */ +#define CMC_EXT_CMC_QUEUE_PARTS ITER, STR + +/** + * ITER + */ +#define CMC_EXT_CMC_QUEUE_ITER(PARAMS) \ + CMC_EXT_CMC_QUEUE_ITER_HEADER(PARAMS) \ + CMC_EXT_CMC_QUEUE_ITER_SOURCE(PARAMS) + +#define CMC_EXT_CMC_QUEUE_ITER_HEADER(PARAMS) \ + CMC_EXT_CMC_QUEUE_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS)) + +#define CMC_EXT_CMC_QUEUE_ITER_SOURCE(PARAMS) \ + CMC_EXT_CMC_QUEUE_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS)) + +#define CMC_EXT_CMC_QUEUE_ITER_HEADER_(PFX, SNAME, V) \ +\ + /* Iterator Initialization */ \ + struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \ + struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \ + /* Iterator State */ \ + bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \ + bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \ + /* Iterator Movement */ \ + bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \ + bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \ + bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \ + bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \ + bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \ + bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \ + bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \ + /* Iterator Access */ \ + V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \ + V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \ + size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter); + +#define CMC_EXT_CMC_QUEUE_ITER_SOURCE_(PFX, SNAME, V) \ +\ + struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \ + { \ + struct CMC_DEF_ITER(SNAME) iter; \ +\ + iter.target = target; \ + iter.cursor = target->front; \ + iter.index = 0; \ + iter.start = true; \ + iter.end = CMC_(PFX, _empty)(target); \ +\ + return iter; \ + } \ +\ + struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \ + { \ + struct CMC_DEF_ITER(SNAME) iter; \ +\ + iter.target = target; \ +\ + if (!CMC_(PFX, _empty)(target)) \ + { \ + if (iter.target->back == 0) \ + iter.cursor = iter.target->capacity - 1; \ + else \ + iter.cursor = iter.target->back - 1; \ +\ + iter.index = iter.target->count - 1; \ + } \ + else \ + { \ + iter.cursor = 0; \ + iter.index = 0; \ + } \ +\ + iter.start = CMC_(PFX, _empty)(target); \ + iter.end = true; \ +\ + return iter; \ + } \ +\ + bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + return CMC_(PFX, _empty)(iter->target) || iter->start; \ + } \ +\ + bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + return CMC_(PFX, _empty)(iter->target) || iter->end; \ + } \ +\ + bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + if (!CMC_(PFX, _empty)(iter->target)) \ + { \ + iter->cursor = iter->target->front; \ + iter->index = 0; \ + iter->start = true; \ + iter->end = false; \ +\ + return true; \ + } \ +\ + return false; \ + } \ +\ + bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + if (!CMC_(PFX, _empty)(iter->target)) \ + { \ + if (iter->target->back == 0) \ + iter->cursor = iter->target->capacity - 1; \ + else \ + iter->cursor = iter->target->back - 1; \ +\ + iter->index = iter->target->count - 1; \ +\ + iter->start = false; \ + iter->end = true; \ +\ + return true; \ + } \ +\ + return false; \ + } \ +\ + bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + if (iter->end) \ + return false; \ +\ + if (iter->index + 1 == iter->target->count) \ + { \ + iter->end = true; \ + return false; \ + } \ +\ + iter->start = CMC_(PFX, _empty)(iter->target); \ +\ + iter->cursor = (iter->cursor + 1) % (iter->target->capacity); \ + iter->index++; \ +\ + return true; \ + } \ +\ + bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + if (iter->start) \ + return false; \ +\ + if (iter->index == 0) \ + { \ + iter->start = true; \ + return false; \ + } \ +\ + iter->end = CMC_(PFX, _empty)(iter->target); \ +\ + iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1; \ + iter->index--; \ +\ + return true; \ + } \ +\ + /* Returns true only if the iterator moved */ \ + bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \ + { \ + if (iter->end) \ + return false; \ +\ + if (iter->index + 1 == iter->target->count) \ + { \ + iter->end = true; \ + return false; \ + } \ +\ + if (steps == 0 || iter->index + steps >= iter->target->count) \ + return false; \ +\ + iter->start = CMC_(PFX, _empty)(iter->target); \ +\ + iter->index += steps; \ + iter->cursor = (iter->cursor + steps) % iter->target->capacity; \ +\ + return true; \ + } \ +\ + /* Returns true only if the iterator moved */ \ + bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \ + { \ + if (iter->start) \ + return false; \ +\ + if (iter->index == 0) \ + { \ + iter->start = true; \ + return false; \ + } \ +\ + if (steps == 0 || iter->index < steps) \ + return false; \ +\ + iter->end = CMC_(PFX, _empty)(iter->target); \ +\ + iter->index -= steps; \ +\ + /* Prevent underflow */ \ + if (iter->cursor < steps) \ + iter->cursor += iter->target->capacity; \ +\ + iter->cursor -= steps; \ +\ + return true; \ + } \ +\ + /* Returns true only if the iterator was able to be positioned at the */ \ + /* given index */ \ + bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \ + { \ + if (index >= iter->target->count) \ + return false; \ +\ + if (iter->index > index) \ + return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \ + else if (iter->index < index) \ + return CMC_(PFX, _iter_advance)(iter, index - iter->index); \ +\ + return true; \ + } \ +\ + V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + if (CMC_(PFX, _empty)(iter->target)) \ + return (V){ 0 }; \ +\ + return iter->target->buffer[iter->cursor]; \ + } \ +\ + V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + if (CMC_(PFX, _empty)(iter->target)) \ + return NULL; \ +\ + return &(iter->target->buffer[iter->cursor]); \ + } \ +\ + size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \ + { \ + return iter->index; \ + } + +/** + * STR + */ +#define CMC_EXT_CMC_QUEUE_STR(PARAMS) \ + CMC_EXT_CMC_QUEUE_STR_HEADER(PARAMS) \ + CMC_EXT_CMC_QUEUE_STR_SOURCE(PARAMS) + +#define CMC_EXT_CMC_QUEUE_STR_HEADER(PARAMS) \ + CMC_EXT_CMC_QUEUE_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS)) + +#define CMC_EXT_CMC_QUEUE_STR_SOURCE(PARAMS) \ + CMC_EXT_CMC_QUEUE_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS)) + +#define CMC_EXT_CMC_QUEUE_STR_HEADER_(PFX, SNAME, V) \ +\ + bool CMC_(PFX, _to_string)(struct SNAME * _queue_, FILE * fptr); \ + bool CMC_(PFX, _print)(struct SNAME * _queue_, FILE * fptr, const char *start, const char *separator, \ + const char *end); + +#define CMC_EXT_CMC_QUEUE_STR_SOURCE_(PFX, SNAME, V) \ +\ + bool CMC_(PFX, _to_string)(struct SNAME * _queue_, FILE * fptr) \ + { \ + struct SNAME *q_ = _queue_; \ +\ + return 0 <= fprintf(fptr, \ + "struct %s<%s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "front:%" PRIuMAX ", " \ + "back:%" PRIuMAX ", " \ + "flag:%d, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks:%p }", \ + CMC_TO_STRING(SNAME), CMC_TO_STRING(V), q_, q_->buffer, q_->capacity, q_->count, \ + q_->front, q_->back, q_->flag, q_->f_val, q_->alloc, CMC_CALLBACKS_GET(q_)); \ + } \ +\ + bool CMC_(PFX, _print)(struct SNAME * _queue_, FILE * fptr, const char *start, const char *separator, \ + const char *end) \ + { \ + fprintf(fptr, "%s", start); \ +\ + for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++) \ + { \ + if (!_queue_->f_val->str(fptr, _queue_->buffer[i])) \ + return false; \ +\ + i = (i + 1) % _queue_->capacity; \ +\ + if (j + 1 < _queue_->count) \ + fprintf(fptr, "%s", separator); \ + } \ +\ + fprintf(fptr, "%s", end); \ +\ + return true; \ + } + +#endif /* CMC_EXT_CMC_QUEUE_H */ diff --git a/src/macro_collections.h b/src/macro_collections.h index 12d0b92..d22bcef 100644 --- a/src/macro_collections.h +++ b/src/macro_collections.h @@ -62,6 +62,7 @@ #include "ext/cmc/intervalheap.h" /* Added in 02/06/2020 */ #include "ext/cmc/linkedlist.h" /* Added in 03/06/2020 */ #include "ext/cmc/list.h" /* Added in 04/06/2020 */ +#include "ext/cmc/queue.h" /* Added in 05/06/2020 */ #include "utl/assert.h" /* Added in 27/06/2019 */ #include "utl/foreach.h" /* Added in 25/02/2019 */ diff --git a/tests/to_string.c b/tests/to_string.c index 72dd3fd..6d906da 100644 --- a/tests/to_string.c +++ b/tests/to_string.c @@ -12,6 +12,7 @@ C_MACRO_COLLECTIONS_ALL(CMC, HEAP, ( h, heap, , , int)) C_MACRO_COLLECTIONS_ALL(CMC, INTERVALHEAP, ( ih, intervalheap, , , int)) C_MACRO_COLLECTIONS_ALL(CMC, LINKEDLIST, ( ll, linkedlist, , , int)) C_MACRO_COLLECTIONS_ALL(CMC, LIST, ( l, list, , , int)) +C_MACRO_COLLECTIONS_ALL(CMC, QUEUE, ( q, queue, , , int)) struct { @@ -39,6 +40,7 @@ int main(void) struct intervalheap *ih = ih_new(100, (struct intervalheap_fval *)&int_ftab); struct linkedlist *ll = ll_new((struct linkedlist_fval *)&int_ftab); struct list *l = l_new(100, (struct list_fval *)&int_ftab); + struct queue *q = q_new(100, (struct queue_fval *)&int_ftab); d_to_string(d, stdout); d_print(d, stdout, "\n[ ", ", ", " ]\n"); @@ -58,6 +60,8 @@ int main(void) ll_print(ll, stdout, "\n[ ", ", ", " ]\n"); l_to_string(l, stdout); l_print(l, stdout, "\n[ ", ", ", " ]\n"); + q_to_string(q, stdout); + q_print(q, stdout, "\n[ ", ", ", " ]\n"); fprintf(stdout, "\n"); @@ -70,6 +74,7 @@ int main(void) ih_insert(ih, 0); ll_push_back(ll, 0); l_push_back(l, 0); + q_enqueue(q, 0); d_to_string(d, stdout); d_print(d, stdout, "\n[ ", ", ", " ]\n"); @@ -89,6 +94,8 @@ int main(void) ll_print(ll, stdout, "\n[ ", ", ", " ]\n"); l_to_string(l, stdout); l_print(l, stdout, "\n[ ", ", ", " ]\n"); + q_to_string(q, stdout); + q_print(q, stdout, "\n[ ", ", ", " ]\n"); for (int i = 1; i < 20; i++) { @@ -101,6 +108,7 @@ int main(void) ih_insert(ih, i); ll_push_back(ll, i); l_push_back(l, i); + q_enqueue(q, i); } fprintf(stdout, "\n"); @@ -123,6 +131,8 @@ int main(void) ll_print(ll, stdout, "\n[ ", ", ", " ]\n"); l_to_string(l, stdout); l_print(l, stdout, "\n[ ", ", ", " ]\n"); + q_to_string(q, stdout); + q_print(q, stdout, "\n[ ", ", ", " ]\n"); d_free(d); hm_free(hm); @@ -133,6 +143,7 @@ int main(void) ih_free(ih); ll_free(ll); l_free(l); + q_free(q); } // clang-format on