Fixing new_custom use

This commit is contained in:
Leonardo committed 2019-12-13 19:28:35 -03:00
1 parent e34443233f
commit cbf24ab217
10 files changed
+104 -70

No files matched your search

+14 -9
View File
@@ -626,7 +626,8 @@ struct cmc_callbacks_hashset
return false; \
\
struct SNAME *_new_set_ = \
PFX##_new(capacity, PFX##_load(_set_), _set_->cmp, _set_->hash); \
PFX##_new_custom(capacity, _set_->load, _set_->cmp, _set_->hash, \
_set_->alloc, _set_->callbacks); \
\
if (!_new_set_) \
return false; \
@@ -741,8 +742,9 @@ struct cmc_callbacks_hashset
\
struct SNAME *PFX##_union(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -769,8 +771,9 @@ struct cmc_callbacks_hashset
struct SNAME *PFX##_intersection(struct SNAME *_set1_, \
struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -796,8 +799,9 @@ struct cmc_callbacks_hashset
\
struct SNAME *PFX##_difference(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -822,8 +826,9 @@ struct cmc_callbacks_hashset
{ \
struct SNAME##_iter iter1, iter2; \
\
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
+4 -2
View File
@@ -881,7 +881,8 @@ struct cmc_callbacks_multimap
return false; \
\
struct SNAME *_new_map_ = \
PFX##_new(capacity, PFX##_load(_map_), _map_->cmp, _map_->hash); \
PFX##_new_custom(capacity, PFX##_load(_map_), _map_->cmp, \
_map_->hash, _map_->alloc, _map_->callbacks); \
\
if (!_new_map_) \
return false; \
@@ -920,7 +921,8 @@ struct cmc_callbacks_multimap
V (*value_copy_func)(V)) \
{ \
struct SNAME *result = \
PFX##_new(_map_->capacity, _map_->load, _map_->cmp, _map_->hash); \
PFX##_new_custom(_map_->capacity, _map_->load, _map_->cmp, \
_map_->hash, _map_->alloc, _map_->callbacks); \
\
if (!result) \
return NULL; \
+21 -13
View File
@@ -698,7 +698,8 @@ struct cmc_callbacks_multiset
return false; \
\
struct SNAME *_new_set_ = \
PFX##_new(capacity, PFX##_load(_set_), _set_->cmp, _set_->hash); \
PFX##_new_custom(capacity, PFX##_load(_set_), _set_->cmp, \
_set_->hash, _set_->alloc, _set_->callbacks); \
\
if (!_new_set_) \
return false; \
@@ -734,7 +735,8 @@ struct cmc_callbacks_multiset
struct SNAME *PFX##_copy_of(struct SNAME *_set_, V (*copy_func)(V)) \
{ \
struct SNAME *result = \
PFX##_new(_set_->capacity, _set_->load, _set_->cmp, _set_->hash); \
PFX##_new_custom(_set_->capacity, _set_->load, _set_->cmp, \
_set_->hash, _set_->alloc, _set_->callbacks); \
\
if (!result) \
return NULL; \
@@ -825,8 +827,9 @@ struct cmc_callbacks_multiset
\
struct SNAME *PFX##_union(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -865,8 +868,9 @@ struct cmc_callbacks_multiset
struct SNAME *PFX##_intersection(struct SNAME *_set1_, \
struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -895,8 +899,9 @@ struct cmc_callbacks_multiset
\
struct SNAME *PFX##_difference(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -921,8 +926,9 @@ struct cmc_callbacks_multiset
\
struct SNAME *PFX##_summation(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -953,8 +959,9 @@ struct cmc_callbacks_multiset
{ \
struct SNAME##_iter iter1, iter2; \
\
struct SNAME *_set_r_ = PFX##_new(_set1_->capacity, _set1_->load, \
_set1_->cmp, _set1_->hash); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -1091,7 +1098,8 @@ struct cmc_callbacks_multiset
\
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
{ \
struct SNAME##_iter *iter = target->alloc->malloc(sizeof(struct SNAME##_iter)); \
struct SNAME##_iter *iter = \
target->alloc->malloc(sizeof(struct SNAME##_iter)); \
\
if (!iter) \
return NULL; \
+2 -1
View File
@@ -463,7 +463,8 @@ struct cmc_callbacks_queue
\
struct SNAME *PFX##_copy_of(struct SNAME *_queue_, V (*copy_func)(V)) \
{ \
struct SNAME *result = PFX##_new(_queue_->capacity); \
struct SNAME *result = PFX##_new_custom( \
_queue_->capacity, _queue_->alloc, _queue_->callbacks); \
\
if (!result) \
return NULL; \
+2 -1
View File
@@ -470,7 +470,8 @@ struct cmc_callbacks_sortedlist
\
struct SNAME *PFX##_copy_of(struct SNAME *_list_, V (*copy_func)(V)) \
{ \
struct SNAME *result = PFX##_new(_list_->capacity, _list_->cmp); \
struct SNAME *result = PFX##_new_custom( \
_list_->capacity, _list_->cmp, _list_->alloc, _list_->callbacks); \
\
if (!result) \
return NULL; \
+3 -2
View File
@@ -302,7 +302,7 @@ struct cmc_callbacks_stack
for (size_t i = 0; i < _stack_->count; i++) \
deallocator(_stack_->buffer[i]); \
} \
\
\
_stack_->alloc->free(_stack_->buffer); \
_stack_->alloc->free(_stack_); \
} \
@@ -402,7 +402,8 @@ struct cmc_callbacks_stack
\
struct SNAME *PFX##_copy_of(struct SNAME *_stack_, V (*copy_func)(V)) \
{ \
struct SNAME *result = PFX##_new(_stack_->capacity); \
struct SNAME *result = PFX##_new_custom( \
_stack_->capacity, _stack_->alloc, _stack_->callbacks); \
\
if (!result) \
return NULL; \
+21 -16
View File
@@ -236,7 +236,8 @@ struct cmc_callbacks_treemap
#define CMC_GENERATE_TREEMAP_SOURCE(PFX, SNAME, K, V) \
\
/* Implementation Detail Functions */ \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_map_, K key, V value); \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_map_, \
K key, V value); \
static struct SNAME##_node *PFX##_impl_get_node(struct SNAME *_map_, \
K key); \
static unsigned char PFX##_impl_h(struct SNAME##_node *node); \
@@ -326,7 +327,7 @@ struct cmc_callbacks_treemap
if (deallocator) \
deallocator(scan->key, scan->value); \
\
_map_->alloc->free(scan); \
_map_->alloc->free(scan); \
scan = NULL; \
} \
\
@@ -335,7 +336,7 @@ struct cmc_callbacks_treemap
if (deallocator) \
deallocator(scan->key, scan->value); \
\
_map_->alloc->free(scan); \
_map_->alloc->free(scan); \
\
if (up->right != NULL) \
{ \
@@ -360,14 +361,14 @@ struct cmc_callbacks_treemap
{ \
PFX##_clear(_map_, deallocator); \
\
_map_->alloc->free(_map_); \
_map_->alloc->free(_map_); \
} \
\
bool PFX##_insert(struct SNAME *_map_, K key, V value) \
{ \
if (PFX##_empty(_map_)) \
{ \
_map_->root = PFX##_impl_new_node(_map_, key, value); \
_map_->root = PFX##_impl_new_node(_map_, key, value); \
\
if (!_map_->root) \
return false; \
@@ -393,7 +394,7 @@ struct cmc_callbacks_treemap
\
if (_map_->cmp(parent->key, key) > 0) \
{ \
parent->left = PFX##_impl_new_node(_map_, key, value); \
parent->left = PFX##_impl_new_node(_map_, key, value); \
\
if (!parent->left) \
return false; \
@@ -403,7 +404,7 @@ struct cmc_callbacks_treemap
} \
else \
{ \
parent->right = PFX##_impl_new_node(_map_, key, value); \
parent->right = PFX##_impl_new_node(_map_, key, value); \
\
if (!parent->right) \
return false; \
@@ -463,7 +464,7 @@ struct cmc_callbacks_treemap
node->parent->left = NULL; \
} \
\
_map_->alloc->free(node); \
_map_->alloc->free(node); \
} \
else if (node->left == NULL) \
{ \
@@ -484,7 +485,7 @@ struct cmc_callbacks_treemap
node->parent->left = node->right; \
} \
\
_map_->alloc->free(node); \
_map_->alloc->free(node); \
} \
else if (node->right == NULL) \
{ \
@@ -505,7 +506,7 @@ struct cmc_callbacks_treemap
node->parent->left = node->left; \
} \
\
_map_->alloc->free(node); \
_map_->alloc->free(node); \
} \
else \
{ \
@@ -544,7 +545,7 @@ struct cmc_callbacks_treemap
temp->parent->left = temp->left; \
} \
\
_map_->alloc->free(temp); \
_map_->alloc->free(temp); \
\
node->key = temp_key; \
node->value = temp_val; \
@@ -643,7 +644,8 @@ struct cmc_callbacks_treemap
struct SNAME *PFX##_copy_of(struct SNAME *_map_, K (*key_copy_func)(K), \
V (*value_copy_func)(V)) \
{ \
struct SNAME *result = PFX##_new(_map_->cmp); \
struct SNAME *result = \
PFX##_new_custom(_map_->cmp, _map_->alloc, _map_->callbacks); \
\
if (!result) \
return NULL; \
@@ -719,7 +721,8 @@ struct cmc_callbacks_treemap
\
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
{ \
struct SNAME##_iter *iter = target->alloc->malloc(sizeof(struct SNAME##_iter)); \
struct SNAME##_iter *iter = \
target->alloc->malloc(sizeof(struct SNAME##_iter)); \
\
if (!iter) \
return NULL; \
@@ -731,7 +734,7 @@ struct cmc_callbacks_treemap
\
void PFX##_iter_free(struct SNAME##_iter *iter) \
{ \
iter->target->alloc->free(iter); \
iter->target->alloc->free(iter); \
} \
\
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target) \
@@ -959,9 +962,11 @@ struct cmc_callbacks_treemap
return iter->index; \
} \
\
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_map_, K key, V value) \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_map_, \
K key, V value) \
{ \
struct SNAME##_node *node = _map_->alloc->malloc(sizeof(struct SNAME##_node)); \
struct SNAME##_node *node = \
_map_->alloc->malloc(sizeof(struct SNAME##_node)); \
\
if (!node) \
return NULL; \
+29 -20
View File
@@ -250,7 +250,8 @@ struct cmc_callbacks_treeset
#define CMC_GENERATE_TREESET_SOURCE(PFX, SNAME, V) \
\
/* Implementation Detail Functions */ \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_set_, V element); \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_set_, \
V element); \
static struct SNAME##_node *PFX##_impl_get_node(struct SNAME *_set_, \
V element); \
static unsigned char PFX##_impl_h(struct SNAME##_node *node); \
@@ -340,7 +341,7 @@ struct cmc_callbacks_treeset
if (deallocator) \
deallocator(scan->value); \
\
_set_->alloc->free(scan); \
_set_->alloc->free(scan); \
scan = NULL; \
} \
\
@@ -349,7 +350,7 @@ struct cmc_callbacks_treeset
if (deallocator) \
deallocator(scan->value); \
\
_set_->alloc->free(scan); \
_set_->alloc->free(scan); \
\
if (up->right != NULL) \
{ \
@@ -374,14 +375,14 @@ struct cmc_callbacks_treeset
{ \
PFX##_clear(_set_, deallocator); \
\
_set_->alloc->free(_set_); \
_set_->alloc->free(_set_); \
} \
\
bool PFX##_insert(struct SNAME *_set_, V element) \
{ \
if (PFX##_empty(_set_)) \
{ \
_set_->root = PFX##_impl_new_node(_set_, element); \
_set_->root = PFX##_impl_new_node(_set_, element); \
\
if (!_set_->root) \
return false; \
@@ -407,7 +408,7 @@ struct cmc_callbacks_treeset
\
if (_set_->cmp(parent->value, element) > 0) \
{ \
parent->left = PFX##_impl_new_node(element); \
parent->left = PFX##_impl_new_node(_set_, element); \
\
if (!parent->left) \
return false; \
@@ -417,7 +418,7 @@ struct cmc_callbacks_treeset
} \
else \
{ \
parent->right = PFX##_impl_new_node(_set_, element); \
parent->right = PFX##_impl_new_node(_set_, element); \
\
if (!parent->right) \
return false; \
@@ -459,7 +460,7 @@ struct cmc_callbacks_treeset
node->parent->left = NULL; \
} \
\
_set_->alloc->free(node); \
_set_->alloc->free(node); \
} \
else if (node->left == NULL) \
{ \
@@ -480,7 +481,7 @@ struct cmc_callbacks_treeset
node->parent->left = node->right; \
} \
\
_set_->alloc->free(node); \
_set_->alloc->free(node); \
} \
else if (node->right == NULL) \
{ \
@@ -501,7 +502,7 @@ struct cmc_callbacks_treeset
node->parent->left = node->left; \
} \
\
_set_->alloc->free(node); \
_set_->alloc->free(node); \
} \
else \
{ \
@@ -539,7 +540,7 @@ struct cmc_callbacks_treeset
temp->parent->left = temp->left; \
} \
\
_set_->alloc->free(temp); \
_set_->alloc->free(temp); \
\
node->value = temp_value; \
} \
@@ -614,7 +615,8 @@ struct cmc_callbacks_treeset
\
struct SNAME *PFX##_copy_of(struct SNAME *_set_, V (*copy_func)(V)) \
{ \
struct SNAME *result = PFX##_new(_set_->cmp); \
struct SNAME *result = \
PFX##_new_custom(_set_->cmp, _set_->alloc, _set_->callbacks); \
\
if (!result) \
return NULL; \
@@ -674,7 +676,8 @@ struct cmc_callbacks_treeset
\
struct SNAME *PFX##_union(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->cmp); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->cmp, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -701,7 +704,8 @@ struct cmc_callbacks_treeset
struct SNAME *PFX##_intersection(struct SNAME *_set1_, \
struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->cmp); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->cmp, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -727,7 +731,8 @@ struct cmc_callbacks_treeset
\
struct SNAME *PFX##_difference(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->cmp); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->cmp, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -750,7 +755,8 @@ struct cmc_callbacks_treeset
struct SNAME *PFX##_symmetric_difference(struct SNAME *_set1_, \
struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = PFX##_new(_set1_->cmp); \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->cmp, _set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -892,7 +898,8 @@ struct cmc_callbacks_treeset
\
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
{ \
struct SNAME##_iter *iter = target->alloc->malloc(sizeof(struct SNAME##_iter)); \
struct SNAME##_iter *iter = \
target->alloc->malloc(sizeof(struct SNAME##_iter)); \
\
if (!iter) \
return NULL; \
@@ -904,7 +911,7 @@ struct cmc_callbacks_treeset
\
void PFX##_iter_free(struct SNAME##_iter *iter) \
{ \
iter->target->alloc->free(iter); \
iter->target->alloc->free(iter); \
} \
\
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target) \
@@ -1117,9 +1124,11 @@ struct cmc_callbacks_treeset
return iter->index; \
} \
\
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_set_, V element) \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_set_, \
V element) \
{ \
struct SNAME##_node *node = _set_->alloc->malloc(sizeof(struct SNAME##_node)); \
struct SNAME##_node *node = \
_set_->alloc->malloc(sizeof(struct SNAME##_node)); \
\
if (!node) \
return NULL; \