Debian Codegraph @

storage/innobase/include/ut0list.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2006, 2026, Oracle and/or its affiliates.
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, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 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
58 struct ib_list_t;
59 struct 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 */
64 ib_list_t *ib_list_create(void);
65
66 /** Free a list. */
67 void 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 */
71 ib_list_node_t *ib_list_add_last(
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 */
79 void ib_list_remove(ib_list_t *list, ib_list_node_t *node);
80
81 /** Get the first node in the list.
82 @return first node, or NULL */
83 static inline ib_list_node_t *ib_list_get_first(
84 ib_list_t *list); /*!< in: list */
85
86 /** Get the last node in the list.
87 @return last node, or NULL */
88 static inline ib_list_node_t *ib_list_get_last(
89 ib_list_t *list); /*!< in: list */
90
91 /********************************************************************
92 Check if list is empty. */
93 static inline bool ib_list_is_empty(
94 /* out: true if empty else */
95 const ib_list_t *list); /* in: list */
96
97 /* List. */
98 struct 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. */
104 struct ib_list_node_t {
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
111 memory heap, so we have this generic struct available to use in those
112 cases. */
113 struct ib_list_helper_t {
114 mem_heap_t *heap; /*!< memory heap */
115 void *data; /*!< user data */
116 };
117
118 #include "ut0list.ic"
119
120 #endif