6
/********************************************************************
14
ib_list_t* list = mem_alloc(sizeof(ib_list_t));
18
list->is_heap_list = FALSE;
23
/********************************************************************
24
Create a new list using the given heap. ib_list_free MUST NOT BE CALLED for
25
lists created with this function. */
31
mem_heap_t* heap) /* in: memory heap to use */
33
ib_list_t* list = mem_heap_alloc(heap, sizeof(ib_list_t));
37
list->is_heap_list = TRUE;
42
/********************************************************************
48
ib_list_t* list) /* in: list */
50
ut_a(!list->is_heap_list);
52
/* We don't check that the list is empty because it's entirely valid
53
to e.g. have all the nodes allocated from a single heap that is then
54
freed after the list itself is freed. */
59
/********************************************************************
60
Add the data to the start of the list. */
65
/* out: new list node*/
66
ib_list_t* list, /* in: list */
67
void* data, /* in: data */
68
mem_heap_t* heap) /* in: memory heap to use */
70
return(ib_list_add_after(list, ib_list_get_first(list), data, heap));
73
/********************************************************************
74
Add the data to the end of the list. */
79
/* out: new list node*/
80
ib_list_t* list, /* in: list */
81
void* data, /* in: data */
82
mem_heap_t* heap) /* in: memory heap to use */
84
return(ib_list_add_after(list, ib_list_get_last(list), data, heap));
87
/********************************************************************
88
Add the data after the indicated node. */
93
/* out: new list node*/
94
ib_list_t* list, /* in: list */
95
ib_list_node_t* prev_node, /* in: node preceding new node (can
97
void* data, /* in: data */
98
mem_heap_t* heap) /* in: memory heap to use */
100
ib_list_node_t* node = mem_heap_alloc(heap, sizeof(ib_list_node_t));
114
} else if (!prev_node) {
118
node->next = list->first;
120
list->first->prev = node;
124
/* Middle or end of list. */
126
node->prev = prev_node;
127
node->next = prev_node->next;
129
prev_node->next = node;
132
node->next->prev = node;
141
/********************************************************************
142
Remove the node from the list. */
147
ib_list_t* list, /* in: list */
148
ib_list_node_t* node) /* in: node to remove */
151
node->prev->next = node->next;
153
/* First item in list. */
155
ut_ad(list->first == node);
157
list->first = node->next;
161
node->next->prev = node->prev;
163
/* Last item in list. */
165
ut_ad(list->last == node);
167
list->last = node->prev;