-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.h
28 lines (21 loc) · 1.06 KB
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef LIST_H_
#define LIST_H_
#include "mem.h"
/* generic list support */
typedef struct _list {
long length; /* how many elements are in the list */
long capacity; /* out of how many possible */
void **data; /* the items */
} LIST;
extern LIST *list_new(); /* create a list */
extern void list_free(LIST *); /* free a list, but not its data */
extern void list_freeData(LIST *, Destructor); /* free a list and its data */
extern long list_length(LIST *); /* return the number of elements in a list */
extern void *list_get(LIST *, long); /* get an element from a list */
extern void list_add(LIST *, void *); /* add to end of list */
extern void list_append(LIST *, LIST *); /* append the second list to the first list */
extern void list_appendAndFree(LIST *, LIST *); /* append the 2nd list to 1st and free the 2nd */
extern LIST *list_addToNew(void *); /* return a new 1-element list with the given element */
extern LIST *list_reverse(LIST *); /* return a reversed copy of the list */
void *list_getRand(LIST *); /* get a random element from a list */
#endif