~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

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.ic
21
 
A vector of pointers to data items
22
 
 
23
 
Created 4/6/2006 Osku Salerma
24
 
************************************************************************/
25
 
 
26
 
/****************************************************************//**
27
 
Get number of elements in vector.
28
 
@return number of elements in vector */
29
 
UNIV_INLINE
30
 
ulint
31
 
ib_vector_size(
32
 
/*===========*/
33
 
        const ib_vector_t*      vec)    /*!< in: vector */
34
 
{
35
 
        return(vec->used);
36
 
}
37
 
 
38
 
/****************************************************************//**
39
 
Get n'th element.
40
 
@return n'th element */
41
 
UNIV_INLINE
42
 
void*
43
 
ib_vector_get(
44
 
/*==========*/
45
 
        ib_vector_t*    vec,    /*!< in: vector */
46
 
        ulint           n)      /*!< in: element index to get */
47
 
{
48
 
        ut_a(n < vec->used);
49
 
 
50
 
        return(vec->data[n]);
51
 
}
52
 
 
53
 
/****************************************************************//**
54
 
Remove the last element from the vector.
55
 
@return last vector element */
56
 
UNIV_INLINE
57
 
void*
58
 
ib_vector_pop(
59
 
/*==========*/
60
 
        ib_vector_t*    vec)    /*!< in/out: vector */
61
 
{
62
 
        void*           elem;
63
 
 
64
 
        ut_a(vec->used > 0);
65
 
        --vec->used;
66
 
        elem = vec->data[vec->used];
67
 
 
68
 
        ut_d(vec->data[vec->used] = NULL);
69
 
        UNIV_MEM_INVALID(&vec->data[vec->used], sizeof(*vec->data));
70
 
 
71
 
        return(elem);
72
 
}
73
 
 
74
 
/****************************************************************//**
75
 
Free the underlying heap of the vector. Note that vec is invalid
76
 
after this call. */
77
 
UNIV_INLINE
78
 
void
79
 
ib_vector_free(
80
 
/*===========*/
81
 
        ib_vector_t*    vec)    /*!< in, own: vector */
82
 
{
83
 
        mem_heap_free(vec->heap);
84
 
}
85
 
 
86
 
/****************************************************************//**
87
 
Test whether a vector is empty or not.
88
 
@return TRUE if empty */
89
 
UNIV_INLINE
90
 
ibool
91
 
ib_vector_is_empty(
92
 
/*===============*/
93
 
        const ib_vector_t*      vec)    /*!< in: vector */
94
 
{
95
 
        return(ib_vector_size(vec) == 0);
96
 
}