Debian Codegraph @

list.h

raw symbols SCIP
1 /** @file list.h
2 Declarations for a doubly linked list.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 This program is released under the GPL with the additional exemption
19 that compiling, linking, and/or using OpenSSL is allowed.
20
21 Copyright (C) 2008 Bertrand Mesot <http://www.objectif-securite.ch>
22 */
23
24 #ifndef LIST_H
25 #define LIST_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /** A list node. */
32
33 typedef struct list_nd_t_ {
34 void *data; /**< The element to be stored. */
35 struct list_nd_t_ *prev; /**< A pointer to the previous node. */
36 struct list_nd_t_ *next; /**< A pointer to the following node. */
37 } list_nd_t;
38
39 /** A doubly linked list. */
40
41 typedef struct list_t_ {
42 int size; /**< The size of the list */
43 list_nd_t *head; /**< A pointer to the head of the list. */
44 list_nd_t *tail; /**< A pointer to the tail of the list. */
45 } list_t;
46
47 /** Allocate memory for a list. */
48
49 list_t *list_alloc(void);
50
51 /** Free the memory used by the list.
52 *
53 * The memory used by the element is not freed. It is therefore your
54 * responsability to clean up that part of the memory.
55 *
56 * @param l A pointer to the list to be cleared.
57 */
58
59 void list_free(list_t *l);
60
61 /** Empty the list. */
62
63 void list_clean(list_t *l);
64
65 /** Add an element to the head of the list.
66 * @param l A pointer to the list.
67 * @param data A pointer to the element.
68 */
69
70 void list_add_head(list_t *l, void *data);
71
72 /** Add an element to the tail of the list.
73 * @param l A pointer to the list.
74 * @param data A pointer to the element.
75 */
76
77 void list_add_tail(list_t *l, void *data);
78
79 /** Remove an element from the head of the list.
80 * @param l A pointer to the list.
81 * @return A pointer to the element stored in the head.
82 */
83
84 void *list_rem_head(list_t *l);
85
86 /** Remove an element from the tail of the list.
87 * @param l A pointer to the list.
88 * @return A pointer to the element stored in the tail.
89 */
90
91 void *list_rem_tail(list_t *l);
92
93 /** Allocate memory for a list node.
94 * @param data A pointer to the element.
95 * @return A list node containing the element.
96 */
97
98 list_nd_t *list_nd_alloc(void *data);
99
100 /** Free the memory used by a node.
101 * @param nd The node to be freed.
102 * @return A pointer to the element stored in the node.
103 */
104
105 void *list_nd_free(list_nd_t *nd);
106
107 #ifdef __cplusplus
108 }
109 #endif
110 #endif