/* Some thx goes to http://c.learncodethehardway.org/book/ex34.html */ #ifndef __LIBADT_DARRAY_H #define __LIBADT_DARRAY_H #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