~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/ut/ut0vec.c

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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 ut/ut0vec.c
21
 
A vector of pointers to data items
22
 
 
23
 
Created 4/6/2006 Osku Salerma
24
 
************************************************************************/
25
 
 
26
1
#include "ut0vec.h"
27
2
#ifdef UNIV_NONINL
28
3
#include "ut0vec.ic"
29
4
#endif
30
5
#include <string.h>
31
6
 
32
 
/****************************************************************//**
33
 
Create a new vector with the given initial size.
34
 
@return vector */
 
7
/********************************************************************
 
8
Create a new vector with the given initial size. */
35
9
UNIV_INTERN
36
10
ib_vector_t*
37
11
ib_vector_create(
38
12
/*=============*/
39
 
        mem_heap_t*     heap,   /*!< in: heap */
40
 
        ulint           size)   /*!< in: initial size */
 
13
                                /* out: vector */
 
14
        mem_heap_t*     heap,   /* in: heap */
 
15
        ulint           size)   /* in: initial size */
41
16
{
 
17
        ib_vector_t*    vec;
 
18
 
42
19
        ut_a(size > 0);
43
20
 
44
 
        ib_vector_t *vec = static_cast<ib_vector_t*>(mem_heap_alloc(heap, sizeof(*vec)));
 
21
        vec = mem_heap_alloc(heap, sizeof(*vec));
45
22
 
46
23
        vec->heap = heap;
47
 
        vec->data = static_cast<void **>(mem_heap_alloc(heap, sizeof(void*) * size));
 
24
        vec->data = mem_heap_alloc(heap, sizeof(void*) * size);
48
25
        vec->used = 0;
49
26
        vec->total = size;
50
27
 
51
28
        return(vec);
52
29
}
53
30
 
54
 
/****************************************************************//**
 
31
/********************************************************************
55
32
Push a new element to the vector, increasing its size if necessary. */
56
33
UNIV_INTERN
57
34
void
58
35
ib_vector_push(
59
36
/*===========*/
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 */
62
39
{
63
40
        if (vec->used >= vec->total) {
64
41
                void**  new_data;
65
42
                ulint   new_total = vec->total * 2;
66
43
 
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);
70
47
 
71
 
                vec->data = static_cast<void **>(new_data);
 
48
                vec->data = new_data;
72
49
                vec->total = new_total;
73
50
        }
74
51