~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/dyn0dyn.h

  • Committer: Monty Taylor
  • Date: 2009-03-20 06:30:59 UTC
  • mfrom: (942.1.17 plugin-registration)
  • mto: This revision was merged to the branch mainline in revision 958.
  • Revision ID: mordred@inaugust.com-20090320063059-lr9hqvw15stxxgn3
Merged plugin registration branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
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
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/**************************************************//**
20
 
@file include/dyn0dyn.h
 
19
/******************************************************
21
20
The dynamically allocated array
22
21
 
23
22
Created 2/5/1996 Heikki Tuuri
30
29
#include "ut0lst.h"
31
30
#include "mem0mem.h"
32
31
 
33
 
/** A block in a dynamically allocated array */
34
32
typedef struct dyn_block_struct         dyn_block_t;
35
 
/** Dynamically allocated array */
36
33
typedef dyn_block_t                     dyn_array_t;
37
34
 
38
35
 
39
 
/** This is the initial 'payload' size of a dynamic array;
 
36
/* This is the initial 'payload' size of a dynamic array;
40
37
this must be > MLOG_BUF_MARGIN + 30! */
41
38
#define DYN_ARRAY_DATA_SIZE     512
42
39
 
43
 
/*********************************************************************//**
44
 
Initializes a dynamic array.
45
 
@return initialized dyn array */
 
40
/*************************************************************************
 
41
Initializes a dynamic array. */
46
42
UNIV_INLINE
47
43
dyn_array_t*
48
44
dyn_array_create(
49
45
/*=============*/
50
 
        dyn_array_t*    arr);   /*!< in: pointer to a memory buffer of
 
46
                                /* out: initialized dyn array */
 
47
        dyn_array_t*    arr);   /* in: pointer to a memory buffer of
51
48
                                size sizeof(dyn_array_t) */
52
 
/************************************************************//**
 
49
/****************************************************************
53
50
Frees a dynamic array. */
54
51
UNIV_INLINE
55
52
void
56
53
dyn_array_free(
57
54
/*===========*/
58
 
        dyn_array_t*    arr);   /*!< in: dyn array */
59
 
/*********************************************************************//**
 
55
        dyn_array_t*    arr);   /* in: dyn array */
 
56
/*************************************************************************
60
57
Makes room on top of a dyn array and returns a pointer to a buffer in it.
61
58
After copying the elements, the caller must close the buffer using
62
 
dyn_array_close.
63
 
@return pointer to the buffer */
 
59
dyn_array_close. */
64
60
UNIV_INLINE
65
61
byte*
66
62
dyn_array_open(
67
63
/*===========*/
68
 
        dyn_array_t*    arr,    /*!< in: dynamic array */
69
 
        ulint           size);  /*!< in: size in bytes of the buffer; MUST be
 
64
                                /* out: pointer to the buffer */
 
65
        dyn_array_t*    arr,    /* in: dynamic array */
 
66
        ulint           size);  /* in: size in bytes of the buffer; MUST be
70
67
                                smaller than DYN_ARRAY_DATA_SIZE! */
71
 
/*********************************************************************//**
 
68
/*************************************************************************
72
69
Closes the buffer returned by dyn_array_open. */
73
70
UNIV_INLINE
74
71
void
75
72
dyn_array_close(
76
73
/*============*/
77
 
        dyn_array_t*    arr,    /*!< in: dynamic array */
78
 
        byte*           ptr);   /*!< in: buffer space from ptr up was not used */
79
 
/*********************************************************************//**
 
74
        dyn_array_t*    arr,    /* in: dynamic array */
 
75
        byte*           ptr);   /* in: buffer space from ptr up was not used */
 
76
/*************************************************************************
80
77
Makes room on top of a dyn array and returns a pointer to
81
78
the added element. The caller must copy the element to
82
 
the pointer returned.
83
 
@return pointer to the element */
 
79
the pointer returned. */
84
80
UNIV_INLINE
85
81
void*
86
82
dyn_array_push(
87
83
/*===========*/
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 */
 
84
                                /* out: pointer to the element */
 
85
        dyn_array_t*    arr,    /* in: dynamic array */
 
86
        ulint           size);  /* in: size in bytes of the element */
 
87
/****************************************************************
 
88
Returns pointer to an element in dyn array. */
93
89
UNIV_INLINE
94
90
void*
95
91
dyn_array_get_element(
96
92
/*==================*/
97
 
        dyn_array_t*    arr,    /*!< in: dyn array */
98
 
        ulint           pos);   /*!< in: position of element as bytes
 
93
                                /* out: pointer to element */
 
94
        dyn_array_t*    arr,    /* in: dyn array */
 
95
        ulint           pos);   /* in: position of element as bytes
99
96
                                from array start */
100
 
/************************************************************//**
101
 
Returns the size of stored data in a dyn array.
102
 
@return data size in bytes */
 
97
/****************************************************************
 
98
Returns the size of stored data in a dyn array. */
103
99
UNIV_INLINE
104
100
ulint
105
101
dyn_array_get_data_size(
106
102
/*====================*/
107
 
        dyn_array_t*    arr);   /*!< in: dyn array */
108
 
/************************************************************//**
 
103
                                /* out: data size in bytes */
 
104
        dyn_array_t*    arr);   /* in: dyn array */
 
105
/****************************************************************
109
106
Gets the first block in a dyn array. */
110
107
UNIV_INLINE
111
108
dyn_block_t*
112
109
dyn_array_get_first_block(
113
110
/*======================*/
114
 
        dyn_array_t*    arr);   /*!< in: dyn array */
115
 
/************************************************************//**
 
111
        dyn_array_t*    arr);   /* in: dyn array */
 
112
/****************************************************************
116
113
Gets the last block in a dyn array. */
117
114
UNIV_INLINE
118
115
dyn_block_t*
119
116
dyn_array_get_last_block(
120
117
/*=====================*/
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 */
 
118
        dyn_array_t*    arr);   /* in: dyn array */
 
119
/************************************************************************
 
120
Gets the next block in a dyn array. */
125
121
UNIV_INLINE
126
122
dyn_block_t*
127
123
dyn_array_get_next_block(
128
124
/*=====================*/
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 */
 
125
                                /* out: pointer to next, NULL if end of list */
 
126
        dyn_array_t*    arr,    /* in: dyn array */
 
127
        dyn_block_t*    block); /* in: dyn array block */
 
128
/************************************************************************
 
129
Gets the number of used bytes in a dyn array block. */
134
130
UNIV_INLINE
135
131
ulint
136
132
dyn_block_get_used(
137
133
/*===============*/
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 */
 
134
                                /* out: number of bytes used */
 
135
        dyn_block_t*    block); /* in: dyn array block */
 
136
/************************************************************************
 
137
Gets pointer to the start of data in a dyn array block. */
142
138
UNIV_INLINE
143
139
byte*
144
140
dyn_block_get_data(
145
141
/*===============*/
146
 
        dyn_block_t*    block); /*!< in: dyn array block */
147
 
/********************************************************//**
 
142
                                /* out: pointer to data */
 
143
        dyn_block_t*    block); /* in: dyn array block */
 
144
/************************************************************
148
145
Pushes n bytes to a dyn array. */
149
146
UNIV_INLINE
150
147
void
151
148
dyn_push_string(
152
149
/*============*/
153
 
        dyn_array_t*    arr,    /*!< in: dyn array */
154
 
        const byte*     str,    /*!< in: string to write */
155
 
        ulint           len);   /*!< in: string length */
 
150
        dyn_array_t*    arr,    /* in: dyn array */
 
151
        const byte*     str,    /* in: string to write */
 
152
        ulint           len);   /* in: string length */
156
153
 
157
154
/*#################################################################*/
158
155
 
159
 
/** @brief A block in a dynamically allocated array.
160
 
NOTE! Do not access the fields of the struct directly: the definition
 
156
/* NOTE! Do not use the fields of the struct directly: the definition
161
157
appears here only for the compiler to know its size! */
162
158
struct dyn_block_struct{
163
 
        mem_heap_t*     heap;   /*!< in the first block this is != NULL
 
159
        mem_heap_t*     heap;   /* in the first block this is != NULL
164
160
                                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
167
 
                                becomes full */
 
161
        ulint           used;   /* number of data bytes used in this block */
168
162
        byte            data[DYN_ARRAY_DATA_SIZE];
169
 
                                /*!< storage for array elements */
 
163
                                /* storage for array elements */
170
164
        UT_LIST_BASE_NODE_T(dyn_block_t) base;
171
 
                                /*!< linear list of dyn blocks: this node is
 
165
                                /* linear list of dyn blocks: this node is
172
166
                                used only in the first block */
173
167
        UT_LIST_NODE_T(dyn_block_t) list;
174
 
                                /*!< linear list node: used in all blocks */
 
168
                                /* linear list node: used in all blocks */
175
169
#ifdef UNIV_DEBUG
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) */
 
170
        ulint           buf_end;/* only in the debug version: if dyn array is
 
171
                                opened, this is the buffer end offset, else
 
172
                                this is 0 */
 
173
        ulint           magic_n;
180
174
#endif
181
175
};
182
176