1
/*****************************************************************************
3
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/dyn0dyn.h
21
The dynamically allocated array
23
Created 2/5/1996 Heikki Tuuri
24
*******************************************************/
33
/** A block in a dynamically allocated array */
34
typedef struct dyn_block_struct dyn_block_t;
35
/** Dynamically allocated array */
36
typedef dyn_block_t dyn_array_t;
39
/** This is the initial 'payload' size of a dynamic array;
40
this must be > MLOG_BUF_MARGIN + 30! */
41
#define DYN_ARRAY_DATA_SIZE 512
43
/*********************************************************************//**
44
Initializes a dynamic array.
45
@return initialized dyn array */
50
dyn_array_t* arr); /*!< in: pointer to a memory buffer of
51
size sizeof(dyn_array_t) */
52
/************************************************************//**
53
Frees a dynamic array. */
58
dyn_array_t* arr); /*!< in: dyn array */
59
/*********************************************************************//**
60
Makes room on top of a dyn array and returns a pointer to a buffer in it.
61
After copying the elements, the caller must close the buffer using
63
@return pointer to the buffer */
68
dyn_array_t* arr, /*!< in: dynamic array */
69
ulint size); /*!< in: size in bytes of the buffer; MUST be
70
smaller than DYN_ARRAY_DATA_SIZE! */
71
/*********************************************************************//**
72
Closes the buffer returned by dyn_array_open. */
77
dyn_array_t* arr, /*!< in: dynamic array */
78
byte* ptr); /*!< in: buffer space from ptr up was not used */
79
/*********************************************************************//**
80
Makes room on top of a dyn array and returns a pointer to
81
the added element. The caller must copy the element to
83
@return pointer to the element */
88
dyn_array_t* arr, /*!< in: dynamic array */
89
ulint size); /*!< in: size in bytes of the element */
90
/************************************************************//**
91
Returns pointer to an element in dyn array.
92
@return pointer to element */
95
dyn_array_get_element(
96
/*==================*/
97
dyn_array_t* arr, /*!< in: dyn array */
98
ulint pos); /*!< in: position of element as bytes
100
/************************************************************//**
101
Returns the size of stored data in a dyn array.
102
@return data size in bytes */
105
dyn_array_get_data_size(
106
/*====================*/
107
dyn_array_t* arr); /*!< in: dyn array */
108
/************************************************************//**
109
Gets the first block in a dyn array. */
112
dyn_array_get_first_block(
113
/*======================*/
114
dyn_array_t* arr); /*!< in: dyn array */
115
/************************************************************//**
116
Gets the last block in a dyn array. */
119
dyn_array_get_last_block(
120
/*=====================*/
121
dyn_array_t* arr); /*!< in: dyn array */
122
/********************************************************************//**
123
Gets the next block in a dyn array.
124
@return pointer to next, NULL if end of list */
127
dyn_array_get_next_block(
128
/*=====================*/
129
dyn_array_t* arr, /*!< in: dyn array */
130
dyn_block_t* block); /*!< in: dyn array block */
131
/********************************************************************//**
132
Gets the number of used bytes in a dyn array block.
133
@return number of bytes used */
138
dyn_block_t* block); /*!< in: dyn array block */
139
/********************************************************************//**
140
Gets pointer to the start of data in a dyn array block.
141
@return pointer to data */
146
dyn_block_t* block); /*!< in: dyn array block */
147
/********************************************************//**
148
Pushes n bytes to a dyn array. */
153
dyn_array_t* arr, /*!< in: dyn array */
154
const byte* str, /*!< in: string to write */
155
ulint len); /*!< in: string length */
157
/*#################################################################*/
159
/** @brief A block in a dynamically allocated array.
160
NOTE! Do not access the fields of the struct directly: the definition
161
appears here only for the compiler to know its size! */
162
struct dyn_block_struct{
163
mem_heap_t* heap; /*!< in the first block this is != NULL
164
if dynamic allocation has been needed */
165
ulint used; /*!< number of data bytes used in this block;
166
DYN_BLOCK_FULL_FLAG is set when the block
168
byte data[DYN_ARRAY_DATA_SIZE];
169
/*!< storage for array elements */
170
UT_LIST_BASE_NODE_T(dyn_block_t) base;
171
/*!< linear list of dyn blocks: this node is
172
used only in the first block */
173
UT_LIST_NODE_T(dyn_block_t) list;
174
/*!< linear list node: used in all blocks */
176
ulint buf_end;/*!< only in the debug version: if dyn
177
array is opened, this is the buffer
178
end offset, else this is 0 */
179
ulint magic_n;/*!< magic number (DYN_BLOCK_MAGIC_N) */
185
#include "dyn0dyn.ic"