Renamed list and linkedlist functions

push - push_at
pop - pop_at

The list prepend, append and insert - seq_push_front, seq_push_back, seq_push_at
This commit is contained in:
Leonardo committed 2019-09-21 00:37:56 -03:00
1 parent 2c84c35264
commit 344e9f77fe
2 files changed
+29 -26

No files matched your search

+6 -6
View File
@@ -112,10 +112,10 @@ static const char *cmc_string_fmt_linkedlist = "%s at %p { count:%" PRIuMAX ", h
void PFX##_free(SNAME *_list_, void (*deallocator)(V)); \
/* Collection Input and Output */ \
bool PFX##_push_front(SNAME *_list_, V element); \
bool PFX##_push(SNAME *_list_, V element, size_t index); \
bool PFX##_push_at(SNAME *_list_, V element, size_t index); \
bool PFX##_push_back(SNAME *_list_, V element); \
bool PFX##_pop_front(SNAME *_list_); \
bool PFX##_pop(SNAME *_list_, size_t index); \
bool PFX##_pop_at(SNAME *_list_, size_t index); \
bool PFX##_pop_back(SNAME *_list_); \
/* Conditional Input and Output */ \
bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition); \
@@ -263,7 +263,7 @@ static const char *cmc_string_fmt_linkedlist = "%s at %p { count:%" PRIuMAX ", h
return true; \
} \
\
bool PFX##_push(SNAME *_list_, V element, size_t index) \
bool PFX##_push_at(SNAME *_list_, V element, size_t index) \
{ \
if (index > _list_->count) \
return false; \
@@ -338,7 +338,7 @@ static const char *cmc_string_fmt_linkedlist = "%s at %p { count:%" PRIuMAX ", h
return true; \
} \
\
bool PFX##_pop(SNAME *_list_, size_t index) \
bool PFX##_pop_at(SNAME *_list_, size_t index) \
{ \
if (PFX##_empty(_list_)) \
return false; \
@@ -393,7 +393,7 @@ static const char *cmc_string_fmt_linkedlist = "%s at %p { count:%" PRIuMAX ", h
bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition) \
{ \
if (condition) \
return PFX##_push(_list_, element, index); \
return PFX##_push_at(_list_, element, index); \
\
return false; \
} \
@@ -401,7 +401,7 @@ static const char *cmc_string_fmt_linkedlist = "%s at %p { count:%" PRIuMAX ", h
bool PFX##_pop_if(SNAME *_list_, size_t index, bool condition) \
{ \
if (condition) \
return PFX##_pop(_list_, index); \
return PFX##_pop_at(_list_, index); \
\
return false; \
} \
+23 -20
View File
@@ -111,20 +111,20 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
void PFX##_free(SNAME *_list_, void (*deallocator)(V)); \
/* Collection Input and Output */ \
bool PFX##_push_front(SNAME *_list_, V element); \
bool PFX##_push(SNAME *_list_, V element, size_t index); \
bool PFX##_push_at(SNAME *_list_, V element, size_t index); \
bool PFX##_push_back(SNAME *_list_, V element); \
bool PFX##_pop_front(SNAME *_list_); \
bool PFX##_pop(SNAME *_list_, size_t index); \
bool PFX##_pop_at(SNAME *_list_, size_t index); \
bool PFX##_pop_back(SNAME *_list_); \
/* Conditional Input and Output */ \
bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition); \
bool PFX##_pop_if(SNAME *_list_, size_t index, bool condition); \
/* Collection Range Input and Output */ \
bool PFX##_prepend(SNAME *_list_, V *elements, size_t size); \
bool PFX##_insert(SNAME *_list_, V *elements, size_t size, size_t index); \
bool PFX##_append(SNAME *_list_, V *elements, size_t size); \
bool PFX##_remove(SNAME *_list_, size_t from, size_t to); \
SNAME *PFX##_extract(SNAME *_list_, size_t from, size_t to); \
/* Collection Sequence Input and Output */ \
bool PFX##_seq_push_front(SNAME *_list_, V *elements, size_t size); \
bool PFX##_seq_push_at(SNAME *_list_, V *elements, size_t size, size_t index); \
bool PFX##_seq_push_back(SNAME *_list_, V *elements, size_t size); \
bool PFX##_seq_pop_at(SNAME *_list_, size_t from, size_t to); \
SNAME *PFX##_seq_sublist(SNAME *_list_, size_t from, size_t to); \
/* Element Access */ \
V PFX##_front(SNAME *_list_); \
V PFX##_get(SNAME *_list_, size_t index); \
@@ -274,7 +274,7 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
return true; \
} \
\
bool PFX##_push(SNAME *_list_, V element, size_t index) \
bool PFX##_push_at(SNAME *_list_, V element, size_t index) \
{ \
if (index > _list_->count) \
return false; \
@@ -328,7 +328,7 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
return true; \
} \
\
bool PFX##_pop(SNAME *_list_, size_t index) \
bool PFX##_pop_at(SNAME *_list_, size_t index) \
{ \
if (PFX##_empty(_list_)) \
return false; \
@@ -365,7 +365,7 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition) \
{ \
if (condition) \
return PFX##_push(_list_, element, index); \
return PFX##_push_at(_list_, element, index); \
\
return false; \
} \
@@ -373,12 +373,12 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
bool PFX##_pop_if(SNAME *_list_, size_t index, bool condition) \
{ \
if (condition) \
return PFX##_pop(_list_, index); \
return PFX##_pop_at(_list_, index); \
\
return false; \
} \
\
bool PFX##_prepend(SNAME *_list_, V *elements, size_t size) \
bool PFX##_seq_push_front(SNAME *_list_, V *elements, size_t size) \
{ \
if (size == 0) \
return false; \
@@ -398,15 +398,15 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
return true; \
} \
\
bool PFX##_insert(SNAME *_list_, V *elements, size_t size, size_t index) \
bool PFX##_seq_push_at(SNAME *_list_, V *elements, size_t size, size_t index) \
{ \
if (size == 0 || index > _list_->count) \
return false; \
\
if (index == 0) \
return PFX##_prepend(_list_, elements, size); \
return PFX##_seq_push_front(_list_, elements, size); \
else if (index == _list_->count) \
return PFX##_append(_list_, elements, size); \
return PFX##_seq_push_back(_list_, elements, size); \
else \
{ \
if (!PFX##_fits(_list_, size)) \
@@ -425,7 +425,7 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
return true; \
} \
\
bool PFX##_append(SNAME *_list_, V *elements, size_t size) \
bool PFX##_seq_push_back(SNAME *_list_, V *elements, size_t size) \
{ \
if (size == 0) \
return false; \
@@ -443,7 +443,7 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
return true; \
} \
\
bool PFX##_remove(SNAME *_list_, size_t from, size_t to) \
bool PFX##_seq_pop_at(SNAME *_list_, size_t from, size_t to) \
{ \
if (from > to || to >= _list_->count) \
return false; \
@@ -459,23 +459,26 @@ static const char *cmc_string_fmt_list = "%s at %p { buffer:%p, capacity:%" PRIu
return true; \
} \
\
SNAME *PFX##_extract(SNAME *_list_, size_t from, size_t to) \
SNAME *PFX##_seq_sublist(SNAME *_list_, size_t from, size_t to) \
{ \
if (from > to || to >= _list_->count) \
return false; \
\
size_t length = to - from + 1; \
\
SNAME *result = PFX##_new_from(_list_->buffer + from, length); \
SNAME *result = PFX##_new(length); \
\
if (!result) \
return NULL; \
\
memcpy(result->buffer, _list_->buffer, _list_->count * sizeof(V)); \
\
memmove(_list_->buffer + from, _list_->buffer + to + 1, (_list_->count - to - 1) * sizeof(V)); \
\
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(V)); \
\
_list_->count -= length; \
result->count = length; \
\
return result; \
} \