~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/ut0vec.h

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
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
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/*******************************************************************//**
20
 
@file include/ut0vec.h
21
 
A vector of pointers to data items
22
 
 
23
 
Created 4/6/2006 Osku Salerma
24
 
************************************************************************/
25
 
 
26
 
#ifndef IB_VECTOR_H
27
 
#define IB_VECTOR_H
28
 
 
29
 
#include "univ.i"
30
 
#include "mem0mem.h"
31
 
 
32
 
/** An automatically resizing vector data type. */
33
 
typedef struct ib_vector_struct ib_vector_t;
34
 
 
35
 
/* An automatically resizing vector datatype with the following properties:
36
 
 
37
 
 -Contains void* items.
38
 
 
39
 
 -The items are owned by the caller.
40
 
 
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.
43
 
 
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.
47
 
*/
48
 
 
49
 
/****************************************************************//**
50
 
Create a new vector with the given initial size.
51
 
@return vector */
52
 
UNIV_INTERN
53
 
ib_vector_t*
54
 
ib_vector_create(
55
 
/*=============*/
56
 
        mem_heap_t*     heap,   /*!< in: heap */
57
 
        ulint           size);  /*!< in: initial size */
58
 
 
59
 
/****************************************************************//**
60
 
Push a new element to the vector, increasing its size if necessary. */
61
 
UNIV_INTERN
62
 
void
63
 
ib_vector_push(
64
 
/*===========*/
65
 
        ib_vector_t*    vec,    /*!< in: vector */
66
 
        void*           elem);  /*!< in: data element */
67
 
 
68
 
/****************************************************************//**
69
 
Get the number of elements in the vector.
70
 
@return number of elements in vector */
71
 
UNIV_INLINE
72
 
ulint
73
 
ib_vector_size(
74
 
/*===========*/
75
 
        const ib_vector_t*      vec);   /*!< in: vector */
76
 
 
77
 
/****************************************************************//**
78
 
Test whether a vector is empty or not.
79
 
@return TRUE if empty */
80
 
UNIV_INLINE
81
 
ibool
82
 
ib_vector_is_empty(
83
 
/*===============*/
84
 
        const ib_vector_t*      vec);   /*!< in: vector */
85
 
 
86
 
/****************************************************************//**
87
 
Get the n'th element.
88
 
@return n'th element */
89
 
UNIV_INLINE
90
 
void*
91
 
ib_vector_get(
92
 
/*==========*/
93
 
        ib_vector_t*    vec,    /*!< in: vector */
94
 
        ulint           n);     /*!< in: element index to get */
95
 
 
96
 
/****************************************************************//**
97
 
Remove the last element from the vector. */
98
 
UNIV_INLINE
99
 
void*
100
 
ib_vector_pop(
101
 
/*==========*/
102
 
        ib_vector_t*    vec);   /*!< in: vector */
103
 
 
104
 
/****************************************************************//**
105
 
Free the underlying heap of the vector. Note that vec is invalid
106
 
after this call. */
107
 
UNIV_INLINE
108
 
void
109
 
ib_vector_free(
110
 
/*===========*/
111
 
        ib_vector_t*    vec);   /*!< in,own: vector */
112
 
 
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 */
119
 
};
120
 
 
121
 
#ifndef UNIV_NONINL
122
 
#include "ut0vec.ic"
123
 
#endif
124
 
 
125
 
#endif