Debian Codegraph @

unittest/gunit/innodb/lob/fut0lst.h

raw symbols SCIP
1 /*****************************************************************************
2
3 Copyright (c) 2016, 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 #ifndef _fut0lst_h_
28 #define _fut0lst_h_
29
30 #include "fil0fil.h"
31 #include "lot0types.h"
32 #include "mach0data.h"
33 #include "mtr0log.h"
34 #include "mtr0types.h"
35 #include "ut0byte.h"
36 #include "ut0dbg.h"
37
38 /* We define the field offsets of a node for the list */
39 #define FLST_PREV \
40 0 /* 6-byte address of the previous list element; \
41 the page part of address is FIL_NULL, if no \
42 previous element */
43 #define FLST_NEXT \
44 FIL_ADDR_SIZE /* 6-byte address of the next \
45 list element; the page part of address \
46 is FIL_NULL, if no next element */
47
48 /* We define the field offsets of a base node for the list */
49 #define FLST_LEN 0 /* 32-bit list length field */
50 #define FLST_FIRST \
51 4 /* 6-byte address of the first element \
52 of the list; undefined if empty list */
53 #define FLST_LAST \
54 (4 + FIL_ADDR_SIZE) /* 6-byte address of the \
55 last element of the list; undefined \
56 if empty list */
57
58 /* The physical size of a list base node in bytes */
59 #define FLST_BASE_NODE_SIZE (4 + 2 * FIL_ADDR_SIZE)
60
61 /* The physical size of a list node in bytes */
62 #define FLST_NODE_SIZE (2 * FIL_ADDR_SIZE)
63
64 typedef byte flst_base_node_t;
65 typedef byte flst_node_t;
66
67 void flst_init(flst_base_node_t *base);
68 void flst_add_last(flst_base_node_t *base, flst_node_t *node);
69
70 inline ulint flst_get_len(const flst_base_node_t *base) {
71 return (mach_read_from_4(base + FLST_LEN));
72 }
73
74 inline fil_addr_t flst_read_addr(const fil_faddr_t *faddr) {
75 fil_addr_t addr;
76
77 addr.page = mach_read_ulint(faddr + FIL_ADDR_PAGE, MLOG_4BYTES);
78 addr.boffset = mach_read_ulint(faddr + FIL_ADDR_BYTE, MLOG_2BYTES);
79 ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
80 ut_a(ut_align_offset(faddr, UNIV_PAGE_SIZE) >= FIL_PAGE_DATA);
81 return (addr);
82 }
83
84 inline fil_addr_t flst_get_prev_addr(const flst_node_t *node) {
85 return (flst_read_addr(node + FLST_PREV));
86 }
87
88 inline fil_addr_t flst_get_last(const flst_base_node_t *base) {
89 return (flst_read_addr(base + FLST_LAST));
90 }
91
92 inline fil_addr_t flst_get_next_addr(const flst_node_t *node) {
93 return (flst_read_addr(node + FLST_NEXT));
94 }
95
96 bool flst_validate(const flst_base_node_t *base);
97
98 inline fil_addr_t flst_get_first(const flst_base_node_t *base) {
99 return (flst_read_addr(base + FLST_FIRST));
100 }
101
102 void flst_remove(flst_base_node_t *base, flst_node_t *node2);
103 void flst_add_first(flst_base_node_t *base, flst_node_t *node);
104
105 /** Insert node2 after node1 in the list base. */
106 void flst_insert_after(flst_base_node_t *base, flst_node_t *node1,
107 flst_node_t *node2);
108 void flst_insert_before(flst_base_node_t *base, flst_node_t *node2,
109 flst_node_t *node3);
110
111 void flst_write_addr(fil_faddr_t *faddr, fil_addr_t addr);
112
113 /** In-memory representation of flst_base_node_t */
114 struct flst_bnode_t {
115 ulint len;
116 fil_addr_t first;
117 fil_addr_t last;
118
119 flst_bnode_t(const flst_base_node_t *base)
120 : len(flst_get_len(base)),
121 first(flst_get_first(base)),
122 last(flst_get_last(base)) {}
123
124 void set(const flst_base_node_t *base) {
125 len = flst_get_len(base);
126 first = flst_get_first(base);
127 last = flst_get_last(base);
128 }
129
130 std::ostream &print(std::ostream &out) const {
131 out << "[flst_base_node_t: len=" << len << ", first=" << first
132 << ", last=" << last << "]";
133 return (out);
134 }
135 };
136
137 inline std::ostream &operator<<(std::ostream &out, const flst_bnode_t &obj) {
138 return (obj.print(out));
139 }
140
141 #endif // _fut0lst_h_