Added print function and renamed 'data' to 'value' in linkedlist
This commit is contained in:
1 parent
9999275ad0
commit
d4f30e3693
5 files changed
+103
-43
No files matched your search
+30
-14
@@ -164,8 +164,8 @@ struct cmc_callbacks_linkedlist
|
||||
/* Doubly-linked list node */ \
|
||||
struct SNAME##_node \
|
||||
{ \
|
||||
/* Node's data */ \
|
||||
V data; \
|
||||
/* Node's value */ \
|
||||
V value; \
|
||||
\
|
||||
/* Pointer to the next node on the linked list */ \
|
||||
struct SNAME##_node *next; \
|
||||
@@ -247,6 +247,7 @@ struct cmc_callbacks_linkedlist
|
||||
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); \
|
||||
\
|
||||
/* Node Related Functions */ \
|
||||
/* Node Allocation and Deallocation */ \
|
||||
@@ -363,7 +364,7 @@ struct cmc_callbacks_linkedlist
|
||||
\
|
||||
if (_list_->f_val->free) \
|
||||
{ \
|
||||
_list_->f_val->free(scan->data); \
|
||||
_list_->f_val->free(scan->value); \
|
||||
} \
|
||||
\
|
||||
_list_->alloc->free(scan); \
|
||||
@@ -578,7 +579,7 @@ struct cmc_callbacks_linkedlist
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
return _list_->head->data; \
|
||||
return _list_->head->value; \
|
||||
} \
|
||||
\
|
||||
V PFX##_get(struct SNAME *_list_, size_t index) \
|
||||
@@ -600,7 +601,7 @@ struct cmc_callbacks_linkedlist
|
||||
if (scan == NULL) \
|
||||
return (V){ 0 }; \
|
||||
\
|
||||
return scan->data; \
|
||||
return scan->value; \
|
||||
} \
|
||||
\
|
||||
V *PFX##_get_ref(struct SNAME *_list_, size_t index) \
|
||||
@@ -622,7 +623,7 @@ struct cmc_callbacks_linkedlist
|
||||
if (scan == NULL) \
|
||||
return NULL; \
|
||||
\
|
||||
return &(scan->data); \
|
||||
return &(scan->value); \
|
||||
} \
|
||||
\
|
||||
V PFX##_back(struct SNAME *_list_) \
|
||||
@@ -635,7 +636,7 @@ struct cmc_callbacks_linkedlist
|
||||
\
|
||||
_list_->flag = cmc_flags.OK; \
|
||||
\
|
||||
return _list_->tail->data; \
|
||||
return _list_->tail->value; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_contains(struct SNAME *_list_, V element) \
|
||||
@@ -646,7 +647,7 @@ struct cmc_callbacks_linkedlist
|
||||
\
|
||||
while (scan != NULL) \
|
||||
{ \
|
||||
if (_list_->f_val->cmp(scan->data, element) == 0) \
|
||||
if (_list_->f_val->cmp(scan->value, element) == 0) \
|
||||
return true; \
|
||||
\
|
||||
scan = scan->next; \
|
||||
@@ -688,9 +689,9 @@ struct cmc_callbacks_linkedlist
|
||||
\
|
||||
if (_list_->f_val->cpy) \
|
||||
new_node = \
|
||||
PFX##_new_node(_list_, _list_->f_val->cpy(scan->data)); \
|
||||
PFX##_new_node(_list_, _list_->f_val->cpy(scan->value)); \
|
||||
else \
|
||||
new_node = PFX##_new_node(_list_, scan->data); \
|
||||
new_node = PFX##_new_node(_list_, scan->value); \
|
||||
\
|
||||
if (!result->head) \
|
||||
{ \
|
||||
@@ -727,7 +728,7 @@ struct cmc_callbacks_linkedlist
|
||||
\
|
||||
while (scan1 != NULL && scan2 != NULL) \
|
||||
{ \
|
||||
if (_list1_->f_val->cmp(scan1->data, scan2->data) != 0) \
|
||||
if (_list1_->f_val->cmp(scan1->value, scan2->value) != 0) \
|
||||
return false; \
|
||||
\
|
||||
scan1 = scan1->next; \
|
||||
@@ -749,6 +750,21 @@ struct cmc_callbacks_linkedlist
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 }; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_print(struct SNAME *_list_, FILE *fptr) \
|
||||
{ \
|
||||
struct SNAME##_node *scan = _list_->head; \
|
||||
\
|
||||
while (scan != NULL) \
|
||||
{ \
|
||||
if (!_list_->f_val->str(fptr, scan->value)) \
|
||||
return false; \
|
||||
\
|
||||
scan = scan->next; \
|
||||
} \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct SNAME##_node *PFX##_new_node(struct SNAME *_list_, V element) \
|
||||
{ \
|
||||
struct SNAME##_node *_node_ = \
|
||||
@@ -760,7 +776,7 @@ struct cmc_callbacks_linkedlist
|
||||
return NULL; \
|
||||
} \
|
||||
\
|
||||
_node_->data = element; \
|
||||
_node_->value = element; \
|
||||
_node_->next = NULL; \
|
||||
_node_->prev = NULL; \
|
||||
\
|
||||
@@ -1115,7 +1131,7 @@ struct cmc_callbacks_linkedlist
|
||||
if (PFX##_empty(iter->target)) \
|
||||
return (V){ 0 }; \
|
||||
\
|
||||
return iter->cursor->data; \
|
||||
return iter->cursor->value; \
|
||||
} \
|
||||
\
|
||||
V *PFX##_iter_rvalue(struct SNAME##_iter *iter) \
|
||||
@@ -1123,7 +1139,7 @@ struct cmc_callbacks_linkedlist
|
||||
if (PFX##_empty(iter->target)) \
|
||||
return NULL; \
|
||||
\
|
||||
return &(iter->cursor->data); \
|
||||
return &(iter->cursor->value); \
|
||||
} \
|
||||
\
|
||||
size_t PFX##_iter_index(struct SNAME##_iter *iter) \
|
||||
|
||||
@@ -259,6 +259,7 @@ struct cmc_callbacks_list
|
||||
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 */ \
|
||||
@@ -882,6 +883,17 @@ struct cmc_callbacks_list
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 }; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_print(struct SNAME *_list_, FILE *fptr) \
|
||||
{ \
|
||||
for (size_t i = 0; i < _list_->count; i++) \
|
||||
{ \
|
||||
if (!_list_->f_val->str(fptr, _list_->buffer[i])) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
|
||||
{ \
|
||||
struct SNAME##_iter *iter = \
|
||||
|
||||
+30
-29
@@ -360,6 +360,7 @@ struct cmc_callbacks_multimap
|
||||
struct SNAME *PFX##_copy_of(struct SNAME *_map_); \
|
||||
bool PFX##_equals(struct SNAME *_map1_, struct SNAME *_map2_); \
|
||||
struct cmc_string PFX##_to_string(struct SNAME *_map_); \
|
||||
bool PFX##_print(struct SNAME *_map_, FILE *fptr); \
|
||||
\
|
||||
/* Iterator Functions */ \
|
||||
/* Iterator Allocation and Deallocation */ \
|
||||
@@ -494,42 +495,23 @@ struct cmc_callbacks_multimap
|
||||
\
|
||||
void PFX##_clear(struct SNAME *_map_) \
|
||||
{ \
|
||||
size_t index = 0; \
|
||||
\
|
||||
while (index < _map_->capacity) \
|
||||
for (size_t i = 0; i < _map_->capacity; i++) \
|
||||
{ \
|
||||
struct SNAME##_entry *scan = _map_->buffer[index][0]; \
|
||||
struct SNAME##_entry *scan = _map_->buffer[i][0]; \
|
||||
\
|
||||
if (scan != NULL) \
|
||||
while (scan != NULL) \
|
||||
{ \
|
||||
if (scan->next == NULL && scan->prev == NULL) \
|
||||
{ \
|
||||
if (_map_->f_key->free) \
|
||||
_map_->f_key->free(scan->key); \
|
||||
if (_map_->f_val->free) \
|
||||
_map_->f_val->free(scan->value); \
|
||||
struct SNAME##_entry *next = scan->next; \
|
||||
\
|
||||
_map_->alloc->free(scan); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
while (scan != NULL) \
|
||||
{ \
|
||||
struct SNAME##_entry *tmp = scan; \
|
||||
if (_map_->f_key->free) \
|
||||
_map_->f_key->free(scan->key); \
|
||||
if (_map_->f_val->free) \
|
||||
_map_->f_val->free(scan->value); \
|
||||
\
|
||||
scan = scan->next; \
|
||||
_map_->alloc->free(scan); \
|
||||
\
|
||||
if (_map_->f_key->free) \
|
||||
_map_->f_key->free(tmp->key); \
|
||||
if (_map_->f_val->free) \
|
||||
_map_->f_val->free(tmp->value); \
|
||||
\
|
||||
_map_->alloc->free(tmp); \
|
||||
} \
|
||||
} \
|
||||
scan = next; \
|
||||
} \
|
||||
\
|
||||
index++; \
|
||||
} \
|
||||
\
|
||||
memset(_map_->buffer, 0, \
|
||||
@@ -1198,6 +1180,25 @@ struct cmc_callbacks_multimap
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 }; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_print(struct SNAME *_map_, FILE *fptr) \
|
||||
{ \
|
||||
for (size_t i = 0; i < _map_->capacity; i++) \
|
||||
{ \
|
||||
struct SNAME##_entry *scan = _map_->buffer[i][0]; \
|
||||
\
|
||||
while (scan != NULL) \
|
||||
{ \
|
||||
if (!_map_->f_key->str(fptr, scan->key) || \
|
||||
!_map_->f_val->str(fptr, scan->value)) \
|
||||
return false; \
|
||||
\
|
||||
scan = scan->next; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
|
||||
{ \
|
||||
struct SNAME##_iter *iter = \
|
||||
|
||||
@@ -323,6 +323,7 @@ struct cmc_callbacks_multiset
|
||||
struct SNAME *PFX##_copy_of(struct SNAME *_set_); \
|
||||
bool PFX##_equals(struct SNAME *_set1_, struct SNAME *_set2_); \
|
||||
struct cmc_string PFX##_to_string(struct SNAME *_set_); \
|
||||
bool PFX##_print(struct SNAME *_set_, FILE *fptr); \
|
||||
\
|
||||
/* Set Operations */ \
|
||||
struct SNAME *PFX##_union(struct SNAME *_set1_, struct SNAME *_set2_); \
|
||||
@@ -959,6 +960,22 @@ struct cmc_callbacks_multiset
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 }; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_print(struct SNAME *_set_, FILE *fptr) \
|
||||
{ \
|
||||
for (size_t i = 0; i < _set_->capacity; i++) \
|
||||
{ \
|
||||
struct SNAME##_entry *entry = &(_set_->buffer[i]); \
|
||||
\
|
||||
if (entry->state == CMC_ES_FILLED) \
|
||||
{ \
|
||||
if (!_set_->f_val->str(fptr, entry->value)) \
|
||||
return false; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_union(struct SNAME *_set1_, struct SNAME *_set2_) \
|
||||
{ \
|
||||
struct SNAME *_set_r_ = \
|
||||
|
||||
@@ -253,6 +253,7 @@ struct cmc_callbacks_queue
|
||||
struct SNAME *PFX##_copy_of(struct SNAME *_queue_); \
|
||||
bool PFX##_equals(struct SNAME *_queue1_, struct SNAME *_queue2_); \
|
||||
struct cmc_string PFX##_to_string(struct SNAME *_queue_); \
|
||||
bool PFX##_print(struct SNAME *_queue_, FILE *fptr); \
|
||||
\
|
||||
/* Iterator Functions */ \
|
||||
/* Iterator Allocation and Deallocation */ \
|
||||
@@ -614,6 +615,19 @@ struct cmc_callbacks_queue
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 }; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_print(struct SNAME *_queue_, FILE *fptr) \
|
||||
{ \
|
||||
for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++) \
|
||||
{ \
|
||||
if (!_queue_->f_val->str(fptr, _queue_->buffer[i])) \
|
||||
return false; \
|
||||
\
|
||||
i = (i + 1) % _queue_->capacity; \
|
||||
} \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
|
||||
{ \
|
||||
struct SNAME##_iter *iter = \
|
||||
|
||||
Reference in new issue
Block a user