~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/*******************************************************************//**
20
@file ut/ut0vec.c
21
A vector of pointers to data items
22
23
Created 4/6/2006 Osku Salerma
24
************************************************************************/
25
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
26
#include "ut0vec.h"
27
#ifdef UNIV_NONINL
28
#include "ut0vec.ic"
29
#endif
30
#include <string.h>
31
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
32
/****************************************************************//**
33
Create a new vector with the given initial size.
34
@return	vector */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
35
UNIV_INTERN
36
ib_vector_t*
37
ib_vector_create(
38
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
39
	mem_heap_t*	heap,	/*!< in: heap */
40
	ulint		size)	/*!< in: initial size */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
41
{
42
	ib_vector_t*	vec;
43
44
	ut_a(size > 0);
45
46
	vec = mem_heap_alloc(heap, sizeof(*vec));
47
48
	vec->heap = heap;
49
	vec->data = mem_heap_alloc(heap, sizeof(void*) * size);
50
	vec->used = 0;
51
	vec->total = size;
52
53
	return(vec);
54
}
55
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
56
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
57
Push a new element to the vector, increasing its size if necessary. */
58
UNIV_INTERN
59
void
60
ib_vector_push(
61
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
62
	ib_vector_t*	vec,	/*!< in: vector */
63
	void*		elem)	/*!< in: data element */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
64
{
65
	if (vec->used >= vec->total) {
66
		void**	new_data;
67
		ulint	new_total = vec->total * 2;
68
69
		new_data = mem_heap_alloc(vec->heap,
70
					  sizeof(void*) * new_total);
71
		memcpy(new_data, vec->data, sizeof(void*) * vec->total);
72
73
		vec->data = new_data;
74
		vec->total = new_total;
75
	}
76
77
	vec->data[vec->used] = elem;
78
	vec->used++;
79
}