32
33
to two or more lists, provided that the list are given different names.
33
34
An example of the usage of the lists can be found in fil0fil.c. */
35
/***********************************************************************
36
/*******************************************************************//**
36
37
This macro expands to the unnamed type definition of a struct which acts
37
38
as the two-way list base node. The base node contains pointers
38
39
to both ends of the list and a count of nodes in the list (excluding
39
the base node from the count). TYPE should be the list node type name. */
40
the base node from the count).
41
@param TYPE the name of the list node data type */
41
42
#define UT_LIST_BASE_NODE_T(TYPE)\
43
ulint count; /* count of nodes in list */\
44
TYPE * start; /* pointer to list start, NULL if empty */\
45
TYPE * end; /* pointer to list end, NULL if empty */\
44
ulint count; /*!< count of nodes in list */\
45
TYPE * start; /*!< pointer to list start, NULL if empty */\
46
TYPE * end; /*!< pointer to list end, NULL if empty */\
48
/***********************************************************************
49
/*******************************************************************//**
49
50
This macro expands to the unnamed type definition of a struct which
50
51
should be embedded in the nodes of the list, the node type must be a struct.
51
52
This struct contains the pointers to next and previous nodes in the list.
52
53
The name of the field in the node struct should be the name given
53
to the list. TYPE should be the list node type name. Example of usage:
55
@param TYPE the list node type name */
55
57
typedef struct LRU_node_struct LRU_node_t;
56
58
struct LRU_node_struct {
57
59
UT_LIST_NODE_T(LRU_node_t) LRU_list;
60
62
The example implements an LRU list of name LRU_list. Its nodes are of type
64
65
#define UT_LIST_NODE_T(TYPE)\
66
TYPE * prev; /* pointer to the previous node,\
67
TYPE * prev; /*!< pointer to the previous node,\
67
68
NULL if start of list */\
68
TYPE * next; /* pointer to next node, NULL if end of list */\
69
TYPE * next; /*!< pointer to next node, NULL if end of list */\
71
/***********************************************************************
72
Initializes the base node of a two-way list. */
72
/*******************************************************************//**
73
Initializes the base node of a two-way list.
74
@param BASE the list base node
74
76
#define UT_LIST_INIT(BASE)\
145
/* Invalidate the pointers in a list node. */
146
151
#ifdef UNIV_LIST_DEBUG
152
/** Invalidate the pointers in a list node.
153
@param NAME list name
154
@param N pointer to the node that was removed */
147
155
# define UT_LIST_REMOVE_CLEAR(NAME, N) \
148
156
((N)->NAME.prev = (N)->NAME.next = (void*) -1)
158
/** Invalidate the pointers in a list node.
159
@param NAME list name
160
@param N pointer to the node that was removed */
150
161
# define UT_LIST_REMOVE_CLEAR(NAME, N) while (0)
153
/***********************************************************************
154
Removes a node from a two-way linked list. BASE has to be the base node
155
(not a pointer to it). N has to be the pointer to the node to be removed
156
from the list. NAME is the list name. */
164
/*******************************************************************//**
165
Removes a node from a two-way linked list.
166
@param NAME list name
167
@param BASE the base node (not a pointer to it)
168
@param N pointer to the node to be removed from the list
158
170
#define UT_LIST_REMOVE(NAME, BASE, N) \
173
185
UT_LIST_REMOVE_CLEAR(NAME, N); \
176
/************************************************************************
177
Gets the next node in a two-way list. NAME is the name of the list
178
and N is pointer to a node. */
188
/********************************************************************//**
189
Gets the next node in a two-way list.
190
@param NAME list name
191
@param N pointer to a node
192
@return the successor of N in NAME, or NULL */
180
193
#define UT_LIST_GET_NEXT(NAME, N)\
181
194
(((N)->NAME).next)
183
/************************************************************************
184
Gets the previous node in a two-way list. NAME is the name of the list
185
and N is pointer to a node. */
196
/********************************************************************//**
197
Gets the previous node in a two-way list.
198
@param NAME list name
199
@param N pointer to a node
200
@return the predecessor of N in NAME, or NULL */
187
201
#define UT_LIST_GET_PREV(NAME, N)\
188
202
(((N)->NAME).prev)
190
/************************************************************************
204
/********************************************************************//**
191
205
Alternative macro to get the number of nodes in a two-way list, i.e.,
192
its length. BASE is the base node (not a pointer to it). */
207
@param BASE the base node (not a pointer to it).
208
@return the number of nodes in the list */
194
209
#define UT_LIST_GET_LEN(BASE)\
197
/************************************************************************
198
Gets the first node in a two-way list, or returns NULL,
199
if the list is empty. BASE is the base node (not a pointer to it). */
212
/********************************************************************//**
213
Gets the first node in a two-way list.
214
@param BASE the base node (not a pointer to it)
215
@return first node, or NULL if the list is empty */
201
216
#define UT_LIST_GET_FIRST(BASE)\
204
/************************************************************************
205
Gets the last node in a two-way list, or returns NULL,
206
if the list is empty. BASE is the base node (not a pointer to it). */
219
/********************************************************************//**
220
Gets the last node in a two-way list.
221
@param BASE the base node (not a pointer to it)
222
@return last node, or NULL if the list is empty */
208
223
#define UT_LIST_GET_LAST(BASE)\
211
/************************************************************************
212
Checks the consistency of a two-way list. NAME is the name of the list,
213
TYPE is the node type, and BASE is the base node (not a pointer to it). */
215
#define UT_LIST_VALIDATE(NAME, TYPE, BASE)\
217
ulint ut_list_i_313;\
218
TYPE * ut_list_node_313;\
220
ut_list_node_313 = (BASE).start;\
222
for (ut_list_i_313 = 0; ut_list_i_313 < (BASE).count;\
224
ut_a(ut_list_node_313);\
225
ut_list_node_313 = (ut_list_node_313->NAME).next;\
228
ut_a(ut_list_node_313 == NULL);\
230
ut_list_node_313 = (BASE).end;\
232
for (ut_list_i_313 = 0; ut_list_i_313 < (BASE).count;\
234
ut_a(ut_list_node_313);\
235
ut_list_node_313 = (ut_list_node_313->NAME).prev;\
238
ut_a(ut_list_node_313 == NULL);\
226
/********************************************************************//**
227
Checks the consistency of a two-way list.
228
@param NAME the name of the list
229
@param TYPE node type
230
@param BASE base node (not a pointer to it)
231
@param ASSERTION a condition on ut_list_node_313 */
232
#define UT_LIST_VALIDATE(NAME, TYPE, BASE, ASSERTION) \
234
ulint ut_list_i_313; \
235
TYPE* ut_list_node_313; \
237
ut_list_node_313 = (BASE).start; \
239
for (ut_list_i_313 = (BASE).count; ut_list_i_313--; ) { \
240
ut_a(ut_list_node_313); \
242
ut_ad((ut_list_node_313->NAME).next || !ut_list_i_313); \
243
ut_list_node_313 = (ut_list_node_313->NAME).next; \
246
ut_a(ut_list_node_313 == NULL); \
248
ut_list_node_313 = (BASE).end; \
250
for (ut_list_i_313 = (BASE).count; ut_list_i_313--; ) { \
251
ut_a(ut_list_node_313); \
253
ut_ad((ut_list_node_313->NAME).prev || !ut_list_i_313); \
254
ut_list_node_313 = (ut_list_node_313->NAME).prev; \
257
ut_a(ut_list_node_313 == NULL); \