#ifndef SWIFT_DATA_LIST_H
#define SWIFT_DATA_LIST_H

#include <swift/stdlib.h>

#include <swift/data/api.h>

typedef struct swift_list_t swift_list_t;
typedef struct swift_list_iter_t swift_list_iter_t;

struct swift_list_t {
	swift_list_t *next, *prev;
};

struct swift_list_iter_t {
	swift_list_t *list, *node, *next;
};

#define SWIFT_LIST_ITER(...) ((swift_list_iter_t){__VA_ARGS__})

SWIFT_DATA_API bool swift_init_list(swift_list_t *list);
SWIFT_DATA_API void swift_term_list(swift_list_t *list);
SWIFT_DATA_API swift_list_t *swift_new_list(void);
SWIFT_DATA_API void swift_del_list(swift_list_t *list);

SWIFT_DATA_API bool swift_list_is_empty(swift_list_t *list);
SWIFT_DATA_API swift_list_iter_t swift_list_first(swift_list_t *list);
SWIFT_DATA_API swift_list_iter_t swift_list_last(swift_list_t *list);
SWIFT_DATA_API bool swift_list_next(swift_list_iter_t *iter);
SWIFT_DATA_API bool swift_list_prev(swift_list_iter_t *iter);

SWIFT_DATA_API bool swift_list_insert_before(swift_list_t *list,
	swift_list_t *entry);
SWIFT_DATA_API bool swift_list_insert_after(swift_list_t *list,
	swift_list_t *entry);
SWIFT_DATA_API bool swift_list_remove(swift_list_t *list, swift_list_t *entry);
SWIFT_DATA_API bool swift_list_push(swift_list_t *list, swift_list_t *entry);
SWIFT_DATA_API bool swift_list_unshift(swift_list_t *list, swift_list_t *entry);
SWIFT_DATA_API swift_list_t *swift_list_pop(swift_list_t *list);
SWIFT_DATA_API swift_list_t *swift_list_shift(swift_list_t *list);

#endif /* SWIFT_DATA_LIST_H */
