Drizzled Public API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ut0list.cc
1
/*****************************************************************************
2
3
Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
4
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
8
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
17
*****************************************************************************/
18
19
/*******************************************************************/
26
#include "
ut0list.h
"
27
#ifdef UNIV_NONINL
28
#include "ut0list.ic"
29
#endif
30
31
/****************************************************************/
34
UNIV_INTERN
35
ib_list_t
*
36
ib_list_create
(
void
)
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
/****************************************************************/
52
UNIV_INTERN
53
ib_list_t
*
54
ib_list_create_heap
(
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
/****************************************************************/
69
UNIV_INTERN
70
void
71
ib_list_free
(
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
/****************************************************************/
87
UNIV_INTERN
88
ib_list_node_t
*
89
ib_list_add_first
(
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
/****************************************************************/
101
UNIV_INTERN
102
ib_list_node_t
*
103
ib_list_add_last
(
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
/****************************************************************/
115
UNIV_INTERN
116
ib_list_node_t
*
117
ib_list_add_after
(
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
/****************************************************************/
168
UNIV_INTERN
169
void
170
ib_list_remove
(
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
}
plugin
innobase
ut
ut0list.cc
Generated on Wed Aug 21 2013 20:36:52 for drizzle by
1.8.4