blob: ae7f0868e9575657e68910e62028b709940044ab [file] [log] [blame]
willy tarreau12350152005-12-18 01:03:27 +01001/*
2 This File is copied from
3
4 http://www.oreilly.com/catalog/masteralgoc/index.html
5 Mastering Algorithms with C
6 By Kyle Loudon
7 ISBN: 1-56592-453-3
8 Publishd by O'Reilly
9
10 */
11
12/*****************************************************************************
13* *
14* -------------------------------- list.h -------------------------------- *
15* *
16*****************************************************************************/
17
18#ifndef LIST_H
19#define LIST_H
20
21#include <stdlib.h>
22
23/*****************************************************************************
24 * *
25 * Define a structure for linked list elements. *
26 * *
27 *****************************************************************************/
28
29typedef struct ListElmt_ {
30
31 void *data;
32 struct ListElmt_ *next;
33} ListElmt;
34
35/*****************************************************************************
36 * *
37 * Define a structure for linked lists. *
38 * *
39 *****************************************************************************/
40
41typedef struct List_ {
42 int size;
43 int (*match)(const void *key1, const void *key2);
44 void (*destroy)(void *data);
45
46 ListElmt *head;
47 ListElmt *tail;
48} List;
49
50/*****************************************************************************
51 * *
52 * --------------------------- Public Interface --------------------------- *
53 * *
54 *****************************************************************************/
55
56void list_init(List *list, void (*destroy)(void *data));
57
58void list_destroy(List *list);
59
60int list_ins_next(List *list, ListElmt *element, const void *data);
61
62int list_rem_next(List *list, ListElmt *element, void **data);
63
64#define list_size(list) ((list)->size)
65
66#define list_head(list) ((list)->head)
67
68#define list_tail(list) ((list)->tail)
69
70#define list_is_head(list, element) ((element) == (list)->head ? 1 : 0)
71
72#define list_is_tail(element) ((element)->next == NULL ? 1 : 0)
73
74#define list_data(element) ((element)->data)
75
76#define list_next(element) ((element)->next)
77
78#endif