~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "ut0vec.h"
 
2
#ifdef UNIV_NONINL
 
3
#include "ut0vec.ic"
 
4
#endif
 
5
#include <string.h>
 
6
 
 
7
/********************************************************************
 
8
Create a new vector with the given initial size. */
 
9
 
 
10
ib_vector_t*
 
11
ib_vector_create(
 
12
/*=============*/
 
13
                                /* out: vector */
 
14
        mem_heap_t*     heap,   /* in: heap */
 
15
        ulint           size)   /* in: initial size */
 
16
{
 
17
        ib_vector_t*    vec;
 
18
 
 
19
        ut_a(size > 0);
 
20
 
 
21
        vec = mem_heap_alloc(heap, sizeof(*vec));
 
22
 
 
23
        vec->heap = heap;
 
24
        vec->data = mem_heap_alloc(heap, sizeof(void*) * size);
 
25
        vec->used = 0;
 
26
        vec->total = size;
 
27
 
 
28
        return(vec);
 
29
}
 
30
 
 
31
/********************************************************************
 
32
Push a new element to the vector, increasing its size if necessary. */
 
33
 
 
34
void
 
35
ib_vector_push(
 
36
/*===========*/
 
37
        ib_vector_t*    vec,    /* in: vector */
 
38
        void*           elem)   /* in: data element */
 
39
{
 
40
        if (vec->used >= vec->total) {
 
41
                void**  new_data;
 
42
                ulint   new_total = vec->total * 2;
 
43
 
 
44
                new_data = mem_heap_alloc(vec->heap,
 
45
                                          sizeof(void*) * new_total);
 
46
                memcpy(new_data, vec->data, sizeof(void*) * vec->total);
 
47
 
 
48
                vec->data = new_data;
 
49
                vec->total = new_total;
 
50
        }
 
51
 
 
52
        vec->data[vec->used] = elem;
 
53
        vec->used++;
 
54
}