diff options
Diffstat (limited to 'darray.h')
-rw-r--r-- | darray.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/darray.h b/darray.h new file mode 100644 index 0000000..3cf7e16 --- /dev/null +++ b/darray.h @@ -0,0 +1,51 @@ +/* Some thx goes to http://c.learncodethehardway.org/book/ex34.html */ +#ifndef __LIBADT_DARRAY_H +#define __LIBADT_DARRAY_H + +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> + +#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 |