Add reserve operation.
This commit is contained in:
1 parent
da5691da40
commit
f69130bb06
2 files changed
+24
No files matched your search
@@ -311,6 +311,23 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C3(array_, name, _reserve)(M_C3(array_, name, _t) v, size_t alloc) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
if (v->size > alloc) { \
|
||||
alloc = v->size; \
|
||||
} \
|
||||
type *ptr = M_GET_REALLOC oplist (type, v->ptr, alloc); \
|
||||
if (M_UNLIKELY (ptr == NULL) ) { \
|
||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||
return; \
|
||||
} \
|
||||
v->ptr = ptr; \
|
||||
v->alloc = alloc; \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C3(array_, name, _set_at2)(M_C3(array_, name,_t) v, size_t idx, type x) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
|
||||
@@ -146,6 +146,13 @@ static void test_uint(void)
|
||||
array_uint_swap(v,v2);
|
||||
assert(array_uint_size(v) == 1005);
|
||||
assert(array_uint_size(v2) == 0);
|
||||
|
||||
array_uint_reserve(v, 100);
|
||||
assert(array_uint_size(v) == 1005);
|
||||
assert(array_uint_capacity(v) == 1005);
|
||||
array_uint_reserve(v, 10000);
|
||||
assert(array_uint_size(v) == 1005);
|
||||
assert(array_uint_capacity(v) == 10000);
|
||||
|
||||
array_uint_clear(v);
|
||||
array_uint_clear(v2);
|
||||
|
||||
Reference in new issue
Block a user