drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
ut0list.cc
1/*****************************************************************************
2
3Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/*******************************************************************/
25
26#include "ut0list.h"
27#ifdef UNIV_NONINL
28#include "ut0list.ic"
29#endif
30
31/****************************************************************/
34UNIV_INTERN
35ib_list_t*
37/*=================*/
38{
39 ib_list_t* list = static_cast<ib_list_t*>(mem_alloc(sizeof(ib_list_t)));
40
41 list->first = NULL;
42 list->last = NULL;
43 list->is_heap_list = FALSE;
44
45 return(list);
46}
47
48/****************************************************************/
52UNIV_INTERN
53ib_list_t*
55/*================*/
56 mem_heap_t* heap)
57{
58 ib_list_t* list = static_cast<ib_list_t *>(mem_heap_alloc(heap, sizeof(ib_list_t)));
59
60 list->first = NULL;
61 list->last = NULL;
62 list->is_heap_list = TRUE;
63
64 return(list);
65}
66
67/****************************************************************/
69UNIV_INTERN
70void
72/*=========*/
73 ib_list_t* list)
74{
75 ut_a(!list->is_heap_list);
76
77 /* We don't check that the list is empty because it's entirely valid
78 to e.g. have all the nodes allocated from a single heap that is then
79 freed after the list itself is freed. */
80
81 mem_free(list);
82}
83
84/****************************************************************/
87UNIV_INTERN
88ib_list_node_t*
90/*==============*/
91 ib_list_t* list,
92 void* data,
93 mem_heap_t* heap)
94{
95 return(ib_list_add_after(list, ib_list_get_first(list), data, heap));
96}
97
98/****************************************************************/
101UNIV_INTERN
102ib_list_node_t*
104/*=============*/
105 ib_list_t* list,
106 void* data,
107 mem_heap_t* heap)
108{
109 return(ib_list_add_after(list, ib_list_get_last(list), data, heap));
110}
111
112/****************************************************************/
115UNIV_INTERN
116ib_list_node_t*
118/*==============*/
119 ib_list_t* list,
120 ib_list_node_t* prev_node,
122 void* data,
123 mem_heap_t* heap)
124{
125 ib_list_node_t* node = static_cast<ib_list_node_t *>(mem_heap_alloc(heap, sizeof(ib_list_node_t)));
126
127 node->data = data;
128
129 if (!list->first) {
130 /* Empty list. */
131
132 ut_a(!prev_node);
133
134 node->prev = NULL;
135 node->next = NULL;
136
137 list->first = node;
138 list->last = node;
139 } else if (!prev_node) {
140 /* Start of list. */
141
142 node->prev = NULL;
143 node->next = list->first;
144
145 list->first->prev = node;
146
147 list->first = node;
148 } else {
149 /* Middle or end of list. */
150
151 node->prev = prev_node;
152 node->next = prev_node->next;
153
154 prev_node->next = node;
155
156 if (node->next) {
157 node->next->prev = node;
158 } else {
159 list->last = node;
160 }
161 }
162
163 return(node);
164}
165
166/****************************************************************/
168UNIV_INTERN
169void
171/*===========*/
172 ib_list_t* list,
173 ib_list_node_t* node)
174{
175 if (node->prev) {
176 node->prev->next = node->next;
177 } else {
178 /* First item in list. */
179
180 ut_ad(list->first == node);
181
182 list->first = node->next;
183 }
184
185 if (node->next) {
186 node->next->prev = node->prev;
187 } else {
188 /* Last item in list. */
189
190 ut_ad(list->last == node);
191
192 list->last = node->prev;
193 }
194}
#define mem_free(PTR)
Definition mem0mem.h:243
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
ib_list_node_t * next
Definition ut0list.h:157
ib_list_node_t * prev
Definition ut0list.h:156
ib_list_node_t * last
Definition ut0list.h:149
ib_list_node_t * first
Definition ut0list.h:148
ibool is_heap_list
Definition ut0list.h:150
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_a(EXPR)
Definition ut0dbg.h:105
UNIV_INTERN ib_list_t * ib_list_create_heap(mem_heap_t *heap)
Definition ut0list.cc:54
UNIV_INLINE ib_list_node_t * ib_list_get_first(ib_list_t *list)
UNIV_INTERN void ib_list_remove(ib_list_t *list, ib_list_node_t *node)
Definition ut0list.cc:170
UNIV_INTERN void ib_list_free(ib_list_t *list)
Definition ut0list.cc:71
UNIV_INTERN ib_list_node_t * ib_list_add_first(ib_list_t *list, void *data, mem_heap_t *heap)
Definition ut0list.cc:89
UNIV_INTERN ib_list_t * ib_list_create(void)
Definition ut0list.cc:36
UNIV_INTERN ib_list_node_t * ib_list_add_last(ib_list_t *list, void *data, mem_heap_t *heap)
Definition ut0list.cc:103
UNIV_INLINE ib_list_node_t * ib_list_get_last(ib_list_t *list)
UNIV_INTERN ib_list_node_t * ib_list_add_after(ib_list_t *list, ib_list_node_t *prev_node, void *data, mem_heap_t *heap)
Definition ut0list.cc:117