Debian Codegraph @

list.c

raw symbols SCIP
1 /** @file list.c
2 Implementation of 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 #include <stdlib.h>
25 #include <assert.h>
26
27 #include "list.h"cxx . . $ `<file>/list.h`/
28 /*-------------------------------------------------------------------------*/
29 list_tcxx . . $ list_t# *list_alloccxx . . $ list_alloc(a211c0eefd2c4fb9).(void) {
30 list_tcxx . . $ list_t# *l = (list_tcxx . . $ list_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(list_tcxx . . $ list_t#));
31
32 l->sizecxx . . $ list_t_#size. = 0;
33 l->headcxx . . $ list_t_#head. = 0;
34 l->tailcxx . . $ list_t_#tail. = 0;
35
36 return l;
37 }
38 /*-------------------------------------------------------------------------*/
39 void list_freecxx . . $ list_free(873e96cd268b28a2).(list_tcxx . . $ list_t# *l) {
40 list_cleancxx . . $ list_clean(873e96cd268b28a2).(l);
41 freecxx . . $ free(5d22bdacc48458e8).(l);
42 }
43 /*-------------------------------------------------------------------------*/
44 void list_cleancxx . . $ list_clean(873e96cd268b28a2).(list_tcxx . . $ list_t# *l) {
45 while (l->sizecxx . . $ list_t_#size.)
46 list_rem_headcxx . . $ list_rem_head(e3a173406177a4b8).(l);
47 }
48 /*-------------------------------------------------------------------------*/
49 void list_add_headcxx . . $ list_add_head(a17800064bb915b4).(list_tcxx . . $ list_t# *l, void *data) {
50 list_nd_tcxx . . $ list_nd_t# *nd = list_nd_alloccxx . . $ list_nd_alloc(c9b460d93d208c57).(data);
51 list_nd_tcxx . . $ list_nd_t# *old = l->headcxx . . $ list_t_#head.;
52
53 nd->prevcxx . . $ list_nd_t_#prev. = old;
54 l->headcxx . . $ list_t_#head. = nd;
55 l->sizecxx . . $ list_t_#size. += 1;
56
57 if (old != 0)
58 old->nextcxx . . $ list_nd_t_#next. = nd;
59 else
60 l->tailcxx . . $ list_t_#tail. = nd;
61 }
62 /*-------------------------------------------------------------------------*/
63 void list_add_tailcxx . . $ list_add_tail(a17800064bb915b4).(list_tcxx . . $ list_t# *l, void *data) {
64 list_nd_tcxx . . $ list_nd_t# *nd = list_nd_alloccxx . . $ list_nd_alloc(c9b460d93d208c57).(data);
65 list_nd_tcxx . . $ list_nd_t# *old = l->tailcxx . . $ list_t_#tail.;
66
67 nd->nextcxx . . $ list_nd_t_#next. = old;
68 l->tailcxx . . $ list_t_#tail. = nd;
69 l->sizecxx . . $ list_t_#size. += 1;
70
71 if (old != 0)
72 old->prevcxx . . $ list_nd_t_#prev. = nd;
73 else
74 l->headcxx . . $ list_t_#head. = nd;
75 }
76 /*-------------------------------------------------------------------------*/
77 void *list_rem_headcxx . . $ list_rem_head(e3a173406177a4b8).(list_tcxx . . $ list_t# *l) {
78 list_nd_tcxx . . $ list_nd_t# *nd = l->headcxx . . $ list_t_#head.;
79
80 if (nd == 0) return 0;
81
82 list_nd_tcxx . . $ list_nd_t# *old = nd->prevcxx . . $ list_nd_t_#prev.;
83
84 l->headcxx . . $ list_t_#head. = old;
85 l->sizecxx . . $ list_t_#size. -= 1;
86
87 if (old != 0)
88 old->nextcxx . . $ list_nd_t_#next. = 0;
89 else
90 l->tailcxx . . $ list_t_#tail. = 0;
91
92 return list_nd_freecxx . . $ list_nd_free(3e4427c9aa9fd2db).(nd);
93 }
94 /*-------------------------------------------------------------------------*/
95 void *list_rem_tailcxx . . $ list_rem_tail(e3a173406177a4b8).(list_tcxx . . $ list_t# *l) {
96 list_nd_tcxx . . $ list_nd_t# *nd = l->tailcxx . . $ list_t_#tail.;
97
98 if (nd == 0) return 0;
99
100 list_nd_tcxx . . $ list_nd_t# *old = nd->nextcxx . . $ list_nd_t_#next.;
101
102 l->tailcxx . . $ list_t_#tail. = old;
103 l->sizecxx . . $ list_t_#size. -= 1;
104
105 if (old != 0)
106 old->prevcxx . . $ list_nd_t_#prev. = 0;
107 else
108 l->headcxx . . $ list_t_#head. = 0;
109
110 return list_nd_freecxx . . $ list_nd_free(3e4427c9aa9fd2db).(nd);
111 }
112 /*-------------------------------------------------------------------------*/
113 list_nd_tcxx . . $ list_nd_t# *list_nd_alloccxx . . $ list_nd_alloc(c9b460d93d208c57).(void *data) {
114 list_nd_tcxx . . $ list_nd_t# *nd = (list_nd_tcxx . . $ list_nd_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(list_nd_tcxx . . $ list_nd_t#));
115
116 nd->prevcxx . . $ list_nd_t_#prev. = 0;
117 nd->nextcxx . . $ list_nd_t_#next. = 0;
118 nd->datacxx . . $ list_nd_t_#data. = data;
119
120 return nd;
121 }
122 /*-------------------------------------------------------------------------*/
123 void *list_nd_freecxx . . $ list_nd_free(3e4427c9aa9fd2db).(list_nd_tcxx . . $ list_nd_t# *nd) {
124 void *data = nd->datacxx . . $ list_nd_t_#data.;
125
126 freecxx . . $ free(5d22bdacc48458e8).(nd);
127
128 return data;
129 }