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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/*******************************************************************//**
20
@file include/ut0vec.h
21
A vector of pointers to data items
23
Created 4/6/2006 Osku Salerma
24
************************************************************************/
30
5
#include "mem0mem.h"
32
/** An automatically resizing vector data type. */
33
7
typedef struct ib_vector_struct ib_vector_t;
35
9
/* An automatically resizing vector datatype with the following properties:
46
20
relatively small or short-lived uses.
49
/****************************************************************//**
50
Create a new vector with the given initial size.
23
/********************************************************************
24
Create a new vector with the given initial size. */
56
mem_heap_t* heap, /*!< in: heap */
57
ulint size); /*!< in: initial size */
30
mem_heap_t* heap, /* in: heap */
31
ulint size); /* in: initial size */
59
/****************************************************************//**
33
/********************************************************************
60
34
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 */
39
ib_vector_t* vec, /* in: vector */
40
void* elem); /* in: data element */
68
/****************************************************************//**
69
Get the number of elements in the vector.
70
@return number of elements in vector */
42
/********************************************************************
43
Get the number of elements in the vector. */
75
const ib_vector_t* vec); /*!< in: vector */
48
/* out: number of elements in vector */
49
const ib_vector_t* vec); /* in: vector */
77
/****************************************************************//**
78
Test whether a vector is empty or not.
79
@return TRUE if empty */
51
/********************************************************************
52
Test whether a vector is empty or not. */
82
55
ib_vector_is_empty(
83
56
/*===============*/
84
const ib_vector_t* vec); /*!< in: vector */
57
/* out: TRUE if empty */
58
const ib_vector_t* vec); /* in: vector */
86
/****************************************************************//**
88
@return n'th element */
60
/********************************************************************
61
Get the n'th element. */
93
ib_vector_t* vec, /*!< in: vector */
94
ulint n); /*!< in: element index to get */
66
/* out: n'th element */
67
ib_vector_t* vec, /* in: vector */
68
ulint n); /* in: element index to get */
96
/****************************************************************//**
70
/********************************************************************
97
71
Remove the last element from the vector. */
102
ib_vector_t* vec); /*!< in: vector */
76
ib_vector_t* vec); /* in: vector */
104
/****************************************************************//**
78
/********************************************************************
105
79
Free the underlying heap of the vector. Note that vec is invalid
106
80
after this call. */
111
ib_vector_t* vec); /*!< in,own: vector */
85
ib_vector_t* vec); /* in,own: vector */
113
/** An automatically resizing vector data type. */
87
/* See comment at beginning of file. */
114
88
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 */
89
mem_heap_t* heap; /* heap */
90
void** data; /* data elements */
91
ulint used; /* number of elements currently used */
92
ulint total; /* number of elements allocated */
121
95
#ifndef UNIV_NONINL