641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
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., 59 Temple
|
|
15 |
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
*****************************************************************************/
|
|
18 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
19 |
/*******************************************************************//**
|
20 |
@file ut/ut0list.c
|
|
21 |
A double-linked list
|
|
22 |
||
23 |
Created 4/26/2006 Osku Salerma
|
|
24 |
************************************************************************/
|
|
25 |
||
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
26 |
#include "ut0list.h" |
27 |
#ifdef UNIV_NONINL
|
|
28 |
#include "ut0list.ic" |
|
29 |
#endif
|
|
30 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
31 |
/****************************************************************//**
|
32 |
Create a new list.
|
|
33 |
@return list */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
34 |
UNIV_INTERN
|
35 |
ib_list_t* |
|
36 |
ib_list_create(void) |
|
37 |
/*=================*/
|
|
38 |
{
|
|
39 |
ib_list_t* list = 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 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
48 |
/****************************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
49 |
Create a new list using the given heap. ib_list_free MUST NOT BE CALLED for
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
50 |
lists created with this function.
|
51 |
@return list */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
52 |
UNIV_INTERN
|
53 |
ib_list_t* |
|
54 |
ib_list_create_heap( |
|
55 |
/*================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
56 |
mem_heap_t* heap) /*!< in: memory heap to use */ |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
57 |
{
|
58 |
ib_list_t* list = 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 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
67 |
/****************************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
68 |
Free a list. */
|
69 |
UNIV_INTERN
|
|
70 |
void
|
|
71 |
ib_list_free( |
|
72 |
/*=========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
73 |
ib_list_t* list) /*!< in: list */ |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
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 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
84 |
/****************************************************************//**
|
85 |
Add the data to the start of the list.
|
|
86 |
@return new list node */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
87 |
UNIV_INTERN
|
88 |
ib_list_node_t* |
|
89 |
ib_list_add_first( |
|
90 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
91 |
ib_list_t* list, /*!< in: list */ |
92 |
void* data, /*!< in: data */ |
|
93 |
mem_heap_t* heap) /*!< in: memory heap to use */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
94 |
{
|
95 |
return(ib_list_add_after(list, ib_list_get_first(list), data, heap)); |
|
96 |
}
|
|
97 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
98 |
/****************************************************************//**
|
99 |
Add the data to the end of the list.
|
|
100 |
@return new list node */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
101 |
UNIV_INTERN
|
102 |
ib_list_node_t* |
|
103 |
ib_list_add_last( |
|
104 |
/*=============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
105 |
ib_list_t* list, /*!< in: list */ |
106 |
void* data, /*!< in: data */ |
|
107 |
mem_heap_t* heap) /*!< in: memory heap to use */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
108 |
{
|
109 |
return(ib_list_add_after(list, ib_list_get_last(list), data, heap)); |
|
110 |
}
|
|
111 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
112 |
/****************************************************************//**
|
113 |
Add the data after the indicated node.
|
|
114 |
@return new list node */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
115 |
UNIV_INTERN
|
116 |
ib_list_node_t* |
|
117 |
ib_list_add_after( |
|
118 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
119 |
ib_list_t* list, /*!< in: list */ |
120 |
ib_list_node_t* prev_node, /*!< in: node preceding new node (can |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
121 |
be NULL) */
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
122 |
void* data, /*!< in: data */ |
123 |
mem_heap_t* heap) /*!< in: memory heap to use */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
124 |
{
|
125 |
ib_list_node_t* node = 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 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
166 |
/****************************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
167 |
Remove the node from the list. */
|
168 |
UNIV_INTERN
|
|
169 |
void
|
|
170 |
ib_list_remove( |
|
171 |
/*===========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
172 |
ib_list_t* list, /*!< in: list */ |
173 |
ib_list_node_t* node) /*!< in: node to remove */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
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 |
}
|