~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
3
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
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 as published by the Free Software
7
Foundation; version 2 of the License.
8
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.
12
13
You should have received a copy of the GNU General Public License along with
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file include/dyn0dyn.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
The dynamically allocated array
22
23
Created 2/5/1996 Heikki Tuuri
24
*******************************************************/
25
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
26
#pragma once
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
27
#ifndef dyn0dyn_h
28
#define dyn0dyn_h
29
30
#include "univ.i"
31
#include "ut0lst.h"
32
#include "mem0mem.h"
33
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
34
/** A block in a dynamically allocated array */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
35
typedef struct dyn_block_struct		dyn_block_t;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
36
/** Dynamically allocated array */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
37
typedef dyn_block_t			dyn_array_t;
38
39
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
40
/** This is the initial 'payload' size of a dynamic array;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
41
this must be > MLOG_BUF_MARGIN + 30! */
42
#define	DYN_ARRAY_DATA_SIZE	512
43
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
44
/*********************************************************************//**
45
Initializes a dynamic array.
46
@return	initialized dyn array */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
47
UNIV_INLINE
48
dyn_array_t*
49
dyn_array_create(
50
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
51
	dyn_array_t*	arr);	/*!< in: pointer to a memory buffer of
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
52
				size sizeof(dyn_array_t) */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
53
/************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
54
Frees a dynamic array. */
55
UNIV_INLINE
56
void
57
dyn_array_free(
58
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
59
	dyn_array_t*	arr);	/*!< in: dyn array */
60
/*********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
61
Makes room on top of a dyn array and returns a pointer to a buffer in it.
62
After copying the elements, the caller must close the buffer using
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
63
dyn_array_close.
64
@return	pointer to the buffer */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
65
UNIV_INLINE
66
byte*
67
dyn_array_open(
68
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
69
	dyn_array_t*	arr,	/*!< in: dynamic array */
70
	ulint		size);	/*!< in: size in bytes of the buffer; MUST be
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
71
				smaller than DYN_ARRAY_DATA_SIZE! */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
72
/*********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
73
Closes the buffer returned by dyn_array_open. */
74
UNIV_INLINE
75
void
76
dyn_array_close(
77
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
78
	dyn_array_t*	arr,	/*!< in: dynamic array */
79
	byte*		ptr);	/*!< in: buffer space from ptr up was not used */
80
/*********************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
81
Makes room on top of a dyn array and returns a pointer to
82
the added element. The caller must copy the element to
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
83
the pointer returned.
84
@return	pointer to the element */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
85
UNIV_INLINE
86
void*
87
dyn_array_push(
88
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
89
	dyn_array_t*	arr,	/*!< in: dynamic array */
90
	ulint		size);	/*!< in: size in bytes of the element */
91
/************************************************************//**
92
Returns pointer to an element in dyn array.
93
@return	pointer to element */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
94
UNIV_INLINE
95
void*
96
dyn_array_get_element(
97
/*==================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
98
	dyn_array_t*	arr,	/*!< in: dyn array */
99
	ulint		pos);	/*!< in: position of element as bytes
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
100
				from array start */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
101
/************************************************************//**
102
Returns the size of stored data in a dyn array.
103
@return	data size in bytes */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
104
UNIV_INLINE
105
ulint
106
dyn_array_get_data_size(
107
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
108
	dyn_array_t*	arr);	/*!< in: dyn array */
109
/************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
110
Gets the first block in a dyn array. */
111
UNIV_INLINE
112
dyn_block_t*
113
dyn_array_get_first_block(
114
/*======================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
115
	dyn_array_t*	arr);	/*!< in: dyn array */
116
/************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
117
Gets the last block in a dyn array. */
118
UNIV_INLINE
119
dyn_block_t*
120
dyn_array_get_last_block(
121
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
122
	dyn_array_t*	arr);	/*!< in: dyn array */
123
/********************************************************************//**
124
Gets the next block in a dyn array.
125
@return	pointer to next, NULL if end of list */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
126
UNIV_INLINE
127
dyn_block_t*
128
dyn_array_get_next_block(
129
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
130
	dyn_array_t*	arr,	/*!< in: dyn array */
131
	dyn_block_t*	block);	/*!< in: dyn array block */
132
/********************************************************************//**
133
Gets the number of used bytes in a dyn array block.
134
@return	number of bytes used */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
135
UNIV_INLINE
136
ulint
137
dyn_block_get_used(
138
/*===============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
139
	dyn_block_t*	block);	/*!< in: dyn array block */
140
/********************************************************************//**
141
Gets pointer to the start of data in a dyn array block.
142
@return	pointer to data */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
143
UNIV_INLINE
144
byte*
145
dyn_block_get_data(
146
/*===============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
147
	dyn_block_t*	block);	/*!< in: dyn array block */
148
/********************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
149
Pushes n bytes to a dyn array. */
150
UNIV_INLINE
151
void
152
dyn_push_string(
153
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
154
	dyn_array_t*	arr,	/*!< in: dyn array */
155
	const byte*	str,	/*!< in: string to write */
156
	ulint		len);	/*!< in: string length */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
157
158
/*#################################################################*/
159
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
160
/** @brief A block in a dynamically allocated array.
161
NOTE! Do not access the fields of the struct directly: the definition
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
162
appears here only for the compiler to know its size! */
163
struct dyn_block_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
164
	mem_heap_t*	heap;	/*!< in the first block this is != NULL
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
165
				if dynamic allocation has been needed */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
166
	ulint		used;	/*!< number of data bytes used in this block;
167
				DYN_BLOCK_FULL_FLAG is set when the block
168
				becomes full */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
169
	byte		data[DYN_ARRAY_DATA_SIZE];
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
170
				/*!< storage for array elements */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
171
	UT_LIST_BASE_NODE_T(dyn_block_t) base;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
172
				/*!< linear list of dyn blocks: this node is
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
173
				used only in the first block */
174
	UT_LIST_NODE_T(dyn_block_t) list;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
175
				/*!< linear list node: used in all blocks */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
176
#ifdef UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
177
	ulint		buf_end;/*!< only in the debug version: if dyn
178
				array is opened, this is the buffer
179
				end offset, else this is 0 */
180
	ulint		magic_n;/*!< magic number (DYN_BLOCK_MAGIC_N) */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
181
#endif
182
};
183
184
185
#ifndef UNIV_NONINL
186
#include "dyn0dyn.ic"
187
#endif
188
189
#endif