// vim: set et sw=4 ts=4 tw=80:
#ifndef COLLECTIONS_H_INCLUDED
#define COLLECTIONS_H_INCLUDED

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
 * Doubly linked list
 */

typedef struct dl_node {
	void* element;
	struct dl_node* prev;
	struct dl_node* next;
} dl_node_t;

typedef struct dl_list {
	dl_node_t* first;
} dl_list_t;

extern size_t dl_list_length(const dl_list_t* self);
extern dl_node_t* dl_list_ith(const dl_list_t* self, const size_t position);
extern dl_node_t* dl_list_ith_or_last(const dl_list_t* self,
        const size_t position, size_t* returned);

extern inline dl_node_t* dl_list_alloc_node(void* element);
extern inline void dl_list_free_node(dl_node_t* node);

extern inline void dl_list_init(dl_list_t* list);
extern inline void dl_list_destroy(dl_list_t* list);

extern size_t dl_list_copy_slice(const dl_list_t* self, dl_list_t* destination,
		const size_t from, const size_t to);

extern int dl_list_insert(dl_list_t* self, const size_t position,
		dl_node_t* node);
extern dl_node_t* dl_list_remove(dl_list_t* self, const size_t position);

typedef struct vector {
    void** elements;
    size_t size;
    size_t capacity;
} vector_t;

extern void vector_init(vector_t* self, const size_t initial_capacity);

#endif
