1
/*****************************************************************************
3
Copyright (C) 2006, 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/ut0vec.h
21
A vector of pointers to data items
23
Created 4/6/2006 Osku Salerma
24
************************************************************************/
32
/** An automatically resizing vector data type. */
33
typedef struct ib_vector_struct ib_vector_t;
35
/* An automatically resizing vector datatype with the following properties:
37
-Contains void* items.
39
-The items are owned by the caller.
41
-All memory allocation is done through a heap owned by the caller, who is
42
responsible for freeing it when done with the vector.
44
-When the vector is resized, the old memory area is left allocated since it
45
uses the same heap as the new memory area, so this is best used for
46
relatively small or short-lived uses.
49
/****************************************************************//**
50
Create a new vector with the given initial size.
56
mem_heap_t* heap, /*!< in: heap */
57
ulint size); /*!< in: initial size */
59
/****************************************************************//**
60
Push a new element to the vector, increasing its size if necessary. */
65
ib_vector_t* vec, /*!< in: vector */
66
void* elem); /*!< in: data element */
68
/****************************************************************//**
69
Get the number of elements in the vector.
70
@return number of elements in vector */
75
const ib_vector_t* vec); /*!< in: vector */
77
/****************************************************************//**
78
Test whether a vector is empty or not.
79
@return TRUE if empty */
84
const ib_vector_t* vec); /*!< in: vector */
86
/****************************************************************//**
88
@return n'th element */
93
ib_vector_t* vec, /*!< in: vector */
94
ulint n); /*!< in: element index to get */
96
/****************************************************************//**
97
Remove the last element from the vector. */
102
ib_vector_t* vec); /*!< in: vector */
104
/****************************************************************//**
105
Free the underlying heap of the vector. Note that vec is invalid
111
ib_vector_t* vec); /*!< in,own: vector */
113
/** An automatically resizing vector data type. */
114
struct ib_vector_struct {
115
mem_heap_t* heap; /*!< heap */
116
void** data; /*!< data elements */
117
ulint used; /*!< number of elements currently used */
118
ulint total; /*!< number of elements allocated */