#ifndef SWIFT_DATA_ARRAY_H
#define SWIFT_DATA_ARRAY_H

#include <swift/stdlib.h>

#include <swift/data/api.h>
#include <swift/data/types.h>

typedef struct swift_array_t swift_array_t;
typedef struct swift_array_iter_t swift_array_iter_t;

struct swift_array_t {
	swift_cmp_fn_t cmp;
	unsigned char *data;
	size_t count, size, item_size;
};

struct swift_array_iter_t {
	swift_array_t *array;
	void *data;
	size_t index;
};

#define SWIFT_ARRAY_ITER(...) ((swift_array_iter_t){__VA_ARGS__})

SWIFT_DATA_API bool swift_init_array_size(swift_array_t *array,
	swift_cmp_fn_t cmp, size_t item_size, size_t size);
SWIFT_DATA_API bool swift_init_array(swift_array_t *array, swift_cmp_fn_t cmp,
	size_t item_size);
SWIFT_DATA_API void swift_term_array(swift_array_t *array);
SWIFT_DATA_API swift_array_t *swift_new_array_size(swift_cmp_fn_t cmp,
	size_t item_size, size_t size);
SWIFT_DATA_API swift_array_t *swift_new_array(swift_cmp_fn_t cmp,
	size_t item_size);
SWIFT_DATA_API void swift_del_array(swift_array_t *array);
SWIFT_DATA_API bool swift_array_resize(swift_array_t *array, size_t size);
SWIFT_DATA_API bool swift_array_expand(swift_array_t *array, size_t count);
SWIFT_DATA_API swift_array_iter_t swift_array_first(swift_array_t *array);
SWIFT_DATA_API swift_array_iter_t swift_array_last(swift_array_t *array);
SWIFT_DATA_API bool swift_array_next(swift_array_iter_t *iter);
SWIFT_DATA_API bool swift_array_prev(swift_array_iter_t *iter);
SWIFT_DATA_API bool swift_array_contains(swift_array_t *array, const void *key);
SWIFT_DATA_API void *swift_array_get(swift_array_t *array, size_t index);
SWIFT_DATA_API size_t swift_array_set(swift_array_t *array, size_t index,
	void *entry);
SWIFT_DATA_API size_t swift_array_insert(swift_array_t *array, size_t index,
	void *entry);
SWIFT_DATA_API size_t swift_array_remove_range(swift_array_t *array,
	size_t index, size_t count);
SWIFT_DATA_API size_t swift_array_remove_index(swift_array_t *array,
	size_t index);
SWIFT_DATA_API size_t swift_array_remove(swift_array_t *array, const void *key);
SWIFT_DATA_API size_t swift_array_push(swift_array_t *array, void *entry);
SWIFT_DATA_API size_t swift_array_pop(swift_array_t *array);
SWIFT_DATA_API bool swift_array_sort(swift_array_t *array);

#endif /* SWIFT_DATA_ARRAY_H */
