Code formatting and moving more things around
This commit is contained in:
1 parent
59a1e2a682
commit
649f02665f
23 files changed
+361
-293
No files matched your search
+2
-2
@@ -206,7 +206,7 @@ static const char *cmc_cmc_string_fmt_bitset = "struct %s "
|
||||
struct SNAME CMC_(PFX, _init_custom)(size_t n_bits, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * CMC_UNUSED(callbacks)) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
struct SNAME _bitset_ = { 0 }; \
|
||||
\
|
||||
@@ -245,7 +245,7 @@ static const char *cmc_cmc_string_fmt_bitset = "struct %s "
|
||||
void CMC_(PFX, _customize)(struct SNAME * _bitset_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_bitset_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -155,7 +155,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
@@ -231,7 +231,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _deque_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_deque_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
@@ -262,14 +262,14 @@
|
||||
struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
||||
struct CMC_DEF_FVAL(SNAME) * f_val) \
|
||||
{ \
|
||||
return CMC_(PFX, _new_custom)(capacity, load, f_key, f_val, NULL, NULL);\
|
||||
return CMC_(PFX, _new_custom)(capacity, load, f_key, f_val, NULL, NULL); \
|
||||
} \
|
||||
\
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
return NULL; \
|
||||
@@ -350,7 +350,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _map_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_map_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -194,7 +194,7 @@
|
||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
return NULL; \
|
||||
@@ -285,7 +285,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _map_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_map_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity == 0 || load <= 0) \
|
||||
return NULL; \
|
||||
@@ -339,7 +339,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _map_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_map_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
return NULL; \
|
||||
@@ -262,7 +262,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _set_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_set_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -156,7 +156,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
return NULL; \
|
||||
@@ -240,7 +240,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _set_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_set_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -152,7 +152,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
@@ -223,7 +223,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _heap_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_heap_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity == 0 || capacity == UINTMAX_MAX) \
|
||||
return NULL; \
|
||||
@@ -218,7 +218,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _heap_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_heap_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!f_val) \
|
||||
return NULL; \
|
||||
@@ -216,7 +216,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _list_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_list_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -165,7 +165,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
@@ -228,7 +228,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _list_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_list_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -181,7 +181,7 @@
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
@@ -256,7 +256,7 @@
|
||||
void CMC_(PFX, _customize)(struct SNAME * _queue_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_queue_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+3
-257
@@ -27,21 +27,6 @@
|
||||
* ------------------------------------------------------------------------- */
|
||||
#include "../cor/core.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* SortedList specific
|
||||
* ------------------------------------------------------------------------- */
|
||||
/* to_string format */
|
||||
static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
"at %p { "
|
||||
"buffer:%p, "
|
||||
"capacity:%" PRIuMAX ", "
|
||||
"count:%" PRIuMAX ", "
|
||||
"is_sorted:%s, "
|
||||
"flag:%d, "
|
||||
"f_val:%p, "
|
||||
"alloc:%p, "
|
||||
"callbacks:%p }";
|
||||
|
||||
/**
|
||||
* Core SortedList implementation
|
||||
*/
|
||||
@@ -109,22 +94,6 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
/* Priority function */ \
|
||||
CMC_DEF_FTAB_PRI(V); \
|
||||
}; \
|
||||
\
|
||||
/* List Iterator */ \
|
||||
struct CMC_DEF_ITER(SNAME) \
|
||||
{ \
|
||||
/* Target list */ \
|
||||
struct SNAME *target; \
|
||||
\
|
||||
/* Cursor's position (index) */ \
|
||||
size_t cursor; \
|
||||
\
|
||||
/* If the iterator has reached the start of the iteration */ \
|
||||
bool start; \
|
||||
\
|
||||
/* If the iterator has reached the end of the iteration */ \
|
||||
bool end; \
|
||||
}; \
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
@@ -155,28 +124,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
bool CMC_(PFX, _resize)(struct SNAME * _list_, size_t capacity); \
|
||||
void CMC_(PFX, _sort)(struct SNAME * _list_); \
|
||||
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _list_); \
|
||||
bool CMC_(PFX, _equals)(struct SNAME * _list1_, struct SNAME * _list2_); \
|
||||
struct cmc_string CMC_(PFX, _to_string)(struct SNAME * _list_); \
|
||||
bool CMC_(PFX, _print)(struct SNAME * _list_, 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); \
|
||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||
bool CMC_(PFX, _equals)(struct SNAME * _list1_, struct SNAME * _list2_);
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Source
|
||||
@@ -197,7 +145,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
@@ -258,7 +206,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
void CMC_(PFX, _customize)(struct SNAME * _list_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_list_->alloc = &cmc_alloc_node_default; \
|
||||
@@ -514,208 +462,6 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct cmc_string CMC_(PFX, _to_string)(struct SNAME * _list_) \
|
||||
{ \
|
||||
struct cmc_string str; \
|
||||
struct SNAME *l_ = _list_; \
|
||||
\
|
||||
int n = \
|
||||
snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_sortedlist, #SNAME, #V, l_, l_->buffer, l_->capacity, \
|
||||
l_->count, l_->is_sorted ? "true" : "false", l_->flag, l_->f_val, l_->alloc, l_->callbacks); \
|
||||
\
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 }; \
|
||||
} \
|
||||
\
|
||||
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr) \
|
||||
{ \
|
||||
CMC_(PFX, _sort)(_list_); \
|
||||
\
|
||||
for (size_t i = 0; i < _list_->count; i++) \
|
||||
{ \
|
||||
if (!_list_->f_val->str(fptr, _list_->buffer[i])) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||
{ \
|
||||
CMC_(PFX, _sort)(target); \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) iter; \
|
||||
\
|
||||
iter.target = target; \
|
||||
iter.cursor = 0; \
|
||||
iter.start = true; \
|
||||
iter.end = CMC_(PFX, _empty)(target); \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||
{ \
|
||||
CMC_(PFX, _sort)(target); \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) iter; \
|
||||
\
|
||||
iter.target = target; \
|
||||
iter.cursor = 0; \
|
||||
iter.start = CMC_(PFX, _empty)(target); \
|
||||
iter.end = true; \
|
||||
\
|
||||
if (!CMC_(PFX, _empty)(target)) \
|
||||
iter.cursor = target->count - 1; \
|
||||
\
|
||||
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 = 0; \
|
||||
iter->start = true; \
|
||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||
{ \
|
||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||
{ \
|
||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||
iter->cursor = iter->target->count - 1; \
|
||||
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->cursor + 1 == iter->target->count) \
|
||||
{ \
|
||||
iter->end = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
iter->cursor++; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
\
|
||||
if (iter->cursor == 0) \
|
||||
{ \
|
||||
iter->start = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
iter->cursor--; \
|
||||
\
|
||||
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->cursor + 1 == iter->target->count) \
|
||||
{ \
|
||||
iter->end = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
||||
return false; \
|
||||
\
|
||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
iter->cursor += steps; \
|
||||
\
|
||||
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->cursor == 0) \
|
||||
{ \
|
||||
iter->start = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (steps == 0 || iter->cursor < steps) \
|
||||
return false; \
|
||||
\
|
||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
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->cursor > index) \
|
||||
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
||||
else if (iter->cursor < index) \
|
||||
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
||||
\
|
||||
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]; \
|
||||
} \
|
||||
\
|
||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||
{ \
|
||||
return iter->cursor; \
|
||||
} \
|
||||
\
|
||||
static size_t CMC_(PFX, _impl_binary_search_first)(struct SNAME * _list_, V value) \
|
||||
{ \
|
||||
|
||||
+2
-2
@@ -193,7 +193,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> "
|
||||
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
@@ -255,7 +255,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> "
|
||||
void CMC_(PFX, _customize)(struct SNAME * _stack_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_stack_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -247,7 +247,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FKEY(SNAME) * f_key, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!f_key || !f_val) \
|
||||
return NULL; \
|
||||
@@ -347,7 +347,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
void CMC_(PFX, _customize)(struct SNAME * _map_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_map_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+2
-2
@@ -232,7 +232,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!f_val) \
|
||||
return NULL; \
|
||||
@@ -327,7 +327,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
void CMC_(PFX, _customize)(struct SNAME * _set_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
if (!alloc) \
|
||||
_set_->alloc = &cmc_alloc_node_default; \
|
||||
|
||||
+1
-2
@@ -102,8 +102,7 @@
|
||||
* Marks a function parameter used or unused depending on the expanded value of
|
||||
* MACRO. It need to expand to either TRUE or FALSE.
|
||||
*/
|
||||
#define CMC_UNUSED_PARAM(MACRO, PARAM) \
|
||||
CMC_(CMC_UNUSED_PARAM_, MACRO)(PARAM)\
|
||||
#define CMC_UNUSED_PARAM(MACRO, PARAM) CMC_(CMC_UNUSED_PARAM_, MACRO)(PARAM)
|
||||
|
||||
#define CMC_UNUSED_PARAM_FALSE(PARAM) PARAM
|
||||
#define CMC_UNUSED_PARAM_TRUE(PARAM)
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@
|
||||
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
struct SNAME _deque_ = { 0 }; \
|
||||
\
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||
{ \
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\
|
||||
CMC_CALLBACKS_MAYBE_UNUSED(callbacks); \
|
||||
\
|
||||
struct SNAME _map_ = { 0 }; \
|
||||
\
|
||||
|
||||
+2
-1
@@ -406,7 +406,8 @@
|
||||
\
|
||||
size_t length = to - from + 1; \
|
||||
\
|
||||
struct SNAME *result = CMC_(PFX, _new_custom)(length, _list_->f_val, _list_->alloc, CMC_CALLBACKS_GET(_list_)); \
|
||||
struct SNAME *result = \
|
||||
CMC_(PFX, _new_custom)(length, _list_->f_val, _list_->alloc, CMC_CALLBACKS_GET(_list_)); \
|
||||
\
|
||||
if (!result) \
|
||||
{ \
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
/**
|
||||
* ext/cmc/sortedlist.h
|
||||
*
|
||||
* Creation Date: 06/06/2020
|
||||
*
|
||||
* Authors:
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CMC_EXT_CMC_SORTEDLIST_H
|
||||
#define CMC_EXT_CMC_SORTEDLIST_H
|
||||
|
||||
#include "../../cor/core.h"
|
||||
|
||||
/**
|
||||
* All the EXT parts of CMC SortedList.
|
||||
*/
|
||||
#define CMC_EXT_CMC_SORTEDLIST_PARTS ITER, STR
|
||||
|
||||
/**
|
||||
* ITER
|
||||
*/
|
||||
#define CMC_EXT_CMC_SORTEDLIST_ITER(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_ITER_HEADER(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_ITER_SOURCE(PARAMS)
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_ITER_HEADER(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_ITER_SOURCE(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_ITER_HEADER_(PFX, SNAME, V) \
|
||||
\
|
||||
/* List Iterator */ \
|
||||
struct CMC_DEF_ITER(SNAME) \
|
||||
{ \
|
||||
/* Target list */ \
|
||||
struct SNAME *target; \
|
||||
\
|
||||
/* Cursor's position (index) */ \
|
||||
size_t cursor; \
|
||||
\
|
||||
/* If the iterator has reached the start of the iteration */ \
|
||||
bool start; \
|
||||
\
|
||||
/* If the iterator has reached the end of the iteration */ \
|
||||
bool end; \
|
||||
}; \
|
||||
\
|
||||
/* 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); \
|
||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_ITER_SOURCE_(PFX, SNAME, V) \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||
{ \
|
||||
CMC_(PFX, _sort)(target); \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) iter; \
|
||||
\
|
||||
iter.target = target; \
|
||||
iter.cursor = 0; \
|
||||
iter.start = true; \
|
||||
iter.end = CMC_(PFX, _empty)(target); \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||
{ \
|
||||
CMC_(PFX, _sort)(target); \
|
||||
\
|
||||
struct CMC_DEF_ITER(SNAME) iter; \
|
||||
\
|
||||
iter.target = target; \
|
||||
iter.cursor = 0; \
|
||||
iter.start = CMC_(PFX, _empty)(target); \
|
||||
iter.end = true; \
|
||||
\
|
||||
if (!CMC_(PFX, _empty)(target)) \
|
||||
iter.cursor = target->count - 1; \
|
||||
\
|
||||
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 = 0; \
|
||||
iter->start = true; \
|
||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||
{ \
|
||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||
{ \
|
||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||
iter->cursor = iter->target->count - 1; \
|
||||
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->cursor + 1 == iter->target->count) \
|
||||
{ \
|
||||
iter->end = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
iter->cursor++; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
\
|
||||
if (iter->cursor == 0) \
|
||||
{ \
|
||||
iter->start = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
iter->cursor--; \
|
||||
\
|
||||
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->cursor + 1 == iter->target->count) \
|
||||
{ \
|
||||
iter->end = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
||||
return false; \
|
||||
\
|
||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
iter->cursor += steps; \
|
||||
\
|
||||
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->cursor == 0) \
|
||||
{ \
|
||||
iter->start = true; \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (steps == 0 || iter->cursor < steps) \
|
||||
return false; \
|
||||
\
|
||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||
\
|
||||
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->cursor > index) \
|
||||
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
||||
else if (iter->cursor < index) \
|
||||
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
||||
\
|
||||
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]; \
|
||||
} \
|
||||
\
|
||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||
{ \
|
||||
return iter->cursor; \
|
||||
}
|
||||
|
||||
/**
|
||||
* STR
|
||||
*/
|
||||
#define CMC_EXT_CMC_SORTEDLIST_STR(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_STR_HEADER(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_STR_SOURCE(PARAMS)
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_STR_HEADER(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_STR_SOURCE(PARAMS) \
|
||||
CMC_EXT_CMC_SORTEDLIST_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_STR_HEADER_(PFX, SNAME, V) \
|
||||
\
|
||||
bool CMC_(PFX, _to_string)(struct SNAME * _list_, FILE * fptr); \
|
||||
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr, const char *start, const char *separator, \
|
||||
const char *end);
|
||||
|
||||
#define CMC_EXT_CMC_SORTEDLIST_STR_SOURCE_(PFX, SNAME, V) \
|
||||
\
|
||||
bool CMC_(PFX, _to_string)(struct SNAME * _list_, FILE * fptr) \
|
||||
{ \
|
||||
struct SNAME *l_ = _list_; \
|
||||
\
|
||||
return 0 <= fprintf(fptr, \
|
||||
"struct %s<%s> " \
|
||||
"at %p { " \
|
||||
"buffer:%p, " \
|
||||
"capacity:%" PRIuMAX ", " \
|
||||
"count:%" PRIuMAX ", " \
|
||||
"is_sorted:%s, " \
|
||||
"flag:%d, " \
|
||||
"f_val:%p, " \
|
||||
"alloc:%p, " \
|
||||
"callbacks:%p }", \
|
||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), l_, l_->buffer, l_->capacity, l_->count, \
|
||||
l_->is_sorted ? "true" : "false", l_->flag, l_->f_val, l_->alloc, CMC_CALLBACKS_GET(l_)); \
|
||||
} \
|
||||
\
|
||||
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr, const char *start, const char *separator, \
|
||||
const char *end) \
|
||||
{ \
|
||||
CMC_(PFX, _sort)(_list_); \
|
||||
\
|
||||
fprintf(fptr, "%s", start); \
|
||||
\
|
||||
for (size_t i = 0; i < _list_->count; i++) \
|
||||
{ \
|
||||
if (!_list_->f_val->str(fptr, _list_->buffer[i])) \
|
||||
return false; \
|
||||
\
|
||||
if (i + 1 < _list_->count) \
|
||||
fprintf(fptr, "%s", separator); \
|
||||
} \
|
||||
\
|
||||
fprintf(fptr, "%s", end); \
|
||||
\
|
||||
return true; \
|
||||
}
|
||||
|
||||
#endif /* CMC_EXT_CMC_SORTEDLIST_H */
|
||||
@@ -64,6 +64,7 @@
|
||||
#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 "ext/cmc/sortedlist.h" /* Added in 06/06/2020 */
|
||||
|
||||
#include "utl/assert.h" /* Added in 27/06/2019 */
|
||||
#include "utl/foreach.h" /* Added in 25/02/2019 */
|
||||
|
||||
Reference in new issue
Block a user