rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit e36df5f3b826d1c365009301b4df47ff04a02d2b
parent 8f9a78a5fe9554ec9fe81f54a8a70a3a55ab32eb
Author: vaplv <vaplv@free.fr>
Date:   Tue, 18 Feb 2014 17:42:29 +0100

Add the resize function on dynamic arrays

Add the min/max math macro

Diffstat:
Msrc/dynamic_array.h | 10++++++++++
Msrc/math.h | 3+++
Msrc/test_dynamic_array.c | 10++++++++++
3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/dynamic_array.h b/src/dynamic_array.h @@ -89,6 +89,16 @@ DARRAY_FUNC__(reserve)(struct DARRAY_TYPE__* darray, const size_t sz) } static FINLINE char +DARRAY_FUNC__(resize)(struct DARRAY_TYPE__* darray, const size_t sz) +{ + ASSERT(darray); + if(DARRAY_FUNC__(reserve)(darray, sz)) + return -1; + darray->size = sz; + return 0; +} + +static FINLINE char DARRAY_FUNC__(push_back) (struct DARRAY_TYPE__* darray, DARRAY_DATA_TYPE* const data) diff --git a/src/math.h b/src/math.h @@ -3,6 +3,9 @@ #include "rsys.h" +#define max(A, B) (A) > (B) ? (A) : (B) +#define min(A, B) (A) < (B) ? (A) : (B) + static FINLINE char is_power_of_2(const size_t i) { diff --git a/src/test_dynamic_array.c b/src/test_dynamic_array.c @@ -52,6 +52,16 @@ main(int argc, char** argv) CHECK(darray_str_size_get(&darray), 0); darray_str_release(&darray); + darray_str_init(&mem_default_allocator, &darray); + CHECK(darray_str_size_get(&darray), 0); + darray_str_resize(&darray, 8); + CHECK(darray_str_size_get(&darray), 8); + darray_str_resize(&darray, 0); + CHECK(darray_str_size_get(&darray), 0); + darray_str_resize(&darray, 33); + CHECK(darray_str_size_get(&darray), 33); + darray_str_release(&darray); + if(MEM_ALLOCATED_SIZE(&allocator_proxy)) { char dump[512]; MEM_DUMP(&allocator_proxy, dump, sizeof(dump)/sizeof(char));