From 043562aacf40373b6544c88a7e1a681d1184fdd1 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 20 Dec 2016 00:32:34 -0800 Subject: [PATCH] Add two headers, one for the general libds stuff and one for vectors. --- include/libds.h | 17 +++++++++++++++++ include/vec.h | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 include/libds.h create mode 100644 include/vec.h diff --git a/include/libds.h b/include/libds.h new file mode 100644 index 0000000..37562db --- /dev/null +++ b/include/libds.h @@ -0,0 +1,17 @@ +#ifndef LIBDS_HEADER +#define LIBDS_HEADER + +#include + +enum libds_result_e { + SUCCSESS, + MALLOC +}; + +typedef enum libds_result_e libds_result; +typedef int (*compare_func)(void*, void*); +typedef int (*foreach_func)(void*, va_list); + +int compare_always(void* a, void* b); + +#endif diff --git a/include/vec.h b/include/vec.h new file mode 100644 index 0000000..a3250f7 --- /dev/null +++ b/include/vec.h @@ -0,0 +1,25 @@ +#ifndef LIBDS_VEC_HEADER +#define LIBDS_VEC_HEADER + +#define LIBDS_VEC_CAPACITY 4 + +#include "libds.h" + +struct vec_s { + void* data; + int capacity; + int size; +}; + +typedef struct vec_s vec; + +libds_result vec_init(vec*); +void vec_free(vec*); + +libds_result vec_add(vec*, void*); +void vec_remove(vec*, void*); + +void* vec_find(vec*, void*, compare_func); +int vec_foreach(vec*, void*, compare_func, foreach_func, ...); + +#endif