#ifndef _INTLIST_H
#define	_INTLIST_H

#include "common.h"

#ifdef	__cplusplus
extern "C" {
#endif

typedef struct _IList IList;
typedef struct _IElement IElement;

/** Element of list of integers*/
struct _IElement {
    IElement* next;
    IElement* prev;
    int val;
};

/** Dumb double linked list of integer with
 *  iteration and reverse iteration(deteration) capability
 */
struct _IList{
    /**List head*/
    IElement* head;
    /**Lis tail*/
    IElement* tail;
    /**Number of elements in the list*/
    int length;
    /**Pointer to current element during iterations*/
    IElement* iter;
    /**Index of element that was found by last iteration*/
    int lastIterIndex;
};


/**\brief Create new list of integers*/
IList* ilist_new();
/**\brief Create new list and add elements using mask
   \param mask Mask
   \param positiveVal Indicates indices what elements 1s or 0s are to be
 *  added to the list
 */
IList* ilist_new_from_mask(unsigned char* mask,int count,unsigned char positiveVal);

/**\brief Create new list and add sequence like 0,1,2,3,...,4...
 * \param count Number of elements of the sequence
 * \return New list of integers
 */
IList* ilist_new_sequence(int count);

/**\brief Create mask based on the list*/
void ilist_make_mask(IList* l,unsigned char* maskPtr,int length,unsigned char positiveVal);
/**\brief Delete list and all its elements*/
void ilist_delete(IList *l);
/**\brief Remove element at specified index*/
void ilist_remove(IList *l,int index);
/**\brief Obtain element at specified index*/
int  ilist_get(IList *l ,int index);
/**\brief Append integer to the list*/
void ilist_append(IList* l,int val);
/**\brief Start iteration from th beginning*/
void ilist_start_iteration(IList* l);
/**\brief Get next element
 * \return 1 when next element available else 0 - end of iteration*/
int ilist_iterate(IList* l, int* retElement);
/**\brief Print the state of the list*/
void ilist_print(IList* l);
/**\brief Start reverse iteration (deteration)*/
void ilist_start_deteration(IList* l);
/**\brief Get previous element
 * \return 1 when previous element available else 0 - end of deteration*/
int ilist_deterate(IList* l, int* retElement);




#ifdef	__cplusplus
}
#endif

#endif	/* _INTLIST_H */


