summaryrefslogtreecommitdiff
path: root/darray.h
diff options
context:
space:
mode:
authorFreeArtMan <=>2015-12-17 20:59:18 +0000
committerFreeArtMan <=>2015-12-17 20:59:18 +0000
commita61ad1cef9ef77f9afd67230df5470b6b55525be (patch)
treed8bae5fc932865e769e4965ce0817b6d107badf2 /darray.h
downloaddm-a61ad1cef9ef77f9afd67230df5470b6b55525be.tar.gz
dm-a61ad1cef9ef77f9afd67230df5470b6b55525be.zip
Initial commit
Diffstat (limited to 'darray.h')
-rw-r--r--darray.h53
1 files changed, 53 insertions, 0 deletions
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 <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/types.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