#ifndef _VECTOR_H_
#define _VECTOR_H_
#include <stdlib.h>
#include <stdio.h>

struct generic_vector {
	void* items;
	int index;
	int size;
}

void vec_resize(struct generic_vector *vec, size_t item_size) {
	if ((vec->index + 1) < vec->size) {
		return;
	}
	vec->size *= 2;
	void* temp = realloc(vec->items, vec->size*item_size);
	if (!temp) {
		printf("Error resizing vector, you might be out of memory.\n");
		exit(-1);
	}
	vec->items = temp;
}

void vec_destroy(struct generic_vector *vec) {
	free(vec->items);
}

void *vec_getitem(struct generic_vector *vec, int index, size_t item_size) {
	return (vec->items + (index * item_size));
}

_Bool vec_contains(struct generic_vector *vec, void *item, size_t item_size) {
	void *list = vec->items;
	for (int i = 0; i/item_size < vec->index; i = (i+1)*item_size) {
		int c = memcmp(list+i, item, item_size);
		if (c == 0)
			return true;
	}
	return false
}

#define VEC_CONTAINS(vec, item) \


#define VEC_PUSH(vec, item) \
	vec_resize((vec), sizeof(item)); ((__typeof__(item *))(vec)->items)[(vec)->index++] = item;

#define VEC_GET(vec, index, out) \
	*out = *((__typeof__(out))vec_getitem((vec), index, sizeof(__typeof__(*out))));

#define VEC_DESTROY(vec) \
	vec_destroy(vec);



#endif
