1
/*****************************************************************************
3
Copyright (c) 2006, 2009, Oracle and/or its affiliates. All Rights Reserved.
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.
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.
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.,
15
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17
*****************************************************************************/
19
/*******************************************************************//**
20
@file include/ut0list.h
23
Created 4/26/2006 Osku Salerma
24
************************************************************************/
26
/*******************************************************************//**
27
A double-linked list. This differs from the one in ut0lst.h in that in this
28
one, each list node contains a pointer to the data, whereas the one in
29
ut0lst.h uses a strategy where the list pointers are embedded in the data
32
Use this one when you need to store arbitrary data in the list where you
33
can't embed the list pointers in the data, if a data item needs to be
34
stored in multiple lists, etc.
36
Note about the memory management: ib_list_t is a fixed-size struct whose
37
allocation/deallocation is done through ib_list_create/ib_list_free, but the
38
memory for the list nodes is allocated through a user-given memory heap,
39
which can either be the same for all nodes or vary per node. Most users will
40
probably want to create a memory heap to store the item-specific data, and
41
pass in this same heap to the list node creation functions, thus
42
automatically freeing the list node when the item's heap is freed.
44
************************************************************************/
52
struct ib_list_node_t;
54
/****************************************************************//**
55
Create a new list using mem_alloc. Lists created with this function must be
56
freed with ib_list_free.
64
/****************************************************************//**
65
Create a new list using the given heap. ib_list_free MUST NOT BE CALLED for
66
lists created with this function.
72
mem_heap_t* heap); /*!< in: memory heap to use */
74
/****************************************************************//**
80
ib_list_t* list); /*!< in: list */
82
/****************************************************************//**
83
Add the data to the start of the list.
84
@return new list node */
89
ib_list_t* list, /*!< in: list */
90
void* data, /*!< in: data */
91
mem_heap_t* heap); /*!< in: memory heap to use */
93
/****************************************************************//**
94
Add the data to the end of the list.
95
@return new list node */
100
ib_list_t* list, /*!< in: list */
101
void* data, /*!< in: data */
102
mem_heap_t* heap); /*!< in: memory heap to use */
104
/****************************************************************//**
105
Add the data after the indicated node.
106
@return new list node */
111
ib_list_t* list, /*!< in: list */
112
ib_list_node_t* prev_node, /*!< in: node preceding new node (can
114
void* data, /*!< in: data */
115
mem_heap_t* heap); /*!< in: memory heap to use */
117
/****************************************************************//**
118
Remove the node from the list. */
123
ib_list_t* list, /*!< in: list */
124
ib_list_node_t* node); /*!< in: node to remove */
126
/****************************************************************//**
127
Get the first node in the list.
128
@return first node, or NULL */
133
ib_list_t* list); /*!< in: list */
135
/****************************************************************//**
136
Get the last node in the list.
137
@return last node, or NULL */
142
ib_list_t* list); /*!< in: list */
144
/********************************************************************
145
Check if list is empty. */
150
/* out: TRUE if empty else */
151
const ib_list_t* list); /* in: list */
155
ib_list_node_t* first; /*!< first node */
156
ib_list_node_t* last; /*!< last node */
157
ibool is_heap_list; /*!< TRUE if this list was
158
allocated through a heap */
162
struct ib_list_node_t {
163
ib_list_node_t* prev; /*!< previous node */
164
ib_list_node_t* next; /*!< next node */
165
void* data; /*!< user data */
168
/* Quite often, the only additional piece of data you need is the per-item
169
memory heap, so we have this generic struct available to use in those
171
struct ib_list_helper_t {
172
mem_heap_t* heap; /*!< memory heap */
173
void* data; /*!< user data */
177
#include "ut0list.ic"