/*
    List.h, Copyright  (c) by George Fankhauser,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
        
   File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Topsy/List.h,v $
   Author(s):             George Fankhauser
   Affiliation:           ETH Zuerich, TIK
   Version:               $Revision: 2922 $
   Creation Date:         
   Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $      by: $Author: baderma $
*/
#ifndef _LIST_H_
#define _LIST_H_

#include "Topsy.h"
#include "MMHeapMemory.h"

#define LIST_ERROR 0
#define LIST_OK 1

typedef struct ListElement_t
{
  void* item;
  struct ListElement_t* next;
  struct ListElement_t* prev;
}
ListElementDesc;

typedef ListElementDesc* ListElement;

typedef struct ListDesc_t
{
  ListElement first;
  ListElement current;
  ListElement last;
}
ListDesc;

typedef ListDesc* List;

/* basic list functions */
List listNew(void);
Error listFree(List list);

Error listAddInFront(List list, void* item, Address* hint);
Error listAddAtEnd(List list, void* item, Address* hint);
Error listRemove(List list, void* item, Address hint);

/* advanced operations that cause no alloc/free */
Error listMoveToEnd(List list, void* item, Address hint);
Error listSwap(List listFrom, List listTo, void* item, Address hint);
int listIsEmpty(List list);

/* iteration */
Error listGetFirst(List list, void** itemPtr);
Error listGetNext(List list, void** itemPtr);

#endif
