Simplified name for functions table ftab_key to fkey and ftab_val to fval
This commit is contained in:
1 parent
5e13c7ba91
commit
eb13fcad01
46 files changed
+841
-856
No files matched your search
+12
-12
@@ -86,10 +86,10 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Key function table */ \
|
||||
struct SNAME##_ftab_key *f_key; \
|
||||
struct SNAME##_fkey *f_key; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -128,7 +128,7 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Key struct function table */ \
|
||||
struct SNAME##_ftab_key \
|
||||
struct SNAME##_fkey \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(K, K); \
|
||||
@@ -150,7 +150,7 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -199,11 +199,11 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val, struct cmc_alloc_node *alloc, \
|
||||
size_t capacity, double load, struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_map_); \
|
||||
void PFX##_free(struct SNAME *_map_); \
|
||||
@@ -280,8 +280,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_map_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -327,8 +327,8 @@ static const char *cmc_string_fmt_bidimap = "struct %s<%s, %s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val, struct cmc_alloc_node *alloc, \
|
||||
size_t capacity, double load, struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
|
||||
+6
-6
@@ -88,7 +88,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
|
||||
/* Flags indicating errors or success */ \
|
||||
int flag; \
|
||||
\
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -103,7 +103,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
|
||||
struct SNAME##_iter (*it_end)(struct SNAME *); \
|
||||
}; \
|
||||
\
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -145,9 +145,9 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_deque_); \
|
||||
void PFX##_free(struct SNAME *_deque_); \
|
||||
@@ -207,7 +207,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_deque_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_deque_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -245,7 +245,7 @@ static const char *cmc_string_fmt_deque = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity < 1) \
|
||||
|
||||
+12
-12
@@ -79,10 +79,10 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Key function table */ \
|
||||
struct SNAME##_ftab_key *f_key; \
|
||||
struct SNAME##_fkey *f_key; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -115,7 +115,7 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Key struct function table */ \
|
||||
struct SNAME##_ftab_key \
|
||||
struct SNAME##_fkey \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(K, K); \
|
||||
@@ -137,7 +137,7 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -186,11 +186,11 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val, struct cmc_alloc_node *alloc, \
|
||||
size_t capacity, double load, struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_map_); \
|
||||
void PFX##_free(struct SNAME *_map_); \
|
||||
@@ -257,8 +257,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_map_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -303,8 +303,8 @@ static const char *cmc_string_fmt_hashmap = "struct %s<%s, %s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val, struct cmc_alloc_node *alloc, \
|
||||
size_t capacity, double load, struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
|
||||
+6
-6
@@ -78,7 +78,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -107,7 +107,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -156,9 +156,9 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, double load, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_set_); \
|
||||
void PFX##_free(struct SNAME *_set_); \
|
||||
@@ -234,7 +234,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_set_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -278,7 +278,7 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, double load, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
|
||||
+10
-12
@@ -100,7 +100,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -116,7 +116,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -156,11 +156,10 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, enum cmc_heap_order HO, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new_custom(size_t capacity, enum cmc_heap_order HO, \
|
||||
struct SNAME##_ftab_val *f_val, \
|
||||
struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks); \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, enum cmc_heap_order HO, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_heap_); \
|
||||
void PFX##_free(struct SNAME *_heap_); \
|
||||
/* Customization of Allocation and Callbacks */ \
|
||||
@@ -218,7 +217,7 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_heap_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, enum cmc_heap_order HO, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -257,10 +256,9 @@ static const char *cmc_string_fmt_heap = "struct %s<%s> "
|
||||
return _heap_; \
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom(size_t capacity, enum cmc_heap_order HO, \
|
||||
struct SNAME##_ftab_val *f_val, \
|
||||
struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, enum cmc_heap_order HO, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity < 1) \
|
||||
return NULL; \
|
||||
|
||||
+138
-138
@@ -54,142 +54,142 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
|
||||
/* -------------------------------------------------------------------------
|
||||
* Header
|
||||
* ------------------------------------------------------------------------- */
|
||||
#define CMC_GENERATE_INTERVALHEAP_HEADER(PFX, SNAME, V) \
|
||||
\
|
||||
/* Heap Structure */ \
|
||||
struct SNAME \
|
||||
{ \
|
||||
/* Dynamic array of nodes */ \
|
||||
struct SNAME##_node *buffer; \
|
||||
\
|
||||
/* Current array capacity (how many nodes can be stored) */ \
|
||||
size_t capacity; \
|
||||
\
|
||||
/* Current amount of nodes in the dynamic array */ \
|
||||
size_t size; \
|
||||
\
|
||||
/* Current amount of elements in the heap */ \
|
||||
size_t count; \
|
||||
\
|
||||
/* Flags indicating errors or success */ \
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
\
|
||||
/* Function that returns an iterator to the start of the heap */ \
|
||||
struct SNAME##_iter (*it_start)(struct SNAME *); \
|
||||
\
|
||||
/* Function that returns an iterator to the end of the heap */ \
|
||||
struct SNAME##_iter (*it_end)(struct SNAME *); \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
\
|
||||
/* Custom callback functions */ \
|
||||
struct cmc_callbacks *callbacks; \
|
||||
}; \
|
||||
\
|
||||
/* Heap Node */ \
|
||||
struct SNAME##_node \
|
||||
{ \
|
||||
/* 0 - Value belonging to the MinHeap */ \
|
||||
/* 1 - Value belonging to the MaxHeap */ \
|
||||
V data[2]; \
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
{ \
|
||||
/* 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); \
|
||||
}; \
|
||||
\
|
||||
/* Heap Iterator */ \
|
||||
struct SNAME##_iter \
|
||||
{ \
|
||||
/* Target heap */ \
|
||||
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##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_heap_); \
|
||||
void PFX##_free(struct SNAME *_heap_); \
|
||||
/* Customization of Allocation and Callbacks */ \
|
||||
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##_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); \
|
||||
/* 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##_empty(struct SNAME *_heap_); \
|
||||
bool PFX##_full(struct SNAME *_heap_); \
|
||||
size_t PFX##_count(struct SNAME *_heap_); \
|
||||
size_t PFX##_capacity(struct SNAME *_heap_); \
|
||||
int PFX##_flag(struct SNAME *_heap_); \
|
||||
/* Collection Utility */ \
|
||||
bool PFX##_resize(struct SNAME *_heap_, size_t capacity); \
|
||||
struct SNAME *PFX##_copy_of(struct SNAME *_set_); \
|
||||
bool PFX##_equals(struct SNAME *_heap1_, struct SNAME *_heap2_); \
|
||||
struct cmc_string PFX##_to_string(struct SNAME *_heap_); \
|
||||
bool PFX##_print(struct SNAME *_heap_, 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); \
|
||||
#define CMC_GENERATE_INTERVALHEAP_HEADER(PFX, SNAME, V) \
|
||||
\
|
||||
/* Heap Structure */ \
|
||||
struct SNAME \
|
||||
{ \
|
||||
/* Dynamic array of nodes */ \
|
||||
struct SNAME##_node *buffer; \
|
||||
\
|
||||
/* Current array capacity (how many nodes can be stored) */ \
|
||||
size_t capacity; \
|
||||
\
|
||||
/* Current amount of nodes in the dynamic array */ \
|
||||
size_t size; \
|
||||
\
|
||||
/* Current amount of elements in the heap */ \
|
||||
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 heap */ \
|
||||
struct SNAME##_iter (*it_start)(struct SNAME *); \
|
||||
\
|
||||
/* Function that returns an iterator to the end of the heap */ \
|
||||
struct SNAME##_iter (*it_end)(struct SNAME *); \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
\
|
||||
/* Custom callback functions */ \
|
||||
struct cmc_callbacks *callbacks; \
|
||||
}; \
|
||||
\
|
||||
/* Heap Node */ \
|
||||
struct SNAME##_node \
|
||||
{ \
|
||||
/* 0 - Value belonging to the MinHeap */ \
|
||||
/* 1 - Value belonging to the MaxHeap */ \
|
||||
V data[2]; \
|
||||
}; \
|
||||
\
|
||||
/* 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); \
|
||||
}; \
|
||||
\
|
||||
/* Heap Iterator */ \
|
||||
struct SNAME##_iter \
|
||||
{ \
|
||||
/* Target heap */ \
|
||||
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 *_heap_); \
|
||||
void PFX##_free(struct SNAME *_heap_); \
|
||||
/* Customization of Allocation and Callbacks */ \
|
||||
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##_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); \
|
||||
/* 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##_empty(struct SNAME *_heap_); \
|
||||
bool PFX##_full(struct SNAME *_heap_); \
|
||||
size_t PFX##_count(struct SNAME *_heap_); \
|
||||
size_t PFX##_capacity(struct SNAME *_heap_); \
|
||||
int PFX##_flag(struct SNAME *_heap_); \
|
||||
/* Collection Utility */ \
|
||||
bool PFX##_resize(struct SNAME *_heap_, size_t capacity); \
|
||||
struct SNAME *PFX##_copy_of(struct SNAME *_set_); \
|
||||
bool PFX##_equals(struct SNAME *_heap1_, struct SNAME *_heap2_); \
|
||||
struct cmc_string PFX##_to_string(struct SNAME *_heap_); \
|
||||
bool PFX##_print(struct SNAME *_heap_, 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); \
|
||||
size_t PFX##_iter_index(struct SNAME##_iter *iter);
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
@@ -205,7 +205,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_heap_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_heap_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -247,7 +247,7 @@ static const char *cmc_string_fmt_intervalheap = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity == 0 || capacity == UINTMAX_MAX) \
|
||||
|
||||
@@ -78,7 +78,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -107,7 +107,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -149,8 +149,8 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_ftab_val *f_val, \
|
||||
struct SNAME *PFX##_new(struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_list_); \
|
||||
@@ -233,7 +233,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
if (!f_val) \
|
||||
return NULL; \
|
||||
@@ -258,7 +258,7 @@ static const char *cmc_string_fmt_linkedlist = "struct %s<%s> "
|
||||
return _list_; \
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_ftab_val *f_val, \
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
|
||||
+6
-6
@@ -93,7 +93,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Function that returns an iterator to the start of the list */ \
|
||||
struct SNAME##_iter (*it_start)(struct SNAME *); \
|
||||
@@ -109,7 +109,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -148,9 +148,9 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
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_); \
|
||||
@@ -224,7 +224,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -257,7 +257,7 @@ static const char *cmc_string_fmt_list = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity < 1) \
|
||||
|
||||
+12
-12
@@ -103,10 +103,10 @@ static const char *cmc_string_fmt_multimap = "struct %s<%s, %s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Key function table */ \
|
||||
struct SNAME##_ftab_key *f_key; \
|
||||
struct SNAME##_fkey *f_key; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -138,7 +138,7 @@ static const char *cmc_string_fmt_multimap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Key struct function table */ \
|
||||
struct SNAME##_ftab_key \
|
||||
struct SNAME##_fkey \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(K, K); \
|
||||
@@ -160,7 +160,7 @@ static const char *cmc_string_fmt_multimap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -211,11 +211,11 @@ static const char *cmc_string_fmt_multimap = "struct %s<%s, %s> "
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val, struct cmc_alloc_node *alloc, \
|
||||
size_t capacity, double load, struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_map_); \
|
||||
void PFX##_free(struct SNAME *_map_); \
|
||||
@@ -288,8 +288,8 @@ static const char *cmc_string_fmt_multimap = "struct %s<%s, %s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_map_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -334,8 +334,8 @@ static const char *cmc_string_fmt_multimap = "struct %s<%s, %s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val, struct cmc_alloc_node *alloc, \
|
||||
size_t capacity, double load, struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity == 0 || load <= 0) \
|
||||
|
||||
+6
-6
@@ -84,7 +84,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Key function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -116,7 +116,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -165,9 +165,9 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, double load, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_set_); \
|
||||
void PFX##_free(struct SNAME *_set_); \
|
||||
@@ -253,7 +253,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_set_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, double load, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -298,7 +298,7 @@ static const char *cmc_string_fmt_multiset = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, double load, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, double load, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||
|
||||
+6
-6
@@ -101,7 +101,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -117,7 +117,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -159,9 +159,9 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_queue_); \
|
||||
void PFX##_free(struct SNAME *_queue_); \
|
||||
@@ -218,7 +218,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_queue_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_queue_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -256,7 +256,7 @@ static const char *cmc_string_fmt_queue = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity < 1) \
|
||||
|
||||
+129
-129
@@ -55,133 +55,133 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
/* -------------------------------------------------------------------------
|
||||
* Header
|
||||
* ------------------------------------------------------------------------- */
|
||||
#define CMC_GENERATE_SORTEDLIST_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; \
|
||||
\
|
||||
/* Flag if the list is sorted or not, used by lazy evaluation */ \
|
||||
bool is_sorted; \
|
||||
\
|
||||
/* Flags indicating errors or success */ \
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
\
|
||||
/* Custom callback functions */ \
|
||||
struct cmc_callbacks *callbacks; \
|
||||
\
|
||||
/* 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 *); \
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
{ \
|
||||
/* 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##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *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##_insert(struct SNAME *_list_, V element); \
|
||||
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); \
|
||||
/* 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_); \
|
||||
size_t PFX##_capacity(struct SNAME *_list_); \
|
||||
int PFX##_flag(struct SNAME *_list_); \
|
||||
/* Collection Utility */ \
|
||||
bool PFX##_resize(struct SNAME *_list_, size_t capacity); \
|
||||
void PFX##_sort(struct SNAME *_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 */ \
|
||||
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); \
|
||||
#define CMC_GENERATE_SORTEDLIST_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; \
|
||||
\
|
||||
/* Flag if the list is sorted or not, used by lazy evaluation */ \
|
||||
bool is_sorted; \
|
||||
\
|
||||
/* Flags indicating errors or success */ \
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
\
|
||||
/* Custom callback functions */ \
|
||||
struct cmc_callbacks *callbacks; \
|
||||
\
|
||||
/* 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 *); \
|
||||
}; \
|
||||
\
|
||||
/* 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##_insert(struct SNAME *_list_, V element); \
|
||||
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); \
|
||||
/* 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_); \
|
||||
size_t PFX##_capacity(struct SNAME *_list_); \
|
||||
int PFX##_flag(struct SNAME *_list_); \
|
||||
/* Collection Utility */ \
|
||||
bool PFX##_resize(struct SNAME *_list_, size_t capacity); \
|
||||
void PFX##_sort(struct SNAME *_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 */ \
|
||||
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); \
|
||||
size_t PFX##_iter_index(struct SNAME##_iter *iter);
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
@@ -201,7 +201,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -238,7 +238,7 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity < 1) \
|
||||
|
||||
+6
-6
@@ -78,7 +78,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -94,7 +94,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -133,9 +133,9 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_stack_); \
|
||||
void PFX##_free(struct SNAME *_stack_); \
|
||||
@@ -192,7 +192,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_stack_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_stack_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
||||
\
|
||||
@@ -228,7 +228,7 @@ static const char *cmc_string_fmt_stack = "struct %s<%s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
size_t capacity, struct SNAME##_ftab_val *f_val, \
|
||||
size_t capacity, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (capacity < 1) \
|
||||
|
||||
+10
-10
@@ -66,10 +66,10 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Key function table */ \
|
||||
struct SNAME##_ftab_key *f_key; \
|
||||
struct SNAME##_fkey *f_key; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -107,7 +107,7 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Key struct function table */ \
|
||||
struct SNAME##_ftab_key \
|
||||
struct SNAME##_fkey \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(K, K); \
|
||||
@@ -129,7 +129,7 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -177,10 +177,10 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new(struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
struct SNAME##_ftab_key *f_key, struct SNAME##_ftab_val *f_val, \
|
||||
struct SNAME##_fkey *f_key, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_map_); \
|
||||
void PFX##_free(struct SNAME *_map_); \
|
||||
@@ -249,8 +249,8 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_map_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_map_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(struct SNAME##_ftab_key *f_key, \
|
||||
struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(struct SNAME##_fkey *f_key, \
|
||||
struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
if (!f_key || !f_val) \
|
||||
return NULL; \
|
||||
@@ -276,7 +276,7 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom( \
|
||||
struct SNAME##_ftab_key *f_key, struct SNAME##_ftab_val *f_val, \
|
||||
struct SNAME##_fkey *f_key, struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
if (!f_key || !f_val) \
|
||||
|
||||
+6
-6
@@ -65,7 +65,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
int flag; \
|
||||
\
|
||||
/* Value function table */ \
|
||||
struct SNAME##_ftab_val *f_val; \
|
||||
struct SNAME##_fval *f_val; \
|
||||
\
|
||||
/* Custom allocation functions */ \
|
||||
struct cmc_alloc_node *alloc; \
|
||||
@@ -100,7 +100,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
struct SNAME##_ftab_val \
|
||||
struct SNAME##_fval \
|
||||
{ \
|
||||
/* Comparator function */ \
|
||||
int (*cmp)(V, V); \
|
||||
@@ -148,8 +148,8 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
\
|
||||
/* Collection Functions */ \
|
||||
/* Collection Allocation and Deallocation */ \
|
||||
struct SNAME *PFX##_new(struct SNAME##_ftab_val *f_val); \
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_ftab_val *f_val, \
|
||||
struct SNAME *PFX##_new(struct SNAME##_fval *f_val); \
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks); \
|
||||
void PFX##_clear(struct SNAME *_set_); \
|
||||
@@ -238,7 +238,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_set_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_set_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(struct SNAME##_ftab_val *f_val) \
|
||||
struct SNAME *PFX##_new(struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
if (!f_val) \
|
||||
return NULL; \
|
||||
@@ -262,7 +262,7 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
return _set_; \
|
||||
} \
|
||||
\
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_ftab_val *f_val, \
|
||||
struct SNAME *PFX##_new_custom(struct SNAME##_fval *f_val, \
|
||||
struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
|
||||
Reference in new issue
Block a user