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