MySQL 9.0.0
Source Code Documentation
ut0list.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2006, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/ut0list.h
29 A double-linked list
30
31 Created 4/26/2006 Osku Salerma
32 ************************************************************************/
33
34/** A double-linked list. This differs from the one in ut0lst.h in that in this
35 one, each list node contains a pointer to the data, whereas the one in
36 ut0lst.h uses a strategy where the list pointers are embedded in the data
37 items themselves.
38
39 Use this one when you need to store arbitrary data in the list where you
40 can't embed the list pointers in the data, if a data item needs to be
41 stored in multiple lists, etc.
42
43 Note about the memory management: ib_list_t is a fixed-size struct whose
44 allocation/deallocation is done through ib_list_create/ib_list_free, but the
45 memory for the list nodes is allocated through a user-given memory heap,
46 which can either be the same for all nodes or vary per node. Most users will
47 probably want to create a memory heap to store the item-specific data, and
48 pass in this same heap to the list node creation functions, thus
49 automatically freeing the list node when the item's heap is freed.
50
51 ************************************************************************/
52
53#ifndef IB_LIST_H
54#define IB_LIST_H
55
56#include "mem0mem.h"
57
58struct ib_list_t;
59struct ib_list_node_t;
60
61/** Create a new list using mem_alloc. Lists created with this function must be
62 freed with ib_list_free.
63 @return list */
65
66/** Free a list. */
67void ib_list_free(ib_list_t *list); /*!< in: list */
68
69/** Add the data to the end of the list.
70 @return new list node */
72 ib_list_t *list, /*!< in: list */
73 void *data, /*!< in: data */
74 mem_heap_t *heap); /*!< in: memory heap to use */
75
76/** Remove the node from the list.
77@param[in] list List
78@param[in] node Node to remove */
80
81/** Get the first node in the list.
82 @return first node, or NULL */
84 ib_list_t *list); /*!< in: list */
85
86/** Get the last node in the list.
87 @return last node, or NULL */
89 ib_list_t *list); /*!< in: list */
90
91/********************************************************************
92Check if list is empty. */
93static inline bool ib_list_is_empty(
94 /* out: true if empty else */
95 const ib_list_t *list); /* in: list */
96
97/* List. */
98struct ib_list_t {
99 ib_list_node_t *first; /*!< first node */
100 ib_list_node_t *last; /*!< last node */
101};
102
103/* A list node. */
105 ib_list_node_t *prev; /*!< previous node */
106 ib_list_node_t *next; /*!< next node */
107 void *data; /*!< user data */
108};
109
110/* Quite often, the only additional piece of data you need is the per-item
111memory heap, so we have this generic struct available to use in those
112cases. */
114 mem_heap_t *heap; /*!< memory heap */
115 void *data; /*!< user data */
116};
117
118#include "ut0list.ic"
119
120#endif
The memory management.
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2879
Definition: ut0list.h:113
mem_heap_t * heap
memory heap
Definition: ut0list.h:114
void * data
user data
Definition: ut0list.h:115
Definition: ut0list.h:104
void * data
user data
Definition: ut0list.h:107
ib_list_node_t * next
next node
Definition: ut0list.h:106
ib_list_node_t * prev
previous node
Definition: ut0list.h:105
Definition: ut0list.h:98
ib_list_node_t * first
first node
Definition: ut0list.h:99
ib_list_node_t * last
last node
Definition: ut0list.h:100
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
static bool ib_list_is_empty(const ib_list_t *list)
ib_list_node_t * ib_list_add_last(ib_list_t *list, void *data, mem_heap_t *heap)
Add the data to the end of the list.
Definition: ut0list.cc:109
static ib_list_node_t * ib_list_get_last(ib_list_t *list)
Get the last node in the list.
void ib_list_remove(ib_list_t *list, ib_list_node_t *node)
Remove the node from the list.
Definition: ut0list.cc:120
static ib_list_node_t * ib_list_get_first(ib_list_t *list)
Get the first node in the list.
ib_list_t * ib_list_create(void)
Create a new list using mem_alloc.
Definition: ut0list.cc:40
void ib_list_free(ib_list_t *list)
Free a list.
Definition: ut0list.cc:46
A double-linked list.