| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1995, 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/fut0lst.h |
| 29 |
File-based list utilities |
| 30 |
|
| 31 |
Created 11/28/1995 Heikki Tuuri |
| 32 |
***********************************************************************/ |
| 33 |
|
| 34 |
#ifndef fut0lst_h |
| 35 |
#define fut0lst_h |
| 36 |
|
| 37 |
#include "univ.i" |
| 38 |
|
| 39 |
#include "fil0fil.h" |
| 40 |
#include "mtr0mtr.h" |
| 41 |
|
| 42 |
/* The C 'types' of base node and list node: these should be used to |
| 43 |
write self-documenting code. Of course, the sizeof macro cannot be |
| 44 |
applied to these types! */ |
| 45 |
|
| 46 |
typedef byte flst_base_node_t; |
| 47 |
typedef byte flst_node_t; |
| 48 |
|
| 49 |
/* The physical size of a list base node in bytes */ |
| 50 |
constexpr ulint FLST_BASE_NODE_SIZE = 4 + 2 * FIL_ADDR_SIZE; |
| 51 |
|
| 52 |
/* The physical size of a list node in bytes */ |
| 53 |
constexpr ulint FLST_NODE_SIZE = 2 * FIL_ADDR_SIZE; |
| 54 |
|
| 55 |
/** Initializes a list base node. |
| 56 |
@param[in] base Pointer to base node |
| 57 |
@param[in] mtr Mini-transaction handle */ |
| 58 |
static inline void flst_init(flst_base_node_t *base, mtr_t *mtr); |
| 59 |
|
| 60 |
/** Adds a node as the last node in a list. |
| 61 |
@param[in] base Pointer to base node of list |
| 62 |
@param[in] node Node to add |
| 63 |
@param[in] mtr Mini-transaction handle */ |
| 64 |
void flst_add_last(flst_base_node_t *base, flst_node_t *node, mtr_t *mtr); |
| 65 |
|
| 66 |
/** Adds a node as the first node in a list. |
| 67 |
@param[in] base Pointer to base node of list |
| 68 |
@param[in] node Node to add |
| 69 |
@param[in] mtr Mini-transaction handle */ |
| 70 |
void flst_add_first(flst_base_node_t *base, flst_node_t *node, mtr_t *mtr); |
| 71 |
|
| 72 |
/** Removes a node. |
| 73 |
@param[in] base Pointer to base node of list |
| 74 |
@param[in] node2 Node to remove |
| 75 |
@param[in] mtr Mini-transaction handle */ |
| 76 |
void flst_remove(flst_base_node_t *base, flst_node_t *node2, mtr_t *mtr); |
| 77 |
|
| 78 |
/** Get the length of a list. |
| 79 |
@param[in] base base node |
| 80 |
@return length */ |
| 81 |
static inline ulint flst_get_len(const flst_base_node_t *base); |
| 82 |
|
| 83 |
/** Gets list first node address. |
| 84 |
@param[in] base Pointer to base node |
| 85 |
@param[in] mtr Mini-transaction handle |
| 86 |
@return file address */ |
| 87 |
static inline fil_addr_t flst_get_first(const flst_base_node_t *base, |
| 88 |
mtr_t *mtr); |
| 89 |
|
| 90 |
/** Gets list last node address. |
| 91 |
@param[in] base Pointer to base node |
| 92 |
@param[in] mtr Mini-transaction handle |
| 93 |
@return file address */ |
| 94 |
static inline fil_addr_t flst_get_last(const flst_base_node_t *base, |
| 95 |
mtr_t *mtr); |
| 96 |
|
| 97 |
/** Gets list next node address. |
| 98 |
@param[in] node Pointer to node |
| 99 |
@param[in] mtr Mini-transaction handle |
| 100 |
@return file address */ |
| 101 |
static inline fil_addr_t flst_get_next_addr(const flst_node_t *node, |
| 102 |
mtr_t *mtr); |
| 103 |
|
| 104 |
/** Gets list prev node address. |
| 105 |
@param[in] node Pointer to node |
| 106 |
@param[in] mtr Mini-transaction handle |
| 107 |
@return file address */ |
| 108 |
static inline fil_addr_t flst_get_prev_addr(const flst_node_t *node, |
| 109 |
mtr_t *mtr); |
| 110 |
|
| 111 |
/** Writes a file address. |
| 112 |
@param[in] faddr Pointer to file faddress |
| 113 |
@param[in] addr File address |
| 114 |
@param[in] mtr Mini-transaction handle */ |
| 115 |
static inline void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr, |
| 116 |
mtr_t *mtr); |
| 117 |
|
| 118 |
/** Reads a file address. |
| 119 |
@param[in] faddr Pointer to file faddress |
| 120 |
@param[in] mtr Mini-transaction handle |
| 121 |
@return file address */ |
| 122 |
static inline fil_addr_t flst_read_addr(const fil_faddr_t *faddr, mtr_t *mtr); |
| 123 |
|
| 124 |
/** Validates a file-based list. |
| 125 |
@param[in] base pointer to base node of list |
| 126 |
@param[in] mtr1 mtr */ |
| 127 |
void flst_validate(const flst_base_node_t *base, mtr_t *mtr1); |
| 128 |
|
| 129 |
/** Inserts a node after another in a list. |
| 130 |
@param[in] base Pointer to base node of list |
| 131 |
@param[in] node1 Node to insert after |
| 132 |
@param[in] node2 Node to add |
| 133 |
@param[in] mtr Mini-transaction handle. */ |
| 134 |
void flst_insert_after(flst_base_node_t *base, flst_node_t *node1, |
| 135 |
flst_node_t *node2, mtr_t *mtr); |
| 136 |
|
| 137 |
/** Inserts a node before another in a list. |
| 138 |
@param[in] base Pointer to base node of list |
| 139 |
@param[in] node2 Node to insert |
| 140 |
@param[in] node3 Node to insert before |
| 141 |
@param[in] mtr Mini-transaction handle. */ |
| 142 |
void flst_insert_before(flst_base_node_t *base, flst_node_t *node2, |
| 143 |
flst_node_t *node3, mtr_t *mtr); |
| 144 |
|
| 145 |
#include "fut0lst.ic" |
| 146 |
|
| 147 |
/** In-memory representation of flst_base_node_t */ |
| 148 |
struct flst_bnode_t { |
| 149 |
ulint len; |
| 150 |
fil_addr_t first; |
| 151 |
fil_addr_t last; |
| 152 |
|
| 153 |
flst_bnode_t() : len(0) {} |
| 154 |
|
| 155 |
flst_bnode_t(const flst_base_node_t *base, mtr_t *mtr) |
| 156 |
: len(flst_get_len(base)), |
| 157 |
first(flst_get_first(base, mtr)), |
| 158 |
last(flst_get_last(base, mtr)) {} |
| 159 |
|
| 160 |
void set(const flst_base_node_t *base, mtr_t *mtr) { |
| 161 |
len = flst_get_len(base); |
| 162 |
first = flst_get_first(base, mtr); |
| 163 |
last = flst_get_last(base, mtr); |
| 164 |
} |
| 165 |
|
| 166 |
void reset() { |
| 167 |
len = 0; |
| 168 |
first = fil_addr_null; |
| 169 |
last = fil_addr_null; |
| 170 |
} |
| 171 |
|
| 172 |
std::ostream &print(std::ostream &out) const { |
| 173 |
out << "[flst_base_node_t: len=" << len << ", first=" << first |
| 174 |
<< ", last=" << last << "]"; |
| 175 |
return (out); |
| 176 |
} |
| 177 |
}; |
| 178 |
|
| 179 |
inline std::ostream &operator<<(std::ostream &out, const flst_bnode_t &obj) { |
| 180 |
return (obj.print(out)); |
| 181 |
} |
| 182 |
|
| 183 |
#endif /* fut0lst_h */ |