From a61ad1cef9ef77f9afd67230df5470b6b55525be Mon Sep 17 00:00:00 2001 From: FreeArtMan <=> Date: Thu, 17 Dec 2015 20:59:18 +0000 Subject: Initial commit --- darray.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 darray.h (limited to 'darray.h') diff --git a/darray.h b/darray.h new file mode 100644 index 0000000..8d8f9e9 --- /dev/null +++ b/darray.h @@ -0,0 +1,53 @@ +/* Some thx goes to http://c.learncodethehardway.org/book/ex34.html */ +#ifndef __LIBADT_DARRAY_H +#define __LIBADT_DARRAY_H + +#include +#include +#include +#include +#include + +//#include "debug.h" +//#include "mmm.h" + +#define DEFAULT_EXPAND_RATE 10 + +typedef struct darray { + int end; //element amount. end <= max + int max; //maximal element number + size_t size; //single element size + size_t expand; //expand size + void **data; +} darray; + +darray* darr_create(ssize_t data_size, ssize_t init_size); +void darr_destroy(darray *da); +void darr_clear(darray *da); +void darr_clear_idx(darray *da, int idx); +int darr_expand(darray *da); +int darr_resize(darray *da, ssize_t size); +int darr_contract(darray *da); +int darr_push(darray *da, void *val); +void* darr_pop(darray *da); +void darr_clear_destroy(darray *da); +int darr_set(darray *da, int idx, void *val); +void* darr_get(darray *da, int idx); +void* darr_remove(darray *da, int idx); +void* darr_new(darray *da); +int darr_isidx(darray *da, int idx); + +#define darr_last(A) ((A)->data[(A)->end - 1]) +#define darr_first(A) ((A)->data[0]) +#define darr_end(A) ((A)->end) +#define darr_count(A) darr_end(A) +#define darr_max(A) ((A)->max) +#define darr_free(E) free((E)) + +/* +when do set it just overwrite data without checking if there is some or not +if set more then max then no error and no resize happens +when get element if error then NULL if value NULL then NULL how distinguish +*/ + +#endif -- cgit v1.2.3