~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0list.h

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
/*******************************************************************//**
 
20
@file include/ut0list.h
 
21
A double-linked list
 
22
 
 
23
Created 4/26/2006 Osku Salerma
 
24
************************************************************************/
 
25
 
 
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
 
30
items themselves.
 
31
 
 
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.
 
35
 
 
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.
 
43
 
 
44
************************************************************************/
 
45
 
 
46
#ifndef IB_LIST_H
 
47
#define IB_LIST_H
 
48
 
 
49
#include "mem0mem.h"
 
50
 
 
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;
 
54
 
 
55
/****************************************************************//**
 
56
Create a new list using mem_alloc. Lists created with this function must be
 
57
freed with ib_list_free.
 
58
@return list */
 
59
UNIV_INTERN
 
60
ib_list_t*
 
61
ib_list_create(void);
 
62
/*=================*/
 
63
 
 
64
 
 
65
/****************************************************************//**
 
66
Create a new list using the given heap. ib_list_free MUST NOT BE CALLED for
 
67
lists created with this function.
 
68
@return list */
 
69
UNIV_INTERN
 
70
ib_list_t*
 
71
ib_list_create_heap(
 
72
/*================*/
 
73
        mem_heap_t*     heap);  /*!< in: memory heap to use */
 
74
 
 
75
/****************************************************************//**
 
76
Free a list. */
 
77
UNIV_INTERN
 
78
void
 
79
ib_list_free(
 
80
/*=========*/
 
81
        ib_list_t*      list);  /*!< in: list */
 
82
 
 
83
/****************************************************************//**
 
84
Add the data to the start of the list.
 
85
@return new list node */
 
86
UNIV_INTERN
 
87
ib_list_node_t*
 
88
ib_list_add_first(
 
89
/*==============*/
 
90
        ib_list_t*      list,   /*!< in: list */
 
91
        void*           data,   /*!< in: data */
 
92
        mem_heap_t*     heap);  /*!< in: memory heap to use */
 
93
 
 
94
/****************************************************************//**
 
95
Add the data to the end of the list.
 
96
@return new list node */
 
97
UNIV_INTERN
 
98
ib_list_node_t*
 
99
ib_list_add_last(
 
100
/*=============*/
 
101
        ib_list_t*      list,   /*!< in: list */
 
102
        void*           data,   /*!< in: data */
 
103
        mem_heap_t*     heap);  /*!< in: memory heap to use */
 
104
 
 
105
/****************************************************************//**
 
106
Add the data after the indicated node.
 
107
@return new list node */
 
108
UNIV_INTERN
 
109
ib_list_node_t*
 
110
ib_list_add_after(
 
111
/*==============*/
 
112
        ib_list_t*      list,           /*!< in: list */
 
113
        ib_list_node_t* prev_node,      /*!< in: node preceding new node (can
 
114
                                        be NULL) */
 
115
        void*           data,           /*!< in: data */
 
116
        mem_heap_t*     heap);          /*!< in: memory heap to use */
 
117
 
 
118
/****************************************************************//**
 
119
Remove the node from the list. */
 
120
UNIV_INTERN
 
121
void
 
122
ib_list_remove(
 
123
/*===========*/
 
124
        ib_list_t*      list,   /*!< in: list */
 
125
        ib_list_node_t* node);  /*!< in: node to remove */
 
126
 
 
127
/****************************************************************//**
 
128
Get the first node in the list.
 
129
@return first node, or NULL */
 
130
UNIV_INLINE
 
131
ib_list_node_t*
 
132
ib_list_get_first(
 
133
/*==============*/
 
134
        ib_list_t*      list);  /*!< in: list */
 
135
 
 
136
/****************************************************************//**
 
137
Get the last node in the list.
 
138
@return last node, or NULL */
 
139
UNIV_INLINE
 
140
ib_list_node_t*
 
141
ib_list_get_last(
 
142
/*=============*/
 
143
        ib_list_t*      list);  /*!< in: list */
 
144
 
 
145
/* 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 */
 
151
};
 
152
 
 
153
/* A list node. */
 
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 */
 
158
};
 
159
 
 
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
 
162
cases. */
 
163
struct ib_list_helper_struct {
 
164
        mem_heap_t*     heap;           /*!< memory heap */
 
165
        void*           data;           /*!< user data */
 
166
};
 
167
 
 
168
#ifndef UNIV_NONINL
 
169
#include "ut0list.ic"
 
170
#endif
 
171
 
 
172
#endif