Changing T's by V's
This commit is contained in:
1 parent
12b68e3b36
commit
aedee24a18
7 files changed
+221
-221
No files matched your search
+36
-36
@@ -18,29 +18,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DEQUE_GENERATE(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define DEQUE_GENERATE(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
/* PRIVATE *******************************************************************/
|
||||
#define DEQUE_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define DEQUE_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define DEQUE_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define DEQUE_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* PUBLIC ********************************************************************/
|
||||
#define DEQUE_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define DEQUE_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define DEQUE_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define DEQUE_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* STRUCT ********************************************************************/
|
||||
#define DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
#define DEQUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
struct SNAME##_s \
|
||||
{ \
|
||||
T *buffer; \
|
||||
V *buffer; \
|
||||
size_t capacity; \
|
||||
size_t count; \
|
||||
size_t front; \
|
||||
@@ -57,23 +57,23 @@
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
#define DEQUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(size_t size); \
|
||||
FMOD void PFX##_free(SNAME *_deque_); \
|
||||
FMOD bool PFX##_push_front(SNAME *_deque_, T element); \
|
||||
FMOD bool PFX##_push_back(SNAME *_deque_, T element); \
|
||||
FMOD bool PFX##_push_front(SNAME *_deque_, V element); \
|
||||
FMOD bool PFX##_push_back(SNAME *_deque_, V element); \
|
||||
FMOD bool PFX##_pop_front(SNAME *_deque_); \
|
||||
FMOD bool PFX##_pop_back(SNAME *_deque_); \
|
||||
FMOD bool PFX##_push_front_if(SNAME *_deque_, T element, bool condition); \
|
||||
FMOD bool PFX##_push_back_if(SNAME *_deque_, T element, bool condition); \
|
||||
FMOD bool PFX##_push_front_if(SNAME *_deque_, V element, bool condition); \
|
||||
FMOD bool PFX##_push_back_if(SNAME *_deque_, V element, bool condition); \
|
||||
FMOD bool PFX##_pop_front_if(SNAME *_deque_, bool condition); \
|
||||
FMOD bool PFX##_pop_back_if(SNAME *_deque_, bool condition); \
|
||||
FMOD T PFX##_back(SNAME *_deque_); \
|
||||
FMOD T PFX##_front(SNAME *_deque_); \
|
||||
FMOD V PFX##_back(SNAME *_deque_); \
|
||||
FMOD V PFX##_front(SNAME *_deque_); \
|
||||
FMOD bool PFX##_empty(SNAME *_deque_); \
|
||||
FMOD bool PFX##_full(SNAME *_deque_); \
|
||||
FMOD size_t PFX##_count(SNAME *_deque_); \
|
||||
@@ -84,11 +84,11 @@
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T) \
|
||||
#define DEQUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
FMOD bool PFX##_grow(SNAME *_deque_); \
|
||||
\
|
||||
@@ -102,7 +102,7 @@
|
||||
if (!_deque_) \
|
||||
return NULL; \
|
||||
\
|
||||
_deque_->buffer = malloc(sizeof(T) * size); \
|
||||
_deque_->buffer = malloc(sizeof(V) * size); \
|
||||
\
|
||||
if (!_deque_->buffer) \
|
||||
{ \
|
||||
@@ -127,7 +127,7 @@
|
||||
free(_deque_); \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_front(SNAME *_deque_, T element) \
|
||||
FMOD bool PFX##_push_front(SNAME *_deque_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_deque_)) \
|
||||
{ \
|
||||
@@ -144,7 +144,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_back(SNAME *_deque_, T element) \
|
||||
FMOD bool PFX##_push_back(SNAME *_deque_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_deque_)) \
|
||||
{ \
|
||||
@@ -189,7 +189,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_front_if(SNAME *_deque_, T element, bool condition) \
|
||||
FMOD bool PFX##_push_front_if(SNAME *_deque_, V element, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_push_front(_deque_, element); \
|
||||
@@ -197,7 +197,7 @@
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_back_if(SNAME *_deque_, T element, bool condition) \
|
||||
FMOD bool PFX##_push_back_if(SNAME *_deque_, V element, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_push_back(_deque_, element); \
|
||||
@@ -221,7 +221,7 @@
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_back(SNAME *_deque_) \
|
||||
FMOD V PFX##_back(SNAME *_deque_) \
|
||||
{ \
|
||||
if (PFX##_empty(_deque_)) \
|
||||
return 0; \
|
||||
@@ -229,7 +229,7 @@
|
||||
return _deque_->buffer[(_deque_->rear == 0) ? _deque_->capacity - 1 : _deque_->rear - 1]; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_front(SNAME *_deque_) \
|
||||
FMOD V PFX##_front(SNAME *_deque_) \
|
||||
{ \
|
||||
if (PFX##_empty(_deque_)) \
|
||||
return 0; \
|
||||
@@ -262,7 +262,7 @@
|
||||
\
|
||||
size_t new_capacity = _deque_->capacity * 2; \
|
||||
\
|
||||
T *new_buffer = malloc(sizeof(T) * new_capacity); \
|
||||
V *new_buffer = malloc(sizeof(V) * new_capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
@@ -322,7 +322,7 @@
|
||||
iter->end = true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->end) \
|
||||
return false; \
|
||||
@@ -342,7 +342,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
|
||||
+4
-4
@@ -14,11 +14,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOR_EACH(PFX, SNAME, K, T, TARGET, BODY) \
|
||||
#define FOR_EACH(PFX, SNAME, K, V, TARGET, BODY) \
|
||||
do \
|
||||
{ \
|
||||
size_t index; \
|
||||
T var; \
|
||||
V var; \
|
||||
SNAME##_iter iter; \
|
||||
PFX##_iter(&iter, TARGET); \
|
||||
while (PFX##_iter_next(&iter, &var, &index)) \
|
||||
@@ -27,11 +27,11 @@
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define FOR_EACH_REV(PFX, SNAME, K, T, TARGET, BODY) \
|
||||
#define FOR_EACH_REV(PFX, SNAME, K, V, TARGET, BODY) \
|
||||
do \
|
||||
{ \
|
||||
size_t index; \
|
||||
T var; \
|
||||
V var; \
|
||||
SNAME##_iter iter; \
|
||||
PFX##_iter(&iter, TARGET); \
|
||||
PFX##_iter_toend(&iter); \
|
||||
|
||||
+41
-41
@@ -25,33 +25,33 @@ typedef enum HeapOrder
|
||||
MinHeap = -1
|
||||
} HeapOrder;
|
||||
|
||||
#define HEAP_GENERATE(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define HEAP_GENERATE(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
/* PRIVATE *******************************************************************/
|
||||
#define HEAP_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define HEAP_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define HEAP_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define HEAP_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* PUBLIC ********************************************************************/
|
||||
#define HEAP_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define HEAP_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define HEAP_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define HEAP_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* STRUCT ********************************************************************/
|
||||
#define HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
#define HEAP_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
struct SNAME##_s \
|
||||
{ \
|
||||
T *buffer; \
|
||||
V *buffer; \
|
||||
size_t capacity; \
|
||||
size_t count; \
|
||||
enum HeapOrder HO; \
|
||||
int (*cmp)(T, T); \
|
||||
int (*cmp)(V, V); \
|
||||
}; \
|
||||
\
|
||||
struct SNAME##_iter_s \
|
||||
@@ -63,18 +63,18 @@ typedef enum HeapOrder
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
#define HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(size_t size, HeapOrder HO, int (*compare)(T, T)); \
|
||||
FMOD SNAME *PFX##_new(size_t size, HeapOrder HO, int (*compare)(V, V)); \
|
||||
FMOD void PFX##_free(SNAME *_heap_); \
|
||||
FMOD bool PFX##_insert(SNAME *_heap_, T element); \
|
||||
FMOD bool PFX##_remove(SNAME *_heap_, T *result); \
|
||||
FMOD bool PFX##_insert_if(SNAME *_heap_, T element, bool condition); \
|
||||
FMOD bool PFX##_remove_if(SNAME *_heap_, T *result, bool condition); \
|
||||
FMOD T PFX##_peek(SNAME *_heap_); \
|
||||
FMOD bool PFX##_insert(SNAME *_heap_, V element); \
|
||||
FMOD bool PFX##_remove(SNAME *_heap_, V *result); \
|
||||
FMOD bool PFX##_insert_if(SNAME *_heap_, V element, bool condition); \
|
||||
FMOD bool PFX##_remove_if(SNAME *_heap_, V *result, bool condition); \
|
||||
FMOD V PFX##_peek(SNAME *_heap_); \
|
||||
FMOD bool PFX##_empty(SNAME *_heap_); \
|
||||
FMOD bool PFX##_full(SNAME *_heap_); \
|
||||
FMOD size_t PFX##_count(SNAME *_heap_); \
|
||||
@@ -85,11 +85,11 @@ typedef enum HeapOrder
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T) \
|
||||
#define HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
FMOD bool PFX##_grow(SNAME *_heap_); \
|
||||
FMOD size_t PFX##_p(size_t index); \
|
||||
@@ -98,7 +98,7 @@ typedef enum HeapOrder
|
||||
FMOD bool PFX##_float_up(SNAME *_heap_, size_t index); \
|
||||
FMOD bool PFX##_float_down(SNAME *_heap_, size_t index); \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(size_t size, HeapOrder HO, int (*compare)(T, T)) \
|
||||
FMOD SNAME *PFX##_new(size_t size, HeapOrder HO, int (*compare)(V, V)) \
|
||||
{ \
|
||||
if (size < 1) \
|
||||
return NULL; \
|
||||
@@ -111,7 +111,7 @@ typedef enum HeapOrder
|
||||
if (!_heap_) \
|
||||
return NULL; \
|
||||
\
|
||||
_heap_->buffer = malloc(sizeof(T) * size); \
|
||||
_heap_->buffer = malloc(sizeof(V) * size); \
|
||||
\
|
||||
if (!_heap_->buffer) \
|
||||
{ \
|
||||
@@ -138,7 +138,7 @@ typedef enum HeapOrder
|
||||
free(_heap_); \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_insert(SNAME *_heap_, T element) \
|
||||
FMOD bool PFX##_insert(SNAME *_heap_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_heap_)) \
|
||||
{ \
|
||||
@@ -160,7 +160,7 @@ typedef enum HeapOrder
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_remove(SNAME *_heap_, T *result) \
|
||||
FMOD bool PFX##_remove(SNAME *_heap_, V *result) \
|
||||
{ \
|
||||
if (PFX##_empty(_heap_)) \
|
||||
return false; \
|
||||
@@ -177,7 +177,7 @@ typedef enum HeapOrder
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_insert_if(SNAME *_heap_, T element, bool condition) \
|
||||
FMOD bool PFX##_insert_if(SNAME *_heap_, V element, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_insert(_heap_, element); \
|
||||
@@ -185,7 +185,7 @@ typedef enum HeapOrder
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_remove_if(SNAME *_heap_, T *result, bool condition) \
|
||||
FMOD bool PFX##_remove_if(SNAME *_heap_, V *result, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_remove(_heap_, result); \
|
||||
@@ -193,7 +193,7 @@ typedef enum HeapOrder
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_peek(SNAME *_heap_) \
|
||||
FMOD V PFX##_peek(SNAME *_heap_) \
|
||||
{ \
|
||||
if (PFX##_empty(_heap_)) \
|
||||
return 0; \
|
||||
@@ -225,7 +225,7 @@ typedef enum HeapOrder
|
||||
{ \
|
||||
size_t new_capacity = _heap_->capacity * 2; \
|
||||
\
|
||||
T *new_buffer = realloc(_heap_->buffer, sizeof(T) * new_capacity); \
|
||||
V *new_buffer = realloc(_heap_->buffer, sizeof(V) * new_capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
@@ -257,14 +257,14 @@ typedef enum HeapOrder
|
||||
FMOD bool PFX##_float_up(SNAME *_heap_, size_t index) \
|
||||
{ \
|
||||
size_t C = index; \
|
||||
T child = _heap_->buffer[C]; \
|
||||
T parent = _heap_->buffer[PFX##_p(C)]; \
|
||||
V child = _heap_->buffer[C]; \
|
||||
V parent = _heap_->buffer[PFX##_p(C)]; \
|
||||
\
|
||||
int mod = _heap_->HO; \
|
||||
\
|
||||
while (C > 0 && _heap_->cmp(child, parent) * mod > 0) \
|
||||
{ \
|
||||
T tmp = _heap_->buffer[C]; \
|
||||
V tmp = _heap_->buffer[C]; \
|
||||
_heap_->buffer[C] = _heap_->buffer[PFX##_p(C)]; \
|
||||
_heap_->buffer[PFX##_p(C)] = tmp; \
|
||||
\
|
||||
@@ -299,7 +299,7 @@ typedef enum HeapOrder
|
||||
\
|
||||
if (C != index) \
|
||||
{ \
|
||||
T tmp = _heap_->buffer[index]; \
|
||||
V tmp = _heap_->buffer[index]; \
|
||||
_heap_->buffer[index] = _heap_->buffer[C]; \
|
||||
_heap_->buffer[C] = tmp; \
|
||||
\
|
||||
@@ -344,7 +344,7 @@ typedef enum HeapOrder
|
||||
iter->end = true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->end) \
|
||||
return false; \
|
||||
@@ -361,7 +361,7 @@ typedef enum HeapOrder
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
|
||||
+42
-42
@@ -18,25 +18,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define LINKEDLIST_GENERATE(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define LINKEDLIST_GENERATE(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
/* PRIVATE *******************************************************************/
|
||||
#define LINKEDLIST_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define LINKEDLIST_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define LINKEDLIST_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define LINKEDLIST_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* PUBLIC ********************************************************************/
|
||||
#define LINKEDLIST_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define LINKEDLIST_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define LINKEDLIST_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define LINKEDLIST_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* STRUCT ********************************************************************/
|
||||
#define LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
#define LINKEDLIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
struct SNAME##_s \
|
||||
{ \
|
||||
@@ -50,7 +50,7 @@
|
||||
struct SNAME##_s *owner; \
|
||||
struct SNAME##_node_s *next; \
|
||||
struct SNAME##_node_s *prev; \
|
||||
T data; \
|
||||
V data; \
|
||||
}; \
|
||||
\
|
||||
struct SNAME##_iter_s \
|
||||
@@ -63,7 +63,7 @@
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
#define LINKEDLIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_node_s SNAME##_node; \
|
||||
@@ -71,24 +71,24 @@
|
||||
\
|
||||
FMOD SNAME *PFX##_new(void); \
|
||||
FMOD void PFX##_free(SNAME *_list_); \
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, T element); \
|
||||
FMOD bool PFX##_push(SNAME *_list_, T element, size_t index); \
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, T element); \
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, V element); \
|
||||
FMOD bool PFX##_push(SNAME *_list_, V element, size_t index); \
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, V element); \
|
||||
FMOD bool PFX##_pop_front(SNAME *_list_); \
|
||||
FMOD bool PFX##_pop(SNAME *_list_, size_t index); \
|
||||
FMOD bool PFX##_pop_back(SNAME *_list_); \
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, T element, size_t index, bool condition); \
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition); \
|
||||
FMOD bool PFX##_pop_if(SNAME *_list_, size_t index, bool condition); \
|
||||
FMOD T PFX##_back(SNAME *_list_); \
|
||||
FMOD T PFX##_get(SNAME *_list_, size_t index); \
|
||||
FMOD T PFX##_front(SNAME *_list_); \
|
||||
FMOD V PFX##_back(SNAME *_list_); \
|
||||
FMOD V PFX##_get(SNAME *_list_, size_t index); \
|
||||
FMOD V PFX##_front(SNAME *_list_); \
|
||||
FMOD bool PFX##_empty(SNAME *_list_); \
|
||||
FMOD size_t PFX##_count(SNAME *_list_); \
|
||||
\
|
||||
FMOD SNAME##_node *PFX##_new_node(SNAME *_owner_, T element); \
|
||||
FMOD SNAME##_node *PFX##_new_node(SNAME *_owner_, V element); \
|
||||
FMOD SNAME##_node *PFX##_get_node(SNAME *_list_, size_t index); \
|
||||
FMOD bool PFX##_insert_nxt(SNAME##_node *node, T element); \
|
||||
FMOD bool PFX##_insert_prv(SNAME##_node *node, T element); \
|
||||
FMOD bool PFX##_insert_nxt(SNAME##_node *node, V element); \
|
||||
FMOD bool PFX##_insert_prv(SNAME##_node *node, V element); \
|
||||
FMOD bool PFX##_remove_nxt(SNAME##_node *node); \
|
||||
FMOD bool PFX##_remove_cur(SNAME##_node *node); \
|
||||
FMOD bool PFX##_remove_prv(SNAME##_node *node); \
|
||||
@@ -98,11 +98,11 @@
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T) \
|
||||
#define LINKEDLIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(void) \
|
||||
{ \
|
||||
@@ -130,7 +130,7 @@
|
||||
free(_list_); \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, T element) \
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, V element) \
|
||||
{ \
|
||||
SNAME##_node *node = PFX##_new_node(_list_, element); \
|
||||
\
|
||||
@@ -154,7 +154,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push(SNAME *_list_, T element, size_t index) \
|
||||
FMOD bool PFX##_push(SNAME *_list_, V element, size_t index) \
|
||||
{ \
|
||||
if (index > _list_->count) \
|
||||
return false; \
|
||||
@@ -185,7 +185,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, T element) \
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, V element) \
|
||||
{ \
|
||||
SNAME##_node *node = PFX##_new_node(_list_, element); \
|
||||
\
|
||||
@@ -278,7 +278,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, T element, size_t index, bool condition) \
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_push(_list_, element, index); \
|
||||
@@ -294,7 +294,7 @@
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_front(SNAME *_list_) \
|
||||
FMOD V PFX##_front(SNAME *_list_) \
|
||||
{ \
|
||||
if (PFX##_empty(_list_)) \
|
||||
return 0; \
|
||||
@@ -302,7 +302,7 @@
|
||||
return _list_->head->data; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_get(SNAME *_list_, size_t index) \
|
||||
FMOD V PFX##_get(SNAME *_list_, size_t index) \
|
||||
{ \
|
||||
if (index >= _list_->count) \
|
||||
return 0; \
|
||||
@@ -318,7 +318,7 @@
|
||||
return scan->data; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_back(SNAME *_list_) \
|
||||
FMOD V PFX##_back(SNAME *_list_) \
|
||||
{ \
|
||||
if (PFX##_empty(_list_)) \
|
||||
return 0; \
|
||||
@@ -336,7 +336,7 @@
|
||||
return _list_->count; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_insert_nxt(SNAME##_node *node, T element) \
|
||||
FMOD bool PFX##_insert_nxt(SNAME##_node *node, V element) \
|
||||
{ \
|
||||
SNAME##_node *new_node = PFX##_new_node(node->owner, element); \
|
||||
\
|
||||
@@ -357,7 +357,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_insert_prv(SNAME##_node *node, T element) \
|
||||
FMOD bool PFX##_insert_prv(SNAME##_node *node, V element) \
|
||||
{ \
|
||||
SNAME##_node *new_node = PFX##_new_node(node->owner, element); \
|
||||
\
|
||||
@@ -439,7 +439,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD SNAME##_node *PFX##_new_node(SNAME *_owner_, T element) \
|
||||
FMOD SNAME##_node *PFX##_new_node(SNAME *_owner_, V element) \
|
||||
{ \
|
||||
SNAME##_node *node = malloc(sizeof(SNAME##_node)); \
|
||||
\
|
||||
@@ -519,7 +519,7 @@
|
||||
iter->end = true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->end) \
|
||||
return false; \
|
||||
@@ -539,7 +539,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
|
||||
+38
-38
@@ -18,29 +18,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define LIST_GENERATE(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define LIST_GENERATE(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
/* PRIVATE *******************************************************************/
|
||||
#define LIST_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define LIST_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define LIST_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define LIST_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* PUBLIC ********************************************************************/
|
||||
#define LIST_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define LIST_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define LIST_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define LIST_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* STRUCT ********************************************************************/
|
||||
#define LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
#define LIST_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
struct SNAME##_s \
|
||||
{ \
|
||||
T *buffer; \
|
||||
V *buffer; \
|
||||
size_t capacity; \
|
||||
size_t count; \
|
||||
}; \
|
||||
@@ -54,24 +54,24 @@
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
#define LIST_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(size_t size); \
|
||||
FMOD void PFX##_free(SNAME *_list_); \
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, T element); \
|
||||
FMOD bool PFX##_push(SNAME *_list_, T element, size_t index); \
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, T element); \
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, V element); \
|
||||
FMOD bool PFX##_push(SNAME *_list_, V element, size_t index); \
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, V element); \
|
||||
FMOD bool PFX##_pop_front(SNAME *_list_); \
|
||||
FMOD bool PFX##_pop(SNAME *_list_, size_t index); \
|
||||
FMOD bool PFX##_pop_back(SNAME *_list_); \
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, T element, size_t index, bool condition); \
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition); \
|
||||
FMOD bool PFX##_pop_if(SNAME *_list_, size_t index, bool condition); \
|
||||
FMOD T PFX##_back(SNAME *_list_); \
|
||||
FMOD T PFX##_get(SNAME *_list_, size_t index); \
|
||||
FMOD T PFX##_front(SNAME *_list_); \
|
||||
FMOD V PFX##_back(SNAME *_list_); \
|
||||
FMOD V PFX##_get(SNAME *_list_, size_t index); \
|
||||
FMOD V PFX##_front(SNAME *_list_); \
|
||||
FMOD bool PFX##_empty(SNAME *_list_); \
|
||||
FMOD bool PFX##_full(SNAME *_list_); \
|
||||
FMOD size_t PFX##_count(SNAME *_list_); \
|
||||
@@ -82,11 +82,11 @@
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T) \
|
||||
#define LIST_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
FMOD bool PFX##_grow(SNAME *_list_); \
|
||||
\
|
||||
@@ -100,7 +100,7 @@
|
||||
if (!_list_) \
|
||||
return NULL; \
|
||||
\
|
||||
_list_->buffer = malloc(sizeof(T) * size); \
|
||||
_list_->buffer = malloc(sizeof(V) * size); \
|
||||
\
|
||||
if (!_list_->buffer) \
|
||||
{ \
|
||||
@@ -125,7 +125,7 @@
|
||||
free(_list_); \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, T element) \
|
||||
FMOD bool PFX##_push_front(SNAME *_list_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_list_)) \
|
||||
{ \
|
||||
@@ -148,7 +148,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push(SNAME *_list_, T element, size_t index) \
|
||||
FMOD bool PFX##_push(SNAME *_list_, V element, size_t index) \
|
||||
{ \
|
||||
if (index > _list_->count) \
|
||||
return false; \
|
||||
@@ -180,7 +180,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, T element) \
|
||||
FMOD bool PFX##_push_back(SNAME *_list_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_list_)) \
|
||||
{ \
|
||||
@@ -242,7 +242,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, T element, size_t index, bool condition) \
|
||||
FMOD bool PFX##_push_if(SNAME *_list_, V element, size_t index, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_push(_list_, element, index); \
|
||||
@@ -258,7 +258,7 @@
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_front(SNAME *_list_) \
|
||||
FMOD V PFX##_front(SNAME *_list_) \
|
||||
{ \
|
||||
if (PFX##_empty(_list_)) \
|
||||
return 0; \
|
||||
@@ -266,7 +266,7 @@
|
||||
return _list_->buffer[0]; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_get(SNAME *_list_, size_t index) \
|
||||
FMOD V PFX##_get(SNAME *_list_, size_t index) \
|
||||
{ \
|
||||
if (index >= _list_->count) \
|
||||
return 0; \
|
||||
@@ -277,7 +277,7 @@
|
||||
return _list_->buffer[index]; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_back(SNAME *_list_) \
|
||||
FMOD V PFX##_back(SNAME *_list_) \
|
||||
{ \
|
||||
if (PFX##_empty(_list_)) \
|
||||
return 0; \
|
||||
@@ -309,7 +309,7 @@
|
||||
{ \
|
||||
size_t new_capacity = _list_->capacity * 2; \
|
||||
\
|
||||
T *new_buffer = realloc(_list_->buffer, sizeof(T) * new_capacity); \
|
||||
V *new_buffer = realloc(_list_->buffer, sizeof(V) * new_capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
@@ -352,7 +352,7 @@
|
||||
iter->end = true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->end) \
|
||||
return false; \
|
||||
@@ -369,7 +369,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
|
||||
+30
-30
@@ -18,29 +18,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define QUEUE_GENERATE(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define QUEUE_GENERATE(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
/* PRIVATE *******************************************************************/
|
||||
#define QUEUE_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define QUEUE_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define QUEUE_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define QUEUE_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* PUBLIC ********************************************************************/
|
||||
#define QUEUE_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define QUEUE_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define QUEUE_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define QUEUE_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* STRUCT ********************************************************************/
|
||||
#define QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
#define QUEUE_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
struct SNAME##_s \
|
||||
{ \
|
||||
T *buffer; \
|
||||
V *buffer; \
|
||||
size_t capacity; \
|
||||
size_t count; \
|
||||
size_t front; \
|
||||
@@ -57,17 +57,17 @@
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
#define QUEUE_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(size_t size); \
|
||||
FMOD void PFX##_free(SNAME *_queue_); \
|
||||
FMOD bool PFX##_enqueue(SNAME *_queue_, T element); \
|
||||
FMOD bool PFX##_enqueue(SNAME *_queue_, V element); \
|
||||
FMOD bool PFX##_dequeue(SNAME *_queue_); \
|
||||
FMOD T PFX##_peek(SNAME *_queue_); \
|
||||
FMOD bool PFX##_enqueue_if(SNAME *_queue_, T element, bool condition); \
|
||||
FMOD V PFX##_peek(SNAME *_queue_); \
|
||||
FMOD bool PFX##_enqueue_if(SNAME *_queue_, V element, bool condition); \
|
||||
FMOD bool PFX##_dequeue_if(SNAME *_queue_, bool condition); \
|
||||
FMOD bool PFX##_empty(SNAME *_queue_); \
|
||||
FMOD bool PFX##_full(SNAME *_queue_); \
|
||||
@@ -79,11 +79,11 @@
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T) \
|
||||
#define QUEUE_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
FMOD bool PFX##_grow(SNAME *_queue_); \
|
||||
\
|
||||
@@ -97,7 +97,7 @@
|
||||
if (!_queue_) \
|
||||
return NULL; \
|
||||
\
|
||||
_queue_->buffer = malloc(sizeof(T) * size); \
|
||||
_queue_->buffer = malloc(sizeof(V) * size); \
|
||||
\
|
||||
if (!_queue_->buffer) \
|
||||
{ \
|
||||
@@ -124,7 +124,7 @@
|
||||
free(_queue_); \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_enqueue(SNAME *_queue_, T element) \
|
||||
FMOD bool PFX##_enqueue(SNAME *_queue_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_queue_)) \
|
||||
{ \
|
||||
@@ -153,7 +153,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_peek(SNAME *_queue_) \
|
||||
FMOD V PFX##_peek(SNAME *_queue_) \
|
||||
{ \
|
||||
if (PFX##_empty(_queue_)) \
|
||||
return 0; \
|
||||
@@ -161,7 +161,7 @@
|
||||
return _queue_->buffer[_queue_->front]; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_enqueue_if(SNAME *_queue_, T element, bool condition) \
|
||||
FMOD bool PFX##_enqueue_if(SNAME *_queue_, V element, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_enqueue(_queue_, element); \
|
||||
@@ -202,7 +202,7 @@
|
||||
\
|
||||
size_t new_capacity = _queue_->capacity * 2; \
|
||||
\
|
||||
T *new_buffer = malloc(sizeof(T) * new_capacity); \
|
||||
V *new_buffer = malloc(sizeof(V) * new_capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
@@ -262,7 +262,7 @@
|
||||
iter->end = true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->end) \
|
||||
return false; \
|
||||
@@ -282,7 +282,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
|
||||
+30
-30
@@ -18,29 +18,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define STACK_GENERATE(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define STACK_GENERATE(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
|
||||
/* PRIVATE *******************************************************************/
|
||||
#define STACK_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define STACK_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define STACK_GENERATE_HEADER_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define STACK_GENERATE_SOURCE_PRIVATE(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* PUBLIC ********************************************************************/
|
||||
#define STACK_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, T)
|
||||
#define STACK_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, T) \
|
||||
STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T)
|
||||
#define STACK_GENERATE_HEADER_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, V)
|
||||
#define STACK_GENERATE_SOURCE_PUBLIC(PFX, SNAME, FMOD, K, V) \
|
||||
STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V)
|
||||
/* STRUCT ********************************************************************/
|
||||
#define STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, T) \
|
||||
#define STACK_GENERATE_STRUCT(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
struct SNAME##_s \
|
||||
{ \
|
||||
T *buffer; \
|
||||
V *buffer; \
|
||||
size_t capacity; \
|
||||
size_t count; \
|
||||
}; \
|
||||
@@ -54,17 +54,17 @@
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, T) \
|
||||
#define STACK_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(size_t size); \
|
||||
FMOD void PFX##_free(SNAME *_stack_); \
|
||||
FMOD bool PFX##_push(SNAME *_stack_, T element); \
|
||||
FMOD bool PFX##_push(SNAME *_stack_, V element); \
|
||||
FMOD bool PFX##_pop(SNAME *_stack_); \
|
||||
FMOD T PFX##_top(SNAME *_stack_); \
|
||||
FMOD bool PFX##_push_if(SNAME *_stack_, T element, bool condition); \
|
||||
FMOD V PFX##_top(SNAME *_stack_); \
|
||||
FMOD bool PFX##_push_if(SNAME *_stack_, V element, bool condition); \
|
||||
FMOD bool PFX##_pop_if(SNAME *_stack_, bool condition); \
|
||||
FMOD bool PFX##_empty(SNAME *_stack_); \
|
||||
FMOD bool PFX##_full(SNAME *_stack_); \
|
||||
@@ -76,11 +76,11 @@
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, T) \
|
||||
#define STACK_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
FMOD bool PFX##_grow(SNAME *_stack_); \
|
||||
\
|
||||
@@ -94,7 +94,7 @@
|
||||
if (!_stack_) \
|
||||
return NULL; \
|
||||
\
|
||||
_stack_->buffer = malloc(sizeof(T) * size); \
|
||||
_stack_->buffer = malloc(sizeof(V) * size); \
|
||||
\
|
||||
if (!_stack_->buffer) \
|
||||
{ \
|
||||
@@ -119,7 +119,7 @@
|
||||
free(_stack_); \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push(SNAME *_stack_, T element) \
|
||||
FMOD bool PFX##_push(SNAME *_stack_, V element) \
|
||||
{ \
|
||||
if (PFX##_full(_stack_)) \
|
||||
{ \
|
||||
@@ -142,7 +142,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD T PFX##_top(SNAME *_stack_) \
|
||||
FMOD V PFX##_top(SNAME *_stack_) \
|
||||
{ \
|
||||
if (PFX##_empty(_stack_)) \
|
||||
return 0; \
|
||||
@@ -150,7 +150,7 @@
|
||||
return _stack_->buffer[_stack_->count - 1]; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_push_if(SNAME *_stack_, T element, bool condition) \
|
||||
FMOD bool PFX##_push_if(SNAME *_stack_, V element, bool condition) \
|
||||
{ \
|
||||
if (condition) \
|
||||
return PFX##_push(_stack_, element); \
|
||||
@@ -190,7 +190,7 @@
|
||||
{ \
|
||||
size_t new_capacity = _stack_->capacity * 2; \
|
||||
\
|
||||
T *new_buffer = realloc(_stack_->buffer, sizeof(T) * new_capacity); \
|
||||
V *new_buffer = realloc(_stack_->buffer, sizeof(V) * new_capacity); \
|
||||
\
|
||||
if (!new_buffer) \
|
||||
return false; \
|
||||
@@ -233,7 +233,7 @@
|
||||
iter->end = true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->end) \
|
||||
return false; \
|
||||
@@ -250,7 +250,7 @@
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, T *result, size_t *index) \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, V *result, size_t *index) \
|
||||
{ \
|
||||
if (iter->start) \
|
||||
return false; \
|
||||
|
||||
Reference in new issue
Block a user