1
/*****************************************************************************
3
Copyright (c) 2006, 2009, Innobase Oy. 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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 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
************************************************************************/
51
typedef struct ib_list_struct ib_list_t;
52
typedef struct ib_list_node_struct ib_list_node_t;
53
typedef struct ib_list_helper_struct ib_list_helper_t;
55
/****************************************************************//**
56
Create a new list using mem_alloc. Lists created with this function must be
57
freed with ib_list_free.
65
/****************************************************************//**
66
Create a new list using the given heap. ib_list_free MUST NOT BE CALLED for
67
lists created with this function.
73
mem_heap_t* heap); /*!< in: memory heap to use */
75
/****************************************************************//**
81
ib_list_t* list); /*!< in: list */
83
/****************************************************************//**
84
Add the data to the start of the list.
85
@return new list node */
90
ib_list_t* list, /*!< in: list */
91
void* data, /*!< in: data */
92
mem_heap_t* heap); /*!< in: memory heap to use */
94
/****************************************************************//**
95
Add the data to the end of the list.
96
@return new list node */
101
ib_list_t* list, /*!< in: list */
102
void* data, /*!< in: data */
103
mem_heap_t* heap); /*!< in: memory heap to use */
105
/****************************************************************//**
106
Add the data after the indicated node.
107
@return new list node */
112
ib_list_t* list, /*!< in: list */
113
ib_list_node_t* prev_node, /*!< in: node preceding new node (can
115
void* data, /*!< in: data */
116
mem_heap_t* heap); /*!< in: memory heap to use */
118
/****************************************************************//**
119
Remove the node from the list. */
124
ib_list_t* list, /*!< in: list */
125
ib_list_node_t* node); /*!< in: node to remove */
127
/****************************************************************//**
128
Get the first node in the list.
129
@return first node, or NULL */
134
ib_list_t* list); /*!< in: list */
136
/****************************************************************//**
137
Get the last node in the list.
138
@return last node, or NULL */
143
ib_list_t* list); /*!< in: list */
146
struct ib_list_struct {
147
ib_list_node_t* first; /*!< first node */
148
ib_list_node_t* last; /*!< last node */
149
ibool is_heap_list; /*!< TRUE if this list was
150
allocated through a heap */
154
struct ib_list_node_struct {
155
ib_list_node_t* prev; /*!< previous node */
156
ib_list_node_t* next; /*!< next node */
157
void* data; /*!< user data */
160
/* Quite often, the only additional piece of data you need is the per-item
161
memory heap, so we have this generic struct available to use in those
163
struct ib_list_helper_struct {
164
mem_heap_t* heap; /*!< memory heap */
165
void* data; /*!< user data */
169
#include "ut0list.ic"