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
/*******************************************************************//**
21
A vector of pointers to data items
23
Created 4/6/2006 Osku Salerma
24
************************************************************************/
28
3
#include "ut0vec.ic"
32
/****************************************************************//**
33
Create a new vector with the given initial size.
7
/********************************************************************
8
Create a new vector with the given initial size. */
39
mem_heap_t* heap, /*!< in: heap */
40
ulint size) /*!< in: initial size */
14
mem_heap_t* heap, /* in: heap */
15
ulint size) /* in: initial size */
44
ib_vector_t *vec = static_cast<ib_vector_t*>(mem_heap_alloc(heap, sizeof(*vec)));
21
vec = mem_heap_alloc(heap, sizeof(*vec));
47
vec->data = static_cast<void **>(mem_heap_alloc(heap, sizeof(void*) * size));
24
vec->data = mem_heap_alloc(heap, sizeof(void*) * size);
54
/****************************************************************//**
31
/********************************************************************
55
32
Push a new element to the vector, increasing its size if necessary. */
60
ib_vector_t* vec, /*!< in: vector */
61
void* elem) /*!< in: data element */
37
ib_vector_t* vec, /* in: vector */
38
void* elem) /* in: data element */
63
40
if (vec->used >= vec->total) {
65
42
ulint new_total = vec->total * 2;
67
new_data = static_cast<void **>(mem_heap_alloc(vec->heap,
68
sizeof(void*) * new_total));
44
new_data = mem_heap_alloc(vec->heap,
45
sizeof(void*) * new_total);
69
46
memcpy(new_data, vec->data, sizeof(void*) * vec->total);
71
vec->data = static_cast<void **>(new_data);
72
49
vec->total = new_total;