#ifndef _Sorted_List
#define _Sorted_List

/****
Sorted list class
-----------------

Usage:-
  s = slist_new(..)
  thing = allocate();      <- allocate 2 objects
  thing2 = allocate();
  slist_insert(s,thing);   <- insert into sorted list
  slist_insert(s,thing2);
  thing = slist_get(s,0);  <- use one
  thing = slist_del(s,0);  <- remove one from the list
  free(thing);             <- free it
  slist_clear(s,free);     <- free remaining items in the list
  slist_free(&s);          <- free list memory

Details:-
   Funtions that return 'int' return -1 on failure.
   List stores pointers to given items, it does not allocate or free objects (except
     when told to i.e. slist_clear)
   List starts at given size, and resizes by  half-again each time it needs new space i.e.
     it might go 10 -> 15 -> 22 -> 33 -> 49 ..etc..
*/

struct slist;
typedef struct slist Slist;

Slist *slist_new(int sz, int(*compare)(const void *, const void *));
void slist_clear(Slist *s, void(*clear)(void *));
void slist_free(Slist **s);

int slist_size(Slist *s);
int slist_items(Slist *s);

int slist_expand(Slist *s, int x);

int slist_insert(Slist *s, void *item);
void *slist_get(Slist *s, int i);
void *slist_del(Slist *s, int i);

#endif
