/*
 * frost_list.h
 *
 *  Created on: Jul 1, 2012
 *      Author: ergino
 */

#ifndef FROST_LIST_H_
#define FROST_LIST_H_

#include "frost_common.h"

typedef struct _FROST_List FROST_List;
struct _FROST_List
{
  frost_pointer data;
  FROST_List *next;
  FROST_List *prev;
};

#define frost_list_next(list) ((list) ? (((FROST_List *) (list))->next) : NULL)
#define frost_list_previous(list) ((list) ? (((FROST_List *) (list))->prev) : NULL)

#ifdef __cplusplus
extern "C"
{
#endif

FROST_List *frost_list_alloc         (void);
FROST_List *frost_list_append        (FROST_List         *list,
                 frost_pointer       data);
FROST_List *frost_list_prepend       (FROST_List         *list,
                 frost_pointer       data);
void   frost_list_free          (FROST_List         *list);
void   frost_list_free_1        (FROST_List         *list);
FROST_List *frost_list_copy          (FROST_List         *list);
frost_uint  frost_list_length        (FROST_List         *list);
frost_int   frost_list_index         (FROST_List         *list,
                 frost_constpointer  data);
FROST_List *frost_list_nth           (FROST_List         *list,
                 frost_uint          n);
frost_pointer frost_list_nth_data      (FROST_List         *list,
                 frost_uint          n);
FROST_List *frost_list_last          (FROST_List         *list);
FROST_List *frost_list_concat        (FROST_List         *list1,
                 FROST_List         *list2);
void   frost_list_foreach       (FROST_List         *list,
                 FROSTFunc          func,
                 frost_pointer       user_data);
FROST_List *frost_list_first         (FROST_List         *list);
FROST_List *frost_list_find          (FROST_List         *list,
                 frost_constpointer  data);
FROST_List *frost_list_find_custom   (FROST_List     *list,
                 frost_constpointer  data,
                 FROSTCompareFunc   func);
FROST_List *frost_list_remove        (FROST_List         *list,
                 frost_constpointer  data);
FROST_List *frost_list_reverse       (FROST_List         *list);
FROST_List *frost_list_remove_link   (FROST_List         *list,
                 FROST_List         *link);
FROST_List *frost_list_delete_link   (FROST_List         *list,
                 FROST_List         *link);
FROST_List *frost_list_insert_sorted (FROST_List         *list,
                 frost_pointer       data,
                 FROSTCompareFunc   func);
FROST_List *frost_list_insert_before (FROST_List         *list,
                 FROST_List         *sibling,
                 frost_pointer       data);
FROST_List *frost_list_sort          (FROST_List         *sort,
                 FROSTCompareFunc   func);

#ifdef __cplusplus
}
#endif

#endif /* FROST_LIST_H_ */
