1/*****************************************************************************
2
3Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/******************************************************************//**
20@file include/fut0lst.h
21File-based list utilities
22
23Created 11/28/1995 Heikki Tuuri
24***********************************************************************/
25
26#ifndef fut0lst_h
27#define fut0lst_h
28
29#ifndef UNIV_INNOCHECKSUM
30
31#include "univ.i"
32
33#include "fil0fil.h"
34#include "mtr0mtr.h"
35
36
37/* The C 'types' of base node and list node: these should be used to
38write self-documenting code. Of course, the sizeof macro cannot be
39applied to these types! */
40
41typedef byte flst_base_node_t;
42typedef byte flst_node_t;
43
44/* The physical size of a list base node in bytes */
45#define FLST_BASE_NODE_SIZE (4 + 2 * FIL_ADDR_SIZE)
46#endif /* !UNIV_INNOCHECKSUM */
47
48/* The physical size of a list node in bytes */
49#define FLST_NODE_SIZE (2 * FIL_ADDR_SIZE)
50
51#ifndef UNIV_INNOCHECKSUM
52/********************************************************************//**
53Initializes a list base node. */
54UNIV_INLINE
55void
56flst_init(
57/*======*/
58 flst_base_node_t* base, /*!< in: pointer to base node */
59 mtr_t* mtr); /*!< in: mini-transaction handle */
60/********************************************************************//**
61Adds a node as the last node in a list. */
62void
63flst_add_last(
64/*==========*/
65 flst_base_node_t* base, /*!< in: pointer to base node of list */
66 flst_node_t* node, /*!< in: node to add */
67 mtr_t* mtr); /*!< in: mini-transaction handle */
68/********************************************************************//**
69Adds a node as the first node in a list. */
70void
71flst_add_first(
72/*===========*/
73 flst_base_node_t* base, /*!< in: pointer to base node of list */
74 flst_node_t* node, /*!< in: node to add */
75 mtr_t* mtr); /*!< in: mini-transaction handle */
76/********************************************************************//**
77Removes a node. */
78void
79flst_remove(
80/*========*/
81 flst_base_node_t* base, /*!< in: pointer to base node of list */
82 flst_node_t* node2, /*!< in: node to remove */
83 mtr_t* mtr); /*!< in: mini-transaction handle */
84/** Get the length of a list.
85@param[in] base base node
86@return length */
87UNIV_INLINE
88ulint
89flst_get_len(
90 const flst_base_node_t* base);
91/********************************************************************//**
92Gets list first node address.
93@return file address */
94UNIV_INLINE
95fil_addr_t
96flst_get_first(
97/*===========*/
98 const flst_base_node_t* base, /*!< in: pointer to base node */
99 mtr_t* mtr); /*!< in: mini-transaction handle */
100/********************************************************************//**
101Gets list last node address.
102@return file address */
103UNIV_INLINE
104fil_addr_t
105flst_get_last(
106/*==========*/
107 const flst_base_node_t* base, /*!< in: pointer to base node */
108 mtr_t* mtr); /*!< in: mini-transaction handle */
109/********************************************************************//**
110Gets list next node address.
111@return file address */
112UNIV_INLINE
113fil_addr_t
114flst_get_next_addr(
115/*===============*/
116 const flst_node_t* node, /*!< in: pointer to node */
117 mtr_t* mtr); /*!< in: mini-transaction handle */
118/********************************************************************//**
119Gets list prev node address.
120@return file address */
121UNIV_INLINE
122fil_addr_t
123flst_get_prev_addr(
124/*===============*/
125 const flst_node_t* node, /*!< in: pointer to node */
126 mtr_t* mtr); /*!< in: mini-transaction handle */
127/********************************************************************//**
128Writes a file address. */
129UNIV_INLINE
130void
131flst_write_addr(
132/*============*/
133 fil_faddr_t* faddr, /*!< in: pointer to file faddress */
134 fil_addr_t addr, /*!< in: file address */
135 mtr_t* mtr); /*!< in: mini-transaction handle */
136/********************************************************************//**
137Reads a file address.
138@return file address */
139UNIV_INLINE
140fil_addr_t
141flst_read_addr(
142/*===========*/
143 const fil_faddr_t* faddr, /*!< in: pointer to file faddress */
144 mtr_t* mtr); /*!< in: mini-transaction handle */
145/********************************************************************//**
146Validates a file-based list.
147@return TRUE if ok */
148ibool
149flst_validate(
150/*==========*/
151 const flst_base_node_t* base, /*!< in: pointer to base node of list */
152 mtr_t* mtr1); /*!< in: mtr */
153
154#include "fut0lst.ic"
155
156#endif /* !UNIV_INNOCHECKSUM */
157
158#endif
159