Refactoring: renaming 'element' to 'value'

This commit is contained in:
Leonardo committed 2020-04-21 01:38:26 -03:00
1 parent 980fb6d432
commit 2e48a033a0
22 files changed
+510 -513

No files matched your search

+9 -9
View File
@@ -155,15 +155,15 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
void PFX##_customize(struct SNAME *_deque_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_push_front(struct SNAME *_deque_, V element); \
bool PFX##_push_back(struct SNAME *_deque_, V element); \
bool PFX##_push_front(struct SNAME *_deque_, V value); \
bool PFX##_push_back(struct SNAME *_deque_, V value); \
bool PFX##_pop_front(struct SNAME *_deque_); \
bool PFX##_pop_back(struct SNAME *_deque_); \
/* Element Access */ \
V PFX##_front(struct SNAME *_deque_); \
V PFX##_back(struct SNAME *_deque_); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_deque_, V element); \
bool PFX##_contains(struct SNAME *_deque_, V value); \
bool PFX##_empty(struct SNAME *_deque_); \
bool PFX##_full(struct SNAME *_deque_); \
size_t PFX##_count(struct SNAME *_deque_); \
@@ -334,7 +334,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
_deque_->flag = cmc_flags.OK; \
} \
\
bool PFX##_push_front(struct SNAME *_deque_, V element) \
bool PFX##_push_front(struct SNAME *_deque_, V value) \
{ \
if (PFX##_full(_deque_)) \
{ \
@@ -345,7 +345,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
_deque_->front = (_deque_->front == 0) ? _deque_->capacity - 1 \
: _deque_->front - 1; \
\
_deque_->buffer[_deque_->front] = element; \
_deque_->buffer[_deque_->front] = value; \
\
_deque_->count++; \
_deque_->flag = cmc_flags.OK; \
@@ -356,7 +356,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
return true; \
} \
\
bool PFX##_push_back(struct SNAME *_deque_, V element) \
bool PFX##_push_back(struct SNAME *_deque_, V value) \
{ \
if (PFX##_full(_deque_)) \
{ \
@@ -364,7 +364,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
return false; \
} \
\
_deque_->buffer[_deque_->back] = element; \
_deque_->buffer[_deque_->back] = value; \
\
_deque_->back = \
(_deque_->back == _deque_->capacity - 1) ? 0 : _deque_->back + 1; \
@@ -456,7 +456,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
: _deque_->back - 1]; \
} \
\
bool PFX##_contains(struct SNAME *_deque_, V element) \
bool PFX##_contains(struct SNAME *_deque_, V value) \
{ \
_deque_->flag = cmc_flags.OK; \
\
@@ -464,7 +464,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
\
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
{ \
if (_deque_->f_val->cmp(_deque_->buffer[i], element) == 0) \
if (_deque_->f_val->cmp(_deque_->buffer[i], value) == 0) \
{ \
result = true; \
break; \
+18 -18
View File
@@ -166,13 +166,13 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
void PFX##_customize(struct SNAME *_set_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_insert(struct SNAME *_set_, V element); \
bool PFX##_remove(struct SNAME *_set_, V element); \
bool PFX##_insert(struct SNAME *_set_, V value); \
bool PFX##_remove(struct SNAME *_set_, V value); \
/* Element Access */ \
bool PFX##_max(struct SNAME *_set_, V *value); \
bool PFX##_min(struct SNAME *_set_, V *value); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_set_, V element); \
bool PFX##_contains(struct SNAME *_set_, V value); \
bool PFX##_empty(struct SNAME *_set_); \
bool PFX##_full(struct SNAME *_set_); \
size_t PFX##_count(struct SNAME *_set_); \
@@ -228,7 +228,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
/* Implementation Detail Functions */ \
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element); \
V value); \
static size_t PFX##_impl_calculate_size(size_t required); \
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_set_); \
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_set_); \
@@ -377,7 +377,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
_set_->flag = cmc_flags.OK; \
} \
\
bool PFX##_insert(struct SNAME *_set_, V element) \
bool PFX##_insert(struct SNAME *_set_, V value) \
{ \
if (PFX##_full(_set_)) \
{ \
@@ -385,13 +385,13 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
return false; \
} \
\
if (PFX##_impl_get_entry(_set_, element) != NULL) \
if (PFX##_impl_get_entry(_set_, value) != NULL) \
{ \
_set_->flag = cmc_flags.DUPLICATE; \
return false; \
} \
\
size_t hash = _set_->f_val->hash(element); \
size_t hash = _set_->f_val->hash(value); \
size_t original_pos = hash % _set_->capacity; \
size_t pos = original_pos; \
\
@@ -399,7 +399,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
\
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED) \
{ \
target->value = element; \
target->value = value; \
target->dist = 0; \
target->state = CMC_ES_FILLED; \
} \
@@ -413,7 +413,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
if (target->state == CMC_ES_EMPTY || \
target->state == CMC_ES_DELETED) \
{ \
target->value = element; \
target->value = value; \
target->dist = pos - original_pos; \
target->state = CMC_ES_FILLED; \
\
@@ -424,10 +424,10 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
V tmp = target->value; \
size_t tmp_dist = target->dist; \
\
target->value = element; \
target->value = value; \
target->dist = pos - original_pos; \
\
element = tmp; \
value = tmp; \
original_pos = pos - tmp_dist; \
} \
} \
@@ -442,7 +442,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_remove(struct SNAME *_set_, V element) \
bool PFX##_remove(struct SNAME *_set_, V value) \
{ \
if (PFX##_empty(_set_)) \
{ \
@@ -450,7 +450,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
return false; \
} \
\
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, value); \
\
if (result == NULL) \
{ \
@@ -541,11 +541,11 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_contains(struct SNAME *_set_, V element) \
bool PFX##_contains(struct SNAME *_set_, V value) \
{ \
_set_->flag = cmc_flags.OK; \
\
bool result = PFX##_impl_get_entry(_set_, element) != NULL; \
bool result = PFX##_impl_get_entry(_set_, value) != NULL; \
\
if (_set_->callbacks && _set_->callbacks->read) \
_set_->callbacks->read(); \
@@ -1234,9 +1234,9 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
} \
\
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element) \
V value) \
{ \
size_t hash = _set_->f_val->hash(element); \
size_t hash = _set_->f_val->hash(value); \
size_t pos = hash % _set_->capacity; \
\
struct SNAME##_entry *target = &(_set_->buffer[pos]); \
@@ -1244,7 +1244,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
while (target->state == CMC_ES_FILLED || \
target->state == CMC_ES_DELETED) \
{ \
if (_set_->f_val->cmp(target->value, element) == 0) \
if (_set_->f_val->cmp(target->value, value) == 0) \
return target; \
\
pos++; \
+6 -6
View File
@@ -166,12 +166,12 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
void PFX##_customize(struct SNAME *_heap_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_insert(struct SNAME *_heap_, V element); \
bool PFX##_insert(struct SNAME *_heap_, V value); \
bool PFX##_remove(struct SNAME *_heap_); \
/* Element Access */ \
V PFX##_peek(struct SNAME *_heap_); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_heap_, V element); \
bool PFX##_contains(struct SNAME *_heap_, V value); \
bool PFX##_empty(struct SNAME *_heap_); \
bool PFX##_full(struct SNAME *_heap_); \
size_t PFX##_count(struct SNAME *_heap_); \
@@ -341,7 +341,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
_heap_->flag = cmc_flags.OK; \
} \
\
bool PFX##_insert(struct SNAME *_heap_, V element) \
bool PFX##_insert(struct SNAME *_heap_, V value) \
{ \
if (PFX##_full(_heap_)) \
{ \
@@ -349,7 +349,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
return false; \
} \
\
_heap_->buffer[_heap_->count++] = element; \
_heap_->buffer[_heap_->count++] = value; \
\
if (!PFX##_empty(_heap_)) \
{ \
@@ -403,7 +403,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
return _heap_->buffer[0]; \
} \
\
bool PFX##_contains(struct SNAME *_heap_, V element) \
bool PFX##_contains(struct SNAME *_heap_, V value) \
{ \
_heap_->flag = cmc_flags.OK; \
\
@@ -411,7 +411,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
\
for (size_t i = 0; i < _heap_->count; i++) \
{ \
if (_heap_->f_val->cmp(_heap_->buffer[i], element) == 0) \
if (_heap_->f_val->cmp(_heap_->buffer[i], value) == 0) \
{ \
result = true; \
break; \
+26 -26
View File
@@ -148,17 +148,17 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
void PFX##_customize(struct SNAME *_heap_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_insert(struct SNAME *_heap_, V element); \
bool PFX##_insert(struct SNAME *_heap_, V value); \
bool PFX##_remove_max(struct SNAME *_heap_); \
bool PFX##_remove_min(struct SNAME *_heap_); \
/* Collection Update */ \
bool PFX##_update_max(struct SNAME *_heap_, V element); \
bool PFX##_update_min(struct SNAME *_heap_, V element); \
bool PFX##_update_max(struct SNAME *_heap_, V value); \
bool PFX##_update_min(struct SNAME *_heap_, V value); \
/* Element Access */ \
V PFX##_max(struct SNAME *_heap_); \
V PFX##_min(struct SNAME *_heap_); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_heap_, V element); \
bool PFX##_contains(struct SNAME *_heap_, V value); \
bool PFX##_empty(struct SNAME *_heap_); \
bool PFX##_full(struct SNAME *_heap_); \
size_t PFX##_count(struct SNAME *_heap_); \
@@ -335,7 +335,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
_heap_->flag = cmc_flags.OK; \
} \
\
bool PFX##_insert(struct SNAME *_heap_, V element) \
bool PFX##_insert(struct SNAME *_heap_, V value) \
{ \
if (PFX##_full(_heap_)) \
{ \
@@ -346,7 +346,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
if (_heap_->count % 2 == 0) \
{ \
/* Occupying a new node */ \
_heap_->buffer[_heap_->size].data[0] = element; \
_heap_->buffer[_heap_->size].data[0] = value; \
_heap_->buffer[_heap_->size].data[1] = (V){ 0 }; \
\
_heap_->size++; \
@@ -356,16 +356,16 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
struct SNAME##_node *node = &(_heap_->buffer[_heap_->size - 1]); \
\
/* Decide if the new element goes into the MinHeap or MaxHeap */ \
if (_heap_->f_val->cmp(node->data[0], element) > 0) \
if (_heap_->f_val->cmp(node->data[0], value) > 0) \
{ \
/* Swap current value and add new element to the MinHeap */ \
node->data[1] = node->data[0]; \
node->data[0] = element; \
node->data[0] = value; \
} \
else \
{ \
/* No need to swap and add the new element to the MaxHeap */ \
node->data[1] = element; \
node->data[1] = value; \
} \
} \
\
@@ -379,9 +379,9 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
struct SNAME##_node *parent = \
&(_heap_->buffer[(_heap_->size - 1) / 2]); \
\
if (_heap_->f_val->cmp(parent->data[0], element) > 0) \
if (_heap_->f_val->cmp(parent->data[0], value) > 0) \
PFX##_impl_float_up_min(_heap_); \
else if (_heap_->f_val->cmp(parent->data[1], element) < 0) \
else if (_heap_->f_val->cmp(parent->data[1], value) < 0) \
PFX##_impl_float_up_max(_heap_); \
/* else no float up required */ \
} \
@@ -498,7 +498,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
return true; \
} \
\
bool PFX##_update_max(struct SNAME *_heap_, V element) \
bool PFX##_update_max(struct SNAME *_heap_, V value) \
{ \
if (PFX##_empty(_heap_)) \
{ \
@@ -508,21 +508,21 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
if (_heap_->count == 1) \
{ \
_heap_->buffer[0].data[0] = element; \
_heap_->buffer[0].data[0] = value; \
} \
else if (_heap_->f_val->cmp(element, _heap_->buffer[0].data[0]) < 0) \
else if (_heap_->f_val->cmp(value, _heap_->buffer[0].data[0]) < 0) \
{ \
/* Corner case: we are updating the Max value but it is less */ \
/* than the Min value */ \
_heap_->buffer[0].data[1] = _heap_->buffer[0].data[0]; \
_heap_->buffer[0].data[0] = element; \
_heap_->buffer[0].data[0] = value; \
\
PFX##_impl_float_down_max(_heap_); \
} \
else \
{ \
/* Update Max element and float it down */ \
_heap_->buffer[0].data[1] = element; \
_heap_->buffer[0].data[1] = value; \
\
PFX##_impl_float_down_max(_heap_); \
} \
@@ -535,7 +535,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
return true; \
} \
\
bool PFX##_update_min(struct SNAME *_heap_, V element) \
bool PFX##_update_min(struct SNAME *_heap_, V value) \
{ \
if (PFX##_empty(_heap_)) \
{ \
@@ -545,21 +545,21 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
if (_heap_->count == 1) \
{ \
_heap_->buffer[0].data[0] = element; \
_heap_->buffer[0].data[0] = value; \
} \
else if (_heap_->f_val->cmp(element, _heap_->buffer[0].data[1]) > 0) \
else if (_heap_->f_val->cmp(value, _heap_->buffer[0].data[1]) > 0) \
{ \
/* Corner case: we are updating the Min value but it is greater */ \
/* than the Max value. */ \
_heap_->buffer[0].data[0] = _heap_->buffer[0].data[1]; \
_heap_->buffer[0].data[1] = element; \
_heap_->buffer[0].data[1] = value; \
\
PFX##_impl_float_down_min(_heap_); \
} \
else \
{ \
/* Update Min element and float it down */ \
_heap_->buffer[0].data[0] = element; \
_heap_->buffer[0].data[0] = value; \
\
PFX##_impl_float_down_min(_heap_); \
} \
@@ -609,7 +609,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
return _heap_->buffer[0].data[0]; \
} \
\
bool PFX##_contains(struct SNAME *_heap_, V element) \
bool PFX##_contains(struct SNAME *_heap_, V value) \
{ \
_heap_->flag = cmc_flags.OK; \
\
@@ -618,7 +618,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
for (size_t i = 0; i < _heap_->count; i++) \
{ \
if (_heap_->f_val->cmp(_heap_->buffer[i / 2].data[i % 2], \
element) == 0) \
value) == 0) \
{ \
result = true; \
break; \
@@ -763,10 +763,10 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
\
for (size_t i = 0; i < _heap1_->count; i++) \
{ \
V element1 = _heap1_->buffer[i / 2].data[i % 2]; \
V element2 = _heap2_->buffer[i / 2].data[i % 2]; \
V value1 = _heap1_->buffer[i / 2].data[i % 2]; \
V value2 = _heap2_->buffer[i / 2].data[i % 2]; \
\
if (_heap1_->f_val->cmp(element1, element2) != 0) \
if (_heap1_->f_val->cmp(value1, value2) != 0) \
return false; \
} \
\
+23 -23
View File
@@ -159,9 +159,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
void PFX##_customize(struct SNAME *_list_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_push_front(struct SNAME *_list_, V element); \
bool PFX##_push_at(struct SNAME *_list_, V element, size_t index); \
bool PFX##_push_back(struct SNAME *_list_, V element); \
bool PFX##_push_front(struct SNAME *_list_, V value); \
bool PFX##_push_at(struct SNAME *_list_, V value, size_t index); \
bool PFX##_push_back(struct SNAME *_list_, V value); \
bool PFX##_pop_front(struct SNAME *_list_); \
bool PFX##_pop_at(struct SNAME *_list_, size_t index); \
bool PFX##_pop_back(struct SNAME *_list_); \
@@ -171,7 +171,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
V *PFX##_get_ref(struct SNAME *_list_, size_t index); \
V PFX##_back(struct SNAME *_list_); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_list_, V element); \
bool PFX##_contains(struct SNAME *_list_, V value); \
bool PFX##_empty(struct SNAME *_list_); \
size_t PFX##_count(struct SNAME *_list_); \
int PFX##_flag(struct SNAME *_list_); \
@@ -183,7 +183,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
\
/* Node Related Functions */ \
/* Node Allocation and Deallocation */ \
struct SNAME##_node *PFX##_new_node(struct SNAME *_list_, V element); \
struct SNAME##_node *PFX##_new_node(struct SNAME *_list_, V value); \
void PFX##_free_node(struct SNAME *_list_, struct SNAME##_node *_node_); \
/* Node Access Relative to a Linked List */ \
struct SNAME##_node *PFX##_head(struct SNAME *_list_); \
@@ -191,9 +191,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
struct SNAME##_node *PFX##_tail(struct SNAME *_list_); \
/* Input and Output Relative to a Node */ \
bool PFX##_add_next(struct SNAME *_owner_, struct SNAME##_node *_node_, \
V element); \
V value); \
bool PFX##_add_prev(struct SNAME *_owner_, struct SNAME##_node *_node_, \
V element); \
V value); \
bool PFX##_del_next(struct SNAME *_owner_, struct SNAME##_node *_node_); \
bool PFX##_del_curr(struct SNAME *_owner_, struct SNAME##_node *_node_); \
bool PFX##_del_prev(struct SNAME *_owner_, struct SNAME##_node *_node_); \
@@ -330,9 +330,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
_list_->flag = cmc_flags.OK; \
} \
\
bool PFX##_push_front(struct SNAME *_list_, V element) \
bool PFX##_push_front(struct SNAME *_list_, V value) \
{ \
struct SNAME##_node *_node_ = PFX##_new_node(_list_, element); \
struct SNAME##_node *_node_ = PFX##_new_node(_list_, value); \
\
if (!_node_) \
return false; \
@@ -358,7 +358,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
return true; \
} \
\
bool PFX##_push_at(struct SNAME *_list_, V element, size_t index) \
bool PFX##_push_at(struct SNAME *_list_, V value, size_t index) \
{ \
if (index > _list_->count) \
{ \
@@ -368,14 +368,14 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
\
if (index == 0) \
{ \
return PFX##_push_front(_list_, element); \
return PFX##_push_front(_list_, value); \
} \
else if (index == _list_->count) \
{ \
return PFX##_push_back(_list_, element); \
return PFX##_push_back(_list_, value); \
} \
\
struct SNAME##_node *_node_ = PFX##_new_node(_list_, element); \
struct SNAME##_node *_node_ = PFX##_new_node(_list_, value); \
\
if (!_node_) \
return false; \
@@ -396,9 +396,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
return true; \
} \
\
bool PFX##_push_back(struct SNAME *_list_, V element) \
bool PFX##_push_back(struct SNAME *_list_, V value) \
{ \
struct SNAME##_node *_node_ = PFX##_new_node(_list_, element); \
struct SNAME##_node *_node_ = PFX##_new_node(_list_, value); \
\
if (!_node_) \
return false; \
@@ -602,7 +602,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
return _list_->tail->value; \
} \
\
bool PFX##_contains(struct SNAME *_list_, V element) \
bool PFX##_contains(struct SNAME *_list_, V value) \
{ \
_list_->flag = cmc_flags.OK; \
\
@@ -612,7 +612,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
\
while (scan != NULL) \
{ \
if (_list_->f_val->cmp(scan->value, element) == 0) \
if (_list_->f_val->cmp(scan->value, value) == 0) \
{ \
result = true; \
break; \
@@ -736,7 +736,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
return true; \
} \
\
struct SNAME##_node *PFX##_new_node(struct SNAME *_list_, V element) \
struct SNAME##_node *PFX##_new_node(struct SNAME *_list_, V value) \
{ \
struct SNAME##_node *_node_ = \
_list_->alloc->malloc(sizeof(struct SNAME##_node)); \
@@ -747,7 +747,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
return NULL; \
} \
\
_node_->value = element; \
_node_->value = value; \
_node_->next = NULL; \
_node_->prev = NULL; \
\
@@ -808,9 +808,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
} \
\
bool PFX##_add_next(struct SNAME *_owner_, struct SNAME##_node *_node_, \
V element) \
V value) \
{ \
struct SNAME##_node *new_node = PFX##_new_node(_owner_, element); \
struct SNAME##_node *new_node = PFX##_new_node(_owner_, value); \
\
if (!new_node) \
return false; \
@@ -832,9 +832,9 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
} \
\
bool PFX##_add_prev(struct SNAME *_owner_, struct SNAME##_node *_node_, \
V element) \
V value) \
{ \
struct SNAME##_node *new_node = PFX##_new_node(_owner_, element); \
struct SNAME##_node *new_node = PFX##_new_node(_owner_, value); \
\
if (!new_node) \
return false; \
+157 -157
View File
@@ -75,144 +75,144 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
/* -------------------------------------------------------------------------
* Header
* ------------------------------------------------------------------------- */
#define CMC_GENERATE_LIST_HEADER(PFX, SNAME, V) \
\
/* List Structure */ \
struct SNAME \
{ \
/* Dynamic array of elements */ \
V *buffer; \
\
/* Current array capacity */ \
size_t capacity; \
\
/* Current amount of elements */ \
size_t count; \
\
/* Flags indicating errors or success */ \
int flag; \
\
/* Value function table */ \
struct SNAME##_fval *f_val; \
\
/* Function that returns an iterator to the start of the list */ \
struct SNAME##_iter (*it_start)(struct SNAME *); \
\
/* Function that returns an iterator to the end of the list */ \
struct SNAME##_iter (*it_end)(struct SNAME *); \
\
/* Custom allocation functions */ \
struct cmc_alloc_node *alloc; \
\
/* Custom callback functions */ \
struct cmc_callbacks *callbacks; \
}; \
\
/* Value struct function table */ \
struct SNAME##_fval \
{ \
/* Comparator function */ \
int (*cmp)(V, V); \
\
/* Copy function */ \
V (*cpy)(V); \
\
/* To string function */ \
bool (*str)(FILE *, V); \
\
/* Free from memory function */ \
void (*free)(V); \
\
/* Hash function */ \
size_t (*hash)(V); \
\
/* Priority function */ \
int (*pri)(V, V); \
}; \
\
/* List Iterator */ \
struct SNAME##_iter \
{ \
/* 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 */ \
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val); \
struct SNAME *PFX##_new_custom( \
size_t capacity, struct SNAME##_fval *f_val, \
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
void PFX##_clear(struct SNAME *_list_); \
void PFX##_free(struct SNAME *_list_); \
/* Customization of Allocation and Callbacks */ \
void PFX##_customize(struct SNAME *_list_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_push_front(struct SNAME *_list_, V element); \
bool PFX##_push_at(struct SNAME *_list_, V element, size_t index); \
bool PFX##_push_back(struct SNAME *_list_, V element); \
bool PFX##_pop_front(struct SNAME *_list_); \
bool PFX##_pop_at(struct SNAME *_list_, size_t index); \
bool PFX##_pop_back(struct SNAME *_list_); \
/* Collection Sequence Input and Output */ \
bool PFX##_seq_push_front(struct SNAME *_list_, V *elements, size_t size); \
bool PFX##_seq_push_at(struct SNAME *_list_, V *elements, size_t size, \
size_t index); \
bool PFX##_seq_push_back(struct SNAME *_list_, V *elements, size_t size); \
bool PFX##_seq_pop_at(struct SNAME *_list_, size_t from, size_t to); \
struct SNAME *PFX##_seq_sublist(struct SNAME *_list_, size_t from, \
size_t to); \
/* Element Access */ \
V PFX##_front(struct SNAME *_list_); \
V PFX##_get(struct SNAME *_list_, size_t index); \
V *PFX##_get_ref(struct SNAME *_list_, size_t index); \
V PFX##_back(struct SNAME *_list_); \
size_t PFX##_index_of(struct SNAME *_list_, V element, bool from_start); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_list_, V element); \
bool PFX##_empty(struct SNAME *_list_); \
bool PFX##_full(struct SNAME *_list_); \
size_t PFX##_count(struct SNAME *_list_); \
bool PFX##_fits(struct SNAME *_list_, size_t size); \
size_t PFX##_capacity(struct SNAME *_list_); \
int PFX##_flag(struct SNAME *_list_); \
/* Collection Utility */ \
bool PFX##_resize(struct SNAME *_list_, size_t capacity); \
struct SNAME *PFX##_copy_of(struct SNAME *_list_); \
bool PFX##_equals(struct SNAME *_list1_, struct SNAME *_list2_); \
struct cmc_string PFX##_to_string(struct SNAME *_list_); \
bool PFX##_print(struct SNAME *_list_, FILE *fptr); \
\
/* Iterator Functions */ \
/* Iterator Allocation and Deallocation */ \
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target); \
void PFX##_iter_free(struct SNAME##_iter *iter); \
/* Iterator Initialization */ \
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target); \
/* Iterator State */ \
bool PFX##_iter_start(struct SNAME##_iter *iter); \
bool PFX##_iter_end(struct SNAME##_iter *iter); \
/* Iterator Movement */ \
void PFX##_iter_to_start(struct SNAME##_iter *iter); \
void PFX##_iter_to_end(struct SNAME##_iter *iter); \
bool PFX##_iter_next(struct SNAME##_iter *iter); \
bool PFX##_iter_prev(struct SNAME##_iter *iter); \
bool PFX##_iter_advance(struct SNAME##_iter *iter, size_t steps); \
bool PFX##_iter_rewind(struct SNAME##_iter *iter, size_t steps); \
bool PFX##_iter_go_to(struct SNAME##_iter *iter, size_t index); \
/* Iterator Access */ \
V PFX##_iter_value(struct SNAME##_iter *iter); \
V *PFX##_iter_rvalue(struct SNAME##_iter *iter); \
#define CMC_GENERATE_LIST_HEADER(PFX, SNAME, V) \
\
/* List Structure */ \
struct SNAME \
{ \
/* Dynamic array of elements */ \
V *buffer; \
\
/* Current array capacity */ \
size_t capacity; \
\
/* Current amount of elements */ \
size_t count; \
\
/* Flags indicating errors or success */ \
int flag; \
\
/* Value function table */ \
struct SNAME##_fval *f_val; \
\
/* Function that returns an iterator to the start of the list */ \
struct SNAME##_iter (*it_start)(struct SNAME *); \
\
/* Function that returns an iterator to the end of the list */ \
struct SNAME##_iter (*it_end)(struct SNAME *); \
\
/* Custom allocation functions */ \
struct cmc_alloc_node *alloc; \
\
/* Custom callback functions */ \
struct cmc_callbacks *callbacks; \
}; \
\
/* Value struct function table */ \
struct SNAME##_fval \
{ \
/* Comparator function */ \
int (*cmp)(V, V); \
\
/* Copy function */ \
V (*cpy)(V); \
\
/* To string function */ \
bool (*str)(FILE *, V); \
\
/* Free from memory function */ \
void (*free)(V); \
\
/* Hash function */ \
size_t (*hash)(V); \
\
/* Priority function */ \
int (*pri)(V, V); \
}; \
\
/* List Iterator */ \
struct SNAME##_iter \
{ \
/* 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 */ \
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val); \
struct SNAME *PFX##_new_custom( \
size_t capacity, struct SNAME##_fval *f_val, \
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
void PFX##_clear(struct SNAME *_list_); \
void PFX##_free(struct SNAME *_list_); \
/* Customization of Allocation and Callbacks */ \
void PFX##_customize(struct SNAME *_list_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_push_front(struct SNAME *_list_, V value); \
bool PFX##_push_at(struct SNAME *_list_, V value, size_t index); \
bool PFX##_push_back(struct SNAME *_list_, V value); \
bool PFX##_pop_front(struct SNAME *_list_); \
bool PFX##_pop_at(struct SNAME *_list_, size_t index); \
bool PFX##_pop_back(struct SNAME *_list_); \
/* Collection Sequence Input and Output */ \
bool PFX##_seq_push_front(struct SNAME *_list_, V *values, size_t size); \
bool PFX##_seq_push_at(struct SNAME *_list_, V *values, size_t size, \
size_t index); \
bool PFX##_seq_push_back(struct SNAME *_list_, V *values, size_t size); \
bool PFX##_seq_pop_at(struct SNAME *_list_, size_t from, size_t to); \
struct SNAME *PFX##_seq_sublist(struct SNAME *_list_, size_t from, \
size_t to); \
/* Element Access */ \
V PFX##_front(struct SNAME *_list_); \
V PFX##_get(struct SNAME *_list_, size_t index); \
V *PFX##_get_ref(struct SNAME *_list_, size_t index); \
V PFX##_back(struct SNAME *_list_); \
size_t PFX##_index_of(struct SNAME *_list_, V value, bool from_start); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_list_, V value); \
bool PFX##_empty(struct SNAME *_list_); \
bool PFX##_full(struct SNAME *_list_); \
size_t PFX##_count(struct SNAME *_list_); \
bool PFX##_fits(struct SNAME *_list_, size_t size); \
size_t PFX##_capacity(struct SNAME *_list_); \
int PFX##_flag(struct SNAME *_list_); \
/* Collection Utility */ \
bool PFX##_resize(struct SNAME *_list_, size_t capacity); \
struct SNAME *PFX##_copy_of(struct SNAME *_list_); \
bool PFX##_equals(struct SNAME *_list1_, struct SNAME *_list2_); \
struct cmc_string PFX##_to_string(struct SNAME *_list_); \
bool PFX##_print(struct SNAME *_list_, FILE *fptr); \
\
/* Iterator Functions */ \
/* Iterator Allocation and Deallocation */ \
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target); \
void PFX##_iter_free(struct SNAME##_iter *iter); \
/* Iterator Initialization */ \
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target); \
/* Iterator State */ \
bool PFX##_iter_start(struct SNAME##_iter *iter); \
bool PFX##_iter_end(struct SNAME##_iter *iter); \
/* Iterator Movement */ \
void PFX##_iter_to_start(struct SNAME##_iter *iter); \
void PFX##_iter_to_end(struct SNAME##_iter *iter); \
bool PFX##_iter_next(struct SNAME##_iter *iter); \
bool PFX##_iter_prev(struct SNAME##_iter *iter); \
bool PFX##_iter_advance(struct SNAME##_iter *iter, size_t steps); \
bool PFX##_iter_rewind(struct SNAME##_iter *iter, size_t steps); \
bool PFX##_iter_go_to(struct SNAME##_iter *iter, size_t index); \
/* Iterator Access */ \
V PFX##_iter_value(struct SNAME##_iter *iter); \
V *PFX##_iter_rvalue(struct SNAME##_iter *iter); \
size_t PFX##_iter_index(struct SNAME##_iter *iter);
/* -------------------------------------------------------------------------
@@ -333,7 +333,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->flag = cmc_flags.OK; \
} \
\
bool PFX##_push_front(struct SNAME *_list_, V element) \
bool PFX##_push_front(struct SNAME *_list_, V value) \
{ \
if (PFX##_full(_list_)) \
{ \
@@ -347,7 +347,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
_list_->count * sizeof(V)); \
} \
\
_list_->buffer[0] = element; \
_list_->buffer[0] = value; \
\
_list_->count++; \
_list_->flag = cmc_flags.OK; \
@@ -358,7 +358,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return true; \
} \
\
bool PFX##_push_at(struct SNAME *_list_, V element, size_t index) \
bool PFX##_push_at(struct SNAME *_list_, V value, size_t index) \
{ \
if (index > _list_->count) \
{ \
@@ -375,7 +375,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
memmove(_list_->buffer + index + 1, _list_->buffer + index, \
(_list_->count - index) * sizeof(V)); \
\
_list_->buffer[index] = element; \
_list_->buffer[index] = value; \
_list_->count++; \
_list_->flag = cmc_flags.OK; \
\
@@ -385,7 +385,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return true; \
} \
\
bool PFX##_push_back(struct SNAME *_list_, V element) \
bool PFX##_push_back(struct SNAME *_list_, V value) \
{ \
if (PFX##_full(_list_)) \
{ \
@@ -393,7 +393,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return false; \
} \
\
_list_->buffer[_list_->count++] = element; \
_list_->buffer[_list_->count++] = value; \
_list_->flag = cmc_flags.OK; \
\
if (_list_->callbacks && _list_->callbacks->create) \
@@ -462,7 +462,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return true; \
} \
\
bool PFX##_seq_push_front(struct SNAME *_list_, V *elements, size_t size) \
bool PFX##_seq_push_front(struct SNAME *_list_, V *values, size_t size) \
{ \
if (size == 0) \
{ \
@@ -479,7 +479,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
memmove(_list_->buffer + size, _list_->buffer, \
_list_->count * sizeof(V)); \
\
memcpy(_list_->buffer, elements, size * sizeof(V)); \
memcpy(_list_->buffer, values, size * sizeof(V)); \
\
_list_->count += size; \
_list_->flag = cmc_flags.OK; \
@@ -490,7 +490,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return true; \
} \
\
bool PFX##_seq_push_at(struct SNAME *_list_, V *elements, size_t size, \
bool PFX##_seq_push_at(struct SNAME *_list_, V *values, size_t size, \
size_t index) \
{ \
if (size == 0) \
@@ -506,9 +506,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
} \
\
if (index == 0) \
return PFX##_seq_push_front(_list_, elements, size); \
return PFX##_seq_push_front(_list_, values, size); \
else if (index == _list_->count) \
return PFX##_seq_push_back(_list_, elements, size); \
return PFX##_seq_push_back(_list_, values, size); \
\
if (!PFX##_fits(_list_, size)) \
{ \
@@ -519,7 +519,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
memmove(_list_->buffer + index + size, _list_->buffer + index, \
(_list_->count - index) * sizeof(V)); \
\
memcpy(_list_->buffer + index, elements, size * sizeof(V)); \
memcpy(_list_->buffer + index, values, size * sizeof(V)); \
\
_list_->count += size; \
_list_->flag = cmc_flags.OK; \
@@ -530,7 +530,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return true; \
} \
\
bool PFX##_seq_push_back(struct SNAME *_list_, V *elements, size_t size) \
bool PFX##_seq_push_back(struct SNAME *_list_, V *values, size_t size) \
{ \
if (size == 0) \
{ \
@@ -544,7 +544,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return false; \
} \
\
memcpy(_list_->buffer + _list_->count, elements, size * sizeof(V)); \
memcpy(_list_->buffer + _list_->count, values, size * sizeof(V)); \
\
_list_->count += size; \
_list_->flag = cmc_flags.OK; \
@@ -707,7 +707,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return _list_->buffer[_list_->count - 1]; \
} \
\
size_t PFX##_index_of(struct SNAME *_list_, V element, bool from_start) \
size_t PFX##_index_of(struct SNAME *_list_, V value, bool from_start) \
{ \
_list_->flag = cmc_flags.OK; \
\
@@ -717,7 +717,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
{ \
for (size_t i = 0; i < _list_->count; i++) \
{ \
if (_list_->f_val->cmp(_list_->buffer[i], element) == 0) \
if (_list_->f_val->cmp(_list_->buffer[i], value) == 0) \
{ \
result = i; \
break; \
@@ -728,7 +728,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
{ \
for (size_t i = _list_->count; i > 0; i--) \
{ \
if (_list_->f_val->cmp(_list_->buffer[i - 1], element) == 0) \
if (_list_->f_val->cmp(_list_->buffer[i - 1], value) == 0) \
{ \
result = i - 1; \
break; \
@@ -742,7 +742,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
return result; \
} \
\
bool PFX##_contains(struct SNAME *_list_, V element) \
bool PFX##_contains(struct SNAME *_list_, V value) \
{ \
_list_->flag = cmc_flags.OK; \
\
@@ -750,7 +750,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
\
for (size_t i = 0; i < _list_->count; i++) \
{ \
if (_list_->f_val->cmp(_list_->buffer[i], element) == 0) \
if (_list_->f_val->cmp(_list_->buffer[i], value) == 0) \
{ \
result = true; \
break; \
+38 -39
View File
@@ -175,17 +175,17 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
void PFX##_customize(struct SNAME *_set_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_insert(struct SNAME *_set_, V element); \
bool PFX##_insert_many(struct SNAME *_set_, V element, size_t count); \
bool PFX##_update(struct SNAME *_set_, V element, size_t multiplicity); \
bool PFX##_remove(struct SNAME *_set_, V element); \
size_t PFX##_remove_all(struct SNAME *_set_, V element); \
bool PFX##_insert(struct SNAME *_set_, V value); \
bool PFX##_insert_many(struct SNAME *_set_, V value, size_t count); \
bool PFX##_update(struct SNAME *_set_, V value, size_t multiplicity); \
bool PFX##_remove(struct SNAME *_set_, V value); \
size_t PFX##_remove_all(struct SNAME *_set_, V value); \
/* Element Access */ \
bool PFX##_max(struct SNAME *_set_, V *value); \
bool PFX##_min(struct SNAME *_set_, V *value); \
size_t PFX##_multiplicity_of(struct SNAME *_set_, V element); \
size_t PFX##_multiplicity_of(struct SNAME *_set_, V value); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_set_, V element); \
bool PFX##_contains(struct SNAME *_set_, V value); \
bool PFX##_empty(struct SNAME *_set_); \
bool PFX##_full(struct SNAME *_set_); \
size_t PFX##_count(struct SNAME *_set_); \
@@ -243,11 +243,11 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
#define CMC_GENERATE_MULTISET_SOURCE(PFX, SNAME, V) \
\
/* Implementation Detail Functions */ \
static size_t PFX##_impl_multiplicity_of(struct SNAME *_set_, V element); \
static size_t PFX##_impl_multiplicity_of(struct SNAME *_set_, V value); \
static struct SNAME##_entry *PFX##_impl_insert_and_return( \
struct SNAME *_set_, V element, bool *new_node); \
struct SNAME *_set_, V value, bool *new_node); \
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element); \
V value); \
static size_t PFX##_impl_calculate_size(size_t required); \
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_set_); \
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_set_); \
@@ -398,12 +398,12 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
_set_->flag = cmc_flags.OK; \
} \
\
bool PFX##_insert(struct SNAME *_set_, V element) \
bool PFX##_insert(struct SNAME *_set_, V value) \
{ \
bool new_node; \
\
struct SNAME##_entry *entry = \
PFX##_impl_insert_and_return(_set_, element, &new_node); \
PFX##_impl_insert_and_return(_set_, value, &new_node); \
\
if (!entry) \
{ \
@@ -423,7 +423,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_insert_many(struct SNAME *_set_, V element, size_t count) \
bool PFX##_insert_many(struct SNAME *_set_, V value, size_t count) \
{ \
if (count == 0) \
goto success; \
@@ -431,7 +431,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
bool new_node; \
\
struct SNAME##_entry *entry = \
PFX##_impl_insert_and_return(_set_, element, &new_node); \
PFX##_impl_insert_and_return(_set_, value, &new_node); \
\
if (!entry) \
{ \
@@ -456,13 +456,12 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_update(struct SNAME *_set_, V element, size_t multiplicity) \
bool PFX##_update(struct SNAME *_set_, V value, size_t multiplicity) \
{ \
if (multiplicity == 0) \
{ \
/* Effectively delete the entry */ \
struct SNAME##_entry *result = \
PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, value); \
\
if (!result) \
/* If no entry was found then its multiplicity is already 0 */ \
@@ -482,7 +481,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
bool new_node; \
\
struct SNAME##_entry *entry = \
PFX##_impl_insert_and_return(_set_, element, &new_node); \
PFX##_impl_insert_and_return(_set_, value, &new_node); \
\
if (!entry) \
return false; \
@@ -505,7 +504,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_remove(struct SNAME *_set_, V element) \
bool PFX##_remove(struct SNAME *_set_, V value) \
{ \
if (PFX##_empty(_set_)) \
{ \
@@ -513,7 +512,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return false; \
} \
\
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, value); \
\
if (!result) \
{ \
@@ -542,7 +541,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return true; \
} \
\
size_t PFX##_remove_all(struct SNAME *_set_, V element) \
size_t PFX##_remove_all(struct SNAME *_set_, V value) \
{ \
if (PFX##_empty(_set_)) \
{ \
@@ -550,7 +549,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return false; \
} \
\
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *result = PFX##_impl_get_entry(_set_, value); \
\
if (!result) \
{ \
@@ -645,9 +644,9 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return true; \
} \
\
size_t PFX##_multiplicity_of(struct SNAME *_set_, V element) \
size_t PFX##_multiplicity_of(struct SNAME *_set_, V value) \
{ \
struct SNAME##_entry *entry = PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *entry = PFX##_impl_get_entry(_set_, value); \
\
_set_->flag = cmc_flags.OK; \
\
@@ -660,11 +659,11 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return entry->multiplicity; \
} \
\
bool PFX##_contains(struct SNAME *_set_, V element) \
bool PFX##_contains(struct SNAME *_set_, V value) \
{ \
_set_->flag = cmc_flags.OK; \
\
bool result = PFX##_impl_get_entry(_set_, element) != NULL; \
bool result = PFX##_impl_get_entry(_set_, value) != NULL; \
\
if (_set_->callbacks && _set_->callbacks->read) \
_set_->callbacks->read(); \
@@ -1393,9 +1392,9 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return iter->index; \
} \
\
static size_t PFX##_impl_multiplicity_of(struct SNAME *_set_, V element) \
static size_t PFX##_impl_multiplicity_of(struct SNAME *_set_, V value) \
{ \
struct SNAME##_entry *entry = PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *entry = PFX##_impl_get_entry(_set_, value); \
\
if (!entry) \
return 0; \
@@ -1404,15 +1403,15 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
} \
\
static struct SNAME##_entry *PFX##_impl_insert_and_return( \
struct SNAME *_set_, V element, bool *new_node) \
struct SNAME *_set_, V value, bool *new_node) \
{ \
/* If the entry already exists simply return it as we might do */ \
/* something with it. This function only guarantees that there is */ \
/* a valid entry for a given element */ \
/* a valid entry for a given value */ \
\
*new_node = false; \
\
struct SNAME##_entry *entry = PFX##_impl_get_entry(_set_, element); \
struct SNAME##_entry *entry = PFX##_impl_get_entry(_set_, value); \
\
if (entry != NULL) \
return entry; \
@@ -1425,7 +1424,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
return NULL; \
} \
\
size_t hash = _set_->f_val->hash(element); \
size_t hash = _set_->f_val->hash(value); \
size_t original_pos = hash % _set_->capacity; \
size_t pos = original_pos; \
/* Current multiplicity. Might change due to robin hood hashing */ \
@@ -1435,7 +1434,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
\
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED) \
{ \
target->value = element; \
target->value = value; \
target->multiplicity = curr_mul; \
target->dist = pos - original_pos; \
target->state = CMC_ES_FILLED; \
@@ -1450,7 +1449,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
if (target->state == CMC_ES_EMPTY || \
target->state == CMC_ES_DELETED) \
{ \
target->value = element; \
target->value = value; \
target->multiplicity = curr_mul; \
target->dist = pos - original_pos; \
target->state = CMC_ES_FILLED; \
@@ -1464,11 +1463,11 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
size_t tmp_dist = target->dist; \
size_t tmp_mul = target->multiplicity; \
\
target->value = element; \
target->value = value; \
target->dist = pos - original_pos; \
target->multiplicity = curr_mul; \
\
element = tmp; \
value = tmp; \
original_pos = pos - tmp_dist; \
curr_mul = tmp_mul; \
} \
@@ -1481,9 +1480,9 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
} \
\
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element) \
V value) \
{ \
size_t hash = _set_->f_val->hash(element); \
size_t hash = _set_->f_val->hash(value); \
size_t pos = hash % _set_->capacity; \
\
struct SNAME##_entry *target = &(_set_->buffer[pos]); \
@@ -1491,7 +1490,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
while (target->state == CMC_ES_FILLED || \
target->state == CMC_ES_DELETED) \
{ \
if (_set_->f_val->cmp(target->value, element) == 0) \
if (_set_->f_val->cmp(target->value, value) == 0) \
return target; \
\
pos++; \
+6 -6
View File
@@ -169,12 +169,12 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
void PFX##_customize(struct SNAME *_queue_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_enqueue(struct SNAME *_queue_, V element); \
bool PFX##_enqueue(struct SNAME *_queue_, V value); \
bool PFX##_dequeue(struct SNAME *_queue_); \
/* Element Access */ \
V PFX##_peek(struct SNAME *_queue_); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_queue_, V element); \
bool PFX##_contains(struct SNAME *_queue_, V value); \
bool PFX##_empty(struct SNAME *_queue_); \
bool PFX##_full(struct SNAME *_queue_); \
size_t PFX##_count(struct SNAME *_queue_); \
@@ -344,7 +344,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
_queue_->flag = cmc_flags.OK; \
} \
\
bool PFX##_enqueue(struct SNAME *_queue_, V element) \
bool PFX##_enqueue(struct SNAME *_queue_, V value) \
{ \
if (PFX##_full(_queue_)) \
{ \
@@ -352,7 +352,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
return false; \
} \
\
_queue_->buffer[_queue_->back] = element; \
_queue_->buffer[_queue_->back] = value; \
\
_queue_->back = \
(_queue_->back == _queue_->capacity - 1) ? 0 : _queue_->back + 1; \
@@ -403,7 +403,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
return _queue_->buffer[_queue_->front]; \
} \
\
bool PFX##_contains(struct SNAME *_queue_, V element) \
bool PFX##_contains(struct SNAME *_queue_, V value) \
{ \
_queue_->flag = cmc_flags.OK; \
\
@@ -411,7 +411,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
\
for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++) \
{ \
if (_queue_->f_val->cmp(_queue_->buffer[i], element) == 0) \
if (_queue_->f_val->cmp(_queue_->buffer[i], value) == 0) \
{ \
result = true; \
break; \
+10 -11
View File
@@ -141,15 +141,15 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
void PFX##_customize(struct SNAME *_list_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_insert(struct SNAME *_list_, V element); \
bool PFX##_insert(struct SNAME *_list_, V value); \
bool PFX##_remove(struct SNAME *_list_, size_t index); \
/* Element Access */ \
V PFX##_max(struct SNAME *_list_); \
V PFX##_min(struct SNAME *_list_); \
V PFX##_get(struct SNAME *_list_, size_t index); \
size_t PFX##_index_of(struct SNAME *_list_, V element, bool from_start); \
size_t PFX##_index_of(struct SNAME *_list_, V value, bool from_start); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_list_, V element); \
bool PFX##_contains(struct SNAME *_list_, V value); \
bool PFX##_empty(struct SNAME *_list_); \
bool PFX##_full(struct SNAME *_list_); \
size_t PFX##_count(struct SNAME *_list_); \
@@ -312,7 +312,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
_list_->flag = cmc_flags.OK; \
} \
\
bool PFX##_insert(struct SNAME *_list_, V element) \
bool PFX##_insert(struct SNAME *_list_, V value) \
{ \
if (PFX##_full(_list_)) \
{ \
@@ -320,7 +320,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
return false; \
} \
\
_list_->buffer[_list_->count++] = element; \
_list_->buffer[_list_->count++] = value; \
\
_list_->is_sorted = false; \
_list_->flag = cmc_flags.OK; \
@@ -418,7 +418,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
return _list_->buffer[index]; \
} \
\
size_t PFX##_index_of(struct SNAME *_list_, V element, bool from_start) \
size_t PFX##_index_of(struct SNAME *_list_, V value, bool from_start) \
{ \
_list_->flag = cmc_flags.OK; \
\
@@ -429,13 +429,13 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
\
if (from_start) \
{ \
return PFX##_impl_binary_search_first(_list_, element); \
return PFX##_impl_binary_search_first(_list_, value); \
} \
\
return PFX##_impl_binary_search_last(_list_, element); \
return PFX##_impl_binary_search_last(_list_, value); \
} \
\
bool PFX##_contains(struct SNAME *_list_, V element) \
bool PFX##_contains(struct SNAME *_list_, V value) \
{ \
_list_->flag = cmc_flags.OK; \
\
@@ -447,8 +447,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
if (_list_->callbacks && _list_->callbacks->read) \
_list_->callbacks->read(); \
\
return PFX##_impl_binary_search_first(_list_, element) < \
_list_->count; \
return PFX##_impl_binary_search_first(_list_, value) < _list_->count; \
} \
\
bool PFX##_empty(struct SNAME *_list_) \
+6 -6
View File
@@ -143,12 +143,12 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
void PFX##_customize(struct SNAME *_stack_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_push(struct SNAME *_stack_, V element); \
bool PFX##_push(struct SNAME *_stack_, V value); \
bool PFX##_pop(struct SNAME *_stack_); \
/* Element Access */ \
V PFX##_top(struct SNAME *_stack_); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_stack_, V element); \
bool PFX##_contains(struct SNAME *_stack_, V value); \
bool PFX##_empty(struct SNAME *_stack_); \
bool PFX##_full(struct SNAME *_stack_); \
size_t PFX##_count(struct SNAME *_stack_); \
@@ -303,7 +303,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
_stack_->flag = cmc_flags.OK; \
} \
\
bool PFX##_push(struct SNAME *_stack_, V element) \
bool PFX##_push(struct SNAME *_stack_, V value) \
{ \
if (PFX##_full(_stack_)) \
{ \
@@ -311,7 +311,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
return false; \
} \
\
_stack_->buffer[_stack_->count++] = element; \
_stack_->buffer[_stack_->count++] = value; \
\
_stack_->flag = cmc_flags.OK; \
\
@@ -355,7 +355,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
return _stack_->buffer[_stack_->count - 1]; \
} \
\
bool PFX##_contains(struct SNAME *_stack_, V element) \
bool PFX##_contains(struct SNAME *_stack_, V value) \
{ \
_stack_->flag = cmc_flags.OK; \
\
@@ -363,7 +363,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
\
for (size_t i = 0; i < _stack_->count; i++) \
{ \
if (_stack_->f_val->cmp(_stack_->buffer[i], element) == 0) \
if (_stack_->f_val->cmp(_stack_->buffer[i], value) == 0) \
{ \
result = true; \
break; \
+21 -21
View File
@@ -158,13 +158,13 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
void PFX##_customize(struct SNAME *_set_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks *callbacks); \
/* Collection Input and Output */ \
bool PFX##_insert(struct SNAME *_set_, V element); \
bool PFX##_remove(struct SNAME *_set_, V element); \
bool PFX##_insert(struct SNAME *_set_, V value); \
bool PFX##_remove(struct SNAME *_set_, V value); \
/* Element Access */ \
bool PFX##_max(struct SNAME *_set_, V *value); \
bool PFX##_min(struct SNAME *_set_, V *value); \
/* Collection State */ \
bool PFX##_contains(struct SNAME *_set_, V element); \
bool PFX##_contains(struct SNAME *_set_, V value); \
bool PFX##_empty(struct SNAME *_set_); \
size_t PFX##_count(struct SNAME *_set_); \
int PFX##_flag(struct SNAME *_set_); \
@@ -226,9 +226,9 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
\
/* Implementation Detail Functions */ \
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_set_, \
V element); \
V value); \
static struct SNAME##_node *PFX##_impl_get_node(struct SNAME *_set_, \
V element); \
V value); \
static unsigned char PFX##_impl_h(struct SNAME##_node *node); \
static unsigned char PFX##_impl_hupdate(struct SNAME##_node *node); \
static void PFX##_impl_rotate_right(struct SNAME##_node **Z); \
@@ -371,11 +371,11 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
_set_->flag = cmc_flags.OK; \
} \
\
bool PFX##_insert(struct SNAME *_set_, V element) \
bool PFX##_insert(struct SNAME *_set_, V value) \
{ \
if (PFX##_empty(_set_)) \
{ \
_set_->root = PFX##_impl_new_node(_set_, element); \
_set_->root = PFX##_impl_new_node(_set_, value); \
\
if (!_set_->root) \
{ \
@@ -392,9 +392,9 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
{ \
parent = scan; \
\
if (_set_->f_val->cmp(scan->value, element) > 0) \
if (_set_->f_val->cmp(scan->value, value) > 0) \
scan = scan->left; \
else if (_set_->f_val->cmp(scan->value, element) < 0) \
else if (_set_->f_val->cmp(scan->value, value) < 0) \
scan = scan->right; \
else \
{ \
@@ -405,9 +405,9 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
\
struct SNAME##_node *node; \
\
if (_set_->f_val->cmp(parent->value, element) > 0) \
if (_set_->f_val->cmp(parent->value, value) > 0) \
{ \
parent->left = PFX##_impl_new_node(_set_, element); \
parent->left = PFX##_impl_new_node(_set_, value); \
\
if (!parent->left) \
{ \
@@ -420,7 +420,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
} \
else \
{ \
parent->right = PFX##_impl_new_node(_set_, element); \
parent->right = PFX##_impl_new_node(_set_, value); \
\
if (!parent->right) \
{ \
@@ -444,7 +444,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_remove(struct SNAME *_set_, V element) \
bool PFX##_remove(struct SNAME *_set_, V value) \
{ \
if (PFX##_empty(_set_)) \
{ \
@@ -452,7 +452,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
return false; \
} \
\
struct SNAME##_node *node = PFX##_impl_get_node(_set_, element); \
struct SNAME##_node *node = PFX##_impl_get_node(_set_, value); \
\
if (!node) \
{ \
@@ -626,9 +626,9 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
return true; \
} \
\
bool PFX##_contains(struct SNAME *_set_, V element) \
bool PFX##_contains(struct SNAME *_set_, V value) \
{ \
bool result = PFX##_impl_get_node(_set_, element) != NULL; \
bool result = PFX##_impl_get_node(_set_, value) != NULL; \
\
if (_set_->callbacks && _set_->callbacks->read) \
_set_->callbacks->read(); \
@@ -1208,7 +1208,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
} \
\
static struct SNAME##_node *PFX##_impl_new_node(struct SNAME *_set_, \
V element) \
V value) \
{ \
struct SNAME##_node *node = \
_set_->alloc->malloc(sizeof(struct SNAME##_node)); \
@@ -1216,7 +1216,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
if (!node) \
return NULL; \
\
node->value = element; \
node->value = value; \
node->right = NULL; \
node->left = NULL; \
node->parent = NULL; \
@@ -1226,15 +1226,15 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
} \
\
static struct SNAME##_node *PFX##_impl_get_node(struct SNAME *_set_, \
V element) \
V value) \
{ \
struct SNAME##_node *scan = _set_->root; \
\
while (scan != NULL) \
{ \
if (_set_->f_val->cmp(scan->value, element) > 0) \
if (_set_->f_val->cmp(scan->value, value) > 0) \
scan = scan->left; \
else if (_set_->f_val->cmp(scan->value, element) < 0) \
else if (_set_->f_val->cmp(scan->value, value) < 0) \
scan = scan->right; \
else \
return scan; \
+9 -9
View File
@@ -39,13 +39,13 @@ void d_clear(struct deque *_deque_);
void d_free(struct deque *_deque_);
void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool d_push_front(struct deque *_deque_, size_t element);
_Bool d_push_back(struct deque *_deque_, size_t element);
_Bool d_push_front(struct deque *_deque_, size_t value);
_Bool d_push_back(struct deque *_deque_, size_t value);
_Bool d_pop_front(struct deque *_deque_);
_Bool d_pop_back(struct deque *_deque_);
size_t d_front(struct deque *_deque_);
size_t d_back(struct deque *_deque_);
_Bool d_contains(struct deque *_deque_, size_t element);
_Bool d_contains(struct deque *_deque_, size_t value);
_Bool d_empty(struct deque *_deque_);
_Bool d_full(struct deque *_deque_);
size_t d_count(struct deque *_deque_);
@@ -171,7 +171,7 @@ void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc,
_deque_->callbacks = callbacks;
_deque_->flag = cmc_flags.OK;
}
_Bool d_push_front(struct deque *_deque_, size_t element)
_Bool d_push_front(struct deque *_deque_, size_t value)
{
if (d_full(_deque_))
{
@@ -180,21 +180,21 @@ _Bool d_push_front(struct deque *_deque_, size_t element)
}
_deque_->front =
(_deque_->front == 0) ? _deque_->capacity - 1 : _deque_->front - 1;
_deque_->buffer[_deque_->front] = element;
_deque_->buffer[_deque_->front] = value;
_deque_->count++;
_deque_->flag = cmc_flags.OK;
if (_deque_->callbacks && _deque_->callbacks->create)
_deque_->callbacks->create();
return 1;
}
_Bool d_push_back(struct deque *_deque_, size_t element)
_Bool d_push_back(struct deque *_deque_, size_t value)
{
if (d_full(_deque_))
{
if (!d_resize(_deque_, _deque_->capacity * 2))
return 0;
}
_deque_->buffer[_deque_->back] = element;
_deque_->buffer[_deque_->back] = value;
_deque_->back =
(_deque_->back == _deque_->capacity - 1) ? 0 : _deque_->back + 1;
_deque_->count++;
@@ -260,13 +260,13 @@ size_t d_back(struct deque *_deque_)
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1
: _deque_->back - 1];
}
_Bool d_contains(struct deque *_deque_, size_t element)
_Bool d_contains(struct deque *_deque_, size_t value)
{
_deque_->flag = cmc_flags.OK;
_Bool result = 0;
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++)
{
if (_deque_->f_val->cmp(_deque_->buffer[i], element) == 0)
if (_deque_->f_val->cmp(_deque_->buffer[i], value) == 0)
{
result = 1;
break;
+18 -18
View File
@@ -48,11 +48,11 @@ void hs_clear(struct hashset *_set_);
void hs_free(struct hashset *_set_);
void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool hs_insert(struct hashset *_set_, size_t element);
_Bool hs_remove(struct hashset *_set_, size_t element);
_Bool hs_insert(struct hashset *_set_, size_t value);
_Bool hs_remove(struct hashset *_set_, size_t value);
_Bool hs_max(struct hashset *_set_, size_t *value);
_Bool hs_min(struct hashset *_set_, size_t *value);
_Bool hs_contains(struct hashset *_set_, size_t element);
_Bool hs_contains(struct hashset *_set_, size_t value);
_Bool hs_empty(struct hashset *_set_);
_Bool hs_full(struct hashset *_set_);
size_t hs_count(struct hashset *_set_);
@@ -89,7 +89,7 @@ _Bool hs_iter_go_to(struct hashset_iter *iter, size_t index);
size_t hs_iter_value(struct hashset_iter *iter);
size_t hs_iter_index(struct hashset_iter *iter);
static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_,
size_t element);
size_t value);
static size_t hs_impl_calculate_size(size_t required);
static struct hashset_iter hs_impl_it_start(struct hashset *_set_);
static struct hashset_iter hs_impl_it_end(struct hashset *_set_);
@@ -200,25 +200,25 @@ void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc,
_set_->callbacks = callbacks;
_set_->flag = cmc_flags.OK;
}
_Bool hs_insert(struct hashset *_set_, size_t element)
_Bool hs_insert(struct hashset *_set_, size_t value)
{
if (hs_full(_set_))
{
if (!hs_resize(_set_, _set_->capacity + 1))
return 0;
}
if (hs_impl_get_entry(_set_, element) != ((void *)0))
if (hs_impl_get_entry(_set_, value) != ((void *)0))
{
_set_->flag = cmc_flags.DUPLICATE;
return 0;
}
size_t hash = _set_->f_val->hash(element);
size_t hash = _set_->f_val->hash(value);
size_t original_pos = hash % _set_->capacity;
size_t pos = original_pos;
struct hashset_entry *target = &(_set_->buffer[pos]);
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED)
{
target->value = element;
target->value = value;
target->dist = 0;
target->state = CMC_ES_FILLED;
}
@@ -231,7 +231,7 @@ _Bool hs_insert(struct hashset *_set_, size_t element)
if (target->state == CMC_ES_EMPTY ||
target->state == CMC_ES_DELETED)
{
target->value = element;
target->value = value;
target->dist = pos - original_pos;
target->state = CMC_ES_FILLED;
break;
@@ -240,9 +240,9 @@ _Bool hs_insert(struct hashset *_set_, size_t element)
{
size_t tmp = target->value;
size_t tmp_dist = target->dist;
target->value = element;
target->value = value;
target->dist = pos - original_pos;
element = tmp;
value = tmp;
original_pos = pos - tmp_dist;
}
}
@@ -253,14 +253,14 @@ _Bool hs_insert(struct hashset *_set_, size_t element)
_set_->callbacks->create();
return 1;
}
_Bool hs_remove(struct hashset *_set_, size_t element)
_Bool hs_remove(struct hashset *_set_, size_t value)
{
if (hs_empty(_set_))
{
_set_->flag = cmc_flags.EMPTY;
return 0;
}
struct hashset_entry *result = hs_impl_get_entry(_set_, element);
struct hashset_entry *result = hs_impl_get_entry(_set_, value);
if (result == ((void *)0))
{
_set_->flag = cmc_flags.NOT_FOUND;
@@ -325,10 +325,10 @@ _Bool hs_min(struct hashset *_set_, size_t *value)
_set_->callbacks->read();
return 1;
}
_Bool hs_contains(struct hashset *_set_, size_t element)
_Bool hs_contains(struct hashset *_set_, size_t value)
{
_set_->flag = cmc_flags.OK;
_Bool result = hs_impl_get_entry(_set_, element) != ((void *)0);
_Bool result = hs_impl_get_entry(_set_, value) != ((void *)0);
if (_set_->callbacks && _set_->callbacks->read)
_set_->callbacks->read();
return result;
@@ -808,14 +808,14 @@ size_t hs_iter_index(struct hashset_iter *iter)
return iter->index;
}
static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_,
size_t element)
size_t value)
{
size_t hash = _set_->f_val->hash(element);
size_t hash = _set_->f_val->hash(value);
size_t pos = hash % _set_->capacity;
struct hashset_entry *target = &(_set_->buffer[pos]);
while (target->state == CMC_ES_FILLED || target->state == CMC_ES_DELETED)
{
if (_set_->f_val->cmp(target->value, element) == 0)
if (_set_->f_val->cmp(target->value, value) == 0)
return target;
pos++;
target = &(_set_->buffer[pos % _set_->capacity]);
+6 -6
View File
@@ -38,10 +38,10 @@ void h_clear(struct heap *_heap_);
void h_free(struct heap *_heap_);
void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool h_insert(struct heap *_heap_, size_t element);
_Bool h_insert(struct heap *_heap_, size_t value);
_Bool h_remove(struct heap *_heap_);
size_t h_peek(struct heap *_heap_);
_Bool h_contains(struct heap *_heap_, size_t element);
_Bool h_contains(struct heap *_heap_, size_t value);
_Bool h_empty(struct heap *_heap_);
_Bool h_full(struct heap *_heap_);
size_t h_count(struct heap *_heap_);
@@ -167,14 +167,14 @@ void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc,
_heap_->callbacks = callbacks;
_heap_->flag = cmc_flags.OK;
}
_Bool h_insert(struct heap *_heap_, size_t element)
_Bool h_insert(struct heap *_heap_, size_t value)
{
if (h_full(_heap_))
{
if (!h_resize(_heap_, _heap_->count * 2))
return 0;
}
_heap_->buffer[_heap_->count++] = element;
_heap_->buffer[_heap_->count++] = value;
if (!h_empty(_heap_))
{
h_impl_float_up(_heap_, _heap_->count - 1);
@@ -212,13 +212,13 @@ size_t h_peek(struct heap *_heap_)
_heap_->callbacks->read();
return _heap_->buffer[0];
}
_Bool h_contains(struct heap *_heap_, size_t element)
_Bool h_contains(struct heap *_heap_, size_t value)
{
_heap_->flag = cmc_flags.OK;
_Bool result = 0;
for (size_t i = 0; i < _heap_->count; i++)
{
if (_heap_->f_val->cmp(_heap_->buffer[i], element) == 0)
if (_heap_->f_val->cmp(_heap_->buffer[i], value) == 0)
{
result = 1;
break;
+26 -26
View File
@@ -42,14 +42,14 @@ void ih_clear(struct intervalheap *_heap_);
void ih_free(struct intervalheap *_heap_);
void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool ih_insert(struct intervalheap *_heap_, size_t element);
_Bool ih_insert(struct intervalheap *_heap_, size_t value);
_Bool ih_remove_max(struct intervalheap *_heap_);
_Bool ih_remove_min(struct intervalheap *_heap_);
_Bool ih_update_max(struct intervalheap *_heap_, size_t element);
_Bool ih_update_min(struct intervalheap *_heap_, size_t element);
_Bool ih_update_max(struct intervalheap *_heap_, size_t value);
_Bool ih_update_min(struct intervalheap *_heap_, size_t value);
size_t ih_max(struct intervalheap *_heap_);
size_t ih_min(struct intervalheap *_heap_);
_Bool ih_contains(struct intervalheap *_heap_, size_t element);
_Bool ih_contains(struct intervalheap *_heap_, size_t value);
_Bool ih_empty(struct intervalheap *_heap_);
_Bool ih_full(struct intervalheap *_heap_);
size_t ih_count(struct intervalheap *_heap_);
@@ -176,7 +176,7 @@ void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc,
_heap_->callbacks = callbacks;
_heap_->flag = cmc_flags.OK;
}
_Bool ih_insert(struct intervalheap *_heap_, size_t element)
_Bool ih_insert(struct intervalheap *_heap_, size_t value)
{
if (ih_full(_heap_))
{
@@ -185,21 +185,21 @@ _Bool ih_insert(struct intervalheap *_heap_, size_t element)
}
if (_heap_->count % 2 == 0)
{
_heap_->buffer[_heap_->size].data[0] = element;
_heap_->buffer[_heap_->size].data[0] = value;
_heap_->buffer[_heap_->size].data[1] = (size_t){ 0 };
_heap_->size++;
}
else
{
struct intervalheap_node *node = &(_heap_->buffer[_heap_->size - 1]);
if (_heap_->f_val->cmp(node->data[0], element) > 0)
if (_heap_->f_val->cmp(node->data[0], value) > 0)
{
node->data[1] = node->data[0];
node->data[0] = element;
node->data[0] = value;
}
else
{
node->data[1] = element;
node->data[1] = value;
}
}
_heap_->count++;
@@ -208,9 +208,9 @@ _Bool ih_insert(struct intervalheap *_heap_, size_t element)
{
struct intervalheap_node *parent =
&(_heap_->buffer[(_heap_->size - 1) / 2]);
if (_heap_->f_val->cmp(parent->data[0], element) > 0)
if (_heap_->f_val->cmp(parent->data[0], value) > 0)
ih_impl_float_up_min(_heap_);
else if (_heap_->f_val->cmp(parent->data[1], element) < 0)
else if (_heap_->f_val->cmp(parent->data[1], value) < 0)
ih_impl_float_up_max(_heap_);
}
if (_heap_->callbacks && _heap_->callbacks->create)
@@ -285,7 +285,7 @@ success:
_heap_->callbacks->delete ();
return 1;
}
_Bool ih_update_max(struct intervalheap *_heap_, size_t element)
_Bool ih_update_max(struct intervalheap *_heap_, size_t value)
{
if (ih_empty(_heap_))
{
@@ -294,17 +294,17 @@ _Bool ih_update_max(struct intervalheap *_heap_, size_t element)
}
if (_heap_->count == 1)
{
_heap_->buffer[0].data[0] = element;
_heap_->buffer[0].data[0] = value;
}
else if (_heap_->f_val->cmp(element, _heap_->buffer[0].data[0]) < 0)
else if (_heap_->f_val->cmp(value, _heap_->buffer[0].data[0]) < 0)
{
_heap_->buffer[0].data[1] = _heap_->buffer[0].data[0];
_heap_->buffer[0].data[0] = element;
_heap_->buffer[0].data[0] = value;
ih_impl_float_down_max(_heap_);
}
else
{
_heap_->buffer[0].data[1] = element;
_heap_->buffer[0].data[1] = value;
ih_impl_float_down_max(_heap_);
}
_heap_->flag = cmc_flags.OK;
@@ -312,7 +312,7 @@ _Bool ih_update_max(struct intervalheap *_heap_, size_t element)
_heap_->callbacks->update();
return 1;
}
_Bool ih_update_min(struct intervalheap *_heap_, size_t element)
_Bool ih_update_min(struct intervalheap *_heap_, size_t value)
{
if (ih_empty(_heap_))
{
@@ -321,17 +321,17 @@ _Bool ih_update_min(struct intervalheap *_heap_, size_t element)
}
if (_heap_->count == 1)
{
_heap_->buffer[0].data[0] = element;
_heap_->buffer[0].data[0] = value;
}
else if (_heap_->f_val->cmp(element, _heap_->buffer[0].data[1]) > 0)
else if (_heap_->f_val->cmp(value, _heap_->buffer[0].data[1]) > 0)
{
_heap_->buffer[0].data[0] = _heap_->buffer[0].data[1];
_heap_->buffer[0].data[1] = element;
_heap_->buffer[0].data[1] = value;
ih_impl_float_down_min(_heap_);
}
else
{
_heap_->buffer[0].data[0] = element;
_heap_->buffer[0].data[0] = value;
ih_impl_float_down_min(_heap_);
}
_heap_->flag = cmc_flags.OK;
@@ -365,13 +365,13 @@ size_t ih_min(struct intervalheap *_heap_)
_heap_->callbacks->read();
return _heap_->buffer[0].data[0];
}
_Bool ih_contains(struct intervalheap *_heap_, size_t element)
_Bool ih_contains(struct intervalheap *_heap_, size_t value)
{
_heap_->flag = cmc_flags.OK;
_Bool result = 0;
for (size_t i = 0; i < _heap_->count; i++)
{
if (_heap_->f_val->cmp(_heap_->buffer[i / 2].data[i % 2], element) == 0)
if (_heap_->f_val->cmp(_heap_->buffer[i / 2].data[i % 2], value) == 0)
{
result = 1;
break;
@@ -484,9 +484,9 @@ _Bool ih_equals(struct intervalheap *_heap1_, struct intervalheap *_heap2_)
return 0;
for (size_t i = 0; i < _heap1_->count; i++)
{
size_t element1 = _heap1_->buffer[i / 2].data[i % 2];
size_t element2 = _heap2_->buffer[i / 2].data[i % 2];
if (_heap1_->f_val->cmp(element1, element2) != 0)
size_t value1 = _heap1_->buffer[i / 2].data[i % 2];
size_t value2 = _heap2_->buffer[i / 2].data[i % 2];
if (_heap1_->f_val->cmp(value1, value2) != 0)
return 0;
}
return 1;
+23 -23
View File
@@ -43,9 +43,9 @@ void ll_clear(struct linkedlist *_list_);
void ll_free(struct linkedlist *_list_);
void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool ll_push_front(struct linkedlist *_list_, size_t element);
_Bool ll_push_at(struct linkedlist *_list_, size_t element, size_t index);
_Bool ll_push_back(struct linkedlist *_list_, size_t element);
_Bool ll_push_front(struct linkedlist *_list_, size_t value);
_Bool ll_push_at(struct linkedlist *_list_, size_t value, size_t index);
_Bool ll_push_back(struct linkedlist *_list_, size_t value);
_Bool ll_pop_front(struct linkedlist *_list_);
_Bool ll_pop_at(struct linkedlist *_list_, size_t index);
_Bool ll_pop_back(struct linkedlist *_list_);
@@ -53,7 +53,7 @@ size_t ll_front(struct linkedlist *_list_);
size_t ll_get(struct linkedlist *_list_, size_t index);
size_t *ll_get_ref(struct linkedlist *_list_, size_t index);
size_t ll_back(struct linkedlist *_list_);
_Bool ll_contains(struct linkedlist *_list_, size_t element);
_Bool ll_contains(struct linkedlist *_list_, size_t value);
_Bool ll_empty(struct linkedlist *_list_);
size_t ll_count(struct linkedlist *_list_);
int ll_flag(struct linkedlist *_list_);
@@ -61,15 +61,15 @@ struct linkedlist *ll_copy_of(struct linkedlist *_list_);
_Bool ll_equals(struct linkedlist *_list1_, struct linkedlist *_list2_);
struct cmc_string ll_to_string(struct linkedlist *_list_);
_Bool ll_print(struct linkedlist *_list_, FILE *fptr);
struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t element);
struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t value);
void ll_free_node(struct linkedlist *_list_, struct linkedlist_node *_node_);
struct linkedlist_node *ll_head(struct linkedlist *_list_);
struct linkedlist_node *ll_get_node(struct linkedlist *_list_, size_t index);
struct linkedlist_node *ll_tail(struct linkedlist *_list_);
_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_,
size_t element);
size_t value);
_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_,
size_t element);
size_t value);
_Bool ll_del_next(struct linkedlist *_owner_, struct linkedlist_node *_node_);
_Bool ll_del_curr(struct linkedlist *_owner_, struct linkedlist_node *_node_);
_Bool ll_del_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_);
@@ -167,9 +167,9 @@ void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc,
_list_->callbacks = callbacks;
_list_->flag = cmc_flags.OK;
}
_Bool ll_push_front(struct linkedlist *_list_, size_t element)
_Bool ll_push_front(struct linkedlist *_list_, size_t value)
{
struct linkedlist_node *_node_ = ll_new_node(_list_, element);
struct linkedlist_node *_node_ = ll_new_node(_list_, value);
if (!_node_)
return 0;
if (ll_empty(_list_))
@@ -189,7 +189,7 @@ _Bool ll_push_front(struct linkedlist *_list_, size_t element)
_list_->callbacks->create();
return 1;
}
_Bool ll_push_at(struct linkedlist *_list_, size_t element, size_t index)
_Bool ll_push_at(struct linkedlist *_list_, size_t value, size_t index)
{
if (index > _list_->count)
{
@@ -198,13 +198,13 @@ _Bool ll_push_at(struct linkedlist *_list_, size_t element, size_t index)
}
if (index == 0)
{
return ll_push_front(_list_, element);
return ll_push_front(_list_, value);
}
else if (index == _list_->count)
{
return ll_push_back(_list_, element);
return ll_push_back(_list_, value);
}
struct linkedlist_node *_node_ = ll_new_node(_list_, element);
struct linkedlist_node *_node_ = ll_new_node(_list_, value);
if (!_node_)
return 0;
struct linkedlist_node *scan = ll_get_node(_list_, index - 1);
@@ -218,9 +218,9 @@ _Bool ll_push_at(struct linkedlist *_list_, size_t element, size_t index)
_list_->callbacks->create();
return 1;
}
_Bool ll_push_back(struct linkedlist *_list_, size_t element)
_Bool ll_push_back(struct linkedlist *_list_, size_t value)
{
struct linkedlist_node *_node_ = ll_new_node(_list_, element);
struct linkedlist_node *_node_ = ll_new_node(_list_, value);
if (!_node_)
return 0;
if (ll_empty(_list_))
@@ -374,14 +374,14 @@ size_t ll_back(struct linkedlist *_list_)
_list_->callbacks->read();
return _list_->tail->value;
}
_Bool ll_contains(struct linkedlist *_list_, size_t element)
_Bool ll_contains(struct linkedlist *_list_, size_t value)
{
_list_->flag = cmc_flags.OK;
_Bool result = 0;
struct linkedlist_node *scan = _list_->head;
while (scan != ((void *)0))
{
if (_list_->f_val->cmp(scan->value, element) == 0)
if (_list_->f_val->cmp(scan->value, value) == 0)
{
result = 1;
break;
@@ -472,7 +472,7 @@ _Bool ll_print(struct linkedlist *_list_, FILE *fptr)
}
return 1;
}
struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t element)
struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t value)
{
struct linkedlist_node *_node_ =
_list_->alloc->malloc(sizeof(struct linkedlist_node));
@@ -481,7 +481,7 @@ struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t element)
_list_->flag = cmc_flags.ALLOC;
return ((void *)0);
}
_node_->value = element;
_node_->value = value;
_node_->next = ((void *)0);
_node_->prev = ((void *)0);
return _node_;
@@ -531,9 +531,9 @@ struct linkedlist_node *ll_tail(struct linkedlist *_list_)
return _list_->tail;
}
_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_,
size_t element)
size_t value)
{
struct linkedlist_node *new_node = ll_new_node(_owner_, element);
struct linkedlist_node *new_node = ll_new_node(_owner_, value);
if (!new_node)
return 0;
new_node->next = _node_->next;
@@ -548,9 +548,9 @@ _Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_,
return 1;
}
_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_,
size_t element)
size_t value)
{
struct linkedlist_node *new_node = ll_new_node(_owner_, element);
struct linkedlist_node *new_node = ll_new_node(_owner_, value);
if (!new_node)
return 0;
new_node->prev = _node_->prev;
+27 -27
View File
@@ -36,24 +36,24 @@ void l_clear(struct list *_list_);
void l_free(struct list *_list_);
void l_customize(struct list *_list_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool l_push_front(struct list *_list_, size_t element);
_Bool l_push_at(struct list *_list_, size_t element, size_t index);
_Bool l_push_back(struct list *_list_, size_t element);
_Bool l_push_front(struct list *_list_, size_t value);
_Bool l_push_at(struct list *_list_, size_t value, size_t index);
_Bool l_push_back(struct list *_list_, size_t value);
_Bool l_pop_front(struct list *_list_);
_Bool l_pop_at(struct list *_list_, size_t index);
_Bool l_pop_back(struct list *_list_);
_Bool l_seq_push_front(struct list *_list_, size_t *elements, size_t size);
_Bool l_seq_push_at(struct list *_list_, size_t *elements, size_t size,
_Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size);
_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size,
size_t index);
_Bool l_seq_push_back(struct list *_list_, size_t *elements, size_t size);
_Bool l_seq_push_back(struct list *_list_, size_t *values, size_t size);
_Bool l_seq_pop_at(struct list *_list_, size_t from, size_t to);
struct list *l_seq_sublist(struct list *_list_, size_t from, size_t to);
size_t l_front(struct list *_list_);
size_t l_get(struct list *_list_, size_t index);
size_t *l_get_ref(struct list *_list_, size_t index);
size_t l_back(struct list *_list_);
size_t l_index_of(struct list *_list_, size_t element, _Bool from_start);
_Bool l_contains(struct list *_list_, size_t element);
size_t l_index_of(struct list *_list_, size_t value, _Bool from_start);
_Bool l_contains(struct list *_list_, size_t value);
_Bool l_empty(struct list *_list_);
_Bool l_full(struct list *_list_);
size_t l_count(struct list *_list_);
@@ -166,7 +166,7 @@ void l_customize(struct list *_list_, struct cmc_alloc_node *alloc,
_list_->callbacks = callbacks;
_list_->flag = cmc_flags.OK;
}
_Bool l_push_front(struct list *_list_, size_t element)
_Bool l_push_front(struct list *_list_, size_t value)
{
if (l_full(_list_))
{
@@ -178,14 +178,14 @@ _Bool l_push_front(struct list *_list_, size_t element)
memmove(_list_->buffer + 1, _list_->buffer,
_list_->count * sizeof(size_t));
}
_list_->buffer[0] = element;
_list_->buffer[0] = value;
_list_->count++;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
_list_->callbacks->create();
return 1;
}
_Bool l_push_at(struct list *_list_, size_t element, size_t index)
_Bool l_push_at(struct list *_list_, size_t value, size_t index)
{
if (index > _list_->count)
{
@@ -199,21 +199,21 @@ _Bool l_push_at(struct list *_list_, size_t element, size_t index)
}
memmove(_list_->buffer + index + 1, _list_->buffer + index,
(_list_->count - index) * sizeof(size_t));
_list_->buffer[index] = element;
_list_->buffer[index] = value;
_list_->count++;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
_list_->callbacks->create();
return 1;
}
_Bool l_push_back(struct list *_list_, size_t element)
_Bool l_push_back(struct list *_list_, size_t value)
{
if (l_full(_list_))
{
if (!l_resize(_list_, _list_->count * 2))
return 0;
}
_list_->buffer[_list_->count++] = element;
_list_->buffer[_list_->count++] = value;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
_list_->callbacks->create();
@@ -264,7 +264,7 @@ _Bool l_pop_back(struct list *_list_)
_list_->callbacks->delete ();
return 1;
}
_Bool l_seq_push_front(struct list *_list_, size_t *elements, size_t size)
_Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size)
{
if (size == 0)
{
@@ -278,14 +278,14 @@ _Bool l_seq_push_front(struct list *_list_, size_t *elements, size_t size)
}
memmove(_list_->buffer + size, _list_->buffer,
_list_->count * sizeof(size_t));
memcpy(_list_->buffer, elements, size * sizeof(size_t));
memcpy(_list_->buffer, values, size * sizeof(size_t));
_list_->count += size;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
_list_->callbacks->create();
return 1;
}
_Bool l_seq_push_at(struct list *_list_, size_t *elements, size_t size,
_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size,
size_t index)
{
if (size == 0)
@@ -299,9 +299,9 @@ _Bool l_seq_push_at(struct list *_list_, size_t *elements, size_t size,
return 0;
}
if (index == 0)
return l_seq_push_front(_list_, elements, size);
return l_seq_push_front(_list_, values, size);
else if (index == _list_->count)
return l_seq_push_back(_list_, elements, size);
return l_seq_push_back(_list_, values, size);
if (!l_fits(_list_, size))
{
if (!l_resize(_list_, _list_->count + size))
@@ -309,14 +309,14 @@ _Bool l_seq_push_at(struct list *_list_, size_t *elements, size_t size,
}
memmove(_list_->buffer + index + size, _list_->buffer + index,
(_list_->count - index) * sizeof(size_t));
memcpy(_list_->buffer + index, elements, size * sizeof(size_t));
memcpy(_list_->buffer + index, values, size * sizeof(size_t));
_list_->count += size;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
_list_->callbacks->create();
return 1;
}
_Bool l_seq_push_back(struct list *_list_, size_t *elements, size_t size)
_Bool l_seq_push_back(struct list *_list_, size_t *values, size_t size)
{
if (size == 0)
{
@@ -328,7 +328,7 @@ _Bool l_seq_push_back(struct list *_list_, size_t *elements, size_t size)
if (!l_resize(_list_, _list_->count + size))
return 0;
}
memcpy(_list_->buffer + _list_->count, elements, size * sizeof(size_t));
memcpy(_list_->buffer + _list_->count, values, size * sizeof(size_t));
_list_->count += size;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
@@ -446,7 +446,7 @@ size_t l_back(struct list *_list_)
_list_->callbacks->read();
return _list_->buffer[_list_->count - 1];
}
size_t l_index_of(struct list *_list_, size_t element, _Bool from_start)
size_t l_index_of(struct list *_list_, size_t value, _Bool from_start)
{
_list_->flag = cmc_flags.OK;
size_t result = _list_->count;
@@ -454,7 +454,7 @@ size_t l_index_of(struct list *_list_, size_t element, _Bool from_start)
{
for (size_t i = 0; i < _list_->count; i++)
{
if (_list_->f_val->cmp(_list_->buffer[i], element) == 0)
if (_list_->f_val->cmp(_list_->buffer[i], value) == 0)
{
result = i;
break;
@@ -465,7 +465,7 @@ size_t l_index_of(struct list *_list_, size_t element, _Bool from_start)
{
for (size_t i = _list_->count; i > 0; i--)
{
if (_list_->f_val->cmp(_list_->buffer[i - 1], element) == 0)
if (_list_->f_val->cmp(_list_->buffer[i - 1], value) == 0)
{
result = i - 1;
break;
@@ -476,13 +476,13 @@ size_t l_index_of(struct list *_list_, size_t element, _Bool from_start)
_list_->callbacks->read();
return result;
}
_Bool l_contains(struct list *_list_, size_t element)
_Bool l_contains(struct list *_list_, size_t value)
{
_list_->flag = cmc_flags.OK;
_Bool result = 0;
for (size_t i = 0; i < _list_->count; i++)
{
if (_list_->f_val->cmp(_list_->buffer[i], element) == 0)
if (_list_->f_val->cmp(_list_->buffer[i], value) == 0)
{
result = 1;
break;
+38 -39
View File
@@ -50,15 +50,15 @@ void ms_clear(struct multiset *_set_);
void ms_free(struct multiset *_set_);
void ms_customize(struct multiset *_set_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool ms_insert(struct multiset *_set_, size_t element);
_Bool ms_insert_many(struct multiset *_set_, size_t element, size_t count);
_Bool ms_update(struct multiset *_set_, size_t element, size_t multiplicity);
_Bool ms_remove(struct multiset *_set_, size_t element);
size_t ms_remove_all(struct multiset *_set_, size_t element);
_Bool ms_insert(struct multiset *_set_, size_t value);
_Bool ms_insert_many(struct multiset *_set_, size_t value, size_t count);
_Bool ms_update(struct multiset *_set_, size_t value, size_t multiplicity);
_Bool ms_remove(struct multiset *_set_, size_t value);
size_t ms_remove_all(struct multiset *_set_, size_t value);
_Bool ms_max(struct multiset *_set_, size_t *value);
_Bool ms_min(struct multiset *_set_, size_t *value);
size_t ms_multiplicity_of(struct multiset *_set_, size_t element);
_Bool ms_contains(struct multiset *_set_, size_t element);
size_t ms_multiplicity_of(struct multiset *_set_, size_t value);
_Bool ms_contains(struct multiset *_set_, size_t value);
_Bool ms_empty(struct multiset *_set_);
_Bool ms_full(struct multiset *_set_);
size_t ms_count(struct multiset *_set_);
@@ -99,12 +99,12 @@ _Bool ms_iter_go_to(struct multiset_iter *iter, size_t index);
size_t ms_iter_value(struct multiset_iter *iter);
size_t ms_iter_multiplicity(struct multiset_iter *iter);
size_t ms_iter_index(struct multiset_iter *iter);
static size_t ms_impl_multiplicity_of(struct multiset *_set_, size_t element);
static size_t ms_impl_multiplicity_of(struct multiset *_set_, size_t value);
static struct multiset_entry *ms_impl_insert_and_return(struct multiset *_set_,
size_t element,
size_t value,
_Bool *new_node);
static struct multiset_entry *ms_impl_get_entry(struct multiset *_set_,
size_t element);
size_t value);
static size_t ms_impl_calculate_size(size_t required);
static struct multiset_iter ms_impl_it_start(struct multiset *_set_);
static struct multiset_iter ms_impl_it_end(struct multiset *_set_);
@@ -218,11 +218,11 @@ void ms_customize(struct multiset *_set_, struct cmc_alloc_node *alloc,
_set_->callbacks = callbacks;
_set_->flag = cmc_flags.OK;
}
_Bool ms_insert(struct multiset *_set_, size_t element)
_Bool ms_insert(struct multiset *_set_, size_t value)
{
_Bool new_node;
struct multiset_entry *entry =
ms_impl_insert_and_return(_set_, element, &new_node);
ms_impl_insert_and_return(_set_, value, &new_node);
if (!entry)
{
_set_->flag = cmc_flags.ERROR;
@@ -236,13 +236,13 @@ _Bool ms_insert(struct multiset *_set_, size_t element)
_set_->callbacks->create();
return 1;
}
_Bool ms_insert_many(struct multiset *_set_, size_t element, size_t count)
_Bool ms_insert_many(struct multiset *_set_, size_t value, size_t count)
{
if (count == 0)
goto success;
_Bool new_node;
struct multiset_entry *entry =
ms_impl_insert_and_return(_set_, element, &new_node);
ms_impl_insert_and_return(_set_, value, &new_node);
if (!entry)
{
_set_->flag = cmc_flags.ERROR;
@@ -259,11 +259,11 @@ success:
_set_->callbacks->create();
return 1;
}
_Bool ms_update(struct multiset *_set_, size_t element, size_t multiplicity)
_Bool ms_update(struct multiset *_set_, size_t value, size_t multiplicity)
{
if (multiplicity == 0)
{
struct multiset_entry *result = ms_impl_get_entry(_set_, element);
struct multiset_entry *result = ms_impl_get_entry(_set_, value);
if (!result)
goto success;
_set_->count--;
@@ -276,7 +276,7 @@ _Bool ms_update(struct multiset *_set_, size_t element, size_t multiplicity)
}
_Bool new_node;
struct multiset_entry *entry =
ms_impl_insert_and_return(_set_, element, &new_node);
ms_impl_insert_and_return(_set_, value, &new_node);
if (!entry)
return 0;
if (new_node)
@@ -290,14 +290,14 @@ success:
_set_->callbacks->update();
return 1;
}
_Bool ms_remove(struct multiset *_set_, size_t element)
_Bool ms_remove(struct multiset *_set_, size_t value)
{
if (ms_empty(_set_))
{
_set_->flag = cmc_flags.EMPTY;
return 0;
}
struct multiset_entry *result = ms_impl_get_entry(_set_, element);
struct multiset_entry *result = ms_impl_get_entry(_set_, value);
if (!result)
{
_set_->flag = cmc_flags.NOT_FOUND;
@@ -319,14 +319,14 @@ _Bool ms_remove(struct multiset *_set_, size_t element)
_set_->callbacks->delete ();
return 1;
}
size_t ms_remove_all(struct multiset *_set_, size_t element)
size_t ms_remove_all(struct multiset *_set_, size_t value)
{
if (ms_empty(_set_))
{
_set_->flag = cmc_flags.EMPTY;
return 0;
}
struct multiset_entry *result = ms_impl_get_entry(_set_, element);
struct multiset_entry *result = ms_impl_get_entry(_set_, value);
if (!result)
{
_set_->flag = cmc_flags.NOT_FOUND;
@@ -394,9 +394,9 @@ _Bool ms_min(struct multiset *_set_, size_t *value)
_set_->callbacks->read();
return 1;
}
size_t ms_multiplicity_of(struct multiset *_set_, size_t element)
size_t ms_multiplicity_of(struct multiset *_set_, size_t value)
{
struct multiset_entry *entry = ms_impl_get_entry(_set_, element);
struct multiset_entry *entry = ms_impl_get_entry(_set_, value);
_set_->flag = cmc_flags.OK;
if (_set_->callbacks && _set_->callbacks->read)
_set_->callbacks->read();
@@ -404,10 +404,10 @@ size_t ms_multiplicity_of(struct multiset *_set_, size_t element)
return 0;
return entry->multiplicity;
}
_Bool ms_contains(struct multiset *_set_, size_t element)
_Bool ms_contains(struct multiset *_set_, size_t value)
{
_set_->flag = cmc_flags.OK;
_Bool result = ms_impl_get_entry(_set_, element) != ((void *)0);
_Bool result = ms_impl_get_entry(_set_, value) != ((void *)0);
if (_set_->callbacks && _set_->callbacks->read)
_set_->callbacks->read();
return result;
@@ -937,19 +937,18 @@ size_t ms_iter_index(struct multiset_iter *iter)
{
return iter->index;
}
static size_t ms_impl_multiplicity_of(struct multiset *_set_, size_t element)
static size_t ms_impl_multiplicity_of(struct multiset *_set_, size_t value)
{
struct multiset_entry *entry = ms_impl_get_entry(_set_, element);
struct multiset_entry *entry = ms_impl_get_entry(_set_, value);
if (!entry)
return 0;
return entry->multiplicity;
}
static struct multiset_entry *ms_impl_insert_and_return(struct multiset *_set_,
size_t element,
_Bool *new_node)
static struct multiset_entry *
ms_impl_insert_and_return(struct multiset *_set_, size_t value, _Bool *new_node)
{
*new_node = 0;
struct multiset_entry *entry = ms_impl_get_entry(_set_, element);
struct multiset_entry *entry = ms_impl_get_entry(_set_, value);
if (entry != ((void *)0))
return entry;
*new_node = 1;
@@ -958,14 +957,14 @@ static struct multiset_entry *ms_impl_insert_and_return(struct multiset *_set_,
if (!ms_resize(_set_, _set_->capacity + 1))
return ((void *)0);
}
size_t hash = _set_->f_val->hash(element);
size_t hash = _set_->f_val->hash(value);
size_t original_pos = hash % _set_->capacity;
size_t pos = original_pos;
size_t curr_mul = 1;
struct multiset_entry *target = &(_set_->buffer[pos]);
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED)
{
target->value = element;
target->value = value;
target->multiplicity = curr_mul;
target->dist = pos - original_pos;
target->state = CMC_ES_FILLED;
@@ -979,7 +978,7 @@ static struct multiset_entry *ms_impl_insert_and_return(struct multiset *_set_,
if (target->state == CMC_ES_EMPTY ||
target->state == CMC_ES_DELETED)
{
target->value = element;
target->value = value;
target->multiplicity = curr_mul;
target->dist = pos - original_pos;
target->state = CMC_ES_FILLED;
@@ -990,10 +989,10 @@ static struct multiset_entry *ms_impl_insert_and_return(struct multiset *_set_,
size_t tmp = target->value;
size_t tmp_dist = target->dist;
size_t tmp_mul = target->multiplicity;
target->value = element;
target->value = value;
target->dist = pos - original_pos;
target->multiplicity = curr_mul;
element = tmp;
value = tmp;
original_pos = pos - tmp_dist;
curr_mul = tmp_mul;
}
@@ -1003,14 +1002,14 @@ static struct multiset_entry *ms_impl_insert_and_return(struct multiset *_set_,
return target;
}
static struct multiset_entry *ms_impl_get_entry(struct multiset *_set_,
size_t element)
size_t value)
{
size_t hash = _set_->f_val->hash(element);
size_t hash = _set_->f_val->hash(value);
size_t pos = hash % _set_->capacity;
struct multiset_entry *target = &(_set_->buffer[pos]);
while (target->state == CMC_ES_FILLED || target->state == CMC_ES_DELETED)
{
if (_set_->f_val->cmp(target->value, element) == 0)
if (_set_->f_val->cmp(target->value, value) == 0)
return target;
pos++;
target = &(_set_->buffer[pos % _set_->capacity]);
+6 -6
View File
@@ -39,10 +39,10 @@ void q_clear(struct queue *_queue_);
void q_free(struct queue *_queue_);
void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool q_enqueue(struct queue *_queue_, size_t element);
_Bool q_enqueue(struct queue *_queue_, size_t value);
_Bool q_dequeue(struct queue *_queue_);
size_t q_peek(struct queue *_queue_);
_Bool q_contains(struct queue *_queue_, size_t element);
_Bool q_contains(struct queue *_queue_, size_t value);
_Bool q_empty(struct queue *_queue_);
_Bool q_full(struct queue *_queue_);
size_t q_count(struct queue *_queue_);
@@ -168,14 +168,14 @@ void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc,
_queue_->callbacks = callbacks;
_queue_->flag = cmc_flags.OK;
}
_Bool q_enqueue(struct queue *_queue_, size_t element)
_Bool q_enqueue(struct queue *_queue_, size_t value)
{
if (q_full(_queue_))
{
if (!q_resize(_queue_, _queue_->capacity * 2))
return 0;
}
_queue_->buffer[_queue_->back] = element;
_queue_->buffer[_queue_->back] = value;
_queue_->back =
(_queue_->back == _queue_->capacity - 1) ? 0 : _queue_->back + 1;
_queue_->count++;
@@ -212,13 +212,13 @@ size_t q_peek(struct queue *_queue_)
_queue_->callbacks->read();
return _queue_->buffer[_queue_->front];
}
_Bool q_contains(struct queue *_queue_, size_t element)
_Bool q_contains(struct queue *_queue_, size_t value)
{
_queue_->flag = cmc_flags.OK;
_Bool result = 0;
for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++)
{
if (_queue_->f_val->cmp(_queue_->buffer[i], element) == 0)
if (_queue_->f_val->cmp(_queue_->buffer[i], value) == 0)
{
result = 1;
break;
+10 -10
View File
@@ -37,13 +37,13 @@ void sl_clear(struct sortedlist *_list_);
void sl_free(struct sortedlist *_list_);
void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool sl_insert(struct sortedlist *_list_, size_t element);
_Bool sl_insert(struct sortedlist *_list_, size_t value);
_Bool sl_remove(struct sortedlist *_list_, size_t index);
size_t sl_max(struct sortedlist *_list_);
size_t sl_min(struct sortedlist *_list_);
size_t sl_get(struct sortedlist *_list_, size_t index);
size_t sl_index_of(struct sortedlist *_list_, size_t element, _Bool from_start);
_Bool sl_contains(struct sortedlist *_list_, size_t element);
size_t sl_index_of(struct sortedlist *_list_, size_t value, _Bool from_start);
_Bool sl_contains(struct sortedlist *_list_, size_t value);
_Bool sl_empty(struct sortedlist *_list_);
_Bool sl_full(struct sortedlist *_list_);
size_t sl_count(struct sortedlist *_list_);
@@ -165,14 +165,14 @@ void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc,
_list_->callbacks = callbacks;
_list_->flag = cmc_flags.OK;
}
_Bool sl_insert(struct sortedlist *_list_, size_t element)
_Bool sl_insert(struct sortedlist *_list_, size_t value)
{
if (sl_full(_list_))
{
if (!sl_resize(_list_, _list_->capacity * 2))
return 0;
}
_list_->buffer[_list_->count++] = element;
_list_->buffer[_list_->count++] = value;
_list_->is_sorted = 0;
_list_->flag = cmc_flags.OK;
if (_list_->callbacks && _list_->callbacks->create)
@@ -243,7 +243,7 @@ size_t sl_get(struct sortedlist *_list_, size_t index)
_list_->callbacks->read();
return _list_->buffer[index];
}
size_t sl_index_of(struct sortedlist *_list_, size_t element, _Bool from_start)
size_t sl_index_of(struct sortedlist *_list_, size_t value, _Bool from_start)
{
_list_->flag = cmc_flags.OK;
sl_sort(_list_);
@@ -251,11 +251,11 @@ size_t sl_index_of(struct sortedlist *_list_, size_t element, _Bool from_start)
_list_->callbacks->read();
if (from_start)
{
return sl_impl_binary_search_first(_list_, element);
return sl_impl_binary_search_first(_list_, value);
}
return sl_impl_binary_search_last(_list_, element);
return sl_impl_binary_search_last(_list_, value);
}
_Bool sl_contains(struct sortedlist *_list_, size_t element)
_Bool sl_contains(struct sortedlist *_list_, size_t value)
{
_list_->flag = cmc_flags.OK;
if (sl_empty(_list_))
@@ -263,7 +263,7 @@ _Bool sl_contains(struct sortedlist *_list_, size_t element)
sl_sort(_list_);
if (_list_->callbacks && _list_->callbacks->read)
_list_->callbacks->read();
return sl_impl_binary_search_first(_list_, element) < _list_->count;
return sl_impl_binary_search_first(_list_, value) < _list_->count;
}
_Bool sl_empty(struct sortedlist *_list_)
{
+6 -6
View File
@@ -36,10 +36,10 @@ void s_clear(struct stack *_stack_);
void s_free(struct stack *_stack_);
void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool s_push(struct stack *_stack_, size_t element);
_Bool s_push(struct stack *_stack_, size_t value);
_Bool s_pop(struct stack *_stack_);
size_t s_top(struct stack *_stack_);
_Bool s_contains(struct stack *_stack_, size_t element);
_Bool s_contains(struct stack *_stack_, size_t value);
_Bool s_empty(struct stack *_stack_);
_Bool s_full(struct stack *_stack_);
size_t s_count(struct stack *_stack_);
@@ -153,14 +153,14 @@ void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc,
_stack_->callbacks = callbacks;
_stack_->flag = cmc_flags.OK;
}
_Bool s_push(struct stack *_stack_, size_t element)
_Bool s_push(struct stack *_stack_, size_t value)
{
if (s_full(_stack_))
{
if (!s_resize(_stack_, _stack_->capacity * 2))
return 0;
}
_stack_->buffer[_stack_->count++] = element;
_stack_->buffer[_stack_->count++] = value;
_stack_->flag = cmc_flags.OK;
if (_stack_->callbacks && _stack_->callbacks->create)
_stack_->callbacks->create();
@@ -191,13 +191,13 @@ size_t s_top(struct stack *_stack_)
_stack_->callbacks->read();
return _stack_->buffer[_stack_->count - 1];
}
_Bool s_contains(struct stack *_stack_, size_t element)
_Bool s_contains(struct stack *_stack_, size_t value)
{
_stack_->flag = cmc_flags.OK;
_Bool result = 0;
for (size_t i = 0; i < _stack_->count; i++)
{
if (_stack_->f_val->cmp(_stack_->buffer[i], element) == 0)
if (_stack_->f_val->cmp(_stack_->buffer[i], value) == 0)
{
result = 1;
break;
+21 -21
View File
@@ -46,11 +46,11 @@ void ts_clear(struct treeset *_set_);
void ts_free(struct treeset *_set_);
void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc,
struct cmc_callbacks *callbacks);
_Bool ts_insert(struct treeset *_set_, size_t element);
_Bool ts_remove(struct treeset *_set_, size_t element);
_Bool ts_insert(struct treeset *_set_, size_t value);
_Bool ts_remove(struct treeset *_set_, size_t value);
_Bool ts_max(struct treeset *_set_, size_t *value);
_Bool ts_min(struct treeset *_set_, size_t *value);
_Bool ts_contains(struct treeset *_set_, size_t element);
_Bool ts_contains(struct treeset *_set_, size_t value);
_Bool ts_empty(struct treeset *_set_);
size_t ts_count(struct treeset *_set_);
int ts_flag(struct treeset *_set_);
@@ -89,9 +89,9 @@ static inline size_t ts_impl_default_value(void)
return _empty_value_;
}
static struct treeset_node *ts_impl_new_node(struct treeset *_set_,
size_t element);
size_t value);
static struct treeset_node *ts_impl_get_node(struct treeset *_set_,
size_t element);
size_t value);
static unsigned char ts_impl_h(struct treeset_node *node);
static unsigned char ts_impl_hupdate(struct treeset_node *node);
static void ts_impl_rotate_right(struct treeset_node **Z);
@@ -206,11 +206,11 @@ void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc,
_set_->callbacks = callbacks;
_set_->flag = cmc_flags.OK;
}
_Bool ts_insert(struct treeset *_set_, size_t element)
_Bool ts_insert(struct treeset *_set_, size_t value)
{
if (ts_empty(_set_))
{
_set_->root = ts_impl_new_node(_set_, element);
_set_->root = ts_impl_new_node(_set_, value);
if (!_set_->root)
{
_set_->flag = cmc_flags.ALLOC;
@@ -224,9 +224,9 @@ _Bool ts_insert(struct treeset *_set_, size_t element)
while (scan != ((void *)0))
{
parent = scan;
if (_set_->f_val->cmp(scan->value, element) > 0)
if (_set_->f_val->cmp(scan->value, value) > 0)
scan = scan->left;
else if (_set_->f_val->cmp(scan->value, element) < 0)
else if (_set_->f_val->cmp(scan->value, value) < 0)
scan = scan->right;
else
{
@@ -235,9 +235,9 @@ _Bool ts_insert(struct treeset *_set_, size_t element)
}
}
struct treeset_node *node;
if (_set_->f_val->cmp(parent->value, element) > 0)
if (_set_->f_val->cmp(parent->value, value) > 0)
{
parent->left = ts_impl_new_node(_set_, element);
parent->left = ts_impl_new_node(_set_, value);
if (!parent->left)
{
_set_->flag = cmc_flags.ALLOC;
@@ -248,7 +248,7 @@ _Bool ts_insert(struct treeset *_set_, size_t element)
}
else
{
parent->right = ts_impl_new_node(_set_, element);
parent->right = ts_impl_new_node(_set_, value);
if (!parent->right)
{
_set_->flag = cmc_flags.ALLOC;
@@ -265,14 +265,14 @@ _Bool ts_insert(struct treeset *_set_, size_t element)
_set_->callbacks->create();
return 1;
}
_Bool ts_remove(struct treeset *_set_, size_t element)
_Bool ts_remove(struct treeset *_set_, size_t value)
{
if (ts_empty(_set_))
{
_set_->flag = cmc_flags.EMPTY;
return 0;
}
struct treeset_node *node = ts_impl_get_node(_set_, element);
struct treeset_node *node = ts_impl_get_node(_set_, value);
if (!node)
{
_set_->flag = cmc_flags.NOT_FOUND;
@@ -407,9 +407,9 @@ _Bool ts_min(struct treeset *_set_, size_t *value)
_set_->callbacks->read();
return 1;
}
_Bool ts_contains(struct treeset *_set_, size_t element)
_Bool ts_contains(struct treeset *_set_, size_t value)
{
_Bool result = ts_impl_get_node(_set_, element) != ((void *)0);
_Bool result = ts_impl_get_node(_set_, value) != ((void *)0);
if (_set_->callbacks && _set_->callbacks->read)
_set_->callbacks->read();
return result;
@@ -811,13 +811,13 @@ size_t ts_iter_index(struct treeset_iter *iter)
return iter->index;
}
static struct treeset_node *ts_impl_new_node(struct treeset *_set_,
size_t element)
size_t value)
{
struct treeset_node *node =
_set_->alloc->malloc(sizeof(struct treeset_node));
if (!node)
return ((void *)0);
node->value = element;
node->value = value;
node->right = ((void *)0);
node->left = ((void *)0);
node->parent = ((void *)0);
@@ -825,14 +825,14 @@ static struct treeset_node *ts_impl_new_node(struct treeset *_set_,
return node;
}
static struct treeset_node *ts_impl_get_node(struct treeset *_set_,
size_t element)
size_t value)
{
struct treeset_node *scan = _set_->root;
while (scan != ((void *)0))
{
if (_set_->f_val->cmp(scan->value, element) > 0)
if (_set_->f_val->cmp(scan->value, value) > 0)
scan = scan->left;
else if (_set_->f_val->cmp(scan->value, element) < 0)
else if (_set_->f_val->cmp(scan->value, value) < 0)
scan = scan->right;
else
return scan;