Refactoring: renaming 'element' to 'value'
This commit is contained in:
1 parent
980fb6d432
commit
2e48a033a0
22 files changed
+510
-513
No files matched your search
+9
-9
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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; \
|
||||
|
||||
Reference in new issue
Block a user