23 return a ? a->
len : 0;
26#define new_mp_vector(mp, type, data) \
27 new_mp_vector(mp, sizeof(type), data)
29#define free_mp_vector(mp, type, data) \
30 free_mp_vector(mp, sizeof(type), data)
32#define mp_vector_add(mp, a, type, data) { \
33 if (++((*a))->len >= ((*a))->cap) \
34 mp_vector_resize(mp, (a), sizeof(type), (*(a))->cap * 2); \
35 *(type*)((*(a))->ptr + ((*a)->len - 1) * sizeof(type)) = (data); }\
37#define mp_vector_at(a, type, index) \
38 ((type*)((a)->ptr + (index) * sizeof(type)))
40#define mp_vector_set(a, type, index, data) \
41 *(type*)((a)->ptr + (index) * sizeof(type)) = (data)
44 if (idx >= a->
len)
return;
47 (a->
len - idx - 1) * size);
51 m_bit *data = ((a)->ptr + (a->
len--) * size);
55#define mp_vector_pop(a, type) \
56 ((type*)mp_vector_pop(a, sizeof(type)))
58#define mp_vector_rem(a, type, idx) \
59 mp_vector_rem(a, sizeof(type), idx)
61#define mp_vector_rem2(a, type, data) \
62 for(uint32_t i = 0; i < a->len; i++) { \
63 if(data == mp_vector_at(a, type, i)) { \
64 mp_vector_rem(a, type, i); \
69#define mp_vector_back(a, type) \
70 ((type*)((a)->ptr + (a->len-1) * sizeof(type)))
72#define MK_VECTOR_TYPE(Type, type, ...) \
73typedef struct Type##List { \
80ANN static inline Type##List *new_##type##list(const MemPool mp, const uint32_t len) { \
81 return (Type##List*)new_mp_vector(mp, Type, len); \
83ANN static inline void free_##type##list(const MemPool mp, Type##List *v) { \
84 mp_free2(mp, sizeof(Type##List) + (m_uint)(v->cap * sizeof(Type)), v); \
86ANN static inline void type##list_resize(const MemPool mp, Type##List **ap, \
87 const uint32_t cap) { \
88 return mp_vector_resize(mp, (MP_Vector**)ap, sizeof(Type), cap); \
90ANN static inline Type type##list_at(const Type##List *v, const uint32_t index) { \
91 return v->ptr[index]; \
93ANN static inline Type* type##list_ptr_at(Type##List *v, const uint32_t index) { \
94 return v->ptr + index; \
96ANN static inline void type##list_set(Type##List *v, const uint32_t index, \
98 v->ptr[index] = data; \
100ANN static inline void type##list_add(const MemPool mp, Type##List **v, \
102 mp_vector_add(mp, (MP_Vector**)v, Type, data); \
104static inline uint32_t type##list_len(const Type##List *a) { \
105 return a ? a->len : 0; \
107ANN static inline Type type##list_back(const Type##List *a) { \
108 return a->ptr[a->len-1]; \
#define mp_vector_rem(a, type, idx)
static uint32_t mp_vector_len(MP_Vector *a)
static ANN void mp_vector_resize(const MemPool mp, MP_Vector **ap, const uint32_t size, const uint32_t cap)
#define new_mp_vector(mp, type, data)
#define mp_vector_pop(a, type)
struct MP_Vector MP_Vector
#define free_mp_vector(mp, type, data)
void * mp_realloc(MemPool mp, void *ptr, const m_uint curr, const m_uint next)
#define mp_free2(p, sz, a)