// Double linked list structure

#ifndef _DLLISTH
#define _DLLISTH

typedef struct Dllist_item *Dllist_item_ptr;

struct Dllist_item{
  void *item;      // the item is a pointer to a transaction
  Dllist_item_ptr next;      // next item in the list
  Dllist_item_ptr prev;      // previous item in the list
};

typedef struct T_Dllist *T_Dllist_ptr;

struct T_Dllist {
  Dllist_item_ptr first;
  Dllist_item_ptr last;

  void (*freeItem)(void *item);
};

T_Dllist_ptr Dllist_create(void (*freeItem)(void *item));

void Dllist_destroy(T_Dllist_ptr);

int Dllist_isEmpty(T_Dllist_ptr);

Dllist_item_ptr Dllist_insert(T_Dllist_ptr, void*);

void Dllist_remove(T_Dllist_ptr, Dllist_item_ptr);

Dllist_item_ptr Dllist_first(T_Dllist_ptr);

Dllist_item_ptr Dllist_next(Dllist_item_ptr);

Dllist_item_ptr Dllist_prev(Dllist_item_ptr);

void Dllist_print(T_Dllist_ptr, void *);

void Dllist_extract(T_Dllist_ptr, Dllist_item_ptr);
Dllist_item_ptr Dllist_enqueue(T_Dllist_ptr, Dllist_item_ptr);
Dllist_item_ptr Dllist_dequeue(T_Dllist_ptr);
#endif
