From 59a1e2a682a70bc4f954ab7afe994b98280b570b Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Fri, 5 Jun 2020 15:46:52 -0300 Subject: [PATCH] Somewhat working optional callbacks --- src/cmc/bitset.h | 6 +- src/cmc/deque.h | 4 ++ src/cmc/hashbidimap.h | 120 +++++--------------------------------- src/cmc/hashmap.h | 31 +++++----- src/cmc/hashmultimap.h | 37 +++++------- src/cmc/hashmultiset.h | 34 +++++------ src/cmc/hashset.h | 22 ++++--- src/cmc/heap.h | 19 +++--- src/cmc/intervalheap.h | 33 +++++------ src/cmc/linkedlist.h | 37 +++++------- src/cmc/list.h | 43 ++++++-------- src/cmc/queue.h | 19 +++--- src/cmc/sortedlist.h | 28 ++++----- src/cmc/stack.h | 19 +++--- src/cmc/treemap.h | 28 ++++----- src/cmc/treeset.h | 19 +++--- src/cor/callbacks.h | 4 +- src/cor/core.h | 10 ++++ src/ext/cmc/deque.h | 2 + src/ext/cmc/hashbidimap.h | 86 ++++++++++++++++++++++++++- src/ext/cmc/hashmap.h | 2 + src/ext/cmc/list.h | 17 ++---- src/macro_collections.h | 1 + tests/to_string.c | 13 +++++ 24 files changed, 304 insertions(+), 330 deletions(-) diff --git a/src/cmc/bitset.h b/src/cmc/bitset.h index 9fa4237..25e4915 100644 --- a/src/cmc/bitset.h +++ b/src/cmc/bitset.h @@ -204,8 +204,10 @@ 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 * callbacks) \ + struct CMC_CALLBACKS_NAME * CMC_UNUSED(callbacks)) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ struct SNAME _bitset_ = { 0 }; \ \ if (n_bits < 1) \ @@ -243,6 +245,8 @@ 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);\ +\ if (!alloc) \ _bitset_->alloc = &cmc_alloc_node_default; \ else \ diff --git a/src/cmc/deque.h b/src/cmc/deque.h index 3f7122f..74c3956 100644 --- a/src/cmc/deque.h +++ b/src/cmc/deque.h @@ -155,6 +155,8 @@ 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);\ +\ if (capacity < 1) \ return NULL; \ \ @@ -229,6 +231,8 @@ void CMC_(PFX, _customize)(struct SNAME * _deque_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _deque_->alloc = &cmc_alloc_node_default; \ else \ diff --git a/src/cmc/hashbidimap.h b/src/cmc/hashbidimap.h index d605142..e5ef175 100644 --- a/src/cmc/hashbidimap.h +++ b/src/cmc/hashbidimap.h @@ -36,22 +36,6 @@ * ------------------------------------------------------------------------- */ #include "../cor/hashtable.h" -/* ------------------------------------------------------------------------- - * HashBidimap Specific - * ------------------------------------------------------------------------- */ -/* to_string format */ -static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "load:%lf, " - "flag:%d, " - "f_key:%p, " - "f_val:%p, " - "alloc:%p, " - "callbacks:%p }"; - /** * Core HashBidiMap implementation */ @@ -235,8 +219,6 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " bool CMC_(PFX, _resize)(struct SNAME * _map_, size_t capacity); \ struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _map_); \ bool CMC_(PFX, _equals)(struct SNAME * _map1_, struct SNAME * _map2_); \ - struct cmc_string CMC_(PFX, _to_string)(struct SNAME * _map_); \ - bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr); \ \ /* Iterator Functions */ \ /* Iterator Allocation and Deallocation */ \ @@ -280,52 +262,15 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " struct SNAME *CMC_(PFX, _new)(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 = &cmc_alloc_node_default; \ -\ - if (capacity == 0 || load <= 0 || load >= 1) \ - return NULL; \ -\ - /* Prevent integer overflow */ \ - if (capacity >= UINTMAX_MAX * load) \ - return NULL; \ -\ - if (!f_key || !f_val) \ - return NULL; \ -\ - size_t real_capacity = CMC_(PFX, _impl_calculate_size)(capacity / load); \ -\ - struct SNAME *_map_ = alloc->malloc(sizeof(struct SNAME)); \ -\ - if (!_map_) \ - return NULL; \ -\ - _map_->buffer = alloc->calloc(real_capacity, sizeof(struct CMC_DEF_ENTRY(SNAME) *[2])); \ -\ - if (!_map_->buffer) \ - { \ - alloc->free(_map_->buffer); \ - alloc->free(_map_); \ - return NULL; \ - } \ -\ - _map_->count = 0; \ - _map_->capacity = real_capacity; \ - _map_->load = load; \ - _map_->flag = CMC_FLAG_OK; \ - _map_->f_key = f_key; \ - _map_->f_val = f_val; \ - _map_->alloc = alloc; \ - CMC_CALLBACKS_ASSIGN(_map_, NULL); \ - _map_->it_start = CMC_(PFX, _impl_it_start); \ - _map_->it_end = CMC_(PFX, _impl_it_end); \ -\ - return _map_; \ + 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);\ +\ if (capacity == 0 || load <= 0 || load >= 1) \ return NULL; \ \ @@ -405,6 +350,8 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "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);\ +\ if (!alloc) \ _map_->alloc = &cmc_alloc_node_default; \ else \ @@ -452,8 +399,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " _map_->count++; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->create) \ - _map_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_map_, create); \ \ return true; \ } \ @@ -516,8 +462,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->update) \ - _map_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_map_, update); \ \ return true; \ } \ @@ -581,8 +526,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->update) \ - _map_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_map_, update); \ \ return true; \ } \ @@ -627,8 +571,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " _map_->count--; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->delete) \ - _map_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_map_, delete); \ \ return true; \ } \ @@ -673,8 +616,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " _map_->count--; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->delete) \ - _map_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_map_, delete); \ \ return true; \ } \ @@ -691,8 +633,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return (*entry)->key; \ } \ @@ -709,8 +650,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return (*entry)->value; \ } \ @@ -721,8 +661,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ bool result = CMC_(PFX, _impl_get_entry_by_key)(_map_, key) != NULL; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return result; \ } \ @@ -733,8 +672,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ bool result = CMC_(PFX, _impl_get_entry_by_val)(_map_, val) != NULL; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return result; \ } \ @@ -857,8 +795,7 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ success: \ \ - if (_map_->callbacks && _map_->callbacks->resize) \ - _map_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_map_, resize); \ \ return true; \ } \ @@ -951,33 +888,6 @@ static const char *cmc_cmc_string_fmt_hashbidimap = "struct %s<%s, %s> " \ return true; \ } \ -\ - struct cmc_string CMC_(PFX, _to_string)(struct SNAME * _map_) \ - { \ - struct cmc_string str; \ - struct SNAME *m_ = _map_; \ -\ - int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_hashbidimap, #SNAME, #K, #V, m_, m_->buffer, \ - m_->capacity, m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, m_->callbacks); \ -\ - return n >= 0 ? str : (struct cmc_string){ 0 }; \ - } \ -\ - bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr) \ - { \ - for (size_t i = 0; i < _map_->capacity; i++) \ - { \ - struct CMC_DEF_ENTRY(SNAME) *target = _map_->buffer[i][0]; \ -\ - if (target && target != CMC_ENTRY_DELETED) \ - { \ - if (!_map_->f_key->str(fptr, target->key) || !_map_->f_val->str(fptr, target->value)) \ - return false; \ - } \ - } \ -\ - return true; \ - } \ \ struct CMC_DEF_ITER(SNAME) * CMC_(PFX, _iter_new)(struct SNAME * target) \ { \ diff --git a/src/cmc/hashmap.h b/src/cmc/hashmap.h index 3ac5ae1..2eb00a9 100644 --- a/src/cmc/hashmap.h +++ b/src/cmc/hashmap.h @@ -194,6 +194,8 @@ struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (capacity == 0 || load <= 0 || load >= 1) \ return NULL; \ \ @@ -283,6 +285,8 @@ void CMC_(PFX, _customize)(struct SNAME * _map_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _map_->alloc = &cmc_alloc_node_default; \ else \ @@ -356,8 +360,7 @@ _map_->count++; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->create) \ - _map_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_map_, create); \ \ return true; \ } \ @@ -385,8 +388,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->update) \ - _map_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_map_, update); \ \ return true; \ } \ @@ -418,8 +420,7 @@ _map_->count--; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->delete) \ - _map_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_map_, delete); \ \ return true; \ } \ @@ -463,8 +464,7 @@ if (value) \ *value = max_val; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return true; \ } \ @@ -508,8 +508,7 @@ if (value) \ *value = min_val; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return true; \ } \ @@ -532,8 +531,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return entry->value; \ } \ @@ -556,8 +554,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return &(entry->value); \ } \ @@ -568,8 +565,7 @@ \ bool result = CMC_(PFX, _impl_get_entry)(_map_, key) != NULL; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return result; \ } \ @@ -678,8 +674,7 @@ \ success: \ \ - if (_map_->callbacks && _map_->callbacks->resize) \ - _map_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_map_, resize); \ \ return true; \ } \ diff --git a/src/cmc/hashmultimap.h b/src/cmc/hashmultimap.h index 38dea54..ac79010 100644 --- a/src/cmc/hashmultimap.h +++ b/src/cmc/hashmultimap.h @@ -223,6 +223,8 @@ struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (capacity == 0 || load <= 0) \ return NULL; \ \ @@ -337,6 +339,8 @@ void CMC_(PFX, _customize)(struct SNAME * _map_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _map_->alloc = &cmc_alloc_node_default; \ else \ @@ -376,8 +380,7 @@ _map_->count++; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->create) \ - _map_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_map_, create); \ \ return true; \ } \ @@ -405,8 +408,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->update) \ - _map_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_map_, update); \ \ return true; \ } \ @@ -466,8 +468,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->update) \ - _map_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_map_, update); \ \ return index; \ } \ @@ -550,8 +551,7 @@ _map_->count--; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->delete) \ - _map_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_map_, delete); \ \ return true; \ } \ @@ -642,8 +642,7 @@ _map_->count -= index; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->delete) \ - _map_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_map_, delete); \ \ return index; \ } \ @@ -687,8 +686,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return true; \ } \ @@ -732,8 +730,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return true; \ } \ @@ -756,8 +753,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return entry->value; \ } \ @@ -780,8 +776,7 @@ \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return &(entry->value); \ } \ @@ -792,8 +787,7 @@ \ bool result = CMC_(PFX, _impl_get_entry)(_map_, key) != NULL; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return result; \ } \ @@ -906,8 +900,7 @@ \ success: \ \ - if (_map_->callbacks && _map_->callbacks->resize) \ - _map_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_map_, resize); \ \ return true; \ } \ diff --git a/src/cmc/hashmultiset.h b/src/cmc/hashmultiset.h index 64553e8..673613b 100644 --- a/src/cmc/hashmultiset.h +++ b/src/cmc/hashmultiset.h @@ -177,6 +177,8 @@ 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);\ +\ if (capacity == 0 || load <= 0 || load >= 1) \ return NULL; \ \ @@ -260,6 +262,8 @@ void CMC_(PFX, _customize)(struct SNAME * _set_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _set_->alloc = &cmc_alloc_node_default; \ else \ @@ -288,8 +292,7 @@ _set_->cardinality++; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->create) \ - _set_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_set_, create); \ \ return true; \ } \ @@ -320,8 +323,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->create) \ - _set_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_set_, create); \ \ return true; \ } \ @@ -366,8 +368,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->update) \ - _set_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_set_, update); \ \ return true; \ } \ @@ -403,8 +404,7 @@ _set_->cardinality--; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->delete) \ - _set_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_set_, delete); \ \ return true; \ } \ @@ -436,8 +436,7 @@ _set_->cardinality -= removed; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->delete) \ - _set_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_set_, delete); \ \ return removed; \ } \ @@ -470,8 +469,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return true; \ } \ @@ -504,8 +502,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return true; \ } \ @@ -516,8 +513,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ if (!entry) \ return 0; \ @@ -531,8 +527,7 @@ \ bool result = CMC_(PFX, _impl_get_entry)(_set_, value) != NULL; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return result; \ } \ @@ -640,8 +635,7 @@ \ success: \ \ - if (_set_->callbacks && _set_->callbacks->resize) \ - _set_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_set_, resize); \ \ return true; \ } \ diff --git a/src/cmc/hashset.h b/src/cmc/hashset.h index d8d9a3c..7acb6be 100644 --- a/src/cmc/hashset.h +++ b/src/cmc/hashset.h @@ -156,6 +156,8 @@ 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);\ +\ if (capacity == 0 || load <= 0 || load >= 1) \ return NULL; \ \ @@ -238,6 +240,8 @@ void CMC_(PFX, _customize)(struct SNAME * _set_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _set_->alloc = &cmc_alloc_node_default; \ else \ @@ -306,8 +310,7 @@ _set_->count++; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->create) \ - _set_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_set_, create); \ \ return true; \ } \ @@ -335,8 +338,7 @@ _set_->count--; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->delete) \ - _set_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_set_, delete); \ \ return true; \ } \ @@ -369,8 +371,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return true; \ } \ @@ -403,8 +404,7 @@ \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return true; \ } \ @@ -415,8 +415,7 @@ \ bool result = CMC_(PFX, _impl_get_entry)(_set_, value) != NULL; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return result; \ } \ @@ -522,8 +521,7 @@ \ success: \ \ - if (_set_->callbacks && _set_->callbacks->resize) \ - _set_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_set_, resize); \ \ return true; \ } \ diff --git a/src/cmc/heap.h b/src/cmc/heap.h index adee37f..d0d52d2 100644 --- a/src/cmc/heap.h +++ b/src/cmc/heap.h @@ -152,6 +152,8 @@ 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);\ +\ if (capacity < 1) \ return NULL; \ \ @@ -221,6 +223,8 @@ void CMC_(PFX, _customize)(struct SNAME * _heap_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _heap_->alloc = &cmc_alloc_node_default; \ else \ @@ -248,8 +252,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->create) \ - _heap_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_heap_, create); \ \ return true; \ } \ @@ -271,8 +274,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->delete) \ - _heap_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_heap_, delete); \ \ return true; \ } \ @@ -287,8 +289,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->read) \ - _heap_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_heap_, read); \ \ return _heap_->buffer[0]; \ } \ @@ -308,8 +309,7 @@ } \ } \ \ - if (_heap_->callbacks && _heap_->callbacks->read) \ - _heap_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_heap_, read); \ \ return result; \ } \ @@ -367,8 +367,7 @@ \ success: \ \ - if (_heap_->callbacks && _heap_->callbacks->resize) \ - _heap_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_heap_, resize); \ \ return true; \ } \ diff --git a/src/cmc/intervalheap.h b/src/cmc/intervalheap.h index f141a6b..ad04db3 100644 --- a/src/cmc/intervalheap.h +++ b/src/cmc/intervalheap.h @@ -124,7 +124,7 @@ int CMC_(PFX, _flag)(struct SNAME * _heap_); \ /* Collection Utility */ \ bool CMC_(PFX, _resize)(struct SNAME * _heap_, size_t capacity); \ - struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _set_); \ + struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _heap_); \ bool CMC_(PFX, _equals)(struct SNAME * _heap1_, struct SNAME * _heap2_); /* ------------------------------------------------------------------------- @@ -146,6 +146,8 @@ 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);\ +\ if (capacity == 0 || capacity == UINTMAX_MAX) \ return NULL; \ \ @@ -216,6 +218,8 @@ void CMC_(PFX, _customize)(struct SNAME * _heap_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _heap_->alloc = &cmc_alloc_node_default; \ else \ @@ -277,8 +281,7 @@ /* else no float up required */ \ } \ \ - if (_heap_->callbacks && _heap_->callbacks->create) \ - _heap_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_heap_, create); \ \ return true; \ } \ @@ -330,8 +333,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->delete) \ - _heap_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_heap_, delete); \ \ return true; \ } \ @@ -383,8 +385,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->delete) \ - _heap_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_heap_, delete); \ \ return true; \ } \ @@ -420,8 +421,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->update) \ - _heap_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_heap_, update); \ \ return true; \ } \ @@ -457,8 +457,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->update) \ - _heap_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_heap_, update); \ \ return true; \ } \ @@ -473,8 +472,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->read) \ - _heap_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_heap_, read); \ \ /* If there is only one element, then the maximum element is the */ \ /* same as the one in the MinHeap */ \ @@ -494,8 +492,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->read) \ - _heap_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_heap_, read); \ \ return _heap_->buffer[0][0]; \ } \ @@ -515,8 +512,7 @@ } \ } \ \ - if (_heap_->callbacks && _heap_->callbacks->read) \ - _heap_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_heap_, read); \ \ return result; \ } \ @@ -587,8 +583,7 @@ \ _heap_->flag = CMC_FLAG_OK; \ \ - if (_heap_->callbacks && _heap_->callbacks->resize) \ - _heap_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_heap_, resize); \ \ return true; \ } \ diff --git a/src/cmc/linkedlist.h b/src/cmc/linkedlist.h index 044a737..3e223f6 100644 --- a/src/cmc/linkedlist.h +++ b/src/cmc/linkedlist.h @@ -158,6 +158,8 @@ 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);\ +\ if (!f_val) \ return NULL; \ \ @@ -214,6 +216,8 @@ void CMC_(PFX, _customize)(struct SNAME * _list_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _list_->alloc = &cmc_alloc_node_default; \ else \ @@ -246,8 +250,7 @@ _list_->count++; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -284,8 +287,7 @@ _list_->count++; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -312,8 +314,7 @@ _list_->count++; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -339,8 +340,7 @@ _list_->count--; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -381,8 +381,7 @@ _list_->count--; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -408,8 +407,7 @@ _list_->count--; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -424,8 +422,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->head->value; \ } \ @@ -449,8 +446,7 @@ if (scan == NULL) \ return (V){ 0 }; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return scan->value; \ } \ @@ -474,8 +470,7 @@ if (scan == NULL) \ return NULL; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return &(scan->value); \ } \ @@ -490,8 +485,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->tail->value; \ } \ @@ -515,8 +509,7 @@ scan = scan->next; \ } \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return result; \ } \ diff --git a/src/cmc/list.h b/src/cmc/list.h index 5ba990a..0a53453 100644 --- a/src/cmc/list.h +++ b/src/cmc/list.h @@ -165,6 +165,8 @@ 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);\ +\ if (capacity < 1) \ return NULL; \ \ @@ -226,6 +228,8 @@ void CMC_(PFX, _customize)(struct SNAME * _list_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _list_->alloc = &cmc_alloc_node_default; \ else \ @@ -254,8 +258,7 @@ _list_->count++; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -280,8 +283,7 @@ _list_->count++; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -297,8 +299,7 @@ _list_->buffer[_list_->count++] = value; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -316,8 +317,7 @@ _list_->buffer[--_list_->count] = (V){ 0 }; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -341,8 +341,7 @@ _list_->buffer[--_list_->count] = (V){ 0 }; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -355,8 +354,7 @@ _list_->buffer[--_list_->count] = (V){ 0 }; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -371,8 +369,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->buffer[0]; \ } \ @@ -393,8 +390,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->buffer[index]; \ } \ @@ -415,8 +411,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return &(_list_->buffer[index]); \ } \ @@ -431,8 +426,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->buffer[_list_->count - 1]; \ } \ @@ -466,8 +460,7 @@ } \ } \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return result; \ } \ @@ -487,8 +480,7 @@ } \ } \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return result; \ } \ @@ -549,8 +541,7 @@ _list_->buffer = new_buffer; \ _list_->capacity = capacity; \ \ - if (_list_->callbacks && _list_->callbacks->resize) \ - _list_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_list_, resize); \ \ return true; \ } \ diff --git a/src/cmc/queue.h b/src/cmc/queue.h index e2cd5ad..652b715 100644 --- a/src/cmc/queue.h +++ b/src/cmc/queue.h @@ -181,6 +181,8 @@ 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);\ +\ if (capacity < 1) \ return NULL; \ \ @@ -254,6 +256,8 @@ void CMC_(PFX, _customize)(struct SNAME * _queue_, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ if (!alloc) \ _queue_->alloc = &cmc_alloc_node_default; \ else \ @@ -278,8 +282,7 @@ _queue_->count++; \ _queue_->flag = CMC_FLAG_OK; \ \ - if (_queue_->callbacks && _queue_->callbacks->create) \ - _queue_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_queue_, create); \ \ return true; \ } \ @@ -298,8 +301,7 @@ _queue_->count--; \ _queue_->flag = CMC_FLAG_OK; \ \ - if (_queue_->callbacks && _queue_->callbacks->delete) \ - _queue_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_queue_, delete); \ \ return true; \ } \ @@ -314,8 +316,7 @@ \ _queue_->flag = CMC_FLAG_OK; \ \ - if (_queue_->callbacks && _queue_->callbacks->read) \ - _queue_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_queue_, read); \ \ return _queue_->buffer[_queue_->front]; \ } \ @@ -337,8 +338,7 @@ i = (i + 1) % _queue_->capacity; \ } \ \ - if (_queue_->callbacks && _queue_->callbacks->read) \ - _queue_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_queue_, read); \ \ return result; \ } \ @@ -405,8 +405,7 @@ \ _queue_->flag = CMC_FLAG_OK; \ \ - if (_queue_->callbacks && _queue_->callbacks->resize) \ - _queue_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_queue_, resize); \ \ return true; \ } \ diff --git a/src/cmc/sortedlist.h b/src/cmc/sortedlist.h index 076e23b..847f047 100644 --- a/src/cmc/sortedlist.h +++ b/src/cmc/sortedlist.h @@ -197,6 +197,8 @@ 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);\ +\ if (capacity < 1) \ return NULL; \ \ @@ -256,6 +258,8 @@ 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);\ +\ if (!alloc) \ _list_->alloc = &cmc_alloc_node_default; \ else \ @@ -279,8 +283,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " _list_->is_sorted = false; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -305,8 +308,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -323,8 +325,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->buffer[_list_->count - 1]; \ } \ @@ -341,8 +342,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->buffer[0]; \ } \ @@ -365,8 +365,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return _list_->buffer[index]; \ } \ @@ -377,8 +376,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ CMC_(PFX, _sort)(_list_); \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ if (from_start) \ { \ @@ -397,8 +395,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ CMC_(PFX, _sort)(_list_); \ \ - if (_list_->callbacks && _list_->callbacks->read) \ - _list_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_list_, read); \ \ return CMC_(PFX, _impl_binary_search_first)(_list_, value) < _list_->count; \ } \ @@ -456,8 +453,7 @@ static const char *cmc_cmc_string_fmt_sortedlist = "struct %s<%s> " \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->resize) \ - _list_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_list_, resize); \ \ return true; \ } \ diff --git a/src/cmc/stack.h b/src/cmc/stack.h index 6207d35..0afa5a3 100644 --- a/src/cmc/stack.h +++ b/src/cmc/stack.h @@ -193,6 +193,8 @@ 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);\ +\ if (capacity < 1) \ return NULL; \ if (!f_val) \ @@ -253,6 +255,8 @@ 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);\ +\ if (!alloc) \ _stack_->alloc = &cmc_alloc_node_default; \ else \ @@ -275,8 +279,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> " \ _stack_->flag = CMC_FLAG_OK; \ \ - if (_stack_->callbacks && _stack_->callbacks->create) \ - _stack_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_stack_, create); \ \ return true; \ } \ @@ -293,8 +296,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> " \ _stack_->flag = CMC_FLAG_OK; \ \ - if (_stack_->callbacks && _stack_->callbacks->delete) \ - _stack_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_stack_, delete); \ \ return true; \ } \ @@ -309,8 +311,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> " \ _stack_->flag = CMC_FLAG_OK; \ \ - if (_stack_->callbacks && _stack_->callbacks->read) \ - _stack_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_stack_, read); \ \ return _stack_->buffer[_stack_->count - 1]; \ } \ @@ -330,8 +331,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> " } \ } \ \ - if (_stack_->callbacks && _stack_->callbacks->read) \ - _stack_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_stack_, read); \ \ return result; \ } \ @@ -389,8 +389,7 @@ static const char *cmc_cmc_string_fmt_stack = "struct %s<%s> " \ _stack_->flag = CMC_FLAG_OK; \ \ - if (_stack_->callbacks && _stack_->callbacks->resize) \ - _stack_->callbacks->resize(); \ + CMC_CALLBACKS_CALL(_stack_, resize); \ \ return true; \ } \ diff --git a/src/cmc/treemap.h b/src/cmc/treemap.h index 0591e3b..e653751 100644 --- a/src/cmc/treemap.h +++ b/src/cmc/treemap.h @@ -247,6 +247,8 @@ 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);\ +\ if (!f_key || !f_val) \ return NULL; \ \ @@ -345,6 +347,8 @@ 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);\ +\ if (!alloc) \ _map_->alloc = &cmc_alloc_node_default; \ else \ @@ -422,8 +426,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " _map_->count++; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->create) \ - _map_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_map_, create); \ \ return true; \ } \ @@ -445,8 +448,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->update) \ - _map_->callbacks->update(); \ + CMC_CALLBACKS_CALL(_map_, update); \ \ return true; \ } \ @@ -584,8 +586,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " _map_->count--; \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->delete) \ - _map_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_map_, delete); \ \ return true; \ } \ @@ -610,8 +611,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return true; \ } \ @@ -636,8 +636,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return true; \ } \ @@ -660,8 +659,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return node->value; \ } \ @@ -684,8 +682,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " \ _map_->flag = CMC_FLAG_OK; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return &(node->value); \ } \ @@ -694,8 +691,7 @@ static const char *cmc_cmc_string_fmt_treemap = "struct %s<%s, %s> " { \ bool result = CMC_(PFX, _impl_get_node)(_map_, key) != NULL; \ \ - if (_map_->callbacks && _map_->callbacks->read) \ - _map_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_map_, read); \ \ return result; \ } \ diff --git a/src/cmc/treeset.h b/src/cmc/treeset.h index 6684f0a..300a340 100644 --- a/src/cmc/treeset.h +++ b/src/cmc/treeset.h @@ -232,6 +232,8 @@ 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);\ +\ if (!f_val) \ return NULL; \ \ @@ -325,6 +327,8 @@ 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);\ +\ if (!alloc) \ _set_->alloc = &cmc_alloc_node_default; \ else \ @@ -402,8 +406,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> " _set_->count++; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->create) \ - _set_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_set_, create); \ \ return true; \ } \ @@ -536,8 +539,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> " _set_->count--; \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->delete) \ - _set_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_set_, delete); \ \ return true; \ } \ @@ -560,8 +562,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> " \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return true; \ } \ @@ -584,8 +585,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> " \ _set_->flag = CMC_FLAG_OK; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return true; \ } \ @@ -594,8 +594,7 @@ static const char *cmc_cmc_string_fmt_treeset = "struct %s<%s> " { \ bool result = CMC_(PFX, _impl_get_node)(_set_, value) != NULL; \ \ - if (_set_->callbacks && _set_->callbacks->read) \ - _set_->callbacks->read(); \ + CMC_CALLBACKS_CALL(_set_, read); \ \ return result; \ } \ diff --git a/src/cor/callbacks.h b/src/cor/callbacks.h index 970634f..0ec86a6 100644 --- a/src/cor/callbacks.h +++ b/src/cor/callbacks.h @@ -20,13 +20,15 @@ #ifdef CMC_NO_CALLBACKS #define CMC_CALLBACKS_DECL -#define CMC_CALLBACKS_GET(ds) NULL /* Placeholder for STR */ +#define CMC_CALLBACKS_MAYBE_UNUSED(param) ((void)param) /* Prevent -Wunused-parameter */ +#define CMC_CALLBACKS_GET(ds) NULL /* Helps with compatibility */ #define CMC_CALLBACKS_ASSIGN(ds, cb) #define CMC_CALLBACKS_CALL(ds, cb) #else #define CMC_CALLBACKS_DECL struct CMC_CALLBACKS_NAME *callbacks +#define CMC_CALLBACKS_MAYBE_UNUSED(param) #define CMC_CALLBACKS_GET(ds) (ds)->callbacks #define CMC_CALLBACKS_ASSIGN(ds, cb) CMC_CALLBACKS_GET(ds) = cb #define CMC_CALLBACKS_CALL(ds, cb) \ diff --git a/src/cor/core.h b/src/cor/core.h index 430d35d..5c13c38 100644 --- a/src/cor/core.h +++ b/src/cor/core.h @@ -98,4 +98,14 @@ #define CMC_PARAM_K CMC_TUP_3 #define CMC_PARAM_V CMC_TUP_4 +/** + * 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_FALSE(PARAM) PARAM +#define CMC_UNUSED_PARAM_TRUE(PARAM) + #endif /* CMC_COR_CORE_H */ diff --git a/src/ext/cmc/deque.h b/src/ext/cmc/deque.h index 8dc1898..dca4386 100644 --- a/src/ext/cmc/deque.h +++ b/src/ext/cmc/deque.h @@ -51,6 +51,8 @@ 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);\ +\ struct SNAME _deque_ = { 0 }; \ \ if (capacity < 1) \ diff --git a/src/ext/cmc/hashbidimap.h b/src/ext/cmc/hashbidimap.h index 5ae56f5..bf1e423 100644 --- a/src/ext/cmc/hashbidimap.h +++ b/src/ext/cmc/hashbidimap.h @@ -16,6 +16,90 @@ /** * All the EXT parts of CMC HashBidiMap. */ -#define CMC_EXT_CMC_HASHBIDIMAP_PARTS +#define CMC_EXT_CMC_HASHBIDIMAP_PARTS STR + +/** + * STR + */ +#define CMC_EXT_CMC_HASHBIDIMAP_STR(PARAMS) \ + CMC_EXT_CMC_HASHBIDIMAP_STR_HEADER(PARAMS) \ + CMC_EXT_CMC_HASHBIDIMAP_STR_SOURCE(PARAMS) + +#define CMC_EXT_CMC_HASHBIDIMAP_STR_HEADER(PARAMS) \ + CMC_EXT_CMC_HASHBIDIMAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \ + CMC_PARAM_V(PARAMS)) + +#define CMC_EXT_CMC_HASHBIDIMAP_STR_SOURCE(PARAMS) \ + CMC_EXT_CMC_HASHBIDIMAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \ + CMC_PARAM_V(PARAMS)) + +#define CMC_EXT_CMC_HASHBIDIMAP_STR_HEADER_(PFX, SNAME, K, V) \ +\ + bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr); \ + bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, const char *start, const char *separator, \ + const char *end, const char *key_val_sep); + +#define CMC_EXT_CMC_HASHBIDIMAP_STR_SOURCE_(PFX, SNAME, K, V) \ +\ + bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr) \ + { \ + struct SNAME *m_ = _map_; \ +\ + return 0 <= fprintf(fptr, \ + "struct %s<%s, %s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "load:%lf, " \ + "flag:%d, " \ + "f_key:%p, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks:%p }", \ + CMC_TO_STRING(SNAME), CMC_TO_STRING(K), CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \ + m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, CMC_CALLBACKS_GET(m_)); \ + } \ +\ + bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, const char *start, const char *separator, \ + const char *end, const char *key_val_sep) \ + { \ + fprintf(fptr, "%s", start); \ +\ + size_t last = 0; \ + for (size_t i = _map_->capacity; i > 0; i--) \ + { \ + struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i - 1][0]; \ +\ + if (entry && entry != CMC_ENTRY_DELETED) \ + { \ + last = i - 1; \ + break; \ + } \ + } \ +\ + for (size_t i = 0; i < _map_->capacity; i++) \ + { \ + struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i][0]; \ +\ + if (entry && entry != CMC_ENTRY_DELETED) \ + { \ + if (!_map_->f_key->str(fptr, entry->key)) \ + return false; \ +\ + fprintf(fptr, "%s", key_val_sep); \ +\ + if (!_map_->f_val->str(fptr, entry->value)) \ + return false; \ +\ + if (i + 1 < last) \ + fprintf(fptr, "%s", separator); \ + } \ + } \ +\ + fprintf(fptr, "%s", end); \ +\ + return true; \ + } #endif /* CMC_EXT_CMC_HASHBIDIMAP_H */ diff --git a/src/ext/cmc/hashmap.h b/src/ext/cmc/hashmap.h index b2adb37..320c8c6 100644 --- a/src/ext/cmc/hashmap.h +++ b/src/ext/cmc/hashmap.h @@ -57,6 +57,8 @@ struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \ struct CMC_CALLBACKS_NAME * callbacks) \ { \ + CMC_CALLBACKS_MAYBE_UNUSED(callbacks);\ +\ struct SNAME _map_ = { 0 }; \ \ if (capacity == 0 || load <= 0 || load >= 1) \ diff --git a/src/ext/cmc/list.h b/src/ext/cmc/list.h index e7e3160..63b2294 100644 --- a/src/ext/cmc/list.h +++ b/src/ext/cmc/list.h @@ -296,8 +296,7 @@ _list_->count += size; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -334,8 +333,7 @@ _list_->count += size; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -359,8 +357,7 @@ _list_->count += size; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->create) \ - _list_->callbacks->create(); \ + CMC_CALLBACKS_CALL(_list_, create); \ \ return true; \ } \ @@ -388,8 +385,7 @@ _list_->count -= to - from + 1; \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return true; \ } \ @@ -410,7 +406,7 @@ \ size_t length = to - from + 1; \ \ - struct SNAME *result = CMC_(PFX, _new_custom)(length, _list_->f_val, _list_->alloc, _list_->callbacks); \ + struct SNAME *result = CMC_(PFX, _new_custom)(length, _list_->f_val, _list_->alloc, CMC_CALLBACKS_GET(_list_)); \ \ if (!result) \ { \ @@ -429,8 +425,7 @@ \ _list_->flag = CMC_FLAG_OK; \ \ - if (_list_->callbacks && _list_->callbacks->delete) \ - _list_->callbacks->delete (); \ + CMC_CALLBACKS_CALL(_list_, delete); \ \ return result; \ } diff --git a/src/macro_collections.h b/src/macro_collections.h index d22bcef..59301d3 100644 --- a/src/macro_collections.h +++ b/src/macro_collections.h @@ -54,6 +54,7 @@ #include "cor/heap.h" /* Added in 01/06/2020 */ #include "ext/cmc/deque.h" /* Added in 25/05/2020 */ +#include "ext/cmc/hashbidimap.h" /* Added in 26/05/2020 */ #include "ext/cmc/hashmap.h" /* Added in 25/05/2020 */ #include "ext/cmc/hashmultimap.h" /* Added in 29/05/2020 */ #include "ext/cmc/hashmultiset.h" /* Added in 30/05/2020 */ diff --git a/tests/to_string.c b/tests/to_string.c index 6d906da..e05c0f3 100644 --- a/tests/to_string.c +++ b/tests/to_string.c @@ -4,6 +4,7 @@ // clang-format off C_MACRO_COLLECTIONS_ALL(CMC, DEQUE, ( d, deque, , , int)) +C_MACRO_COLLECTIONS_ALL(CMC, HASHBIDIMAP, (hbm, hashbidimap, , int, int)) C_MACRO_COLLECTIONS_ALL(CMC, HASHMAP, ( hm, hashmap, , int, int)) C_MACRO_COLLECTIONS_ALL(CMC, HASHMULTIMAP, (hmm, hashmultimap, , int, int)) C_MACRO_COLLECTIONS_ALL(CMC, HASHMULTISET, (hms, hashmultiset, , , int)) @@ -27,6 +28,9 @@ struct int main(void) { struct deque *d = d_new(100, (struct deque_fval *)&int_ftab); + struct hashbidimap *hbm = hbm_new(100, 0.8, + (struct hashbidimap_fkey *)&int_ftab, + (struct hashbidimap_fval *)&int_ftab); struct hashmap *hm = hm_new(100, 0.6, (struct hashmap_fkey *)&int_ftab, (struct hashmap_fval *)&int_ftab); struct hashmultimap *hmm = hmm_new(100, 0.8, @@ -44,6 +48,8 @@ int main(void) d_to_string(d, stdout); d_print(d, stdout, "\n[ ", ", ", " ]\n"); + hbm_to_string(hbm, stdout); + hbm_print(hbm, stdout, "\n[ {", "}, {", "} ]\n", " : "); hm_to_string(hm, stdout); hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : "); hmm_to_string(hmm, stdout); @@ -66,6 +72,7 @@ int main(void) fprintf(stdout, "\n"); d_push_back(d, 0); + hbm_insert(hbm, 0, 0); hm_insert(hm, 0, 0); hmm_insert(hmm, 0, 0); hms_insert(hms, 0); @@ -78,6 +85,8 @@ int main(void) d_to_string(d, stdout); d_print(d, stdout, "\n[ ", ", ", " ]\n"); + hbm_to_string(hbm, stdout); + hbm_print(hbm, stdout, "\n[ {", "}, {", "} ]\n", " : "); hm_to_string(hm, stdout); hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : "); hmm_to_string(hmm, stdout); @@ -100,6 +109,7 @@ int main(void) for (int i = 1; i < 20; i++) { d_push_back(d, i); + hbm_insert(hbm, i, i); hm_insert(hm, i, i); hmm_insert(hmm, i, i); hms_insert(hms, i); @@ -115,6 +125,8 @@ int main(void) d_to_string(d, stdout); d_print(d, stdout, "\n[ ", ", ", " ]\n"); + hbm_to_string(hbm, stdout); + hbm_print(hbm, stdout, "\n[ {", "}, {", "} ]\n", " : "); hm_to_string(hm, stdout); hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : "); hmm_to_string(hmm, stdout); @@ -135,6 +147,7 @@ int main(void) q_print(q, stdout, "\n[ ", ", ", " ]\n"); d_free(d); + hbm_free(hbm); hm_free(hm); hmm_free(hmm); hms_free(hms);